public void AddChild(BtNodeData child) { if (children == null) { children = new List <BtNodeData>(); } children.Add(child); }
public static BtNode AddChildNode(BehaviourTree owner, BtNode parent, BtNodeData data) { data.SetPosition(owner.GenNodePos(data.GetPosition())); //避免重叠 var child = new BtNode(owner, parent, data); owner.AddNode(child); parent.ChildNodeList.Add(child); return(child); }
public BtNode(BehaviourTree owner, BtNode parent, BtNodeData data) { Owner = owner; Parent = parent; Data = data; BtNodeGraph = new BtNodeGraph(); NodeName = data.name; BtNodeGraph.RealRect = new Rect(data.posX, data.posY, BtConst.DefaultWidth, BtConst.DefaultHeight); ChildNodeList = new List <BtNode>(); Guid = BtHelper.GenerateUniqueStringId(); Type = BtHelper.CreateNodeType(this); }
public BtNodeData Clone() { var clone = new BtNodeData(name, type, posX, posY) { displayName = displayName }; if (data != null) { clone.data = new Dictionary <string, string>(data); } return(clone); }
public static BtNode AddChildNode(BehaviourTree owner, BtNode parent, string name) { var pos = parent.BtNodeGraph.RealRect.position; if (!mNodeTypeDict.ContainsKey(name)) { throw new ArgumentNullException(name, "找不到该类型"); } var data = new BtNodeData(name, mNodeTypeDict[name], pos.x, pos.y + BtConst.DefaultHeight + BtConst.DefaultSpacingY); parent.Data.AddChild(data); return(AddChildNode(owner, parent, data)); }
public BehaviourTree(string name, BtNodeData data = null) { Name = name; NodeDict = new Dictionary <string, BtNode>(); NodePosDict = new Dictionary <string, int>(); BrokenNodeDict = new Dictionary <string, BtNode>(); if (data == null) { data = new BtNodeData(BtConst.RootName, null, (BtEditorWindow.Window.position.width - BtConst.RightInspectWidth) / 2, 50); data.AddData("restart", "1"); } Root = new BtNode(this, null, data); AddNode(Root); BtHelper.AutoAlignPosition(Root); }
private void DrawDataInspector(BtNodeData data) { EditorGUIUtility.labelWidth = 24; if (!string.IsNullOrEmpty(mDelKey)) { data.RemoveData(mDelKey); if (mChangeDict.ContainsKey(mDelKey)) { mChangeDict.Remove(mDelKey); } mDelKey = null; } foreach (var key in mChangeDict.Keys) { data.AddData(key, mChangeDict[key]); } mChangeDict.Clear(); if (data.data != null) { foreach (var kv in data.data) { DrawItemInspector(kv); } } EditorGUILayout.BeginHorizontal(); { mKey = EditorGUILayout.TextField("key:", mKey); mValue = EditorGUILayout.TextField("val:", mValue); if (GUILayout.Button("+", GUILayout.MaxWidth(20))) { if (!string.IsNullOrEmpty(mKey)) { data.AddData(mKey, mValue); mKey = ""; mValue = ""; } } } EditorGUILayout.EndHorizontal(); }