コード例 #1
0
ファイル: BTHelper.cs プロジェクト: mengtest/BehaviorTree-3
        public static BTNode AddChild(BehaviourTree owner, BTNode parent, BTNodeData data)
        {
            var child = new BTNode(owner, parent, data);

            owner.AddNode(child);
            parent.ChildNodeList.Add(child);
            return(child);
        }
コード例 #2
0
ファイル: BTHelper.cs プロジェクト: mengtest/BehaviorTree-3
 public void AddChild(BTNodeData child)
 {
     if (children == null)
     {
         children = new List <BTNodeData> ();
     }
     children.Add(child);
 }
コード例 #3
0
ファイル: BTHelper.cs プロジェクト: mengtest/BehaviorTree-3
        public BTNodeData Clone()
        {
            BTNodeData clone = new BTNodeData(name, type, posX, posY);

            clone.displayName = displayName;
            if (data != null)
            {
                clone.data = new Dictionary <string, string> (data);
            }
            return(clone);
        }
コード例 #4
0
ファイル: BTNode.cs プロジェクト: mengtest/BehaviorTree-3
 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);
 }
コード例 #5
0
ファイル: BTHelper.cs プロジェクト: mengtest/BehaviorTree-3
        public static BTNode AddChild(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(AddChild(owner, parent, data));
        }
コード例 #6
0
 public BehaviourTree(string name, BTNodeData data = null)
 {
     Name           = name;
     BTNodeDict     = new Dictionary <string, BTNode> ();
     OrphanNodeDict = new Dictionary <string, BTNode> ();
     if (data == null)
     {
         data = new BTNodeData(BTConst.RootName, null,
                               (BTEditorWindow.window.position.width - BTConst.RIGHT_INSPECT_WIDTH) / 2, 50);
         data.AddData("restart", "1");
     }
     Root = new BTNode(this, null, data);
     AddNode(Root);
     BTHelper.AutoAlignPosition(Root);
 }
コード例 #7
0
        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();
        }