Esempio n. 1
0
 public void btreloadall()
 {
     this.m_currentBT = null;
     this.BTStack.Clear();
     if (this.m_behaviorTreeTasks != null)
     {
         List <string> list = new List <string>();
         using (ListView <BehaviorTreeTask> .Enumerator enumerator = this.m_behaviorTreeTasks.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 BehaviorTreeTask current = enumerator.get_Current();
                 string           name    = current.GetName();
                 if (list.IndexOf(name) == -1)
                 {
                     list.Add(name);
                 }
             }
         }
         for (int i = 0; i < list.get_Count(); i++)
         {
             string relativePath = list.get_Item(i);
             Workspace.Load(relativePath, true);
         }
         this.BehaviorTreeTasks.Clear();
     }
     this.Variables.Unload();
 }
Esempio n. 2
0
 public void btunload(string relativePath)
 {
     if (this.m_currentBT != null && this.m_currentBT.GetName() == relativePath)
     {
         BehaviorNode node = this.m_currentBT.GetNode();
         BehaviorTree bt   = node as BehaviorTree;
         this.btunload_pars(bt);
         this.m_currentBT = null;
     }
     for (int i = 0; i < this.BTStack.Count; i++)
     {
         Agent.BehaviorTreeStackItem_t behaviorTreeStackItem_t = this.BTStack[i];
         if (behaviorTreeStackItem_t.bt.GetName() == relativePath)
         {
             this.BTStack.Remove(behaviorTreeStackItem_t);
             break;
         }
     }
     for (int j = 0; j < this.BehaviorTreeTasks.Count; j++)
     {
         BehaviorTreeTask behaviorTreeTask = this.BehaviorTreeTasks[j];
         if (behaviorTreeTask.GetName() == relativePath)
         {
             Workspace.DestroyBehaviorTreeTask(behaviorTreeTask, this);
             this.BehaviorTreeTasks.Remove(behaviorTreeTask);
             break;
         }
     }
     Workspace.UnLoad(relativePath);
 }
Esempio n. 3
0
 public static void DestroyBehaviorTreeTask(BehaviorTreeTask behaviorTreeTask, Agent agent)
 {
     if (behaviorTreeTask != null)
     {
         if (ms_allBehaviorTreeTasks.ContainsKey(behaviorTreeTask.GetName()))
         {
             BTItem_t _t = ms_allBehaviorTreeTasks[behaviorTreeTask.GetName()];
             _t.bts.Remove(behaviorTreeTask);
             if (agent != null)
             {
                 _t.agents.Remove(agent);
             }
         }
         BehaviorTask.DestroyTask(behaviorTreeTask);
     }
 }
Esempio n. 4
0
 private void _btsetcurrent(string relativePath, TriggerMode triggerMode, bool bByEvent)
 {
     if (!string.IsNullOrEmpty(relativePath))
     {
         if (!Workspace.Load(relativePath))
         {
             string text = base.GetType().get_FullName();
             text += "::";
             text += base.name;
         }
         else
         {
             Workspace.RecordBTAgentMapping(relativePath, this);
             if (this.m_currentBT != null)
             {
                 if (triggerMode == TriggerMode.TM_Return)
                 {
                     Agent.BehaviorTreeStackItem_t item = new Agent.BehaviorTreeStackItem_t(this.m_currentBT, triggerMode, bByEvent);
                     this.BTStack.Add(item);
                 }
                 else if (triggerMode == TriggerMode.TM_Transfer)
                 {
                     this.m_currentBT.abort(this);
                     this.m_currentBT.reset(this);
                 }
             }
             BehaviorTreeTask behaviorTreeTask = null;
             for (int i = 0; i < this.BehaviorTreeTasks.Count; i++)
             {
                 BehaviorTreeTask behaviorTreeTask2 = this.BehaviorTreeTasks[i];
                 if (behaviorTreeTask2.GetName() == relativePath)
                 {
                     behaviorTreeTask = behaviorTreeTask2;
                     break;
                 }
             }
             bool flag = false;
             if (behaviorTreeTask != null && this.BTStack.Count > 0)
             {
                 for (int j = 0; j < this.BTStack.Count; j++)
                 {
                     Agent.BehaviorTreeStackItem_t behaviorTreeStackItem_t = this.BTStack[j];
                     if (behaviorTreeStackItem_t.bt.GetName() == relativePath)
                     {
                         flag = true;
                         break;
                     }
                 }
             }
             if (behaviorTreeTask == null || flag)
             {
                 behaviorTreeTask = Workspace.CreateBehaviorTreeTask(relativePath);
                 this.BehaviorTreeTasks.Add(behaviorTreeTask);
             }
             this.m_currentBT = behaviorTreeTask;
         }
     }
 }
Esempio n. 5
0
 private void _btsetcurrent(string relativePath, TriggerMode triggerMode, bool bByEvent)
 {
     if (!string.IsNullOrEmpty(relativePath))
     {
         if (!Workspace.Load(relativePath))
         {
             string str = base.GetType().FullName + "::" + base.name;
         }
         else
         {
             Workspace.RecordBTAgentMapping(relativePath, this);
             if (this.m_currentBT != null)
             {
                 if (triggerMode == TriggerMode.TM_Return)
                 {
                     BehaviorTreeStackItem_t _t = new BehaviorTreeStackItem_t(this.m_currentBT, triggerMode, bByEvent);
                     this.BTStack.Add(_t);
                 }
                 else if (triggerMode == TriggerMode.TM_Transfer)
                 {
                     this.m_currentBT.abort(this);
                     this.m_currentBT.reset(this);
                 }
             }
             BehaviorTreeTask item = null;
             for (int i = 0; i < this.BehaviorTreeTasks.Count; i++)
             {
                 BehaviorTreeTask task2 = this.BehaviorTreeTasks[i];
                 if (task2.GetName() == relativePath)
                 {
                     item = task2;
                     break;
                 }
             }
             bool flag3 = false;
             if ((item != null) && (this.BTStack.Count > 0))
             {
                 for (int j = 0; j < this.BTStack.Count; j++)
                 {
                     BehaviorTreeStackItem_t _t2 = this.BTStack[j];
                     if (_t2.bt.GetName() == relativePath)
                     {
                         flag3 = true;
                         break;
                     }
                 }
             }
             if ((item == null) || flag3)
             {
                 item = Workspace.CreateBehaviorTreeTask(relativePath);
                 this.BehaviorTreeTasks.Add(item);
             }
             this.m_currentBT = item;
         }
     }
 }
Esempio n. 6
0
 public static void DestroyBehaviorTreeTask(BehaviorTreeTask behaviorTreeTask, Agent agent)
 {
     if (behaviorTreeTask != null)
     {
         if (Workspace.ms_allBehaviorTreeTasks.ContainsKey(behaviorTreeTask.GetName()))
         {
             Workspace.BTItem_t bTItem_t = Workspace.ms_allBehaviorTreeTasks.get_Item(behaviorTreeTask.GetName());
             bTItem_t.bts.Remove(behaviorTreeTask);
             if (agent != null)
             {
                 bTItem_t.agents.Remove(agent);
             }
         }
         BehaviorTask.DestroyTask(behaviorTreeTask);
     }
 }
Esempio n. 7
0
        public static string GetTickInfo(Agent pAgent, BehaviorTask b, string action)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                if (pAgent != null && pAgent.IsMasked())
                {
                    //BEHAVIAC_PROFILE("GetTickInfo", true);

                    string bClassName = b.GetClassNameString();

                    //filter out intermediate bt, whose class name is empty
                    if (!string.IsNullOrEmpty(bClassName))
                    {
                        int nodeId          = b.GetId();
                        BehaviorTreeTask bt = pAgent != null?pAgent.btgetcurrent() : null;

                        //TestBehaviorGroup\scratch.xml.EventetTask[0]:enter
                        string bpstr = "";
                        if (bt != null)
                        {
                            string btName = bt.GetName();

                            bpstr = string.Format("{0}.xml->", btName);
                        }

                        bpstr += string.Format("{0}[{1}]", bClassName, nodeId);

                        if (!string.IsNullOrEmpty(action))
                        {
                            bpstr += string.Format(":{0}", action);
                        }

                        return(bpstr);
                    }
                }
            }
#endif
            return(string.Empty);
        }
Esempio n. 8
0
        //profiler
        public void Log(Agent pAgent, string btMsg, long time)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                if (Config.IsProfiling)
                {
                    //BEHAVIAC_PROFILE("LogManager.Instance.LogProfiler");

                    if (!System.Object.ReferenceEquals(pAgent, null) && pAgent.IsMasked())
                    {
                        //string agentClassName = pAgent.GetObjectTypeName();
                        //string agentInstanceName = pAgent.GetName();

                        BehaviorTreeTask bt = !System.Object.ReferenceEquals(pAgent, null) ? pAgent.btgetcurrent() : null;

                        string btName;

                        if (bt != null)
                        {
                            btName = bt.GetName();
                        }
                        else
                        {
                            btName = "None";
                        }

                        //[profiler]Ship.Ship_1 ships\suicide.xml.BehaviorTree[0] 0.031
                        string buffer;

                        //buffer = FormatString("[profiler]%s.%s %s.%s %d\n", agentClassName, agentInstanceName, btName, btMsg, time);
                        buffer = string.Format("[profiler]{0}.xml.{1} {2}\n", btName, btMsg, time);

                        Output(pAgent, buffer);
                    }
                }
            }
#endif
        }
Esempio n. 9
0
        public static void DestroyBehaviorTreeTask(BehaviorTreeTask behaviorTreeTask, Agent agent)
        {
            if (behaviorTreeTask != null)
            {
                if (ms_allBehaviorTreeTasks.ContainsKey(behaviorTreeTask.GetName()))
                {
                    BTItem_t btItem = ms_allBehaviorTreeTasks[behaviorTreeTask.GetName()];
                    btItem.bts.Remove(behaviorTreeTask);

					if (agent != null)
					{
                        btItem.agents.Remove(agent);
					}
                }

                BehaviorTask.DestroyTask(behaviorTreeTask);
            }
        }