public void Export(BaseNode rootNode, string configName) { string configPath = BTUtils.GetGenPath() + configName + ".json"; string fullConfigPath = BTUtils.GetGenPath() + configName + "_full.json"; string nodeMapPath = BTUtils.GetGenPath() + configName + "_node_map.json"; Dictionary <string, BaseNodeData> baseNodeDataDict = new Dictionary <string, BaseNodeData>(); Dictionary <string, MergePyData> dataDict = new Dictionary <string, MergePyData>(); BTUtils.DumpTree(rootNode, (BaseNode node) => { BaseNodeData nodeData = NodeDataManager.Get(node); if (nodeData != null) { nodeData.Serialize(node); dataDict[node.name] = new MergePyData(node); baseNodeDataDict[node.name] = nodeData; } }); BTUtils.SaveJsonToFile <Dictionary <string, MergePyData> >(dataDict, configPath); BaseNodeData rootNodeData = NodeDataManager.Get(rootNode); BTUtils.SaveJsonToFile <BaseNodeData>(rootNodeData, fullConfigPath); BTUtils.SaveJsonToFile <Dictionary <string, BaseNodeData> >(baseNodeDataDict, nodeMapPath); }
private void CheckNodeType(BaseNodeData baseNodeData) // Checking node type based on its data { switch (baseNodeData) { case StartNodeData nodeData: RunNode(nodeData); break; case DialogueNodeData nodeData: RunNode(nodeData); break; case EventNodeData nodeData: RunNode(nodeData); break; case EndNodeData nodeData: RunNode(nodeData); break; case StatCheckNodeData nodeData: RunNode(nodeData); break; case ItemCheckNodeData nodeData: RunNode(nodeData); break; default: throw new IndexOutOfRangeException(); } }
private void EvaluateConditionNode(ConditionNodeData node) { List <NodeLinkData> nextNodes = GetLinks(node.guid); BaseNodeData nextNode = GetTargetNode(node.conditionToTest.Value ? nextNodes[0] : nextNodes[1]); PlayNode(nextNode); }
public virtual void Sync(BaseNodeData otherData) { this.id = otherData.id; this.name = otherData.name; this.x = (int)otherData.x; this.y = (int)otherData.y; this.outPoint = otherData.outPoint; this.inPoint = otherData.inPoint; this.properties = otherData.properties; }
private void RemoveTreeConnection() { //out's child remove in this.outPoint.node.childs.Remove(this.inPoint.node); //out's child remove in BaseNodeData outNodeData = NodeDataManager.Get(this.outPoint.node); BaseNodeData inNodeData = NodeDataManager.Get(this.inPoint.node); NodeDataManager.Remove(this, outNodeData); }
public static void SaveCurrentNode() { if (selectedNode != null) { BaseNodeData nodeData = NodeDataManager.Get(selectedNode); if (nodeData != null) { nodeData.Serialize(selectedNode); } } }
private void OnButtonClick(NodeLinkData linkData, DialogueCondition conditionToToggle) { if (conditionToToggle != null) { conditionToToggle.ToggleValue(); } BaseNodeData nextNode = GetTargetNode(linkData); PlayNode(nextNode); }
public BaseNodeData CopyData(bool keepGuid = true) { var data = new BaseNodeData { guid = keepGuid ? guid : Guid.NewGuid().ToString(), nodeName = nodeName, position = GetPosition().position, nodeType = nodeType, }; return(data); }
public static void Remove(BaseNode node) { BaseNodeData logicInfo = Get(node); for (int i = 0; i < s_nodeDataList.Count; i++) { if (logicInfo.id == s_nodeDataList[i].id) { s_nodeDataList.RemoveAt(i); break; } } }
public static void Remove(Connection connection, BaseNodeData outNodeData) { ConnectionData data = Get(connection); for (int i = 0; i < s_connectionDataList.Count; i++) { if (data.id == s_connectionDataList[i].id) { s_connectionDataList.RemoveAt(i); outNodeData.connectionList.Remove(s_connectionDataList[i]); break; } } }
/// <summary> /// 获取节点数据 /// </summary> /// <param name="node"></param> /// <returns></returns> public static BaseNodeData Get(int id) { BaseNodeData nodeData = null; for (int i = 0; i < s_nodeDataList.Count; i++) { if (id == s_nodeDataList[i].id) { nodeData = s_nodeDataList[i]; break; } } return(nodeData); }
private void BuildTreeConnection() { //out's child is in this.outPoint.node.childs.Add(this.inPoint.node); //out's child is in BaseNodeData outNodeData = NodeDataManager.Get(this.outPoint.node); BaseNodeData inNodeData = NodeDataManager.Get(this.inPoint.node); ConnectionData connectionData = NodeDataManager.CreateConnectionData(this); connectionData.targetNodeId = inNodeData.id; outNodeData.connectionList.Add(connectionData); }
public virtual void DeSerialize(ref BaseNode node) { BaseNodeData oldData = NodeDataManager.Get(node); //this可能不是node对应的那份数据 oldData.Sync(this); node.id = this.id; node.name = this.name; node.rect.x = this.x; node.rect.y = this.y; //node.outPoint = BTEditorManager.GetObject<ConnectionPoint>(this.outPoint); //node.inPoint = BTEditorManager.GetObject<ConnectionPoint>(this.inPoint); node.properties = this.properties; }
public void Import(string configName) { BTEditorManager.Clear(); //string configPath = BTUtils.GetGenPath() + configName + ".json"; //string fullConfigPath = BTUtils.GetGenPath() + configName + "_full.json"; //BaseNodeData rootNodeData = BTUtils.GetJsonFromFile<BaseNodeData>(fullConfigPath); string nodeMapPath = BTUtils.GetGenPath() + configName + "_node_map.json"; nodeMap = BTUtils.GetJsonFromFile <Dictionary <string, BaseNodeData> >(nodeMapPath); BaseNodeData rootNodeData = GetNodeMapData(0); CreateTree(0, null, rootNodeData, null); }
public void PlayDialogue(DialogueContainer container) { if (container == null) { Debug.LogError("No dialogue provided by trigger. Aborting conversation."); return; } dialogueContainer = container; BaseNodeData startingNode = GetTargetNode(dialogueContainer.nodeLinkData.Find(data => data.baseNodeGuid == dialogueContainer.entryNode.guid)); PlayNode(startingNode); dialoguePanel.gameObject.SetActive(true); }
public void Next(int selectedId = -1) { Debug.Log("Going next.."); if (currentNodeLink.nextNodeGuid == null) { Debug.Log("Dialogue Ended"); return; } // If pressing Next on DialogueSingle (no multiple options - one outcome) if (selectedId == -1) { currentNode = currentContainer.nodesContainer.baseNodesData.Find(x => x.guid == currentNodeLink.nextNodeGuid); currentNodeLink = currentContainer.nodesContainer.nodeLinks.Find(x => x.thisNodeGuid == currentNode.guid); } else // If pressing Next on DialogueOptions (need to find a correspondent option) { var allNextLinks = currentContainer.nodesContainer.nodeLinks.FindAll(x => x.thisNodeGuid == currentNodeLink.thisNodeGuid); currentNodeLink = currentContainer.nodesContainer.nodeLinks.Find(x => x.thisNodeGuid == allNextLinks[selectedId].nextNodeGuid); currentNode = currentContainer.nodesContainer.baseNodesData.Find(x => x.guid == currentNodeLink.thisNodeGuid); } Debug.Log($"Current Node: {currentNode.nodeType} {currentNode.guid}"); switch (currentNode.nodeType) { case NodeType.ChoiceNode: var currentNodeDataChoice = currentContainer.nodesContainer.choiceNodesData.Find(x => x.guid == currentNode.guid); var allNextLinks = currentContainer.nodesContainer.nodeLinks.FindAll(x => x.thisNodeGuid == currentNodeLink.thisNodeGuid); dialogueOptions.SetupDialogue(currentNodeDataChoice.speaker, currentNodeDataChoice.dialogueText, allNextLinks); break; case NodeType.DialogueNode: var currentNodeDataDialogue = currentContainer.nodesContainer.dialogueNodesData.Find(x => x.guid == currentNode.guid); dialogueSingle.SetupDialogue(currentNodeDataDialogue.speaker, currentNodeDataDialogue.dialogueTexts); break; case NodeType.EndNode: Debug.Log("Dialogue Ended"); break; case NodeType.StartNode: Debug.Log("Dialogue Started, but how.."); break; } }
public void PlayDialogue(string dialogueName) { var dialogueIndex = dialoguesContainer.FindIndex(x => x.dialogueName.Equals(dialogueName)); Debug.Log($"Playing Dialogue {dialogueName} ({dialogueIndex})"); if (dialogueIndex == -1) { return; } currentContainer = dialoguesContainer[dialogueIndex]; currentNode = currentContainer.nodesContainer.baseNodesData.Find(x => x.nodeType == NodeType.StartNode); currentNodeLink = currentContainer.nodesContainer.nodeLinks.Find(x => x.thisNodeGuid == currentNode.guid); Debug.Log($"Current Node: {currentNode.nodeType} {currentNode.guid}"); Next(); }
private void CreateTree(int deepth, BaseNodeData lastNodeData, BaseNodeData nodeDummyData, ConnectionData connectionData) { if (deepth >= 10) { return; } //创建当前节点 BaseNode node = null; if (nodeDummyData != null) { node = BTEditorManager.AddNode <ExcelNode>(new Vector2(nodeDummyData.x, nodeDummyData.y)); nodeDummyData.DeSerialize(ref node); } //创建connection连线 if (lastNodeData != null && connectionData != null) { BaseNode lastNode = BTEditorManager.GetObject <BaseNode>(lastNodeData.id); Connection connection = BTEditorManager.CreateConnection(lastNode.outPoint, node.inPoint); connectionData.DeSerialize(ref connection); } //遍历下一个connection for (int i = 0; i < nodeDummyData.connectionList.Count; i++) { ConnectionData nextConnectionData = nodeDummyData.connectionList[i]; BaseNodeData targetNodeData = GetNodeMapData(nextConnectionData.targetNodeId); if (targetNodeData == null) { Debug.LogError(string.Format("找不到{0}的节点!", nextConnectionData.targetNodeId)); return; } CreateTree( deepth + 1, //deepth nodeDummyData, //last targetNodeData, //this nextConnectionData ); } }
public ChoiceNode(DialogueGraphView _graphView, BaseNodeData baseData, ChoiceNodeData choiceNodeData, List<NodeLinkData> choicePorts) { graphView = _graphView; Initialize(baseData.nodeName, baseData.guid, choiceNodeData.dialogueText); SetupInputPort(); // Generate dropdown for Character var propertyIndex = _graphView.exposedProperties.FindIndex(x => x.PropertyName == choiceNodeData.speaker); SetupCharacterSelection(propertyIndex); RefreshExpandedState(); RefreshPorts(); SetPosition(new Rect(baseData.position, defaultNodeSize)); foreach (var port in choicePorts) { AddChoicePort(port.portName); } }
private static BaseNodeData GetNodeMapData(int id) { BaseNodeData result = null; if (nodeMap != null) { foreach (var kv in nodeMap) { string nodeName = kv.Key; BaseNodeData nodeData = kv.Value; if (nodeData.id.Equals(id)) { result = nodeData; break; } } } return(result); }
public DialogueNode(DialogueGraphView _graphView, BaseNodeData baseData, DialogueNodeData dialogueData) { graphView = _graphView; Initialize(baseData.nodeName, baseData.guid); SetupPorts(); var propertyIndex = _graphView.exposedProperties.FindIndex(x => x.PropertyName == dialogueData.speaker); SetupCharacterSelection(propertyIndex); SetPosition(new Rect(baseData.position, defaultNodeSize)); RefreshExpandedState(); RefreshPorts(); foreach (var text in dialogueData.dialogueTexts) { AddTextField(text); } }
private void PlayNode(BaseNodeData node) { switch (node.type) { case NodeType.NotSet: break; case NodeType.Entry: break; case NodeType.Condition: EvaluateConditionNode(node as ConditionNodeData); break; case NodeType.Dialogue: DisplayDialogueNode(node as DialogueNodeData); break; default: throw new ArgumentOutOfRangeException(); } }
private void CheckNodeType(BaseNodeData _baseNodeData) { switch (_baseNodeData) { case StartNodeData nodeData: RunNode(nodeData); break; case DialogueNodeData nodeData: RunNode(nodeData); break; case EventNodeData nodeData: RunNode(nodeData); break; case EndNodeData nodeData: RunNode(nodeData); break; default: break; } }
public NodeWidget(BaseNodeData nodeData, GlobalKey parentContainerStackKey = null, Key key = null) : base(key) { this.nodeData = nodeData; this.parentContainerStackKey = parentContainerStackKey; }
public NodeWidgetCanvasWrapperState(BaseNodeData nodeData, Key key = null) { this.nodeData = nodeData ?? new BaseNodeData(); }
// Getting next node by its link data protected BaseNodeData GetNextNode(BaseNodeData baseNodeData) { NodeLinkData nodeLinkData = currentDialogue.NodeLinkDatas.Find(egde => egde.BaseNodeGuid == baseNodeData.NodeGuid); return(GetNodeByGuid(nodeLinkData.TargetNodeGuid)); }
protected BaseNodeData GetNextNode(BaseNodeData _baseNodeData) { NodeLinkData nodeLinkData = dialogueContainer.NodeLinkDatas.Find(edge => edge.BaseNodeGuid == _baseNodeData.NodeGuid); return(GetNodeByGuid(nodeLinkData.TargetNodeGuid)); }