public void Step() { for (int i = 0; i < mBTTrees.Count; i++) { BTTree tree = mBTTrees[i]; EBTStatus pStatus = tree.Step(); switch (pStatus) { case EBTStatus.BT_INITIAL: break; case EBTStatus.BT_RUNNING: break; case EBTStatus.BT_SUCCESS: case EBTStatus.BT_FAILURE: { mDeleteList.Add(tree); } break; } } for (int i = 0; i < mDeleteList.Count; i++) { BTTree tree = mDeleteList[i]; mBTTrees.Remove(tree); tree.Clear(); } mDeleteList.Clear(); }
// Use this for initialization void Awake() { //create a tree with just the attack node senses = GetComponentInChildren <AIPerceptor>(); tree = new BTTree ( new BTSelector(new List <BTTask>() { new BTSequence(new List <BTTask>() { new CheckIfPlayerUnderAttack(), new RLFightOrFlight() }), new FollowPlayerSequence(), new Idle() } )); //setup the blackboard values tree.Blackboard = new Blackboard(); senses = GetComponentInChildren <AIPerceptor>(); senses.SetBlackboard(tree.Blackboard); tree.Blackboard.SetValue("owner", this.gameObject); tree.Blackboard.SetValue("senses", senses); if (player) { tree.Blackboard.SetValue("player", player); } tree.BeginTree(); }
public void Step() { for (int i = 0; i < m_BTTrees.Count; i++) { BTTree tree = m_BTTrees[i]; BTStatus pStatus = tree.Step(); switch (pStatus) { case BTStatus.Initial: break; case BTStatus.Running: break; case BTStatus.Success: case BTStatus.Failure: { m_DeleteList.Add(tree); } break; } } for (int i = 0; i < m_DeleteList.Count; i++) { BTTree tree = m_DeleteList[i]; m_BTTrees.Remove(tree); tree.Clear(); } m_DeleteList.Clear(); }
// Use this for initialization void Awake() { tree.Blackboard = new Blackboard(); senses = GetComponentInChildren <AIPerceptor>(); //create the behaviour tree tree = new BTTree( new BTSelector(new List <BTTask>() { new Timer( new BTSequence( new List <BTTask>() { new MoveTo(), new SelectNextLocation() }), 5f), new RLAttack( new List <BTTask>() { new FireballAttack(), new WaterAttack(), new AirAttack(), new EarthAttack() }) })); tree.Blackboard.SetValue("owner", this.gameObject); tree.Blackboard.SetValue("patrolPoints", GetComponent <Patrol>().GetPatrolPoints()); tree.Blackboard.SetValue("moveToPos", GetComponent <Patrol>().GetPatrolPoints()[0].transform.position); tree.Blackboard.SetValue("distanceToArrival", 0.5f); tree.Blackboard.SetValue("senses", senses); tree.BeginTree(); }
public override void onCreate(EntityInfo data) { base.onCreate(data); fsm = new MonsterFSM(this); onChangeState(StateType.spawn); treeAI = new MonsterBTAI(); dt = WorkingDataFactroy.createData(this); }
public void Remove(BTTree tree) { if (tree == null) { return; } m_DeleteList.Add(tree); }
// Use this for initialization void Start() { database.characterManager = GetComponent <CharacterManager>(); bt = BTTree.CloneTree(bt); bt.Initialize(database); }
public void ClearData(BTNode pNode, string key) { BTTree result = GetFirstTreeInParent(pNode); if (result != null) { result.SetData(key, null); } }
private string CommandCreateBTTreeForManager() { BTTree btTree = new BTTree(); btTree.Root = CreateBTTree(); Mgr <CatProject> .Singleton.BTTreeManager.AddBTTree("TestTree", btTree); return("BTTree has been created and inserted into BTTreeManager"); }
public void Run(BTTree tree) { if (tree == null) { return; } tree.Clear(); m_BTTrees.Add(tree); }
// Use this for initialization void Start () { database.characterManager = GetComponent<CharacterManager>(); bt = BTTree.CloneTree (bt); bt.Initialize (database); }
public object Execute() { BTTree btTree = new BTTree(); btTree.Root = CreateBTTree(); Mgr <CatProject> .Singleton.BTTreeManager.AddBTTree(m_btTreeName, btTree); return("BTTree has been created and inserted into BTTreeManager"); }
public void Clear() { for (int i = 0; i < m_BTTrees.Count; i++) { BTTree tree = m_BTTrees[i]; tree.Clear(); } m_BTTrees.Clear(); }
public void SaveData(BTNode pNode, string key, object value) { BTTree result = GetFirstTreeInParent(pNode); if (result != null) { result.SetData(key, value); } }
public ActorBase GetOwnerByNode(BTNode pNode) { BTTree tree = GetFirstTreeInParent(pNode); if (tree == null) { return(null); } return(tree.Owner); }
public object GetData(BTNode pNode, string key) { BTTree result = GetFirstTreeInParent(pNode); if (result != null) { return(result.GetData(key)); } return(null); }
public object Execute() { BTTree btTree = Mgr <CatProject> .Singleton.BTTreeManager.LoadBTTree(m_btTreeName); if (btTree != null) { Mgr <MapEditor> .Singleton.m_btTreeEditor.OpenBTTree(btTree); } return("BTTree loaded and opened in viewer"); }
/** * @brief set BTTree * Warning: if it is observing a runtimepack, this action will stop * the observation **/ public void SetBTTree(BTTree _btree) { if (IsObservingRuntimePack()) { m_observingRuntimePack = null; } m_btTree = _btree; CreateChart(); AutoLayoutChart(); Refresh(); }
public BTTree GetFirstTreeInParent(BTNode pNode) { BTTree result = null; GetTreeInParents(pNode, ref result); if (result == null) { Debug.LogError("找不到BTree类型的Parent:" + pNode); return(null); } return(result); }
public object Execute() { BTTree btTree = Mgr <CatProject> .Singleton.BTTreeManager.LoadBTTree(m_btTreeName); if (btTree != null) { return("The btree has been loaded."); } else { return("Fail to load btree: " + m_btTreeName); } }
public void OnEditBTNodeClick(object sender, EventArgs e) { if (Mgr <CatProject> .Singleton != null && Mgr <CatProject> .Singleton.BTTreeManager != null) { string selected = (string)(contentList.SelectedItem); if (selected != null) { BTTree btTree = Mgr <CatProject> .Singleton.BTTreeManager.LoadBTTree(selected); Mgr <MapEditor> .Singleton.BTTreeEditor.OpenBTTree(btTree); Mgr <MapEditor> .Singleton.BTTreeEditor.ShowDialog(this); } } }
public void GetTreeInParents(BTNode pNode, ref BTTree result) { if (pNode == null) { return; } if (pNode.Parent is BTTree) { result = pNode.Parent as BTTree; } else { GetTreeInParents(pNode.Parent, ref result); } }
private void LoadBTTree(string _btTreeName) { if (Mgr <CatProject> .Singleton != null && Mgr <CatProject> .Singleton.BTTreeManager != null) { BTTree btTree = Mgr <CatProject> .Singleton.BTTreeManager.LoadBTTree(_btTreeName); if (btTree != null) { OpenBTTree(btTree); } else { Debug.Assert(false, "Cannot open BTTree: " + _btTreeName); } } }
void OnGUI() { _go = (GameObject)EditorGUI.ObjectField(new Rect(position.xMax - 350, position.yMin - 40, 300, 20), "BTTree GameObject", _go, typeof(GameObject), true); BTTree tree; if (_go == null || (tree = _go.GetComponent <BTTree>()) == null) { EditorGUI.LabelField(new Rect(position.xMax - 350, position.y - 17, 500, 20), "Find a GameObject with component inherited from BTTree."); return; } if (_previousTree == null || _previousTree.GetType() != tree.GetType()) { BTNode root = tree.root == null?tree.Init() : tree.root; _levelToCount = new Dictionary <int, int>(); _info = ParseNodeInfo(root, 0, 0); _previousTree = tree; } int maxCount = 0; foreach (int count in _levelToCount.Values) { if (count > maxCount) { maxCount = count; } } _scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width - 1, position.height - 1), _scrollPosition, new Rect(0, 0, maxCount * _offset.x + 50, _levelToCount.Keys.Count * _offset.y + 50)); BeginWindows(); _currentWindowId = 0; DrawNodeInfo(_info, null); EndWindows(); GUI.EndScrollView(); }
private void CreateNewBTTree() { string treeName = "UntitledBTTree"; InputDialog inputDialog = new InputDialog(); inputDialog.InitializeDate("Input a name for BTTree", "Input a name for BTTree", treeName); if (inputDialog.ShowDialog(this) == DialogResult.OK) { treeName = inputDialog.Result; if (Mgr <CatProject> .Singleton != null && Mgr <CatProject> .Singleton.BTTreeManager != null) { while (Mgr <CatProject> .Singleton.BTTreeManager.HasBTTreeWithName(treeName)) { inputDialog = new InputDialog(); inputDialog.InitializeDate("Tree " + treeName + "exists", "Input a new name for BTTree", treeName); if (inputDialog.ShowDialog(this) == DialogResult.OK) { treeName = inputDialog.Result; } else { return; } } BTTree btTree = Mgr <CatProject> .Singleton.BTTreeManager.CreateAndSaveEmptyBTTree(treeName); OpenBTTree(btTree); } else { Debug.Assert(false, "Cannot find CatProject instance."); return; } } else { return; } }
// Start is called before the first frame update void Awake() { //singleton if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); rootSelector = new Selector(); Sequence seq = new Sequence(); rootSelector.AddChild(new Obj()); rootSelector.AddChild(new Npc()); rootSelector.AddChild(new Destination()); rootSelector.AddChild(seq); }
void OnGUI() { _go = (GameObject) EditorGUI.ObjectField(new Rect(position.xMax - 350, position.yMin-40, 300, 20), "BTTree GameObject", _go, typeof(GameObject), true); BTTree tree; if (_go == null || (tree = _go.GetComponent<BTTree>()) == null) { EditorGUI.LabelField(new Rect(position.xMax - 350, position.y-17, 500, 20), "Find a GameObject with component inherited from BTTree."); return ; } if (_previousTree == null || _previousTree.GetType() != tree.GetType()) { BTNode root = tree.root == null ? tree.Init() : tree.root; _levelToCount = new Dictionary<int, int>(); _info = ParseNodeInfo(root, 0, 0); _previousTree = tree; } int maxCount = 0; foreach (int count in _levelToCount.Values) { if (count > maxCount) { maxCount = count; } } _scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width - 1, position.height - 1), _scrollPosition, new Rect(0, 0, maxCount * _offset.x + 50, _levelToCount.Keys.Count * _offset.y + 50)); BeginWindows(); _currentWindowId = 0; DrawNodeInfo(_info, null); EndWindows(); GUI.EndScrollView(); }
void OnEnable() { _previousTree = null; }
void OnGUI() { //draw behaviour tree scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width - 240, position.height), scrollPosition, new Rect(0, 0, maxSize.x, maxSize.y)); Texture2D text1 = new Texture2D(1, 1); text1.SetPixel(0, 0, Color.white); text1.Apply(); //Texture2D text2 = new Texture2D( 1 , 1 ); //text2.SetPixel( 0 , 0 , Color.gray ); //text2.Apply(); for (int i = 0; i < 1000; ++i) { GUI.DrawTexture(new Rect(0, i * NODE_HEIGH, 2 * _Instance.position.width, NODE_HEIGH), text1); //++i; //GUI.DrawTexture( new Rect( 0 , i * NODE_HEIGH , 2 * _Instance.position.width , NODE_HEIGH ) , text2 ); } if (currentTree != null && currentTree.treeRoot != null) { int xx = 0, yy = 0; currentTree.treeRoot.RenderNode(xx, ref yy); } GUI.EndScrollView(); //draw editor GUI.BeginGroup(new Rect(position.width - GUI_WIDTH, 0, 300, 1000)); int x = 20, y = 20; List <BTTree> treeList = BehaviourTreeFactory._Instance.GetAllTrees(); if (GUI.Button(new Rect(x, y, 200, 40), "Load Json")) { selectedNode = null; currentNode = null; currentTree = null; currentTreeIndex = -1; lastTreeIndex = -1; creatNodeId = -1; BehaviourTreeFactory._Instance.EditorLoad(); } y += 60; if (GUI.Button(new Rect(x, y, 200, 40), "Save Json")) { BehaviourTreeFactory._Instance.EditorSave(); AssetDatabase.Refresh(); } y += 40; GUI.Label(new Rect(x, y, 200, 20), "=========================="); y += 20; inputName = GUI.TextField(new Rect(x, y + 10, 200, 20), inputName); y += 40; if (GUI.Button(new Rect(x, y, 200, 40), "creat tree")) { if (inputName != "") { currentNode = null; BTTree newTree = new BTTree(); newTree.treeName = inputName; BehaviourTreeFactory._Instance.AddTree(newTree); currentTree = newTree; tickRateStr = ""; treeList = BehaviourTreeFactory._Instance.GetAllTrees(); for (int i = 0; i < treeList.Count; ++i) { if (treeList[i].treeName == newTree.treeName) { currentTreeIndex = i; break; } } lastTreeIndex = currentTreeIndex; Repaint(); } } if (treeList.Count != 0) { y += 40; GUI.Label(new Rect(x, y, 200, 20), "=========================="); y += 20; string[] treeNames = new string[treeList.Count]; for (int i = 0; i < treeNames.Length; ++i) { treeNames[i] = treeList[i].treeName; } currentTreeIndex = EditorGUI.Popup(new Rect(x, y, 200, 45), currentTreeIndex, treeNames); if (currentTreeIndex != lastTreeIndex) { lastTreeIndex = currentTreeIndex; currentTree = treeList[currentTreeIndex]; tickRateStr = ""; currentNode = null; } y += 40; if (GUI.Button(new Rect(x, y, 200, 40), "remove tree")) { currentNode = null; BehaviourTreeFactory._Instance.RemoveTree(currentTree); currentTree = null; currentTreeIndex = -1; lastTreeIndex = -1; treeList = BehaviourTreeFactory._Instance.GetAllTrees(); Repaint(); } } if (currentTree != null) { y += 40; GUI.Label(new Rect(x, y, 200, 20), "=========================="); y += 20; GUI.Label(new Rect(x, y, 100, 20), "Tree name : "); currentTree.treeName = GUI.TextField(new Rect(x + 100, y, 100, 20), currentTree.treeName); y += 20; GUI.Label(new Rect(x, y, 100, 20), "Tree Tick Rate : "); if (tickRateStr == "") { tickRateStr = currentTree.tickRate.ToString(); } tickRateStr = GUI.TextField(new Rect(x + 100, y, 100, 20), tickRateStr); currentTree.tickRate = double.Parse(tickRateStr); if (currentTree.treeRoot == null) { creatNodeId = EditorGUI.Popup(new Rect(x, y + 20, 200, 40), creatNodeId, BehaviourTreeFactory._Instance.GetCompostieNodeNamesList()); y += 40; if (creatNodeId != -1) { if (GUI.Button(new Rect(x, y, 200, 40), "Create Root")) { BTNode newNode = BehaviourTreeFactory._Instance.CreateRoot(creatNodeId); currentTree.treeRoot = newNode; currentNode = newNode; y += 40; } } } } if (currentNode != null) { y += 40; GUI.Label(new Rect(x, y, 200, 20), "=========================="); y += 20; GUI.Label(new Rect(x, y, 300, 20), "Node Type : " + currentNode.GetType().FullName); y += 20; GUI.Label(new Rect(x, y, 200, 20), "Node Name : " + currentNode.GetType().Name); y += 20; GUI.Label(new Rect(x, y, 100, 20), "Node Description : "); y += 20; string tempNodeDestricption = currentNode.GetNodeDestricption(); tempNodeDestricption = GUI.TextField(new Rect(x, y, 200, 40), tempNodeDestricption); currentNode.SetNodeDestricption(tempNodeDestricption); y += 40; GUI.Label(new Rect(x, y, 100, 20), "Reverse Result : "); bool tempReverseResult = currentNode.IsReverseResult(); tempReverseResult = GUI.Toggle(new Rect(x + 100, y, 100, 20), tempReverseResult, ""); currentNode.SetReverseResult(tempReverseResult); y += 15; currentNode.RenderSelfProperty(x, y); } GUI.EndGroup(); }
/** * @brief open BTTree **/ public void OpenBTTree(BTTree _btTree) { InitializeAll(); btTreeViewer.SetBTTree(_btTree); }