So, I have a custom class, with a custom inspector, and I need to alter a array with the custom inspector. The problem is, I can’t use the default array inspector, because I need to change 2 values of each class in the array. I have the class:
#InteractiveObject.js
#pragma strict
class InteractiveObject extends MonoBehaviour {
public static var name : String = "Unnamed Object";
public static var version : int = 0x001;
public var propagate : InteractionPacket[];
final function Start() {
//Reserved
Init();
}
public function Interact(type : InteractionType, sender : InteractiveObject) : InteractionResults {
return InteractionResults.NotImplemented;
}
private function Init() {}
static public function Interact(sender : InteractiveObject, p :InteractionPacket) : InteractionResults {
return p.target.Interact(p.type, sender);
}
}
public enum InteractionType {
Activate,
Toggle,
Deactivate,
TurnOn,
TurnOff
}
public enum InteractionResults {
Sucess,
Failed,
InvalidInput,
NotImplemented,
Exception
}
public class InteractionPacket {
public var type : InteractionType;
public var target : InteractiveObject;
}
And its editor class:
Editor/InteractiveObjectEditor.js
#pragma strict
@CustomEditor(InteractiveObject)
@CanEditMultipleObjects
class InteractiveObjectEditor extends Editor {
var propagate : SerializedProperty;
//EDITOR SCRIPT VARIABLES
private var propagateControls : boolean[] = new boolean[4];
//END EDITOR SCRIPT VARIABLES
function OnEnable() {
propagate = serializedObject.FindProperty("propagate");
}
function OnInspectorGUI() {
serializedObject.Update();
EditorGUILayout.BeginHorizontal();
propagateControls[0] = EditorGUILayout.Foldout(propagateControls[0], "Propagate");
propagateControls[1] = GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.MaxWidth(30));
propagateControls[2] = GUILayout.Button("-", EditorStyles.miniButtonMid, GUILayout.MaxWidth(30));
propagateControls[3] = GUILayout.Button("Clear", EditorStyles.miniButtonRight);
EditorGUILayout.EndHorizontal();
if (propagateControls[0]) {
}
}
}
I want to create a editor that displays each entry in the propagate
variable like this:
A selector for a InteractiveObject class, a enum dropdown for InteractionType and a button to remove the entry.
It would be simple, if I could access the variable contents. I can’t seem to find a way to modify a array as a SerializedProperty…