Beispiel #1
0
        public override AINodeResult Execute(ref AINode lastRunningNode, AIMember aiMember)
        {
            lastRunningNode = null;
            for (; index < Childs.Count; index++)
            {
                AINode       node    = Childs[index];
                AINodeResult nResult = node.Run(ref lastRunningNode, aiMember);

                if (nResult == AINodeResult.Failure)
                {
                    continue;
                }

                if (nResult == AINodeResult.Success)
                {
                    index = 0;
                    return(AINodeResult.Success);
                }

                if (nResult == AINodeResult.Running)
                {
                    lastRunningNode = node;
                    return(AINodeResult.Running);
                }
            }

            index = 0;
            return(AINodeResult.Failure);
        }
Beispiel #2
0
 public void Init(AIMember aiMember, RootNode rootNode)
 {
     AllNodes.Add(rootNode);
     SearchChilds(rootNode);
     _aiMember = aiMember;
     _rootNode = rootNode;
 }
Beispiel #3
0
        public AINodeResult Run(ref AINode lastRunningNode, AIMember aiMember)
        {
            AINodeResult result = Execute(ref lastRunningNode, aiMember);

            ResultState = result;
            return(result);
        }
Beispiel #4
0
        private RootNode TestCase(AIMember aiMember)
        {
            RootNode root = new RootNode();

            root
            .AddChild(new Selector()
                      .AddChild(new Condition(() => _timer > 3 && aiMember.Index < 1)
                                .AddChild(new Sequeter()
                                          .AddChild(new PrintAction("[1]State In"))
                                          .AddChild(new SetValAction(() => aiMember.Index = 1))
                                          .AddChild(new DelayAction(5f))
                                          .AddChild(new PrintAction("[1]State Out"))))
                      .AddChild(new Condition(() => _timer > 10 && aiMember.Index < 2)
                                .AddChild(new Sequeter()
                                          .AddChild(new PrintAction("[2]State In"))
                                          .AddChild(new SetValAction(() => aiMember.Index = 2))
                                          .AddChild(new DelayAction(5f))
                                          .AddChild(new PrintAction("[2]State Out"))))
                      .AddChild(new Condition(() => _timer > 20f)
                                .AddChild(new Sequeter()
                                          .AddChild(new SetValAction(() => _timer         = 0))
                                          .AddChild(new SetValAction(() => aiMember.Index = 0))))
                      .AddChild(new PrintAction("[3] Default Case")));

            return(root);
        }
Beispiel #5
0
        public static RootNode Parser(Transform t, AIMember aiMember)
        {
            RootNode result = new RootNode();

            SearchAndSetChild(t, result, aiMember);
            return(result);
        }
Beispiel #6
0
 public override AINodeResult Execute(ref AINode lastRunningNode, AIMember aiMember)
 {
     if (!string.IsNullOrEmpty(_print))
     {
         Debug.LogFormat("[PrintAction] {0}", _print);
     }
     return(AINodeResult.Failure);
 }
Beispiel #7
0
        public Condition Create(AIMember aiMember)
        {
            _aiMember = aiMember;

            Condition instance = new Condition(Comparison);

            OnGetInstance(instance);
            return(instance);
        }
Beispiel #8
0
        private AINodeResult RunTrueNode(ref AINode lastRunningNode, AIMember aiMember)
        {
            AINodeResult nResult = TrueNode.Run(ref lastRunningNode, aiMember);

            if (nResult == AINodeResult.Running)
            {
                _trueNodeInRunning = true;
                lastRunningNode    = TrueNode;
                return(AINodeResult.Running);
            }

            return(nResult);
        }
Beispiel #9
0
        private void Awake()
        {
            // 可以創建任何 有繼承 AIMemeber的Class 塞進去

            AGAIMember agM = new AGAIMember();

            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube.name = "[IM AG TEST CUBE]";
            cube.transform.position = Vector3.zero;
            agM.TestGameObject      = cube;
            _aiMember = agM;

            RootNode root = AITreeHelper.Parser(transform, _aiMember);

            _aiController.Init(_aiMember, root);
            _aiController.StartAI();
        }
Beispiel #10
0
        public override AINodeResult Execute(ref AINode lastRunningNode, AIMember aiMember)
        {
            if (_trueNodeInRunning)
            {
                _trueNodeInRunning = false;
                return(RunTrueNode(ref lastRunningNode, aiMember));
            }

            if (_conditionFunc() == false)
            {
                return(AINodeResult.Failure);
            }

            if (TrueNode == null)
            {
                return(AINodeResult.Success);
            }
            else
            {
                return(RunTrueNode(ref lastRunningNode, aiMember));
            }
        }
Beispiel #11
0
        public SetValAction Create(AIMember aiMember)
        {
            _aiMember = aiMember;



            SetValAction instance = null;

            if (_setValType == SetValType.Assign)
            {
                instance = new SetValAction(AssignVal);
            }
            else if (_setValType == SetValType.Add)
            {
                instance = new SetValAction(AddVal);
            }
            else if (_setValType == SetValType.Sub)
            {
                instance = new SetValAction(SubVal);
            }

            OnGetInstance(instance);
            return(instance);
        }
Beispiel #12
0
 public override AINodeResult Execute(ref AINode lastRunningNode, AIMember aiMember)
 {
     Debug.LogFormat("[PrintAction] {0}", _print);
     return(AINodeResult.Success);
 }
Beispiel #13
0
 public override AINodeResult Execute(ref AINode lastRunningNode, AIMember aiMember)
 {
     _setValAction();
     return(AINodeResult.Success);
 }
Beispiel #14
0
 public abstract AINodeResult Execute(ref AINode lastRunningNode, AIMember aiMember);
Beispiel #15
0
        private static void SearchAndSetChild(Transform t, AINodeContainer composite, AIMember aiMember)
        {
            foreach (Transform child in t)
            {
                AINode node = null;

                SelectMono selectMono = child.GetComponent <SelectMono>();
                if (selectMono != null)
                {
                    node = selectMono.Create();
                }

                SequeterMono sequterMono = child.GetComponent <SequeterMono>();
                if (sequterMono != null)
                {
                    node = sequterMono.Create();
                }

                ConditionMono conditionMono = child.GetComponent <ConditionMono>();
                if (conditionMono != null)
                {
                    if (conditionMono is WhileConditionMono)
                    {
                        WhileConditionMono wCondition = conditionMono as WhileConditionMono;
                        node = wCondition.Create(aiMember);
                    }
                    else
                    {
                        node = conditionMono.Create(aiMember);
                    }
                }

                PrintActionMono printMono = child.GetComponent <PrintActionMono>();
                if (printMono != null)
                {
                    node = printMono.Create();
                }

                DelayActionMono delayMono = child.GetComponent <DelayActionMono>();
                if (delayMono != null)
                {
                    node = delayMono.Create();
                }

                SetValActionMono setValMono = child.GetComponent <SetValActionMono>();
                if (setValMono != null)
                {
                    node = setValMono.Create(aiMember);
                }

                #region AGAction
                CustomAiNodeMono customMono = child.GetComponent <CustomAiNodeMono>();
                if (customMono != null)
                {
                    node = customMono.Create();
                }
                MonsterSwitchNavNodeMono monsterNavMono = child.GetComponent <MonsterSwitchNavNodeMono>();
                if (monsterNavMono != null)
                {
                    node = monsterNavMono.Create();
                }
                ShootBulletNodeMono shootMono = child.GetComponent <ShootBulletNodeMono>();
                if (shootMono != null)
                {
                    node = shootMono.Create();
                }
                MonsterAtkNodeMono monsterAtkMono = child.GetComponent <MonsterAtkNodeMono>();
                if (monsterAtkMono != null)
                {
                    node = monsterAtkMono.Create();
                }

                #endregion
                composite.AddChild(node);
                if (node is AINodeContainer)
                {
                    AINodeContainer nodeC = node as AINodeContainer;
                    SearchAndSetChild(child.transform, nodeC, aiMember);
                }
            }
        }