示例#1
0
    private int GetTypeNumber(int i)
    {
        ActionList _target = (ActionList)target;

        int number = 0;

        if (actionsManager)
        {
            for (int j = 0; j < actionsManager.GetActionsSize(); j++)
            {
                try
                {
                    if (_target.actions[i].GetType().ToString() == actionsManager.GetActionName(j))
                    {
                        number = j;
                        break;
                    }
                }

                catch
                {
                    string defaultAction = actionsManager.GetDefaultAction();
                    _target.actions[i] = (Action)CreateInstance(defaultAction);
                }
            }
        }

        return(number);
    }
示例#2
0
    private Action RebuildAction(Action action, int number)
    {
        actionsManager = AdvGame.GetReferences().actionsManager;

        if (actionsManager)
        {
            string ClassName = actionsManager.GetActionName(number);

            if (action.GetType().ToString() != ClassName)
            {
                action = (Action)CreateInstance(ClassName);
            }
        }

        return(action);
    }
示例#3
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);
        }
    }
示例#4
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);
            }
        }
    }
示例#5
0
    public override void OnInspectorGUI()
    {
        ActionListAsset _target = (ActionListAsset)target;

        EditorGUILayout.BeginVertical("Button");
        EditorGUILayout.LabelField("Asset properties", EditorStyles.boldLabel);
        _target.actionListType = (ActionListType)EditorGUILayout.EnumPopup("When running:", _target.actionListType);
        if (_target.actionListType == ActionListType.PauseGameplay)
        {
            _target.isSkippable        = EditorGUILayout.Toggle("Is skippable?", _target.isSkippable);
            _target.unfreezePauseMenus = EditorGUILayout.Toggle("Unfreeze 'pause' Menus?", _target.unfreezePauseMenus);
        }
        _target.useParameters = EditorGUILayout.Toggle("Use parameters?", _target.useParameters);
        EditorGUILayout.EndVertical();

        if (_target.useParameters)
        {
            ShowParametersGUI(_target);
        }
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
        {
            Undo.RecordObject(_target, "Expand actions");
            foreach (AC.Action action in _target.actions)
            {
                action.isDisplayed = true;
            }
        }
        if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
        {
            Undo.RecordObject(_target, "Collapse actions");
            foreach (AC.Action action in _target.actions)
            {
                action.isDisplayed = false;
            }
        }
        if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
        {
            ActionListEditorWindow.Init(_target);
        }
        if (!Application.isPlaying)
        {
            GUI.enabled = false;
        }
        if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
        {
            AdvGame.RunActionListAsset(_target);
        }
        GUI.enabled = true;
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        if (actionsManager == null)
        {
            EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
            OnEnable();
            return;
        }

        if (!actionsManager.displayActionsInInspector)
        {
            EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
            return;
        }

        for (int i = 0; i < _target.actions.Count; i++)
        {
            int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]);

            if (_target.actions[i] == null)
            {
                _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], typeIndex, _target));
            }

            _target.actions[i].isAssetFile = true;

            EditorGUILayout.BeginVertical("Button");

            string actionLabel = " " + (i).ToString() + ": " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel();

            EditorGUILayout.BeginHorizontal();
            _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
            if (!_target.actions[i].isEnabled)
            {
                EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f));
            }

            Texture2D icon = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof(Texture2D));
            if (GUILayout.Button(icon, GUILayout.Width(20f), GUILayout.Height(15f)))
            {
                ActionSideMenu(_target.actions[i]);
            }
            EditorGUILayout.EndHorizontal();

            if (_target.actions[i].isDisplayed)
            {
                if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                {
                    EditorGUILayout.HelpBox("This Action type has been disabled in the Actions Manager", MessageType.Warning);
                }
                else
                {
                    int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                    if (newTypeIndex >= 0)
                    {
                        // Rebuild constructor if Subclass and type string do not match
                        ActionEnd _end = new ActionEnd();
                        _end.resultAction   = _target.actions[i].endAction;
                        _end.skipAction     = _target.actions[i].skipAction;
                        _end.linkedAsset    = _target.actions[i].linkedAsset;
                        _end.linkedCutscene = _target.actions[i].linkedCutscene;

                        Undo.RecordObject(_target, "Change Action type");

                        _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], newTypeIndex, _target, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene));
                    }

                    EditorGUILayout.Space();
                    GUI.enabled = _target.actions[i].isEnabled;

                    if (_target.useParameters)
                    {
                        _target.actions[i].ShowGUI(_target.parameters);
                    }
                    else
                    {
                        _target.actions[i].ShowGUI(null);
                    }
                }
                GUI.enabled = true;
            }

            if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
            {
                _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
            }

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

        if (GUILayout.Button("Add new Action"))
        {
            AddAction(actionsManager.GetActionName(actionsManager.defaultClass), _target.actions.Count, _target);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(_target);
        }
    }