Esempio n. 1
0
 private void FinishDecorators()
 {
     if (_aliveBehavior.decorators.Length > 0)
     {
         for (int i = 0; i < _aliveBehavior.decorators.Length; i++)
         {
             RuntimeDecorator rd = GetRuntimeDecorator(_aliveBehavior.decorators[i]);
             if (rd.activeSelf)
             {
                 rd.activeSelf = false;
             }
         }
     }
 }
Esempio n. 2
0
        private bool StartDecorator(RuntimeDecorator runtimeDecorator)
        {
            bool value = runtimeDecorator.inversed ? runtimeDecorator.decoratorFunc() : !runtimeDecorator.decoratorFunc();

            if (value)
            {
#if UNITY_EDITOR
                runtimeDecorator.closed = true;
#endif
                return(false);
            }
#if UNITY_EDITOR
            runtimeDecorator.closed = false;
#endif

            return(true);
        }
Esempio n. 3
0
 private void InitializeDecorator(Node node)
 {
     if (node.decorators.Length > 0)
     {
         for (int i = 0; i < node.decorators.Length; i++)
         {
             Decorator        dc   = node.decorators[i];
             RuntimeDecorator rd   = new RuntimeDecorator(node, dc, dc.inversed);
             MonoBehaviour    comp = GetEqualTypeComponent(dc.targetScript.GetType()) as MonoBehaviour;
             if (comp == null)
             {
                 comp = gameObject.AddComponent(dc.targetScript.GetType()) as MonoBehaviour;
                 IBTAI ibtai = comp as IBTAI;
                 ibtai.InitializeAI();
             }
             rd.decoratorFunc = Delegate.CreateDelegate(typeof(Func <bool>), comp, dc.targetMethod) as Func <bool>;
             _runtimeDecorators.Add(rd);
         }
     }
 }
Esempio n. 4
0
        public void StartNode(Node node)
        {
            if (node == null)
            {
                return;
            }

            _aliveBehavior = node;
            if (node.decorators.Length > 0)
            {
                for (int i = 0; i < node.decorators.Length; i++)
                {
                    RuntimeDecorator rd = GetRuntimeDecorator(node.decorators[i]);
#if UNITY_EDITOR
                    rd.closed = false;
#endif
                    if (!StartDecorator(rd))
                    {
                        FinishExecute(false);
                        return;
                    }
                }
            }

            if (node is Task)
            {
                StartTask(node);
            }
            else
            {
                if (node is Composite)
                {
                    if ((node as Composite).services.Length > 0)
                    {
                        for (int i = 0; i < _runtimeServices.Count; i++)
                        {
                            if (_runtimeServices[i].parent == node as Composite)
                            {
                                StartService(_runtimeServices[i]);
                            }
                        }
                    }
                    if (node.childNodes.Length == 0)
                    {
                        if (node is Selector)
                        {
                            FinishExecute(true);
                        }
                        else if (node is Sequence)
                        {
                            FinishExecute(false);
                        }
                    }
                }

                if (_currentChildNodeIndex.ContainsKey(node))
                {
                    int startnodeIndex = _currentChildNodeIndex[node];
                    if (startnodeIndex < node.childNodes.Length)
                    {
                        StartNode(node.childNodes[startnodeIndex]);
                    }
                }
                else
                {
                    StartNode(_root);
                    Debug.LogError(string.Format("Brain StartNode Name : {0} Comment : {1}", node.name, node.comment));
                }
            }
        }