Ejemplo n.º 1
0
 private void ShowParametersGUI(ActionListAsset _targetAsset)
 {
     EditorGUILayout.Space();
     EditorGUILayout.BeginVertical("Button");
     EditorGUILayout.LabelField("Parameters", EditorStyles.boldLabel);
     ActionListEditor.ShowParametersGUI(_targetAsset.parameters);
     EditorGUILayout.EndVertical();
 }
Ejemplo n.º 2
0
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string Property = e.Link.LinkData as string;

            PropertyInfo info = action.GetType().GetProperty(Property);

            if (info == null)
            {
                MessageBox.Show("Property " + Property + " Does not exist for " + action.GetType().Name);
                return;
            }

            DialogResult result = DialogResult.Cancel;

            string valueResult = "";

            if (info.PropertyType == typeof(NumberValue))
            {
                VariableEditor editor = new VariableEditor();
                if (Variables != null)
                {
                    editor.SetVariable(Variables.Select(x => x.Name));
                }
                else
                {
                    editor.SetVariable(new string[] { });
                }
                NumberValue val = info.GetMethod.Invoke(action, new object[] { }) as NumberValue;
                editor.SetDefault(val == null ? "" : val.ToString());
                editor.Text = "Variable Editor - " + Property;

                result = editor.ShowDialog();

                if (result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { new NumberValue(valueResult) });
                }
            }
            if (info.PropertyType == typeof(TargetKey))
            {
                TargetKeyEditor editor = new TargetKeyEditor();
                editor.SetPresets(ActionContext);
                editor.VariableList = Variables;

                TargetKey t = info.GetMethod.Invoke(action, new object[] { }) as TargetKey;
                if (t == null)
                {
                    t = new TargetKey();
                }
                editor.Target = t;

                result = editor.ShowDialog();

                if (result == DialogResult.OK)
                {
                    TargetKey target = editor.Target;
                    info.SetMethod.Invoke(action, new object[] { target });
                }
            }
            //It's an Enum!
            if (typeof(Enum).IsAssignableFrom(info.PropertyType))
            {
                Enum enumValue = info.GetMethod.Invoke(action, new object[] { }) as Enum;


                //Find out if it's a flag and open the flag editor
                if (info.PropertyType.GetCustomAttribute <FlagsAttribute>() != null)
                {
                    FlagCheckBoxEditor editor = new FlagCheckBoxEditor();
                    editor.EnumValue = enumValue;

                    result = editor.ShowDialog();

                    enumValue = editor.EnumValue;
                }
                else
                {
                    EnumEditor editor = new EnumEditor();
                    editor.EnumValue = enumValue;

                    result = editor.ShowDialog();

                    enumValue = editor.EnumValue;
                }

                if (result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { enumValue });

                    valueResult = enumValue.ToString();
                }
            }

            if (typeof(bool) == info.PropertyType)
            {
                bool val = (bool)info.GetMethod.Invoke(action, new object[] { });

                BoolEditor editor = new BoolEditor();
                editor.Value = val;

                result = editor.ShowDialog();

                if (result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { editor.Value });
                }
            }
            if (typeof(string) == info.PropertyType)
            {
                string val = (string)info.GetMethod.Invoke(action, new object[] { });

                TextPrompt editor = new TextPrompt();

                editor.Text       = Property;
                editor.PromptText = val;

                result = editor.ShowDialog();
                if (result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { editor.PromptText });
                }
            }
            if (typeof(ActionCollection) == info.PropertyType)
            {
                ActionCollection actions = info.GetMethod.Invoke(action, new object[] { }) as ActionCollection;

                ActionListEditor editor = new ActionListEditor();
                if (actions == null)
                {
                    actions = new ActionCollection(Property);
                }

                editor.ActionContext = ActionContext;
                editor.Variables     = Variables;
                editor.Actions       = actions;

                result = editor.ShowDialog();

                if (result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { editor.Actions });
                }
            }


            if (result == DialogResult.OK)
            {
                UpdateLinkTexts();
            }

            if (LinkClicked != null)
            {
                LinkClicked.Invoke(this, new LinkClickedEventArgs(e.Link.LinkData as string));
            }
        }
Ejemplo n.º 3
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);
        }
    }