Support for Interfaces

Vote for new features, or make your own requests here.
Post Reply

Support for Interfaces

Yes, I would like this feature.
4
100%
No, I would not like this feature.
0
No votes
 
Total votes: 4

User avatar
Joel
Moodkie Staff
Posts: 3678
Joined: Wed Nov 07, 2012 10:32 pm

Support for Interfaces

Post by Joel »

Status

Requested

Complexity

5/10

Description

Ability to store interfaces rather than concrete classes.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started

MilkyBrain
Posts: 1
Joined: Sat May 30, 2020 11:28 am

Re: Support for Interfaces

Post by MilkyBrain »

It would be great!!!!

User avatar
TauCetiLabs
Posts: 3
Joined: Mon Dec 28, 2020 2:31 pm
Contact:

Re: Support for Interfaces

Post by TauCetiLabs »

I have figured out a work around using references and handling the data in a custom way. One caveat is the component must already exists in the reference manager upon loading:


Both the "m_PickupLocation" and "m_DropoffLocation" refer to a private interface, namely 'ISubstanceAccessible'.

Code: Select all

namespace ES3Types
{
	[UnityEngine.Scripting.Preserve]
	[ES3PropertiesAttribute("m_CurrentState", "m_PickupLocation", "m_DropoffLocation", "m_TransferVolume", "enabled", "name")]
	public class ES3UserType_SubstanceHandler : ES3ComponentType
	{
		public static ES3Type Instance = null;

		public ES3UserType_SubstanceHandler() : base(typeof(SubstanceHandler)){ Instance = this; priority = 1;}


		protected override void WriteComponent(object obj, ES3Writer writer)
		{
			var instance = (SubstanceHandler)obj;
			
			writer.WritePrivateField("m_CurrentState", instance);
			writer.WriteProperty<long>("m_PickupLocation", ES3Internal.ES3ReferenceMgrBase.Current.Get((UnityEngine.Object)instance.PickupLocation));
			writer.WriteProperty<long>("m_DropoffLocation", ES3Internal.ES3ReferenceMgrBase.Current.Get((UnityEngine.Object)instance.DropoffLocation));
			writer.WritePrivateField("m_TransferVolume", instance);
			writer.WriteProperty("enabled", instance.enabled, ES3Type_bool.Instance);
		}

		protected override void ReadComponent<T>(ES3Reader reader, object obj)
		{
			var instance = (SubstanceHandler)obj;
			foreach(string propertyName in reader.Properties)
			{
				switch(propertyName)
				{
					
					case "m_CurrentState":
						reader.SetPrivateField("m_CurrentState", reader.Read<SubstanceHandler.State>(), instance);
						break;
					case "m_PickupLocation":
						reader.SetPrivateField("m_PickupLocation", ES3Internal.ES3ReferenceMgrBase.Current.Get(reader.Read<long>()), instance);
						break;
					case "m_DropoffLocation":
						reader.SetPrivateField("m_DropoffLocation", ES3Internal.ES3ReferenceMgrBase.Current.Get(reader.Read<long>()), instance);
						break;
					case "m_TransferVolume":
						reader.SetPrivateField("m_TransferVolume", reader.Read<System.Single>(), instance);
						break;
					case "enabled":
						instance.enabled = reader.Read<System.Boolean>(ES3Type_bool.Instance);
						break;
					default:
						reader.Skip();
						break;
				}
			}
		}
	}


	public class ES3UserType_SubstanceHandlerArray : ES3ArrayType
	{
		public static ES3Type Instance;

		public ES3UserType_SubstanceHandlerArray() : base(typeof(SubstanceHandler[]), ES3UserType_SubstanceHandler.Instance)
		{
			Instance = this;
		}
	}
}

Post Reply