Example #1
0
    public override void createUIDescription(CutScene cutScene, SerializedObject serializedObject)
    {
        ExecuteFunctionNode node = this;

        GUILayout.Label("<<Execute Function>>");
        eventCallee  = (MonoBehaviour)EditorGUILayout.ObjectField("Object: ", eventCallee, typeof(MonoBehaviour), true);
        functionName = EditorGUILayout.TextField("FuncitonName: ", functionName);
    }
Example #2
0
        public async Task <IStateMachineMonad <TKey, TState, TEvent, TParam, TCtx, TUserId, TR> > Run <TR>(Func <TCtx, TValue, Task <IStateMachineMonad <TKey, TState, TEvent, TParam, TCtx, TUserId, TR> > > func)
        {
            var executeNode = new ExecuteFunctionNode <TKey, TState, TEvent, TParam, TCtx, TUserId,
                                                       IStateMachineMonad <TKey, TState, TEvent, TParam, TCtx, TUserId, TR> >(
                (ctx) => { return(func(ctx, this.Value)); });
            var result = await this.ctx.Add(new EventActionNodePersist <TKey, TState, TEvent, TParam, TCtx, TUserId>
            {
                RunOnThread = true,
                Func        = executeNode
            });

            if (result)
            {
                return(await executeNode.TaskCompletionSource.Task);
            }
            else
            {
                // TODO return an error.
                return(null);
            }
        }
Example #3
0
    public override void OnInspectorGUI()
    {
        cutScene = (CutScene)target;
        if (cutScene.nodeList == null)
        {
            cutScene.nodeList      = new List <CutSceneNodes>();
            cutScene.csnl          = ScriptableObject.CreateInstance <CutSceneNodeList>();
            cutScene.csnl.nodeList = cutScene.nodeList;
            createCutSceneAsset();
        }

        //CutSceneSystem
        cutScene.css  = GameObject.Find("CutSceneSystem").GetComponent <CutSceneSystem>();
        cutScene.css  = (CutSceneSystem)EditorGUILayout.ObjectField("Cut Scene System", cutScene.css, typeof(CutSceneSystem), true);
        cutScene.csnl = (CutSceneNodeList)EditorGUILayout.ObjectField("Cut Scene Asset:", cutScene.csnl, typeof(CutSceneNodeList), true);
        if (cutScene.csnl != null)
        {
            cutScene.nodeList = cutScene.csnl.nodeList;
        }


        //switch system here:
        listOfSwitches.Clear();
        listOfSwitches.Add("None");
        foreach (GameSwitch gameSwitch in cutScene.css.SwitchVariables)
        {
            listOfSwitches.Add(gameSwitch.name);
        }
        cutScene.indexOfSwitch = EditorGUILayout.Popup("Switch to check: ", cutScene.indexOfSwitch, listOfSwitches.ToArray());
        if (cutScene.css.SwitchVariables.Count > 0 && (cutScene.indexOfSwitch - 1) >= 0)
        {
            cutScene.gameSwitch = cutScene.css.SwitchVariables [cutScene.indexOfSwitch - 1];
        }
        else
        {
            cutScene.gameSwitch = null;
        }

        //draw bool options
        bool pauseGame = GUILayout.Toggle(cutScene.pauseGame, "Pause The Game", GUILayout.Width(300));

        cutScene.pauseGame = pauseGame;

        //show list
        grouping = false;
        foreach (CutSceneNodes nodeS in cutScene.nodeList)
        {
            GUILayout.BeginVertical("box");

            if (!(nodeS is CompositeCutSceneNode))
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("- Delete", GUILayout.Width(100)))
                {
                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(nodeS));
                    cutScene.nodeList.Remove(nodeS);
                }
                if (GUILayout.Button("[MOVE UP]", GUILayout.Width(100)))
                {
                    changeOrder       = true;
                    nodeToChange      = nodeS;
                    directionToChange = -1;
                }
                if (GUILayout.Button("[MOVE DOWN]", GUILayout.Width(100)))
                {
                    changeOrder       = true;
                    nodeToChange      = nodeS;
                    directionToChange = 1;
                }
                GUILayout.EndHorizontal();
                nodeS.createUIDescription(cutScene, serializedObject);
                if (cutScene.nodeList.IndexOf(nodeS) + 1 < cutScene.nodeList.Count)
                {
                    if (GUILayout.Button("Group With Next Node"))
                    {
                        grouping = true;
                        index1   = cutScene.nodeList.IndexOf(nodeS);
                        index2   = index1 + 1;
                    }
                }
            }
            else
            {
                CompositeCutSceneNode nodeC = (CompositeCutSceneNode)nodeS;
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("[MOVE UP]", GUILayout.Width(100)))
                {
                    changeOrder       = true;
                    nodeToChange      = nodeS;
                    directionToChange = -1;
                }
                if (GUILayout.Button("[MOVE DOWN]", GUILayout.Width(100)))
                {
                    changeOrder       = true;
                    nodeToChange      = nodeS;
                    directionToChange = 1;
                }
                GUILayout.EndHorizontal();
                if (nodeC.children.Count > 0)
                {
                    for (int j = 0; j < nodeC.children.Count; j++)
                    {
                        CutSceneNodes nodeSC = nodeC.children[j];
                        if (GUILayout.Button("- Delete", GUILayout.Width(100)))
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(nodeSC));
                            nodeC.children.Remove(nodeSC);
                        }
                        nodeSC.createUIDescription(cutScene, serializedObject);
                        if (j + 1 < nodeC.children.Count)
                        {
                            if (GUILayout.Button("-- Break Group Here --"))
                            {
                                CompositeCutSceneNode newComp = new CompositeCutSceneNode();
                                newComp.children = nodeC.children.GetRange(j + 1, nodeC.children.Count - 1 - j);
                                nodeC.children.RemoveRange(j + 1, nodeC.children.Count - 1 - j);
                                int index = cutScene.nodeList.IndexOf(nodeS);
                                cutScene.nodeList.Insert(index + 1, newComp);
                            }
                        }
                    }
                }

                if (cutScene.nodeList.IndexOf(nodeS) + 1 < cutScene.nodeList.Count)
                {
                    if (GUILayout.Button("Group With Next Node"))
                    {
                        grouping = true;
                        index1   = cutScene.nodeList.IndexOf(nodeS);
                        index2   = index1 + 1;
                    }
                }
            }
            //nodeS.playWithNext = EditorGUILayout.Toggle("Play With Next: ",nodeS.playWithNext);
            GUILayout.EndVertical();
            EditorUtility.SetDirty(cutScene);
        }

        //draw buttons for adding and subtracting the cutscene sequence:
        GUILayout.BeginHorizontal();
        type = (TypesOfNode)EditorGUILayout.EnumPopup("Type of node: ", type);
        if (GUILayout.Button("Add Node", GUILayout.Width(100)))
        {
            switch (type)
            {
            case TypesOfNode.Animation:
                AnimationNode newAnimation = ScriptableObject.CreateInstance <AnimationNode>();
                newAnimation.cutScene = cutScene;
                cutScene.nodeList.Add(newAnimation);
                createNodeAsset(newAnimation);
                break;

            case TypesOfNode.Dialogue:
                Dialogue newDialogue = ScriptableObject.CreateInstance <Dialogue>();
                newDialogue.cutScene = cutScene;
                cutScene.nodeList.Add(newDialogue);
                createNodeAsset(newDialogue);
                break;

            case TypesOfNode.DialogueNonStop:
                DialogueNonStop newDialogueNonStop = ScriptableObject.CreateInstance <DialogueNonStop>();
                newDialogueNonStop.cutScene = cutScene;
                cutScene.nodeList.Add(newDialogueNonStop);
                createNodeAsset(newDialogueNonStop);
                break;

            case TypesOfNode.ExecuteFunctionNode:
                ExecuteFunctionNode newExecuteFunctionNode = ScriptableObject.CreateInstance <ExecuteFunctionNode>();
                newExecuteFunctionNode.cutScene = cutScene;
                cutScene.nodeList.Add(newExecuteFunctionNode);
                createNodeAsset(newExecuteFunctionNode);
                break;

            case TypesOfNode.SetActiveNode:
                SetActiveNode newSetActiveNode = ScriptableObject.CreateInstance <SetActiveNode>();
                newSetActiveNode.cutScene = cutScene;
                cutScene.nodeList.Add(newSetActiveNode);
                createNodeAsset(newSetActiveNode);
                break;

            case TypesOfNode.SetSwitchValue:
                SetSwitchValueNode newSetSwitchValueNode = ScriptableObject.CreateInstance <SetSwitchValueNode>();
                newSetSwitchValueNode.cutScene = cutScene;
                cutScene.nodeList.Add(newSetSwitchValueNode);
                createNodeAsset(newSetSwitchValueNode);
                break;

            case TypesOfNode.DecisionOnSwitchNode:
                DecisionSwitchNode newDecisionSwitchNode = ScriptableObject.CreateInstance <DecisionSwitchNode>();
                newDecisionSwitchNode.cutScene = cutScene;
                cutScene.nodeList.Add(newDecisionSwitchNode);
                createNodeAsset(newDecisionSwitchNode);
                break;

            case TypesOfNode.WaitForSecondsNode:
                WaitForTimeNode newWaitForSeconds = ScriptableObject.CreateInstance <WaitForTimeNode>();
                newWaitForSeconds.cutScene = cutScene;
                cutScene.nodeList.Add(newWaitForSeconds);
                createNodeAsset(newWaitForSeconds);
                break;

            case TypesOfNode.PlayAudioNode:
                PlayAudio newPlayAudio = ScriptableObject.CreateInstance <PlayAudio>();
                newPlayAudio.cutScene = cutScene;
                cutScene.nodeList.Add(newPlayAudio);
                createNodeAsset(newPlayAudio);
                break;

            case TypesOfNode.FunctionWithParametersNode:
                FunctionWithParametersNode newFunctionWithParametersNode = ScriptableObject.CreateInstance <FunctionWithParametersNode>();
                newFunctionWithParametersNode.cutScene = cutScene;
                cutScene.nodeList.Add(newFunctionWithParametersNode);
                createNodeAsset(newFunctionWithParametersNode);
                break;

            case TypesOfNode.FadeInNode:
                FadeInSpriteNode newFadeInSpriteNode = ScriptableObject.CreateInstance <FadeInSpriteNode>();
                newFadeInSpriteNode.cutScene = cutScene;
                cutScene.nodeList.Add(newFadeInSpriteNode);
                createNodeAsset(newFadeInSpriteNode);
                break;

            case TypesOfNode.FadeOutNode:
                FadeOutSpriteNode newFadeOutSpriteNode = ScriptableObject.CreateInstance <FadeOutSpriteNode>();
                newFadeOutSpriteNode.cutScene = cutScene;
                cutScene.nodeList.Add(newFadeOutSpriteNode);
                createNodeAsset(newFadeOutSpriteNode);
                break;
            }
        }

        /*if(GUILayout.Button("+Dialogo",GUILayout.Width(100))){
         *      Dialogue newDialogue = new Dialogue();
         *      newDialogue.cutScene = cutScene;
         *      cutScene.nodeList.Add(newDialogue);
         *      //EditorUtility.SetDirty(newDialogue);
         * }
         * if(GUILayout.Button("+Animation",GUILayout.Width(100))){
         *      AnimationNode newAnimation = new AnimationNode();
         *      newAnimation.cutScene = cutScene;
         *      cutScene.nodeList.Add(newAnimation);
         * }*/
        GUILayout.EndHorizontal();

        if (grouping)
        {
            CutSceneNodes g1 = cutScene.nodeList[index1];
            CutSceneNodes g2 = cutScene.nodeList[index2];
            if (g1 is CompositeCutSceneNode)
            {
                if (g2 is CompositeCutSceneNode)
                {
                    ((CompositeCutSceneNode)g1).children.AddRange(((CompositeCutSceneNode)g2).children);
                    cutScene.nodeList.Remove(g2);
                }
                else
                {
                    ((CompositeCutSceneNode)g1).children.Add(g2);
                    cutScene.nodeList.Remove(g2);
                }
            }
            else
            {
                if (g2 is CompositeCutSceneNode)
                {
                    ((CompositeCutSceneNode)g2).children.Insert(0, g1);
                    cutScene.nodeList.Remove(g1);
                }
                else
                {
                    CompositeCutSceneNode composite = new CompositeCutSceneNode();
                    composite.children.Add(g1);
                    composite.children.Add(g2);
                    cutScene.nodeList.Insert(index2 + 1, composite);
                    cutScene.nodeList.Remove(g1);
                    cutScene.nodeList.Remove(g2);
                }
            }
            grouping = false;
        }

        foreach (CutSceneNodes nodeS in cutScene.nodeList)
        {
            if (nodeS is CompositeCutSceneNode)
            {
                if (((CompositeCutSceneNode)nodeS).children.Count < 1)
                {
                    cutScene.nodeList.Remove(nodeS);
                }
                else if (((CompositeCutSceneNode)nodeS).children.Count == 1)
                {
                    int index = cutScene.nodeList.IndexOf(nodeS);
                    cutScene.nodeList.Insert(index + 1, ((CompositeCutSceneNode)nodeS).children[0]);
                    cutScene.nodeList.Remove(nodeS);
                }
            }
        }
        //changeOrderHere
        if (changeOrder)
        {
            int indexOld = cutScene.nodeList.IndexOf(nodeToChange);
            int newIndex = indexOld + directionToChange;
            if (newIndex >= 0 && newIndex < cutScene.nodeList.Count)
            {
                CutSceneNodes n = cutScene.nodeList[newIndex];
                if (indexOld > newIndex)
                {
                    cutScene.nodeList.RemoveAt(indexOld);
                    cutScene.nodeList.RemoveAt(newIndex);
                    cutScene.nodeList.Insert(newIndex, nodeToChange);
                    cutScene.nodeList.Insert(indexOld, n);
                }
                else
                {
                    cutScene.nodeList.RemoveAt(newIndex);
                    cutScene.nodeList.RemoveAt(indexOld);
                    cutScene.nodeList.Insert(indexOld, n);
                    cutScene.nodeList.Insert(newIndex, nodeToChange);
                }
            }
        }
        //finish changing order
        changeOrder       = false;
        nodeToChange      = null;
        directionToChange = 0;
        if (GUI.changed)
        {
            serializedObject.ApplyModifiedProperties();
        }
    }