Пример #1
0
    public override void OnInspectorGUI()
    {
        InvActionList _target = (InvActionList)target;

        actionsManager = AdvGame.GetReferences().actionsManager;

        for (int i = 0; i < _target.actions.Count; i++)
        {
            EditorGUILayout.BeginVertical("Button");

            string actionLabel = " " + (i).ToString() + ": " + _target.actions[i].title + _target.actions[i].SetLabel();

            _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);

            if (_target.actions[i].isDisplayed)
            {
                EditorGUILayout.Space();
                ShowActionGUI(_target.actions[i], i, _target.actions.Count);
                EditorGUILayout.BeginHorizontal();

                if (i > 0)
                {
                    if (GUILayout.Button("Move up"))
                    {
                        _target.actions = AdvGame.SwapActions(_target.actions, i, i - 1);
                    }
                }

                if (GUILayout.Button("Delete"))
                {
                    DeleteAction(_target.actions[i]);
                }

                if (i < _target.actions.Count - 1)
                {
                    if (GUILayout.Button("Move down"))
                    {
                        _target.actions = AdvGame.SwapActions(_target.actions, i, i + 1);
                    }
                }

                EditorGUILayout.EndHorizontal();
            }


            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Type:", labelWidth);

        if (typeNumber == -1)
        {
            typeNumber = actionsManager.defaultClass;
        }

        typeNumber = EditorGUILayout.Popup(typeNumber, actionsManager.GetActionTitles());

        if (GUILayout.Button("Add new"))
        {
            AddAction(actionsManager.GetActionName(typeNumber));
        }
        EditorGUILayout.EndHorizontal();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(_target);
        }
    }
Пример #2
0
    protected void DrawSharedElements()
    {
        if (AdvGame.GetReferences() == null)
        {
            Debug.LogError("A References file is required - please use the Adventure Creator window to create one.");
            EditorGUILayout.LabelField("No References file found!");
        }
        else
        {
            actionsManager = AdvGame.GetReferences().actionsManager;

            ActionList _target = (ActionList)target;

            if (actionsManager)
            {
                int numActions = _target.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;

                    string defaultAction = actionsManager.GetDefaultAction();

                    _target.actions.Add((Action)CreateInstance(defaultAction));
                }

                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Expand all"))
                {
                    Undo.RegisterUndo(_target, "Expand actions");

                    foreach (Action action in _target.actions)
                    {
                        action.isDisplayed = true;
                    }
                }

                if (GUILayout.Button("Collapse all"))
                {
                    Undo.RegisterUndo(_target, "Collapse actions");

                    foreach (Action action in _target.actions)
                    {
                        action.isDisplayed = false;
                    }
                }

                EditorGUILayout.EndHorizontal();

                for (int i = 0; i < _target.actions.Count; i++)
                {
                    EditorGUILayout.BeginVertical("Button");
                    typeNumber = GetTypeNumber(i);

                    string actionLabel = " " + (i).ToString() + ": " + _target.actions[i].title + _target.actions[i].SetLabel();

                    _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);

                    if (_target.actions[i].isDisplayed)
                    {
                        typeNumber = EditorGUILayout.Popup("Action type:", typeNumber, actionsManager.GetActionTitles());
                        EditorGUILayout.Space();

                        // Rebuild constructor if Subclass and type string do not match
                        if (_target.actions[i].GetType().ToString() != actionsManager.GetActionName(typeNumber))
                        {
                            _target.actions[i] = RebuildAction(_target.actions[i], typeNumber);
                        }

                        ShowActionGUI(_target.actions[i], _target.gameObject, i, _target.actions.Count);

                        EditorGUILayout.BeginHorizontal();

                        if (i > 0)
                        {
                            if (GUILayout.Button("Move up"))
                            {
                                Undo.RegisterUndo(_target, "Move action up");
                                _target.actions = AdvGame.SwapActions(_target.actions, i, i - 1);
                            }
                        }

                        if (i < _target.actions.Count - 1)
                        {
                            if (GUILayout.Button("Insert new"))
                            {
                                Undo.RegisterUndo(_target, "Create action");

                                numActions += 1;

                                _target.actions = ResizeList(_target.actions, numActions);
                                // Swap all elements up one
                                for (int k = numActions - 1; k > i + 1; k--)
                                {
                                    _target.actions = AdvGame.SwapActions(_target.actions, k, k - 1);
                                }
                            }
                        }

                        if (_target.actions.Count > 1)
                        {
                            if (GUILayout.Button("Delete"))
                            {
                                Undo.RegisterUndo(_target, "Delete action");

                                _target.actions.RemoveAt(i);
                                numActions -= 1;
                            }
                        }

                        if (i < _target.actions.Count - 1)
                        {
                            if (GUILayout.Button("Move down"))
                            {
                                Undo.RegisterUndo(_target, "Move action down");
                                _target.actions = AdvGame.SwapActions(_target.actions, i, i + 1);
                            }
                        }

                        EditorGUILayout.EndHorizontal();
                    }

                    EditorGUILayout.EndVertical();
                    EditorGUILayout.Space();
                }

                if (GUILayout.Button("Add new action"))
                {
                    Undo.RegisterUndo(_target, "Create action");
                    numActions += 1;
                }

                _target.actions = ResizeList(_target.actions, numActions);
            }
        }
    }