Exemplo n.º 1
0
    private void OnClickAddDialogueLineNode(Vector2 mousePosition)
    {
        if (nodes == null)
        {
            nodes = new List <Node>();
        }

        currentHighestID++;
        DialogueLineNode node = CreateInstance <DialogueLineNode>();

        node.Init(currentHighestID, mousePosition, DialogueLineNode.width, DialogueLineNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);

        nodes.Add(node);
    }
Exemplo n.º 2
0
    private void Load()
    {
        // Show file browser
        string assetPath = EditorUtility.OpenFilePanel("Select asset", "Assets/Resources/Dialogues", "asset");

        if (assetPath != "")
        {
            // Make selected path relative instead of absolute
            assetPath = assetPath.Replace(Application.dataPath, "Assets");
            string[] splitAssetPath = assetPath.Split('/');
            lastSavedName = splitAssetPath[splitAssetPath.Length - 1];
        }
        else
        {
            return;
        }
        // Load selected asset into container class
        dialogue = (DialogueContainer)AssetDatabase.LoadAssetAtPath(assetPath, typeof(DialogueContainer));
        // Clear nodes and connections of current dialogue
        nodes.Clear();
        connections.Clear();
        // Loop through all nodes and connections in loaded container class and add them to current dialogue
        foreach (Node node in dialogue.nodes)
        {
            if (node is StartNode)
            {
                StartNode newNode = CreateInstance <StartNode>();
                newNode.Init(node.id, node.rect.position, StartNode.width, StartNode.defaultHeight, nodeStyle, selectedNodeStyle, outPointStyle, OnClickOutPoint, OnClickRemoveNode);
                nodes.Add(newNode);
            }
            if (node is DialogueLineNode)
            {
                DialogueLineNode newNode = CreateInstance <DialogueLineNode>();
                newNode.Init(node.id, node.rect.position, DialogueLineNode.width, DialogueLineNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                DialogueLineNode tempNode = (DialogueLineNode)node;
                newNode.Load(tempNode.actorName, tempNode.dialogueLine, node.inPoints.Count, tempNode.DayBank, tempNode.Day, tempNode.Clip, tempNode.Char, tempNode._fmod, tempNode.Dia);
                nodes.Add(newNode);
            }
            else if (node is PlayerChoiceNode)
            {
                PlayerChoiceNode newNode = CreateInstance <PlayerChoiceNode>();
                newNode.Init(node.id, node.rect.position, PlayerChoiceNode.width, PlayerChoiceNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                PlayerChoiceNode tempNode = (PlayerChoiceNode)node;
                newNode.Load(tempNode.optionLines, node.inPoints.Count, node.outPoints.Count);
                nodes.Add(newNode);
            }
            else if (node is CheckVariableNode)
            {
                CheckVariableNode newNode = CreateInstance <CheckVariableNode>();
                newNode.Init(node.id, node.rect.position, CheckVariableNode.width, CheckVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                CheckVariableNode tempNode = (CheckVariableNode)node;
                newNode.Load(tempNode.boolIndex, node.inPoints.Count);
                nodes.Add(newNode);
            }
            else if (node is SetVariableNode)
            {
                SetVariableNode newNode = CreateInstance <SetVariableNode>();
                newNode.Init(node.id, node.rect.position, SetVariableNode.width, SetVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                SetVariableNode tempNode = (SetVariableNode)node;
                newNode.Load(tempNode.boolIndex, tempNode.boolValueIndex, node.inPoints.Count);
                nodes.Add(newNode);
            }

            // Make sure currentHighestID is updated to avoid multiple nodes with same id
            if (node.id > currentHighestID)
            {
                currentHighestID = node.id;
            }
        }
        foreach (Connection connection in dialogue.connections)
        {
            Connection newConnection = CreateInstance <Connection>();
            Node       inPointNode   = null;
            Node       outPointNode  = null;
            // Go through all nodes in current dialogue to find which ones to create a connection between
            foreach (Node node in nodes)
            {
                if (connection.inPoint.node.id == node.id)
                {
                    inPointNode = node;
                }
                if (connection.outPoint.node.id == node.id)
                {
                    outPointNode = node;
                }
            }
            if (inPointNode != null && outPointNode != null)
            {
                // Create a connection between nodes
                newConnection.Load(inPointNode, outPointNode, connection.inPoint.index, connection.outPoint.index, OnClickRemoveConnection);
                connections.Add(newConnection);
            }
            else
            {
                Debug.Log("Load connection failed. inPointNode: " + inPointNode + " outPointNode: " + outPointNode);
            }
        }
    }
Exemplo n.º 3
0
    private void LoadSpecific(string assetPath)
    {
        // Load selected asset into container class
        dialogue = (DialogueContainer)AssetDatabase.LoadAssetAtPath(assetPath, typeof(DialogueContainer));
        // Clear nodes and connections of current dialogue
        nodes.Clear();
        connections.Clear();
        // Loop through all nodes and connections in loaded container class and add them to current dialogue
        foreach (Node node in dialogue.nodes)
        {
            if (node is StartNode)
            {
                StartNode newNode = CreateInstance <StartNode>();
                newNode.Init(node.id, node.rect.position, StartNode.width, StartNode.defaultHeight, nodeStyle, selectedNodeStyle, outPointStyle, OnClickOutPoint, OnClickRemoveNode);
                nodes.Add(newNode);
            }
            if (node is DialogueLineNode)
            {
                DialogueLineNode newNode = CreateInstance <DialogueLineNode>();
                newNode.Init(node.id, node.rect.position, DialogueLineNode.width, DialogueLineNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                DialogueLineNode tempNode = (DialogueLineNode)node;
                newNode.Load(tempNode.actorName, tempNode.dialogueLine, node.inPoints.Count, tempNode.DayBank, tempNode.Day, tempNode.Clip, tempNode.Char, tempNode._fmod, tempNode.Dia);
                nodes.Add(newNode);
            }
            else if (node is PlayerChoiceNode)
            {
                PlayerChoiceNode newNode = CreateInstance <PlayerChoiceNode>();
                newNode.Init(node.id, node.rect.position, PlayerChoiceNode.width, PlayerChoiceNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                PlayerChoiceNode tempNode = (PlayerChoiceNode)node;
                newNode.Load(tempNode.optionLines, node.inPoints.Count, node.outPoints.Count);
                nodes.Add(newNode);
            }
            else if (node is CheckVariableNode)
            {
                CheckVariableNode newNode = CreateInstance <CheckVariableNode>();
                newNode.Init(node.id, node.rect.position, CheckVariableNode.width, CheckVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                CheckVariableNode tempNode = (CheckVariableNode)node;
                newNode.Load(tempNode.boolIndex, node.inPoints.Count);
                nodes.Add(newNode);
            }
            else if (node is SetVariableNode)
            {
                SetVariableNode newNode = CreateInstance <SetVariableNode>();
                newNode.Init(node.id, node.rect.position, SetVariableNode.width, SetVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);
                SetVariableNode tempNode = (SetVariableNode)node;
                newNode.Load(tempNode.boolIndex, tempNode.boolValueIndex, node.inPoints.Count);
                nodes.Add(newNode);
            }

            // Make sure currentHighestID is updated to avoid multiple nodes with same id
            if (node.id > currentHighestID)
            {
                currentHighestID = node.id;
            }
        }
        foreach (Connection connection in dialogue.connections)
        {
            Connection newConnection = CreateInstance <Connection>();
            Node       inPointNode   = null;
            Node       outPointNode  = null;
            // Go through all nodes in current dialogue to find which ones to create a connection between
            foreach (Node node in nodes)
            {
                if (connection.inPoint.node.id == node.id)
                {
                    inPointNode = node;
                }
                if (connection.outPoint.node.id == node.id)
                {
                    outPointNode = node;
                }
            }
            if (inPointNode != null && outPointNode != null)
            {
                // Create a connection between nodes
                newConnection.Load(inPointNode, outPointNode, connection.inPoint.index, connection.outPoint.index, OnClickRemoveConnection);
                connections.Add(newConnection);
            }
            else
            {
                Debug.Log("Load connection failed. inPointNode: " + inPointNode + " outPointNode: " + outPointNode);
            }
        }
    }
Exemplo n.º 4
0
    void NextNode(int option)
    {
        print("NextNode");
        //Remove dialogue if last
        if (!currentDialogue.nodes.ContainsKey(currentNode.nextNodesID[option]))
        {
            aOugrah.SetBool("talking", false);
            aGaregh.SetBool("talking", false);

            dialogueNameText.text        = "";
            dialogueText.text            = "";
            inDialogue                   = false;
            GameManager.instance.talking = false;
            Cursor.lockState             = CursorLockMode.Locked;
            if (_EventInstance != null)
            {
                _EventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            }
            return;
        }

        //Set current node
        currentNode = currentDialogue.GetNode(currentNode.nextNodesID[option]);

        //Check if currentNode is dialogueLine or playerLine
        if (currentNode is DialogueLineNode)
        {
            isChoice = false;
            DialogueLineNode tempNode = (DialogueLineNode)currentNode;
            setFmodParams(tempNode.DayBank, tempNode.Char, tempNode.Day, tempNode.Clip);
            if (voiceSetup)
            {
                updatePosition(tempNode.Char);
                base.Start();
                _EventInstance.start();
            }
            dialogueNameText.text = tempNode.actorName;
            dialogueText.text     = tempNode.dialogueLine;

            if (tempNode.actorName == "Ougrah")
            {
                aOugrah.SetBool("talking", true);
                aGaregh.SetBool("talking", false);
                aHania.SetBool("talking", false);
            }
            if (tempNode.actorName == "Garegh")
            {
                aOugrah.SetBool("talking", false);
                aGaregh.SetBool("talking", true);
            }
            if (tempNode.actorName == "Hania")
            {
                aOugrah.SetBool("talking", false);
                aHania.SetBool("talking", true);
            }

            if (currentDialogue.walkAndTalk)
            {
                walkietalkie  = true;
                autoClearTime = Time.time + (tempNode.dialogueLine.Length * displayTimePerChar);
            }
            else
            {
                walkietalkie = false;
            }
        }
        else if (currentNode is PlayerChoiceNode)
        {
            isChoice = true;
            PlayerChoiceNode tempNode = (PlayerChoiceNode)currentNode;

            for (int i = 0; i < tempNode.optionLines.Count; i++)
            {
                // Spawn buttons with offset
                Button choiceButton = (Button)Instantiate(choiceButtonPrefab, new Vector3((Screen.width / 2), (150 + optionsOffset.y * tempNode.optionLines.Count)) - (optionsOffset * i), Quaternion.identity);
                choiceButton.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 12 * tempNode.optionLines[i].Length);
                choiceButton.transform.SetParent(dialogueText.transform.parent);
                choiceButton.GetComponentInChildren <Text>().text = tempNode.optionLines[i];
                choiceButtons.Add(choiceButton);
            }
        }
        else if (currentNode is CheckVariableNode)
        {
            CheckVariableNode tempNode = (CheckVariableNode)currentNode;
            if (AllFlags.Instance.flags[tempNode.boolIndex].value)
            {
                NextNode(0);
            }
            else
            {
                NextNode(1);
            }
        }
        else if (currentNode is SetVariableNode)
        {
            SetVariableNode tempNode = (SetVariableNode)currentNode;
            if (tempNode.boolValueIndex == 0)
            {
                AllFlags.Instance.flags[tempNode.boolIndex].value = true;
            }
            else
            {
                AllFlags.Instance.flags[tempNode.boolIndex].value = false;
            }

            NextNode(0);
        }
    }