Hello,
I’ve built a custom editor script but I can’t save the data upon play. Also note that I do not need to have the data visible in the Inspector, just that it needs to be there upon playing.
[System.Serializable]
class InterfaceTest: MonoBehaviour {
[SerializeField]
public IMyInterface[] interfaceArray = new IMyInterface[0];
void Start(){
Debug.log( interfaceArray.Length ); //produces a 0, which is bad
}
}
using System.LINQ;
using UnityEditor;
[CustomEditor(typeof(InterfaceTest))]
class InterfaceTestEditor: Editor {
public override void OnInspectorGUI (){
serializedObject.Update();
InterfaceTest myTarget = target as InterfaceTest;
myTarget.interfaceArray = myTarget.gameObject.GetInterfaces<IMyInterface>().Cast<IMyInterface>().ToArray(); //my ext method stuff + LINQ
Debug.log( myTarget.interfaceArray.Length ); //produces a 1, which is good
serializedObject.ApplyModifiedProperties();
}
}
I need to always be able to refresh the InterfaceArray in case I add or remove scripts that implement . In OnInspectorGUI, I receive a value showing that it finds a script and should work…but upon playing the game I don’t have that value stored in myTarget/base script which I need it to have. Any help on this would be greatly appreciated, thank you!