private void CreateNode() { NodeMeta nodeProto = BTEntity.Instance.GetNodeMeta(BTEntity.Instance.selectNodeName); BehaviorNodeData nodeData = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name); CreateNode(nodeData, MousePosToGraphPos(mMousePos)); }
public NodeDesigner(BehaviorNodeData data) { NodeData = data; DesignerData = new NodeDesignerProto(); Init(); UpdateChildren(); }
private void CreateNode() { NodeMeta nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(BTEditor.Instance.selectNodeName); BehaviorNodeData nodeData = BTEditor.Instance.CreateNode(nodeProto.name); CreateNode(nodeData, MousePosToGraphPos(mMousePos)); }
public void SelectNode(BehaviorNodeData node) { selectedNode = node; NodeProto nodeProto = NodeDataToNodeProto(node); inputValueList = GetSelectNodeInputValueList(nodeProto); }
//有待优化 private void ChangeNodeType(object obj) { string nodeType = (string)obj; NodeMeta nodeProto = BTEntity.Instance.GetNodeMeta(nodeType); BehaviorNodeData nodeData = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name); NodeDesigner oldNode = mSelectedNode; NodeDesigner newNode = new NodeDesigner(nodeData); if (oldNode == RootNode) { newNode.NodeData.Id = RootNode.NodeData.Id; RootNode = newNode; BehaviorTreeData oldTree = BTEntity.Instance.CurTree; BehaviorTreeData newTree = new BehaviorTreeData(oldTree.Id); newTree.classify = oldTree.classify; newTree.Root = nodeData; BTEntity.Instance.CurTree = newTree; } else { int idx = oldNode.Parent.Children.IndexOf(oldNode); oldNode.Parent.AddChild(newNode, idx); oldNode.Parent.RemoveChild(oldNode); } foreach (NodeDesigner child in oldNode.Children) { newNode.AddChild(child); } BTEntity.Instance.ResetTreeId(); Game.Scene.GetComponent <EventComponent>().Run(EventIdType.BehaviorTreeAfterChangeNodeType); }
public BehaviorNodeData CopyNode(BehaviorNodeData node) { BehaviorNodeData copyNode = new BehaviorNodeData(); copyNode.name = node.name; copyNode.describe = node.describe; copyNode.Pos = node.Pos; copyNode.args_dict = new BehaviorTreeArgsDict(); foreach (var item in node.args_dict) { ValueBase valueBase = ValueBase.Clone(item.Value); copyNode.args_dict.Add(item.Key, valueBase); } List <BehaviorNodeData> list = new List <BehaviorNodeData>(); foreach (var item in node.children) { list.Add(item); } foreach (var child in list) { copyNode.AddChild(CopyNode(child)); } copyNode.ResetId(); return(copyNode); }
public void PrintTree(BehaviorNodeData nodeData) { Log.Info($"PrintTree : {nodeData.Id} {nodeData}"); foreach (BehaviorNodeData data in nodeData.children) { this.PrintTree(data); } }
public void printTree(BehaviorNodeData nodeData) { Log.Info($"printTree : {nodeData.nodeId} {nodeData}"); foreach (var data in nodeData.children) { printTree(data); } }
private static void _ClearDebugState(BehaviorNodeData nodeData) { nodeData.NodeDeubgState = DebugState.Normal; foreach (BehaviorNodeData child in nodeData.children) { _ClearDebugState(child); } }
public void onCreateNode(params object[] list) { string nodeName = (string)list[0]; Vector2 pos = (Vector2)list[1]; NodeMeta nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeName); BehaviorNodeData nodeData = BTEditor.Instance.CreateNode(nodeProto.name); CreateNode(nodeData, pos); }
public void onCreateNode(params object[] list) { string name = (string)list[0]; Vector2 pos = (Vector2)list[1]; NodeMeta nodeProto = BTEntity.Instance.GetNodeMeta(name); BehaviorNodeData nodeData = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name); CreateNode(nodeData, pos); }
private void SetDebugState(BehaviorTree tree, int nodeId) { if (this.BehaviorTreeConfig != null && tree.behaviorTreeConfig.gameObject.name == this.BehaviorTreeConfig.gameObject.name) { BehaviorNodeData nodeData = GetNodeData(CurTree.Root, nodeId); if (nodeData != null) { nodeData.NodeDeubgState = DebugState.True; } } }
private void SetDebugState(int nodeId) { if (this.BehaviorTreeConfig != null) { BehaviorNodeData nodeData = GetNodeData(CurTree.Root, nodeId); if (nodeData != null) { nodeData.NodeDeubgState = DebugState.True; } } }
public BehaviorNodeData GetNode(BehaviorNodeData nodeData, int nodeId) { if (nodeData.Id == nodeId) { return(nodeData); } foreach (BehaviorNodeData data in nodeData.children) { return(GetNode(data, nodeId)); } return(null); }
public BehaviorNodeData CreateNode(int treeId, string nodeName) { if (!mName2NodeProtoDict.ContainsKey(nodeName)) { Debug.LogError($"节点类型:{nodeName}不存在"); return(null); } BehaviorNodeData node = new BehaviorNodeData(nodeName); node.nodeId = AutoNodeId(); node.name = nodeName; return(node); }
public void PasteNode() { if (mCutNode != null && mCutNode != mSelectedNode) { ConnectNode(mCutNode, mSelectedNode); } if (mCopyNode != null && mCopyNode != mSelectedNode) { BehaviorNodeData data = BTEntity.Instance.CopyNode(mCopyNode.NodeData); BTEntity.Instance.ResetTreeId(); NodeDesigner node = CreateNode(data, Vector2.zero); ConnectNode(node, mSelectedNode); } }
public List <string> GetNodeOutPutEnvKeyList(BehaviorNodeData nodeData, NodeFieldDesc desc = null) { NodeProto rootNode = this.BehaviorNodeDataToNodeProto(CurTree.Root); NodeProto inputNode = this.BehaviorNodeDataToNodeProto(nodeData); List <NodeFieldDesc> descList = _GetNodeOutPutEnvKeyList(rootNode, inputNode, desc); List <string> list = new List <string>(); foreach (NodeFieldDesc item in descList) { string str = item.value?.ToString() ?? ""; list.Add(str); } return(list); }
public BehaviorNodeConfig BehaviorNodeDataToNodeConfig(BehaviorNodeData nodeData) { GameObject go = new GameObject(); BehaviorNodeConfig nodeConfig = go.AddComponent <BehaviorNodeConfig>(); nodeConfig.id = nodeData.Id; nodeConfig.name = nodeData.Name; go.name = nodeData.Name; nodeConfig.describe = nodeData.Desc; List <string> unUseList = new List <string>(); foreach (KeyValuePair <string, object> args in nodeData.Args.Dict()) { if (!NodeMetaHelper.NodeHasField(nodeData.Name, args.Key)) { unUseList.Add(args.Key); continue; } Type originType = NodeMetaHelper.GetFieldType(nodeData.Name, args.Key); try { string fieldName = args.Key; object fieldValue = args.Value; Type type = BTTypeManager.GetBTType(originType); Component comp = go.AddComponent(type); FieldInfo fieldNameInfo = type.GetField("fieldName"); fieldNameInfo.SetValue(comp, fieldName); FieldInfo fieldValueinfo = type.GetField("fieldValue"); if (TypeHelper.IsEnumType(originType)) { fieldValue = fieldValue.ToString(); } fieldValueinfo.SetValue(comp, fieldValue); } catch (Exception e) { throw new Exception($"transform failed,nodeName:{nodeData.Name} fieldName:{args.Key} fieldType:{originType}", e); } } foreach (string key in unUseList) { nodeData.Args.Remove(key); } foreach (BehaviorNodeData child in nodeData.children) { BehaviorNodeConfig childConfig = this.BehaviorNodeDataToNodeConfig(child); childConfig.gameObject.transform.parent = nodeConfig.gameObject.transform; } return(nodeConfig); }
public BehaviorNodeConfig NodeDataToNodeConfig(BehaviorNodeData nodeData) { GameObject go = new GameObject(); BehaviorNodeConfig nodeConfig = go.AddComponent <BehaviorNodeConfig>(); nodeConfig.id = nodeData.nodeId; ((Object)nodeConfig).name = nodeData.name; go.name = nodeData.name; nodeConfig.describe = nodeData.describe; List <string> unUseList = new List <string>(); foreach (var args in nodeData.args_dict) { if (!ExportNodeTypeConfig.NodeHasField(nodeData.name, args.Key)) { unUseList.Add(args.Key); continue; } Type originType = ExportNodeTypeConfig.GetFieldType(nodeData.name, args.Key); try { string fieldName = args.Key; object fieldValue = args.Value.GetValueByType(originType); Type type = BTTypeManager.GetBTType(originType); Component comp = go.AddComponent(type); FieldInfo fieldNameInfo = type.GetField("fieldName"); fieldNameInfo.SetValue(comp, fieldName); FieldInfo fieldValueinfo = type.GetField("fieldValue"); if (BehaviorTreeArgsDict.IsEnumType(originType)) { fieldValue = fieldValue.ToString(); } fieldValueinfo.SetValue(comp, fieldValue); } catch (Exception e) { throw new Exception($"transform failed,nodeName:{nodeData.name} fieldName:{args.Key} fieldType:{originType}", e); } } foreach (string key in unUseList) { nodeData.args_dict.Remove(key); } foreach (var child in nodeData.children) { BehaviorNodeConfig childConfig = NodeDataToNodeConfig(child); childConfig.gameObject.transform.parent = nodeConfig.gameObject.transform; } return(nodeConfig); }
//private List<NodeFieldDesc> GetFieldDescList(NodeProto nodeProto, Type type) //{ // List<NodeFieldDesc> list = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.name, type); // foreach (NodeProto childProto in nodeProto.children) // { // list.AddRange(GetFieldDescList(childProto, type)); // } // return list; //} public BehaviorNodeData CreateNode(string nodeName) { if (!this.GetComponent <BTNodeInfoComponent>().ContainsKey(nodeName)) { Debug.LogError($"节点类型:{nodeName}不存在"); return(null); } BehaviorNodeData node = new BehaviorNodeData(nodeName) { Id = AutoNodeId(), Name = nodeName }; return(node); }
public BehaviorNodeData NodeProtoToNodeData(NodeProto nodeProto) { BehaviorNodeData nodeData = new BehaviorNodeData(); nodeData.nodeId = nodeProto.nodeId; nodeData.name = nodeProto.name; nodeData.describe = nodeProto.describe; nodeData.args_dict = nodeProto.args_dict; nodeData.children = new List <BehaviorNodeData>(); foreach (var child in nodeProto.children) { nodeData.children.Add(this.NodeProtoToNodeData(child)); } return(nodeData); }
public List <string> GetCanInPutEnvKeyList(BehaviorNodeData nodeData, NodeFieldDesc desc) { List <string> list1 = Instance.GetNodeOutPutEnvKeyList(nodeData, desc); HashSet <string> hashSet = new HashSet <string>(); foreach (string item in list1) { hashSet.Add(item); } List <string> resultList = new List <string>(); foreach (string item in hashSet) { resultList.Add(item); } return(resultList); }
public NodeProto BehaviorNodeDataToNodeProto(BehaviorNodeData nodeData) { NodeProto nodeProto = new NodeProto { Id = nodeData.Id, Name = nodeData.Name, Desc = nodeData.Desc, Args = nodeData.Args, children = new List <NodeProto>() }; foreach (BehaviorNodeData child in nodeData.children) { nodeProto.children.Add(this.BehaviorNodeDataToNodeProto(child)); } return(nodeProto); }
public BehaviorNodeData NodeProtoToBehaviorNodeData(NodeProto nodeProto) { BehaviorNodeData nodeData = new BehaviorNodeData { Id = nodeProto.Id, Name = nodeProto.Name, Desc = nodeProto.Desc, Args = nodeProto.Args, children = new List <BehaviorNodeData>() }; foreach (NodeProto child in nodeProto.children) { nodeData.children.Add(this.NodeProtoToBehaviorNodeData(child)); } return(nodeData); }
public BehaviorNodeData GetNodeData(BehaviorNodeData nodeData, int nodeId) { BehaviorNodeData result = null; if (nodeData.Id == nodeId) { return(nodeData); } foreach (BehaviorNodeData child in nodeData.children) { result = GetNodeData(child, nodeId); if (result != null) { break; } } return(result); }
public NodeProto NodeDataToNodeProto(BehaviorNodeData nodeData) { NodeProto nodeProto = new NodeProto(); nodeProto.nodeId = nodeData.nodeId; nodeProto.name = nodeData.name; nodeProto.describe = nodeData.describe; nodeProto.nodeIdList = new List <int>(); nodeProto.args_dict = nodeData.args_dict; nodeProto.children = new List <NodeProto>(); foreach (var child in nodeData.children) { nodeProto.children.Add(NodeDataToNodeProto(child)); nodeProto.nodeIdList.Add(child.nodeId); } return(nodeProto); }
public NodeDesigner CreateNode(BehaviorNodeData nodeData, Vector2 pos) { NodeDesigner node = new NodeDesigner(nodeData); node.Pos = pos == Vector2.zero? CenterPosInBorder() : pos; if (mSelectedNode != null) { mSelectedNode.AddChild(node); mSelectedNode.AutoSort(); } else { mDetachedNodes.Add(node); } BehaviorManager.GetInstance().ResetTreeId(); Game.Scene.GetComponent <EventComponent>().Run(EventIdType.BehaviorTreeCreateNode, node); return(node); }
public BehaviorNodeData NodeConfigToNodeData(BehaviorNodeConfig nodeProto) { BehaviorNodeData nodeData = new BehaviorNodeData() { Id = nodeProto.id, Name = nodeProto.name, Desc = nodeProto.describe, Args = nodeProto.GetArgsDict(), children = new List <BehaviorNodeData>() }; foreach (Transform child in nodeProto.gameObject.transform) { BehaviorNodeConfig nodeConfig = child.gameObject.GetComponent <BehaviorNodeConfig>(); BehaviorNodeData childData = NodeConfigToNodeData(nodeConfig); nodeData.children.Add(childData); } return(nodeData); }
public bool IsHighLight(BehaviorNodeData node) { NodeProto nodeProto = NodeDataToNodeProto(node); List <NodeFieldDesc> list = ExportNodeTypeConfig.GetNodeFieldInOutPutDescList(nodeProto.name, typeof(NodeOutputAttribute)); foreach (var desc in list) { if (!nodeProto.args_dict.ContainsKey(desc.name)) { continue; } string value = nodeProto.args_dict.GetTreeDictValue(desc.type, desc.name)?.ToString(); List <string> resultList = inputValueList.FindAll(str => { return(str == value); }); if (resultList.Count > 0) { return(true); } } return(false); }
public bool IsHighLight(BehaviorNodeData node) { NodeProto nodeProto = this.BehaviorNodeDataToNodeProto(node); List <NodeFieldDesc> list = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.Name, typeof(NodeOutputAttribute)); foreach (NodeFieldDesc desc in list) { if (!nodeProto.Args.ContainsKey(desc.name)) { continue; } string value = nodeProto.Args.Get(desc.name)?.ToString(); List <string> resultList = inputValueList.FindAll(str => { return(str == value); }); if (resultList.Count > 0) { return(true); } } return(false); }