I have a script which gets FieldInfo from constructor arguments and store it within an Action class. I am trying to create instances of my own event class in inspector via reflection.
using UnityEngine;
using System.Collections;
using System.Reflection;
using System.Collections.Generic;
[CustomEditor(typeof(EventScript))]
public class EventScript : MonoBehaviour {
public class Action
{
float time;
List<FieldInfo> fieldInfos;
List<object> fieldValues;
public Action(float time, FieldInfo[] fieldInfos, string eventName)
{
this.time = time;
this.fieldInfos = fieldInfos;
this.fieldValues = new List<object>();
}
}
public List<Action> actions;
void CreateEvent()
{
// Call constructor of Event via reflection
}
}
Then I try to get access to this List actions from Editor script and call a constructor with entered values;
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
public class EventEditor : Editor {
private List<EventScript.Action> actions;
private EventScript currentEventScript;
void OnEnable()
{
...
}
void OnInspectorGUI()
{
// Fields for creating an instance of Event
currentEventScript.CreateEvent(object[] arguments);
}
}
How to get access to List “events” and current instance of EventScript from editor script? Or maybe there is a completely different approach?
I tried few different ways, but each time I’ve ended up with NullReferenceException.
The whole thing looks like these madskills below: different EventScripts contain different Actions and call constructors in different time.