Esempio n. 1
0
    public override void OnInspectorGUI()
    {
        StateMachine     machine            = target as StateMachine;
        SerializedObject serialized_machine = new SerializedObject(machine);

        if (GUILayout.Button("Edit"))
        {
            StateMachineEditorWindow.ShowWindow(machine);
        }

        GUI.enabled = false;


        SerializedProperty property = serialized_machine.FindProperty("states");

        DrawFoldoutList(ref are_states_folded_out, property, property.arraySize + " States");

        property = serialized_machine.FindProperty("transitions");
        DrawFoldoutList(ref are_transitions_folded_out, property, property.arraySize + " Transitions");

        property = serialized_machine.FindProperty("parameters");
        DrawFoldoutList(ref are_parameters_folded_out, property, property.arraySize + " Parameters");

        GUI.enabled = true;

        serialized_machine.ApplyModifiedProperties();
    }
Esempio n. 2
0
    public static bool OpenIfStateMachine(int instanceID, int line)
    {
        StateMachine machine = EditorUtility.InstanceIDToObject(instanceID) as StateMachine;

        if (machine == null)
        {
            return(false);
        }
        StateMachineEditorWindow.ShowWindow(machine);
        return(true);
    }
                public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
                {
                    EditorGUI.BeginProperty(position, label, property);

                    Rect foldoutPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

                    property.isExpanded = EditorGUI.Foldout(foldoutPosition, property.isExpanded, property.displayName);
                    _height             = EditorGUIUtility.singleLineHeight;

                    if (property.isExpanded)
                    {
                        int origIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel++;

                        Rect filePosition = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight);

                        SerializedProperty fileProp = property.FindPropertyRelative("_file");
                        fileProp.objectReferenceValue = EditorGUI.ObjectField(filePosition, "File", fileProp.objectReferenceValue, typeof(TextAsset), true);

                        _height += EditorGUIUtility.singleLineHeight;

                        if (fileProp.objectReferenceValue != null)
                        {
                            SerializedProperty stateIdProp  = property.FindPropertyRelative("_stateId");
                            StateMachine       stateMachine = StateMachine.FromTextAsset((TextAsset)fileProp.objectReferenceValue, FindParentGameObject(property));

                            if (stateMachine != null)
                            {
                                State[] states = stateMachine._states;

                                if (states != null && states.Length > 0)
                                {
                                    string[] stateNames = new string[states.Length];
                                    int      index      = 0;
                                    for (int i = 0; i < states.Length; i++)
                                    {
                                        stateNames[i] = "State" + states[i]._stateId + " (" + states[i]._editorDescription + ")";

                                        if (states[i]._stateId == stateIdProp.intValue)
                                        {
                                            index = i;
                                        }
                                    }

                                    Rect statePosition = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 2, position.width, EditorGUIUtility.singleLineHeight);

                                    index = EditorGUI.Popup(statePosition, "Initial State", index, stateNames);
                                    stateIdProp.intValue = states[index]._stateId;

                                    _height += EditorGUIUtility.singleLineHeight;
                                }

                                Rect editButtonPosition = new Rect(position.x + EditorGUIUtility.labelWidth, position.y + EditorGUIUtility.singleLineHeight * 3, position.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);

                                if (GUI.Button(editButtonPosition, "Edit"))
                                {
                                    StateMachineEditorWindow.Load(fileProp.objectReferenceValue as TextAsset);
                                }

                                _height += EditorGUIUtility.singleLineHeight;
                            }
                        }

                        EditorGUI.indentLevel = origIndent;
                    }

                    EditorGUI.EndProperty();
                }
Esempio n. 4
0
 private static void CreateWindow()
 {
     // Get existing open window or if none, make a new one:
     _instance = (StateMachineEditorWindow)GetWindow(typeof(StateMachineEditorWindow), false, kWindowWindowName);
 }
Esempio n. 5
0
    static void ShowWindow()
    {
        StateMachineEditorWindow editor = GetWindow <StateMachineEditorWindow>();

        editor.Init();
    }
Esempio n. 6
0
    public static void ShowWindow(StateMachine machine)
    {
        StateMachineEditorWindow editor = GetWindow <StateMachineEditorWindow>();

        editor.LoadStateMachine(machine);
    }