Пример #1
0
        private IEnumerator RunAction(Action action)
        {
            if (useParameters)
            {
                action.AssignValues(parameters);
            }
            else
            {
                action.AssignValues(null);
            }

            if (isSkipping)
            {
                action.Skip();
            }
            else
            {
                if (action is ActionRunActionList)
                {
                    ActionRunActionList actionRunActionList = (ActionRunActionList)action;
                    actionRunActionList.isSkippable = IsSkippable();
                }

                action.isRunning = false;
                float waitTime = action.Run();

                if (action is ActionParallel)
                {
                }
                else if (waitTime > 0f)
                {
                    while (action.isRunning)
                    {
                        if (this is RuntimeActionList && actionListType == ActionListType.PauseGameplay && !unfreezePauseMenus)
                        {
                            float endTime = Time.realtimeSinceStartup + waitTime;
                            while (Time.realtimeSinceStartup < endTime)
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            yield return(new WaitForSeconds(waitTime));
                        }

                        waitTime = action.Run();
                    }
                }
            }

            if (action is ActionParallel)
            {
                EndActionParallel((ActionParallel)action);
            }
            else
            {
                EndAction(action);
            }
        }
Пример #2
0
        /**
         * <summary>Creates a new instance of the 'ActionList: Run' Action</summary>
         * <param name = "actionListAsset">The ActionList asset to run</param>
         * <param name = "startingActionIndex">The index number of the Action to start from</param>
         * <returns>The generated Action</returns>
         */
        public static ActionRunActionList CreateNew(ActionListAsset actionListAsset, int startingActionIndex = 0)
        {
            ActionRunActionList newAction = (ActionRunActionList)CreateInstance <ActionRunActionList>();

            newAction.listSource    = ListSource.AssetFile;
            newAction.invActionList = actionListAsset;
            newAction.runFromStart  = (startingActionIndex <= 0);
            newAction.jumpToAction  = startingActionIndex;
            return(newAction);
        }
Пример #3
0
        private IEnumerator RunAction(Action action)
        {
            action.AssignParentList(this);
            if (useParameters)
            {
                action.AssignValues(parameters);
            }
            else
            {
                action.AssignValues(null);
            }

            if (isSkipping)
            {
                skipIteractions++;
                action.Skip();
            }
            else
            {
                if (action is ActionRunActionList)
                {
                    ActionRunActionList actionRunActionList = (ActionRunActionList)action;
                    actionRunActionList.isSkippable = IsSkippable();
                }

                action.isRunning = false;
                float waitTime = action.Run();

                if (KickStarter.settingsManager.printActionCommentsInConsole)
                {
                    action.PrintComment(this);
                }

                if (action is ActionParallel)
                {
                }
                else if (waitTime != 0f)
                {
                    while (action.isRunning)
                    {
                        bool runInRealtime = (this is RuntimeActionList && actionListType == ActionListType.PauseGameplay && !unfreezePauseMenus && KickStarter.playerMenus.ArePauseMenusOn(null));

                        if (waitTime < 0)
                        {
                            //yield return new WaitForEndOfFrame (); // OLD

                            if (!runInRealtime && Time.timeScale == 0f)
                            {
                                while (Time.timeScale == 0f)
                                {
                                    yield return(new WaitForEndOfFrame());
                                }
                            }
                            else
                            {
                                yield return(new WaitForEndOfFrame());
                            }
                        }
                        else if (runInRealtime)
                        {
                            float endTime = Time.realtimeSinceStartup + waitTime;
                            while (Time.realtimeSinceStartup < endTime)
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            yield return(new WaitForSeconds(waitTime));
                        }

                        if (!action.isRunning)
                        {
                            // In rare cases (once an actionlist is reset) isRunning may be false but this while loop will still run
                            ResetList();
                            break;
                        }

                        waitTime = action.Run();
                    }
                }
            }

            if (action is ActionParallel)
            {
                EndActionParallel((ActionParallel)action);
            }
            else
            {
                EndAction(action);
            }
        }
Пример #4
0
        public static void ShowLocalParametersGUI(List <ActionParameter> localParameters, List <ActionParameter> assetParameters, bool isAssetFile)
        {
            int numParameters = assetParameters.Count;

            if (numParameters < localParameters.Count)
            {
                localParameters.RemoveRange(numParameters, localParameters.Count - numParameters);
            }
            else if (numParameters > localParameters.Count)
            {
                if (numParameters > localParameters.Capacity)
                {
                    localParameters.Capacity = numParameters;
                }
                for (int i = localParameters.Count; i < numParameters; i++)
                {
                    ActionParameter newParameter = new ActionParameter(ActionListEditor.GetParameterIDArray(localParameters));
                    localParameters.Add(newParameter);
                }
            }

            for (int i = 0; i < numParameters; i++)
            {
                string label = assetParameters[i].label;
                localParameters[i].parameterType = assetParameters[i].parameterType;

                if (assetParameters[i].parameterType == ParameterType.String)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(label + ":", GUILayout.Width(145f));
                    EditorStyles.textField.wordWrap = true;
                    localParameters[i].stringValue  = EditorGUILayout.TextArea(localParameters[i].stringValue, GUILayout.MaxWidth(400f));
                    EditorGUILayout.EndHorizontal();
                }
                else if (assetParameters[i].parameterType == ParameterType.Float)
                {
                    localParameters[i].floatValue = EditorGUILayout.FloatField(label + ":", localParameters[i].floatValue);
                }
                else if (assetParameters[i].parameterType == ParameterType.Integer)
                {
                    localParameters[i].intValue = EditorGUILayout.IntField(label + ":", localParameters[i].intValue);
                }
                else if (assetParameters[i].parameterType == ParameterType.Boolean)
                {
                    BoolValue boolValue = BoolValue.False;
                    if (localParameters[i].intValue == 1)
                    {
                        boolValue = BoolValue.True;
                    }

                    boolValue = (BoolValue)EditorGUILayout.EnumPopup(label + ":", boolValue);

                    if (boolValue == BoolValue.True)
                    {
                        localParameters[i].intValue = 1;
                    }
                    else
                    {
                        localParameters[i].intValue = 0;
                    }
                }
                else if (assetParameters[i].parameterType == ParameterType.GlobalVariable)
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().variablesManager)
                    {
                        VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                        localParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", variablesManager.vars, localParameters[i].intValue);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A Variables Manager is required to pass Global Variables.", MessageType.Warning);
                    }
                }
                else if (assetParameters[i].parameterType == ParameterType.InventoryItem)
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                        localParameters[i].intValue = ActionRunActionList.ShowInvItemSelectorGUI(label + ":", inventoryManager.items, localParameters[i].intValue);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required to pass Inventory items.", MessageType.Warning);
                    }
                }
                else if (assetParameters[i].parameterType == ParameterType.LocalVariable)
                {
                    if (KickStarter.localVariables)
                    {
                        localParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", KickStarter.localVariables.localVars, localParameters[i].intValue);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A GameEngine prefab is required to pass Local Variables.", MessageType.Warning);
                    }
                }
                if (assetParameters[i].parameterType == ParameterType.GameObject)
                {
                    if (isAssetFile)
                    {
                        // ID
                        localParameters[i].intValue   = EditorGUILayout.IntField(label + " (ID):", localParameters[i].intValue);
                        localParameters[i].gameObject = null;
                    }
                    else
                    {
                        // Gameobject
                        localParameters[i].gameObject = (GameObject)EditorGUILayout.ObjectField(label + ":", localParameters[i].gameObject, typeof(GameObject), true);
                        localParameters[i].intValue   = 0;
                        if (localParameters[i].gameObject != null && localParameters[i].gameObject.GetComponent <ConstantID>() == null)
                        {
                            localParameters[i].gameObject.AddComponent <ConstantID>();
                        }
                    }
                }
                else if (assetParameters[i].parameterType == ParameterType.UnityObject)
                {
                    localParameters[i].objectValue = (Object)EditorGUILayout.ObjectField(label + ":", localParameters[i].objectValue, typeof(Object), true);
                }
            }
        }
Пример #5
0
        private IEnumerator RunAction(Action action)
        {
            action.AssignParentList(this);
            if (useParameters)
            {
                action.AssignValues(parameters);
            }
            else
            {
                action.AssignValues(null);
            }

            if (isSkipping)
            {
                skipIteractions++;
                action.Skip();
            }
            else
            {
                if (action is ActionRunActionList)
                {
                    ActionRunActionList actionRunActionList = (ActionRunActionList)action;
                    actionRunActionList.isSkippable = IsSkippable();
                }

                action.isRunning = false;
                float waitTime = action.Run();

                if (action is ActionParallel)
                {
                }
                else if (waitTime != 0f)
                {
                    while (action.isRunning)
                    {
                        if (this is RuntimeActionList && actionListType == ActionListType.PauseGameplay && !unfreezePauseMenus)
                        {
                            float endTime = Time.realtimeSinceStartup + waitTime;
                            while (Time.realtimeSinceStartup < endTime)
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            yield return(new WaitForSeconds(waitTime));
                        }

                        if (!action.isRunning)
                        {
                            // In rare cases (once an actionlist is reset) isRunning may be false but this while loop will still run
                            ResetList();
                            break;
                        }
                        waitTime = action.Run();
                    }
                }
            }

            if (action is ActionParallel)
            {
                EndActionParallel((ActionParallel)action);
            }
            else
            {
                EndAction(action);
            }
        }
Пример #6
0
        private IEnumerator RunAction(Action action)
        {
            action.AssignParentList(this);
            if (useParameters)
            {
                action.AssignValues(parameters);
            }
            else
            {
                action.AssignValues(null);
            }

            if (isSkipping)
            {
                skipIteractions++;
                action.Skip();

                if (KickStarter.settingsManager.printActionCommentsInConsole)
                {
                    action.PrintComment(this);
                }
            }
            else
            {
                if (action is ActionRunActionList)
                {
                    ActionRunActionList actionRunActionList = (ActionRunActionList)action;
                    actionRunActionList.isSkippable = IsSkippable();
                }

                if (isChangingScene)
                {
                    ACDebug.Log("Cannot begin Action #" + actions.IndexOf(action) + " " + action.category + ": " + action.title + " in list " + gameObject.name + " while changing scene, will resume once loading is complete.", this);
                    while (isChangingScene)
                    {
                        yield return(null);
                    }
                }

                action.isRunning = false;
                float waitTime = action.Run();

                if (KickStarter.settingsManager.printActionCommentsInConsole)
                {
                    action.PrintComment(this);
                }

                if (action is ActionParallel)
                {
                }
                else if (!Mathf.Approximately(waitTime, 0f))
                {
                    while (action.isRunning)
                    {
                        bool runInRealtime = (this is RuntimeActionList && actionListType == ActionListType.PauseGameplay && !unfreezePauseMenus && KickStarter.playerMenus.ArePauseMenusOn(null));

                        if (isChangingScene)
                        {
                            ACDebug.Log("Cannot continue Action #" + actions.IndexOf(action) + " " + action.category + ": " + action.title + " in list " + gameObject.name + " while changing scene, will resume once loading is complete.", this);
                            while (isChangingScene)
                            {
                                yield return(null);
                            }
                        }

                        if (waitTime < 0)
                        {
                            if (!runInRealtime && Time.timeScale <= 0f)
                            {
                                while (Time.timeScale <= 0f)
                                {
                                    yield return(new WaitForEndOfFrame());
                                }
                            }
                            else
                            {
                                yield return(new WaitForEndOfFrame());
                            }
                        }
                        else if (runInRealtime)
                        {
                            float endTime = Time.realtimeSinceStartup + waitTime;
                            while (Time.realtimeSinceStartup < endTime)
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            yield return(new WaitForSeconds(waitTime));
                        }

                        if (!action.isRunning)
                        {
                            // In rare cases (once an actionlist is reset) isRunning may be false but this while loop will still run
                            ResetList();
                            break;
                        }

                        waitTime = action.Run();
                    }
                }
            }

            if (action is ActionParallel)
            {
                EndActionParallel((ActionParallel)action);
            }
            else
            {
                EndAction(action);
            }
        }
        public static GUIData SetParametersGUI(List <ActionParameter> externalParameters, bool isAssetFile, GUIData guiData, List <ActionParameter> ownParameters = null)
        {
            guiData = SyncLists(externalParameters, guiData);

            EditorGUILayout.BeginVertical("Button");
            for (int i = 0; i < externalParameters.Count; i++)
            {
                string label    = externalParameters[i].label;
                int    linkedID = (i < guiData.parameterIDs.Count)
                                                                ? guiData.parameterIDs[i]
                                                                : -1;

                //guiData.fromParameters[i].ID = externalParameters[i].ID;
                guiData.fromParameters[i].parameterType = externalParameters[i].parameterType;
                if (externalParameters[i].parameterType == ParameterType.GameObject)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.GameObject);
                    if (linkedID < 0)
                    {
                        if (isAssetFile)
                        {
                            guiData.fromParameters[i].gameObject = (GameObject)EditorGUILayout.ObjectField(label + ":", guiData.fromParameters[i].gameObject, typeof(GameObject), true);
                            if (guiData.fromParameters[i].gameObject != null)
                            {
                                if (!UnityVersionHandler.IsPrefabFile(guiData.fromParameters[i].gameObject))
                                {
                                    guiData.fromParameters[i].intValue   = Action.FieldToID(guiData.fromParameters[i].gameObject, guiData.fromParameters[i].intValue, false, isAssetFile);
                                    guiData.fromParameters[i].gameObject = Action.IDToField(guiData.fromParameters[i].gameObject, guiData.fromParameters[i].intValue, true, false, isAssetFile);
                                }
                                else
                                {
                                    // A prefab, ask if we want to affect the prefab or the scene-based instance?
                                    guiData.fromParameters[i].gameObjectParameterReferences = (GameObjectParameterReferences)EditorGUILayout.EnumPopup("GameObject parameter:", guiData.fromParameters[i].gameObjectParameterReferences);
                                }
                            }
                            else
                            {
                                guiData.fromParameters[i].intValue = EditorGUILayout.IntField(label + " (ID #):", guiData.fromParameters[i].intValue);
                            }
                        }
                        else
                        {
                            // Gameobject
                            guiData.fromParameters[i].gameObject = (GameObject)EditorGUILayout.ObjectField(label + ":", guiData.fromParameters[i].gameObject, typeof(GameObject), true);
                            guiData.fromParameters[i].intValue   = 0;
                            if (guiData.fromParameters[i].gameObject != null && guiData.fromParameters[i].gameObject.GetComponent <ConstantID>() == null)
                            {
                                UnityVersionHandler.AddConstantIDToGameObject <ConstantID> (guiData.fromParameters[i].gameObject);
                            }
                        }
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.UnityObject)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.UnityObject);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].objectValue = (Object)EditorGUILayout.ObjectField(label + ":", guiData.fromParameters[i].objectValue, typeof(Object), true);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.GlobalVariable)
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().variablesManager)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.GlobalVariable);
                        if (linkedID < 0)
                        {
                            VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", variablesManager.vars, guiData.fromParameters[i].intValue);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A Variables Manager is required to pass Global Variables.", MessageType.Warning);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.InventoryItem)
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.InventoryItem);
                        if (linkedID < 0)
                        {
                            InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowInvItemSelectorGUI(label + ":", inventoryManager.items, guiData.fromParameters[i].intValue);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required to pass Inventory items.", MessageType.Warning);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.Document)
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Document);
                        if (linkedID < 0)
                        {
                            InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowDocumentSelectorGUI(label + ":", inventoryManager.documents, guiData.fromParameters[i].intValue);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required to pass Documents.", MessageType.Warning);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.LocalVariable)
                {
                    if (KickStarter.localVariables)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.LocalVariable);
                        if (linkedID < 0)
                        {
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", KickStarter.localVariables.localVars, guiData.fromParameters[i].intValue);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A GameEngine prefab is required to pass Local Variables.", MessageType.Warning);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.String)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.String);
                    if (linkedID < 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(label + ":", GUILayout.Width(145f));
                        EditorStyles.textField.wordWrap       = true;
                        guiData.fromParameters[i].stringValue = EditorGUILayout.TextArea(guiData.fromParameters[i].stringValue, GUILayout.MaxWidth(400f));
                        EditorGUILayout.EndHorizontal();
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.Float)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Float);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].floatValue = EditorGUILayout.FloatField(label + ":", guiData.fromParameters[i].floatValue);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.Integer)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Integer);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].intValue = EditorGUILayout.IntField(label + ":", guiData.fromParameters[i].intValue);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.Vector3)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Vector3);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].vector3Value = EditorGUILayout.Vector3Field(label + ":", guiData.fromParameters[i].vector3Value);
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.Boolean)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Boolean);
                    if (linkedID < 0)
                    {
                        BoolValue boolValue = BoolValue.False;
                        if (guiData.fromParameters[i].intValue == 1)
                        {
                            boolValue = BoolValue.True;
                        }

                        boolValue = (BoolValue)EditorGUILayout.EnumPopup(label + ":", boolValue);

                        if (boolValue == BoolValue.True)
                        {
                            guiData.fromParameters[i].intValue = 1;
                        }
                        else
                        {
                            guiData.fromParameters[i].intValue = 0;
                        }
                    }
                }
                else if (externalParameters[i].parameterType == ParameterType.ComponentVariable)
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.ComponentVariable);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].variables = (Variables)EditorGUILayout.ObjectField("'" + label + "' component:", guiData.fromParameters[i].variables, typeof(Variables), true);
                        if (guiData.fromParameters[i].variables != null)
                        {
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", guiData.fromParameters[i].variables.vars, guiData.fromParameters[i].intValue);
                        }
                    }
                }

                if (i < guiData.parameterIDs.Count)
                {
                    guiData.parameterIDs[i] = linkedID;
                }

                if (i < externalParameters.Count - 1)
                {
                    EditorGUILayout.Space();
                }
            }
            EditorGUILayout.EndVertical();

            return(guiData);
        }
Пример #8
0
        public void ShowGUI(bool isAssetFile, bool onlyEditValues = false, bool readOnly = false)
        {
            if (Application.isPlaying || readOnly)
            {
                EditorGUILayout.LabelField("Type:", parameterType.ToString());
                EditorGUILayout.LabelField("Current value:", "'" + GetLabel() + "'");
                CustomGUILayout.TokenLabel("[param:" + ID.ToString() + "]");
            }
            else
            {
                if (onlyEditValues)
                {
                    EditorGUILayout.LabelField("Type:", parameterType.ToString());
                }
                else
                {
                    parameterType = (ParameterType)EditorGUILayout.EnumPopup("Type:", parameterType);
                }

                switch (parameterType)
                {
                case ParameterType.Boolean:
                    BoolValue boolValue = (intValue == 1) ? BoolValue.True : BoolValue.False;
                    boolValue = (BoolValue)EditorGUILayout.EnumPopup("Default value:", boolValue);
                    intValue  = (boolValue == BoolValue.True) ? 1 : 0;
                    break;

                case ParameterType.Integer:
                    intValue = EditorGUILayout.IntField("Default value:", intValue);
                    break;

                case ParameterType.Float:
                    floatValue = EditorGUILayout.FloatField("Default value:", floatValue);
                    break;

                case ParameterType.String:
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Default value:", GUILayout.Width(145f));
                    EditorStyles.textField.wordWrap = true;
                    stringValue = EditorGUILayout.TextArea(stringValue, GUILayout.MaxWidth(400f));
                    EditorGUILayout.EndHorizontal();
                    break;

                case ParameterType.Vector3:
                    vector3Value = EditorGUILayout.Vector3Field("Default value:", vector3Value);
                    break;

                case ParameterType.UnityObject:
                    objectValue = (Object)EditorGUILayout.ObjectField("Default value:", objectValue, typeof(Object), true);
                    break;

                case ParameterType.Document:
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                        intValue = ActionRunActionList.ShowDocumentSelectorGUI("Default value:", inventoryManager.documents, intValue);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required.", MessageType.Warning);
                    }
                    break;

                case ParameterType.InventoryItem:
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                        intValue = ActionRunActionList.ShowInvItemSelectorGUI("Default value:", inventoryManager.items, intValue);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required to pass Inventory items.", MessageType.Warning);
                    }
                    break;

                case ParameterType.GlobalVariable:
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().variablesManager)
                    {
                        VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                        intValue = ActionRunActionList.ShowVarSelectorGUI("Default value:", variablesManager.vars, intValue);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A Variables Manager is required to pass Global Variables.", MessageType.Warning);
                    }
                    break;

                case ParameterType.LocalVariable:
                    if (isAssetFile)
                    {
                        intValue = 0;
                        EditorGUILayout.HelpBox("Local Variable parameters cannot have default values in ActionList Assets.", MessageType.Info);
                    }
                    else
                    {
                        if (KickStarter.localVariables)
                        {
                            intValue = ActionRunActionList.ShowVarSelectorGUI("Default value:", KickStarter.localVariables.localVars, intValue);
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("A GameEngine prefab is required to pass Local Variables.", MessageType.Warning);
                        }
                    }
                    break;

                case ParameterType.ComponentVariable:
                    if (isAssetFile)
                    {
                        variables = null;
                        intValue  = 0;
                        EditorGUILayout.HelpBox("Component Variable parameters cannot have default values in ActionList Assets.", MessageType.Info);
                    }
                    else
                    {
                        variables = (Variables)EditorGUILayout.ObjectField("Variables component:", variables, typeof(Variables), true);
                        if (variables != null)
                        {
                            intValue = ActionRunActionList.ShowVarSelectorGUI("Default value:", variables.vars, intValue);
                        }
                    }
                    break;

                case ParameterType.GameObject:
                    if (isAssetFile)
                    {
                        gameObject = (GameObject)EditorGUILayout.ObjectField("Default value:", gameObject, typeof(GameObject), true);
                        if (gameObject != null)
                        {
                            if (!UnityVersionHandler.IsPrefabFile(gameObject))
                            {
                                intValue   = Action.FieldToID(gameObject, intValue, false, isAssetFile);
                                gameObject = Action.IDToField(gameObject, intValue, true, false, isAssetFile);
                            }
                            else
                            {
                                // A prefab, ask if we want to affect the prefab or the scene-based instance?
                                gameObjectParameterReferences = (GameObjectParameterReferences)EditorGUILayout.EnumPopup("GameObject parameter:", gameObjectParameterReferences);
                            }
                        }
                        else
                        {
                            intValue = EditorGUILayout.IntField("Default value (ID #):", intValue);
                        }
                    }
                    else
                    {
                        // Gameobject
                        gameObject = (GameObject)EditorGUILayout.ObjectField("Default value:", gameObject, typeof(GameObject), true);
                        intValue   = 0;
                        if (gameObject != null && gameObject.GetComponent <ConstantID> () == null)
                        {
                            UnityVersionHandler.AddConstantIDToGameObject <ConstantID> (gameObject);
                        }
                    }
                    break;

                default:
                    break;
                }

                CustomGUILayout.TokenLabel("[param:" + ID.ToString() + "]");
            }
        }
Пример #9
0
        public static GUIData SetParametersGUI(List <ActionParameter> externalParameters, bool isAssetFile, GUIData guiData, List <ActionParameter> ownParameters = null)
        {
            guiData = SyncLists(externalParameters, guiData);

            CustomGUILayout.BeginVertical();
            for (int i = 0; i < externalParameters.Count; i++)
            {
                string label    = externalParameters[i].label;
                string tooltip  = externalParameters[i].description;
                int    linkedID = (i < guiData.parameterIDs.Count)
                                                                ? guiData.parameterIDs[i]
                                                                : -1;

                guiData.fromParameters[i].parameterType = externalParameters[i].parameterType;

                switch (externalParameters[i].parameterType)
                {
                case ParameterType.GameObject:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.GameObject);
                    if (linkedID < 0)
                    {
                        if (isAssetFile)
                        {
                            guiData.fromParameters[i].gameObject = (GameObject)CustomGUILayout.ObjectField <GameObject> (label + ":", guiData.fromParameters[i].gameObject, true, string.Empty, tooltip);
                            if (guiData.fromParameters[i].gameObject)
                            {
                                if (!UnityVersionHandler.IsPrefabFile(guiData.fromParameters[i].gameObject))
                                {
                                    guiData.fromParameters[i].intValue   = Action.FieldToID(guiData.fromParameters[i].gameObject, guiData.fromParameters[i].intValue, false, isAssetFile);
                                    guiData.fromParameters[i].gameObject = Action.IDToField(guiData.fromParameters[i].gameObject, guiData.fromParameters[i].intValue, true, false, isAssetFile);
                                }
                                else
                                {
                                    // A prefab, ask if we want to affect the prefab or the scene-based instance?
                                    guiData.fromParameters[i].gameObjectParameterReferences = (GameObjectParameterReferences)EditorGUILayout.EnumPopup("GameObject parameter:", guiData.fromParameters[i].gameObjectParameterReferences);
                                }
                            }
                            else
                            {
                                guiData.fromParameters[i].intValue = CustomGUILayout.IntField(label + " (ID #):", guiData.fromParameters[i].intValue, string.Empty, tooltip);
                            }
                        }
                        else
                        {
                            // Gameobject
                            guiData.fromParameters[i].gameObject = (GameObject)CustomGUILayout.ObjectField <GameObject> (label + ":", guiData.fromParameters[i].gameObject, true, string.Empty, tooltip);
                            guiData.fromParameters[i].intValue   = 0;
                            if (guiData.fromParameters[i].gameObject && guiData.fromParameters[i].gameObject.GetComponent <ConstantID>() == null)
                            {
                                UnityVersionHandler.AddConstantIDToGameObject <ConstantID> (guiData.fromParameters[i].gameObject);
                            }
                        }
                    }
                }
                break;

                case ParameterType.UnityObject:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.UnityObject);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].objectValue = (Object)CustomGUILayout.ObjectField <Object> (label + ":", guiData.fromParameters[i].objectValue, true, string.Empty, tooltip);
                    }
                }
                break;

                case ParameterType.GlobalVariable:
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().variablesManager)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.GlobalVariable, -1, tooltip);
                        if (linkedID < 0)
                        {
                            VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", variablesManager.vars, guiData.fromParameters[i].intValue, tooltip);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A Variables Manager is required to pass Global Variables.", MessageType.Warning);
                    }
                }
                break;

                case ParameterType.InventoryItem:
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.InventoryItem, -1, tooltip);
                        if (linkedID < 0)
                        {
                            InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowInvItemSelectorGUI(label + ":", inventoryManager.items, guiData.fromParameters[i].intValue, tooltip);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required to pass Inventory items.", MessageType.Warning);
                    }
                }
                break;

                case ParameterType.Document:
                {
                    if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Document, -1, tooltip);
                        if (linkedID < 0)
                        {
                            InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowDocumentSelectorGUI(label + ":", inventoryManager.documents, guiData.fromParameters[i].intValue, tooltip);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("An Inventory Manager is required to pass Documents.", MessageType.Warning);
                    }
                }
                break;

                case ParameterType.LocalVariable:
                {
                    if (KickStarter.localVariables)
                    {
                        linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.LocalVariable, -1, tooltip);
                        if (linkedID < 0)
                        {
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", KickStarter.localVariables.localVars, guiData.fromParameters[i].intValue, tooltip);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A GameEngine prefab is required to pass Local Variables.", MessageType.Warning);
                    }
                }
                break;

                case ParameterType.String:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.String, -1, tooltip);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].stringValue = CustomGUILayout.TextArea(label, guiData.fromParameters[i].stringValue, string.Empty, tooltip);
                    }
                }
                break;

                case ParameterType.Float:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Float, -1, tooltip);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].floatValue = CustomGUILayout.FloatField(label + ":", guiData.fromParameters[i].floatValue, string.Empty, tooltip);
                    }
                }
                break;

                case ParameterType.Integer:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Integer, -1, tooltip);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].intValue = CustomGUILayout.IntField(label + ":", guiData.fromParameters[i].intValue, string.Empty, tooltip);
                    }
                }
                break;

                case ParameterType.Vector3:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Vector3, -1, tooltip);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].vector3Value = CustomGUILayout.Vector3Field(label + ":", guiData.fromParameters[i].vector3Value, string.Empty, tooltip);
                    }
                }
                break;

                case ParameterType.Boolean:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.Boolean, -1, tooltip);
                    if (linkedID < 0)
                    {
                        BoolValue boolValue = BoolValue.False;
                        if (guiData.fromParameters[i].intValue == 1)
                        {
                            boolValue = BoolValue.True;
                        }

                        boolValue = (BoolValue)CustomGUILayout.EnumPopup(label + ":", boolValue, string.Empty, tooltip);

                        if (boolValue == BoolValue.True)
                        {
                            guiData.fromParameters[i].intValue = 1;
                        }
                        else
                        {
                            guiData.fromParameters[i].intValue = 0;
                        }
                    }
                }
                break;

                case ParameterType.ComponentVariable:
                {
                    linkedID = Action.ChooseParameterGUI(label + ":", ownParameters, linkedID, ParameterType.ComponentVariable);
                    if (linkedID < 0)
                    {
                        guiData.fromParameters[i].variables = (Variables)EditorGUILayout.ObjectField("'" + label + "' component:", guiData.fromParameters[i].variables, typeof(Variables), true);
                        if (guiData.fromParameters[i].variables != null)
                        {
                            guiData.fromParameters[i].intValue = ActionRunActionList.ShowVarSelectorGUI(label + ":", guiData.fromParameters[i].variables.vars, guiData.fromParameters[i].intValue);
                        }
                    }
                }
                break;

                default:
                    break;
                }

                if (i < guiData.parameterIDs.Count)
                {
                    guiData.parameterIDs[i] = linkedID;
                }

                if (i < externalParameters.Count - 1)
                {
                    EditorGUILayout.Space();
                }
            }
            CustomGUILayout.EndVertical();

            return(guiData);
        }