- Home /
How to access one class instance in editor script?
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.
Answer by Wiking_Division · Jun 13, 2014 at 07:14 PM
Solved!
Add [ExecuteInEditMode] to EventScript
and EventScript the_script = (EventScript)target; in EditorScript!
Wiking_Division, are you still there?
Could you please explain what is "this_script" in your solution and where that command placed in EditorScript exactly? Thank you
Your answer
Follow this Question
Related Questions
Custom Editor Script resets values on Play 1 Answer
How To Force an Inspector to Repaint 3 Answers
TexturePropertySingleLine in Editor class 0 Answers
Editor Script, Index Out of Range Exception after Play 1 Answer
Gizmos.DrawLine is dissapearing after returning to editor after Playing the scene 0 Answers