예제 #1
0
    public void DrawNodeGraph(Rect graphRect, DialogueAssetBuilder asset)
    {
        if (asset != null)
        {
            m_nodeGraphModel = asset.m_nodeGraphModel;
            m_assetBuilder   = asset;
        }

        if (m_nodeGraphModel.startNodeID == 0)
        {
            int id = m_nodeGraphModel.AddNode(new Vector2(10, 10));
            m_nodeGraphModel.AddOutputPlugToNode(id);
            m_nodeGraphModel.GetDataFromNodeID(id).m_isStartNode = true;
            m_nodeGraphModel.startNodeID = id;
        }

        m_nodeGraphRect = graphRect;
        BeginArea(graphRect);
        Label("Node Graph");

        // write out asset errors

        DrawGrid(graphRect, 20, 0.2f, Color.gray);  // light grid-lines
        DrawGrid(graphRect, 100, 0.4f, Color.gray); // dark grid-lines
        DrawNodes();
        DrawConnections();
        DrawActiveConnection(Event.current);
        if (m_isMultiSelectOn)
        {
            DrawMultiSelectBox();
        }
        EndArea();
    }
예제 #2
0
        public async Task <ActionResult> NodeGraph(string nodeId, string type, string subId)
        {
            var n  = DashboardModule.GetNodeById(nodeId);
            var vd = new NodeGraphModel
            {
                Node = n,
                Type = type
            };

            if (n != null)
            {
                switch (type)
                {
                case NodeGraphModel.KnownTypes.Live:
                    await PopulateModel(vd, NodeGraphModel.KnownTypes.CPU, subId).ConfigureAwait(false);
                    await PopulateModel(vd, NodeGraphModel.KnownTypes.Memory, subId).ConfigureAwait(false);

                    //await PopulateModel(vd, NodeGraphModel.KnownTypes.Network, subId);
                    break;

                case NodeGraphModel.KnownTypes.CPU:
                case NodeGraphModel.KnownTypes.Memory:
                case NodeGraphModel.KnownTypes.Network:
                case NodeGraphModel.KnownTypes.Volume:
                case NodeGraphModel.KnownTypes.VolumePerformance:
                    await PopulateModel(vd, type, subId).ConfigureAwait(false);

                    break;
                }
            }

            return(View("Node.Graph", vd));
        }
예제 #3
0
        private async Task PopulateModel(NodeGraphModel vd, string type, string subId)
        {
            var n = vd.Node;

            switch (type)
            {
            case NodeGraphModel.KnownTypes.CPU:
                vd.Title   = "CPU Utilization (" + (n.PrettyName ?? "Unknown") + ")";
                vd.CpuData = await GraphController.CPUData(n, summary : true).ConfigureAwait(false);

                break;

            case NodeGraphModel.KnownTypes.Memory:
                vd.Title      = "Memory Utilization (" + (n.TotalMemory?.ToSize() ?? "Unknown Max") + ")";
                vd.MemoryData = await GraphController.MemoryData(n, summary : true).ConfigureAwait(false);

                break;

            case NodeGraphModel.KnownTypes.Network:
                if (subId.HasValue())
                {
                    var i = vd.Node.GetInterface(subId);
                    vd.Interface   = i;
                    vd.Title       = "Network Utilization (" + (i?.PrettyName ?? "Unknown") + ")";
                    vd.NetworkData = await GraphController.NetworkData(i, summary : true).ConfigureAwait(false);
                }
                else
                {
                    vd.Title       = "Network Utilization (" + (n.PrettyName ?? "Unknown") + ")";
                    vd.NetworkData = await GraphController.NetworkData(n, summary : true).ConfigureAwait(false);
                }
                break;

            case NodeGraphModel.KnownTypes.Volume:
            {
                var v = vd.Node.GetVolume(subId);
                vd.Volume = v;
                vd.Title  = "Volume Usage (" + (v?.PrettyName ?? "Unknown") + ")";
                // TODO: Volume data
            }
            break;

            case NodeGraphModel.KnownTypes.VolumePerformance:
                if (subId.HasValue())
                {
                    var v = vd.Node.GetVolume(subId);
                    vd.Volume = v;
                    vd.Title  = "Volume Performance (" + (v?.PrettyName ?? "Unknown") + ")";
                    vd.VolumePerformanceData = await GraphController.VolumePerformanceData(v, summary : true).ConfigureAwait(false);
                }
                else
                {
                    vd.Title = "Volume Performance (" + (n.PrettyName ?? "Unknown") + ")";
                    vd.VolumePerformanceData = await GraphController.VolumePerformanceData(n, summary : true).ConfigureAwait(false);
                }
                break;
            }
        }
예제 #4
0
    public void SaveAsset(NodeGraphModel model_data)
    {
        if (m_dialogueAsset.SceneName != SceneManager.GetActiveScene().name)
        {
            return;
        }

        m_dialogueAsset.m_assetData = "";
        // save connections
        m_dialogueAsset.m_assetData += model_data.GetConnections().Count + "`";
        foreach (KeyValuePair <int, Connection> connection_pair in model_data.GetConnections())
        {
            Connection connection = connection_pair.Value;
            m_dialogueAsset.m_assetData += connection.m_id + "`";
            m_dialogueAsset.m_assetData += connection.m_inputNodeId + "`";
            m_dialogueAsset.m_assetData += connection.m_outputNodeId + "`";
            m_dialogueAsset.m_assetData += connection.m_inputPlugId + "`";
            m_dialogueAsset.m_assetData += connection.m_outputPlugId + "`";
        }

        // save nodes
        m_dialogueAsset.m_assetData += model_data.GetNodes().Count + "`";
        foreach (KeyValuePair <int, Node> node_pair in model_data.GetNodes())
        {
            Node node = node_pair.Value;
            m_dialogueAsset.m_assetData += node.m_id + "`";
            m_dialogueAsset.m_assetData += node.m_position.x + "`" + node.m_position.y + "`";
            m_dialogueAsset.m_assetData += node.m_dimension.x + "`" + node.m_dimension.y + "`";
            m_dialogueAsset.m_assetData += node.isConditionalNode + "`";
            SavePlugData(node.m_inputPlug);
            m_dialogueAsset.m_assetData += node.m_outputPlugs.Count + "`";
            foreach (KeyValuePair <int, Plug> plug_pair in node.m_outputPlugs)
            {
                Plug plug = plug_pair.Value;
                SavePlugData(plug);
            }
        }

        //clear current node assets in dialogue asset


        // save dialogue data
        ClearAsset();
        PopulateDialogueList(model_data);
        SaveBuiltDialogueData(model_data);

        // only set it to current scene if there is no scene set in the past
        if (m_dialogueAsset.SceneName == null)
        {
            m_dialogueAsset.SceneName = SceneManager.GetActiveScene().name;
        }

        EditorUtility.SetDirty(m_dialogueAsset); // tells unity to data in this asset has changed and needs to saved if user asks
        AssetDatabase.SaveAssets();
    }
예제 #5
0
    public NodeGraphView()
    {
        m_nodeGraphModel = new NodeGraphModel();

        // initializing the different syles for nodes and plugs
        m_nodeStyle = new GUIStyle();
        m_nodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node2.png") as Texture2D;
        m_nodeStyle.hover.background  = EditorGUIUtility.Load("builtin skins/darkskin/images/node4.png") as Texture2D;
        m_nodeStyle.border            = new RectOffset(12, 12, 12, 12);

        // conditional node style
        m_conditionalNodeStyle = new GUIStyle();
        m_conditionalNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node1.png") as Texture2D;
        m_conditionalNodeStyle.hover.background  = EditorGUIUtility.Load("builtin skins/darkskin/images/node4.png") as Texture2D;
        m_conditionalNodeStyle.border            = new RectOffset(12, 12, 12, 12);

        // action node style
        m_actionNodeStyle = new GUIStyle();
        m_actionNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node3.png") as Texture2D;
        m_actionNodeStyle.hover.background  = EditorGUIUtility.Load("builtin skins/darkskin/images/node4.png") as Texture2D;
        m_actionNodeStyle.border            = new RectOffset(12, 12, 12, 12);

        // option node style
        m_optionNodeStyle = new GUIStyle();
        m_optionNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node5.png") as Texture2D;
        m_optionNodeStyle.hover.background  = EditorGUIUtility.Load("builtin skins/darkskin/images/node4.png") as Texture2D;
        m_optionNodeStyle.border            = new RectOffset(12, 12, 12, 12);

        m_nodeSelectedStyle = new GUIStyle();
        m_nodeSelectedStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node4.png") as Texture2D;
        m_nodeSelectedStyle.border            = new RectOffset(15, 15, 15, 15);

        m_inputPlugStyle = new GUIStyle();
        m_inputPlugStyle.normal.background = EditorGUIUtility.Load("builtin skins/lightskin/images/btn left.png") as Texture2D;
        m_inputPlugStyle.active.background = EditorGUIUtility.Load("builtin skins/lightskin/images/btn left on.png") as Texture2D;
        m_inputPlugStyle.border            = new RectOffset(4, 4, 12, 12);

        m_outputPlugStyle = new GUIStyle();
        m_outputPlugStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right.png") as Texture2D;
        m_outputPlugStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right on.png") as Texture2D;
        m_outputPlugStyle.border            = new RectOffset(4, 4, 12, 12);

        // conditional plug styles
        //true
        m_outputTruePlugStyle = new GUIStyle();
        m_outputTruePlugStyle.normal.background = EditorGUIUtility.Load("builtin skins/lightskin/images/btn right.png") as Texture2D;
        m_outputTruePlugStyle.active.background = EditorGUIUtility.Load("builtin skins/lightskin/images/btn right on.png") as Texture2D;
        m_outputTruePlugStyle.border            = new RectOffset(4, 4, 12, 12);
        //false
        m_outputFalsePlugStyle = new GUIStyle();
        m_outputFalsePlugStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right.png") as Texture2D;
        m_outputFalsePlugStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right on.png") as Texture2D;
        m_outputFalsePlugStyle.border            = new RectOffset(4, 4, 12, 12);
    }
예제 #6
0
 // edit here when dialogue data changes
 private void SaveEditorDialogueData(NodeGraphModel model_data)
 {
     // save dialogue data
     m_dialogueAsset.m_assetData += model_data.GetDialogueData().Count + "`";
     foreach (KeyValuePair <int, DialogueData> pair in model_data.GetDialogueData())
     {
         DialogueData dialogue = pair.Value;
         m_dialogueAsset.m_assetData += dialogue.node_id + "`";
         m_dialogueAsset.m_assetData += dialogue.characterName + "`";
         m_dialogueAsset.m_assetData += dialogue.dialogueText + "`";
         m_dialogueAsset.m_assetData += dialogue.previewDialogueText + "`";
         m_dialogueAsset.m_assetData += dialogue.m_isStartNode + "`";
     }
 }
예제 #7
0
        public async Task <ActionResult> NodeGraph(string nodeId, string type, string subId)
        {
            var n  = DashboardData.GetNodeById(nodeId);
            var vd = new NodeGraphModel
            {
                Node = n,
                Type = type
            };

            if (n != null)
            {
                switch (type)
                {
                case NodeGraphModel.KnownTypes.CPU:
                    vd.Title     = "CPU Utilization (" + (n.PrettyName ?? "Unknown") + ")";
                    vd.GraphData = await GraphController.CPUData(n, summary : true);

                    break;

                case NodeGraphModel.KnownTypes.Memory:
                    vd.Title     = "Memory Utilization (" + (n.TotalMemory?.ToSize() ?? "Unknown Max") + ")";
                    vd.GraphData = await GraphController.MemoryData(n, summary : true);

                    break;

                case NodeGraphModel.KnownTypes.Network:
                    if (subId.HasValue())
                    {
                        var i = vd.Node.GetInterface(subId);
                        vd.Interface = i;
                        vd.Title     = "Network Utilization (" + (i?.PrettyName ?? "Unknown") + ")";
                        vd.GraphData = await GraphController.NetworkData(i, summary : true);
                    }
                    else
                    {
                        vd.Title     = "Network Utilization (" + (n.PrettyName ?? "Unknown") + ")";
                        vd.GraphData = await GraphController.NetworkData(n, summary : true);
                    }
                    break;

                case NodeGraphModel.KnownTypes.Volume:
                    var v = vd.Node.GetVolume(subId);
                    vd.Volume = v;
                    vd.Title  = "Volume Usage (" + (v?.PrettyName ?? "Unknown") + ")";
                    break;
                }
            }

            return(View("Node.Graph", vd));
        }
예제 #8
0
    public void DrawNodeProperties(Rect propertiesRect, Node selected_node, DialogueAssetBuilder asset)
    {
        if (asset != null)
        {
            m_nodeGraphModel = asset.m_nodeGraphModel;
        }

        m_nodePropertiesRect = new Rect(propertiesRect.position.x + 5f, propertiesRect.position.y + 5f, propertiesRect.width - 10f, propertiesRect.height - 10f);
        BeginArea(m_nodePropertiesRect);
        if (selected_node != null) // if there has been a node selected, display that node's properties
        {
            int node_id = selected_node.m_id;
            Label("Node Properties");
            DialogueData data = m_nodeGraphModel.GetDataFromNodeID(node_id);
            if (data != null)
            {
                data.m_isStartNode = Toggle(data.m_isStartNode, "Is start node");
                Label(" ");

                Label("Character Speaking");
                data.characterName = TextArea(data.characterName);

                Label("Preview Text");
                data.previewDialogueText = TextArea(data.previewDialogueText, Height(50));

                Label("Dialogue Text");
                data.dialogueText = TextArea(data.dialogueText, Height(m_nodePropertiesRect.height * 0.5f));
            }

            if (m_nodeGraphModel != null)
            {
                if (Button("Add Dialogue Option"))
                {
                    m_nodeGraphModel.AddOutputPlugToNode(node_id);
                }
            }
        }
        else if (asset != null) // display asset properties
        {
            Label("Dialogue Asset");
            if (Button("Save Asset"))
            {
                // save asset
                asset.SaveAsset(m_nodeGraphModel);
            }
        }
        EndArea();
    }
예제 #9
0
    private void PopulateDialogueList(NodeGraphModel model_data)
    {
        m_dialogueAsset.m_dialogueData = new Dictionary <int, DialogueData>();

        foreach (KeyValuePair <int, DialogueData> dialogue_pair in model_data.GetDialogueData())
        {
            List <NextDialogueDataContent> nextData = new List <NextDialogueDataContent>();
            DialogueData dialogue = dialogue_pair.Value;
            // populating next branch ids
            dialogue.m_isBranching      = model_data.GetNodeFromID(dialogue.node_id).m_outputPlugs.Count > 1;
            dialogue.m_nextDialogueData = new List <int>();
            foreach (KeyValuePair <int, Connection> connection_pair in model_data.GetConnections())
            {
                Connection connection = connection_pair.Value;
                if (connection.m_outputNodeId == dialogue.node_id)
                {
                    // adding branching indices
                    DialogueData            next_data       = model_data.GetDataFromNodeID(connection.m_inputNodeId);
                    NextDialogueDataContent nextDataContent = new NextDialogueDataContent();

                    if (next_data.branchingIndex == -1)
                    {
                        Plug outputplug_index = model_data.GetNodeFromID(connection.m_outputNodeId).m_outputPlugs[connection.m_outputPlugId];
                        Debug.Log(outputplug_index.m_plugIndex);
                        next_data.branchingIndex = outputplug_index.m_plugIndex;
                    }

                    nextDataContent.branchingIndex = next_data.branchingIndex;
                    nextDataContent.nextNodeIndex  = connection.m_inputNodeId;
                    nextData.Add(nextDataContent);
                }
            }

            nextData.Sort(delegate(NextDialogueDataContent c1, NextDialogueDataContent c2) { return(c1.branchingIndex.CompareTo(c2.branchingIndex)); });
            foreach (NextDialogueDataContent next_data in nextData)
            {
                dialogue.m_nextDialogueData.Add(next_data.nextNodeIndex);
            }

            // sort the next dialogue data by index;
            m_dialogueAsset.m_dialogueData.Add(dialogue.node_id, dialogue);
        }
    }
예제 #10
0
    private void PopulateDialogueList(NodeGraphModel model_data)
    {
        m_dialogueAsset.m_dialogueData = new Dictionary <int, DialogueData>();

        foreach (KeyValuePair <int, DialogueData> dialogue_pair in model_data.GetDialogueData())
        {
            DialogueData dialogue = dialogue_pair.Value;
            // populating next branch ids
            dialogue.m_isBranching      = model_data.GetNodeFromID(dialogue.node_id).m_outputPlugs.Count > 1;
            dialogue.m_nextDialogueData = new List <int>();
            foreach (KeyValuePair <int, Connection> connection_pair in model_data.GetConnections())
            {
                Connection connection = connection_pair.Value;
                if (connection.m_outputNodeId == dialogue.node_id)
                {
                    dialogue.m_nextDialogueData.Add(connection.m_inputNodeId);
                }
            }
            m_dialogueAsset.m_dialogueData.Add(dialogue.node_id, dialogue);
        }
    }
예제 #11
0
    public void DrawNodeGraph(Rect graphRect, DialogueAssetBuilder asset)
    {
        if (asset != null)
        {
            m_nodeGraphModel = asset.m_nodeGraphModel;
        }

        m_nodeGraphRect = graphRect;
        BeginArea(graphRect);
        Label("Node Graph");
        DrawGrid(graphRect, 20, 0.2f, Color.gray);  // light grid-lines
        DrawGrid(graphRect, 100, 0.4f, Color.gray); // dark grid-lines
        DrawNodes();
        DrawConnections();
        DrawActiveConnection(Event.current);
        if (m_isMultiSelectOn)
        {
            DrawMultiSelectBox();
        }
        EndArea();
    }
예제 #12
0
    private void SaveBuiltDialogueData(NodeGraphModel model_data)
    {
        m_dialogueAsset.m_runtimeBuiltData = new List <DialogueData>();
        int start_node_index = 0;

        foreach (KeyValuePair <int, DialogueData> pair in m_dialogueAsset.m_dialogueData)
        {
            DialogueData dialogue = pair.Value;
            if (dialogue.m_isStartNode)
            {
                start_node_index = dialogue.node_id;
            }

            m_dialogueAsset.m_runtimeBuiltData.Add(dialogue);
            dialogue.name = dialogue.node_id.ToString();
            AssetDatabase.AddObjectToAsset(dialogue, m_dialogueAsset);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(dialogue));
            EditorUtility.SetDirty(dialogue);
        }
        m_dialogueAsset.m_startIndex = start_node_index;
        m_dialogueAsset.m_charactersInvolvedStrings = m_dialogueAsset.GetInvolvedCharacterStrings();
    }
예제 #13
0
    public void SaveAsset(NodeGraphModel model_data)
    {
        m_dialogueAsset.m_assetData = "";
        // save connections
        m_dialogueAsset.m_assetData += model_data.GetConnections().Count + "`";
        foreach (KeyValuePair <int, Connection> connection_pair in model_data.GetConnections())
        {
            Connection connection = connection_pair.Value;
            m_dialogueAsset.m_assetData += connection.m_id + "`";
            m_dialogueAsset.m_assetData += connection.m_inputNodeId + "`";
            m_dialogueAsset.m_assetData += connection.m_outputNodeId + "`";
            m_dialogueAsset.m_assetData += connection.m_inputPlugId + "`";
            m_dialogueAsset.m_assetData += connection.m_outputPlugId + "`";
        }

        // save nodes
        m_dialogueAsset.m_assetData += model_data.GetNodes().Count + "`";
        foreach (KeyValuePair <int, Node> node_pair in model_data.GetNodes())
        {
            Node node = node_pair.Value;
            m_dialogueAsset.m_assetData += node.m_id + "`";
            m_dialogueAsset.m_assetData += node.m_position.x + "`" + node.m_position.y + "`";
            m_dialogueAsset.m_assetData += node.m_dimension.x + "`" + node.m_dimension.y + "`";
            SavePlugData(node.m_inputPlug);
            m_dialogueAsset.m_assetData += node.m_outputPlugs.Count + "`";
            foreach (KeyValuePair <int, Plug> plug_pair in node.m_outputPlugs)
            {
                Plug plug = plug_pair.Value;
                SavePlugData(plug);
            }
        }

        // save dialogue data
        SaveEditorDialogueData(model_data);
        SaveRuntimeDialogueData(model_data);

        EditorUtility.SetDirty(m_dialogueAsset); // tells unity to data in this asset has changed and needs to saved if user asks
    }
예제 #14
0
    public List <int> GetNextDialogueData(DialogueData data, NodeGraphModel model_data)
    {
        List <NextDialogueDataContent> nextData = new List <NextDialogueDataContent>();
        DialogueData dialogue = data;

        // populating next branch ids
        dialogue.m_nextDialogueData = new List <int>();
        foreach (KeyValuePair <int, Connection> connection_pair in model_data.GetConnections())
        {
            Connection connection = connection_pair.Value;
            if (connection.m_outputNodeId == dialogue.node_id)
            {
                // adding branching indices
                DialogueData            next_data       = model_data.GetDataFromNodeID(connection.m_inputNodeId);
                NextDialogueDataContent nextDataContent = new NextDialogueDataContent();

                if (next_data.branchingIndex == -1)
                {
                    Plug outputplug_index = model_data.GetNodeFromID(connection.m_outputNodeId).m_outputPlugs[connection.m_outputPlugId];
                    Debug.Log(outputplug_index.m_plugIndex);
                    next_data.branchingIndex = outputplug_index.m_plugIndex;
                }
                nextDataContent.branchingIndex = next_data.branchingIndex;
                nextDataContent.nextNodeIndex  = connection.m_inputNodeId;
                nextData.Add(nextDataContent);
            }
        }

        nextData.Sort(delegate(NextDialogueDataContent c1, NextDialogueDataContent c2) { return(c1.branchingIndex.CompareTo(c2.branchingIndex)); });
        foreach (NextDialogueDataContent next_data in nextData)
        {
            dialogue.m_nextDialogueData.Add(next_data.nextNodeIndex);
        }

        return(dialogue.m_nextDialogueData);
    }
예제 #15
0
    public void LoadEditorSaveData()
    {
        m_nodeGraphModel = new NodeGraphModel();

        string[] data       = m_dialogueAsset.m_assetData.Split("`".ToCharArray());
        int      data_index = 0;

        if (data.Length <= 1) // no data in the asset at the moment
        {
            return;
        }

        // load connections
        int connectionCount = int.Parse(data[data_index++]);

        for (int connection_index = 0; connection_index < connectionCount; ++connection_index)
        {
            Connection connection = new Connection();
            connection.m_id           = int.Parse(data[data_index++]);
            connection.m_inputNodeId  = int.Parse(data[data_index++]);
            connection.m_outputNodeId = int.Parse(data[data_index++]);
            connection.m_inputPlugId  = int.Parse(data[data_index++]);
            connection.m_outputPlugId = int.Parse(data[data_index++]);
            m_nodeGraphModel.AddConnection(connection);
        }

        // load nodes
        int node_count = int.Parse(data[data_index++]);

        for (int node_index = 0; node_index < node_count; ++node_index)
        {
            Node node = new Node();
            node.m_id          = int.Parse(data[data_index++]);
            node.m_position    = new Vector2();
            node.m_position.x  = float.Parse(data[data_index++]); node.m_position.y = float.Parse(data[data_index++]);
            node.m_dimension   = new Vector2();
            node.m_dimension.x = float.Parse(data[data_index++]); node.m_dimension.y = float.Parse(data[data_index++]);
            node.m_inputPlug   = LoadInputPlug(data, ref data_index, PlugType.kIn);
            int output_plug_count = int.Parse(data[data_index++]);
            node.m_outputPlugs = new Dictionary <int, Plug>();
            for (int i = 0; i < output_plug_count; ++i)
            {
                Plug out_plug = LoadInputPlug(data, ref data_index, PlugType.kOut);
                node.m_outputPlugs.Add(out_plug.m_plugId, out_plug);
            }
            m_nodeGraphModel.AddNode(node);
        }

        // edit here when dialogue data changes
        // load dialogue data (for editor use)
        int dialogue_count = int.Parse(data[data_index++]);

        for (int dialogue_index = 0; dialogue_index < dialogue_count; ++dialogue_index)
        {
            DialogueData dialogue = new DialogueData();
            dialogue.node_id             = int.Parse(data[data_index++]);
            dialogue.characterName       = data[data_index++];
            dialogue.dialogueText        = data[data_index++];
            dialogue.previewDialogueText = data[data_index++];
            dialogue.m_isStartNode       = bool.Parse(data[data_index++]);
            m_nodeGraphModel.AddDialogueData(dialogue);
        }
    }
예제 #16
0
 private void SaveRuntimeDialogueData(NodeGraphModel model_data)
 {
     PopulateDialogueList(model_data); // kind of like what an asset builder would do but super duper lightwieght
     SaveToRuntimeDialogueData();      // a format that the game will use during runtime
 }
예제 #17
0
 public DialogueAssetBuilder()
 {
     m_nodeGraphModel = new NodeGraphModel();
 }
예제 #18
0
    public void LoadEditorSaveData()
    {
        m_nodeGraphModel = new NodeGraphModel();

        string[] data       = m_dialogueAsset.m_assetData.Split("`".ToCharArray());
        int      data_index = 0;

        if (data.Length <= 1) // no data in the asset at the moment
        {
            return;
        }

        // load connections
        int connectionCount = int.Parse(data[data_index++]);

        for (int connection_index = 0; connection_index < connectionCount; ++connection_index)
        {
            Connection connection = new Connection();
            connection.m_id           = int.Parse(data[data_index++]);
            connection.m_inputNodeId  = int.Parse(data[data_index++]);
            connection.m_outputNodeId = int.Parse(data[data_index++]);
            connection.m_inputPlugId  = int.Parse(data[data_index++]);
            connection.m_outputPlugId = int.Parse(data[data_index++]);
            m_nodeGraphModel.AddConnection(connection);
        }

        // load nodes
        int node_count = int.Parse(data[data_index++]);

        for (int node_index = 0; node_index < node_count; ++node_index)
        {
            Node node = new Node();
            node.m_id              = int.Parse(data[data_index++]);
            node.m_position        = new Vector2();
            node.m_position.x      = float.Parse(data[data_index++]); node.m_position.y = float.Parse(data[data_index++]);
            node.m_dimension       = new Vector2();
            node.m_dimension.x     = float.Parse(data[data_index++]); node.m_dimension.y = float.Parse(data[data_index++]);
            node.isConditionalNode = bool.Parse(data[data_index++]);
            node.m_inputPlug       = LoadInputPlug(data, ref data_index, PlugType.kIn);
            int output_plug_count = int.Parse(data[data_index++]);
            node.m_outputPlugs = new Dictionary <int, Plug>();
            for (int i = 0; i < output_plug_count; ++i)
            {
                Plug out_plug = LoadInputPlug(data, ref data_index, PlugType.kOut);
                node.m_outputPlugs.Add(out_plug.m_plugId, out_plug);
            }
            m_nodeGraphModel.AddNode(node);
        }

        // edit here when dialogue data changes
        for (int dialogue_index = 0; dialogue_index < m_dialogueAsset.m_runtimeBuiltData.Count; ++dialogue_index)
        {
            DialogueData dialogue = m_dialogueAsset.m_runtimeBuiltData[dialogue_index];
            dialogue.eventObjects = new List <GameObject>();
            for (int i = 0; i < dialogue.eventObjectNames.Count; ++i)
            {
                dialogue.eventObjects.Add(m_dialogueAsset.FindGameObject(dialogue.eventObjectNames[i]));
            }
            m_nodeGraphModel.AddDialogueData(dialogue);
        }
        m_nodeGraphModel.startNodeID = m_dialogueAsset.m_startIndex;
        //updating involved characters gameobject list
        m_dialogueAsset.LoadCharactersInvolvedGameObjects();
    }
예제 #19
0
    public void DrawNodeProperties(Rect propertiesRect, List <int> selected_nodes, DialogueAssetBuilder asset)
    {
        if (asset != null)
        {
            m_nodeGraphModel = asset.m_nodeGraphModel;
        }

        m_nodePropertiesRect = new Rect(propertiesRect.position.x + 5f, propertiesRect.position.y + 5f, propertiesRect.width - 10f, propertiesRect.height - 10f);
        BeginArea(m_nodePropertiesRect);
        scrollPosition = BeginScrollView(scrollPosition, false, false, Width(m_nodePropertiesRect.width), Height(m_nodePropertiesRect.height));

        EditorGUI.BeginChangeCheck();

        if (SceneManager.GetActiveScene().name == asset.m_dialogueAsset.SceneName)
        {
            // display first node properties
            if (selected_nodes != null) // if there has been a node selected, display that node's properties
            {
                Node first_node = m_nodeGraphModel.GetNodeFromID(selected_nodes[0]);
                int  node_id    = first_node.m_id;
                Label("Node Properties", EditorStyles.boldLabel);
                DialogueData data = m_nodeGraphModel.GetDataFromNodeID(node_id);
                if (data != null)
                {
                    // draw start node
                    if (data.m_isStartNode)
                    {
                        DisplayStartNodeProperties(data, node_id);
                    }
                    // draw condition node
                    else if (data.isConditionalBranching)
                    {
                        DisplayConditionalNodeProperties(data, node_id, asset);
                    }
                    // draw option node
                    else if (data.m_isBranching && !data.isConditionalBranching)
                    {
                        DisplayOptionNodeProperties(data, node_id, asset);
                    }
                    else if (data.m_isEventNode)
                    {
                        DisplayEventNode(data);
                    }
                    // draw normal node
                    else
                    {
                        DisplayNormalNodeProperties(data, asset);
                    }
                }
            }
            else if (asset != null) // display asset properties
            {
                DisplayAssetProperties(asset);
                // cheat sheet for the tags in the markup so far
                {
                    DisplayMarkupCheatSheet();
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(asset.m_dialogueAsset, "");
            }
        }
        else
        {
            Label("Used in Scene :" + asset.m_dialogueAsset.SceneName, EditorStyles.boldLabel);
            Label("Asset locked and not editable because you are in the incorrect scene");

            Label("", EditorStyles.boldLabel);
            Label("", EditorStyles.boldLabel);
            Label("ONLY DO THIS IF YOU'RE SURE", EditorStyles.boldLabel);
            if (Button("Change Asset to Current Scene"))
            {
                asset.m_dialogueAsset.SceneName = SceneManager.GetActiveScene().name;
            }
        }
        EndScrollView();
        EndArea();
    }