Ok, so.. I've been playing around with custom inspectors all day now. I can build an inspector, get & set variables in it, create dynamically sized option sets and so forth, and all is well. What I can't do, is work out how to reference the object the script instance is attached to. I've been testing with having a tag field in the Inspector, choosing the tag of the GO I want to manipulate and then FindWithTag()-ing to get the GO I want, but now I'm having issues with saving the variables I enter into the inspector, so I want to know how to do this properly. The documentation on this is very thin, but here's a trivial example of what I'm trying to achieve:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class TestClass : MonoBehaviour {
public string myString;
...
void Start () {
Debug.Log(myString);
}
...
}
combined with:
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(TestClass))]
public class TestClassEditor : Editor {
// How do set the value of this string in the custom inspector, and have it reflected in the associated instance?
public string myString = "";
...
override public void OnInspectorGUI() {
myString = EditorGUILayout.TextField(myString);
}
}