示例#1
0
        public override void OnAction(AISController ctrl)
        {
            base.OnAction(ctrl);

            AISVarList l = (AISVarList)ctrl.GetVar(listKey);

            l.PassToSingle((AISVarSingle)ctrl.GetVar(best), GetBest(ctrl, l));
        }
示例#2
0
 public IEnumerator ActionCoroutine(AISController ctrl)
 {
     while (true)
     {
         OnAction(ctrl);
         yield return(new WaitForSeconds(updateTime));
     }
 }
示例#3
0
 IEnumerator ScoreCoroutine(AISController ctrl)
 {
     while (true)
     {
         Score(ctrl);
         yield return(new WaitForSeconds(updateTime));
     }
 }
示例#4
0
        public void InitComponent(AISController ctrl)
        {
            mb = ctrl.GetComponent(type);

            if (!mb)
            {
                ic = ctrl.GetComponent <ItemHolder>().item.GetComponent(type);
            }
        }
示例#5
0
 public override int CalculateScore(AISController ai)
 {
     if (Evaluate(ai))
     {
         return(trueScore);
     }
     else
     {
         return(falseScore);
     }
 }
示例#6
0
        float Score(AISController ctrl, AISVarList l, int idx)
        {
            float scor = 0;

            foreach (var v in varScorers)
            {
                scor += v.Score(ctrl, l, idx);
            }

            return(scor);
        }
示例#7
0
        public static T GetSingleObject <T>(AISController ctrl, AISVariable key) where T : Object
        {
            if (!ctrl.ContainsKey(key))
            {
                return(null);
            }

            AISVarSingle var = (AISVarSingle)ctrl.GetVar(key);

            return(var.@object as T);
        }
示例#8
0
        public int Score(AISController ctrl)
        {
            int s = 0;

            for (int i = 0; i < scorers.Count; i++)
            {
                s += scorers[i].GetScore(ctrl);
            }

            return(s);
        }
示例#9
0
        public static List <Vector3> GetListVector3(AISController ctrl, AISVariable key)
        {
            if (!ctrl.ContainsKey(key))
            {
                return(null);
            }

            AISVarList vars = (AISVarList)ctrl.GetVar(key);

            return(vars.vector3);
        }
示例#10
0
        public static Vector3 GetSingleVector3(AISController ctrl, AISVariable key)
        {
            if (!ctrl.ContainsKey(key))
            {
                return(Vector3.zero);
            }

            AISVarSingle var = (AISVarSingle)ctrl.GetVar(key);

            return(var.vector3);
        }
示例#11
0
        public static List <float> GetListFloat(AISController ctrl, AISVariable key)
        {
            if (!ctrl.ContainsKey(key))
            {
                return(null);
            }

            AISVarList vars = (AISVarList)ctrl.GetVar(key);

            return(vars.@float);
        }
示例#12
0
        public static float GetSingleFloat(AISController ctrl, AISVariable key)
        {
            if (!ctrl.ContainsKey(key))
            {
                return(0);
            }

            AISVarSingle var = (AISVarSingle)ctrl.GetVar(key);

            return(var.@float);
        }
示例#13
0
        public static int GetSingleInt <T>(AISController ctrl, AISVariable key)
        {
            if (!ctrl.ContainsKey(key))
            {
                return(0);
            }

            AISVarSingle var = (AISVarSingle)ctrl.GetVar(key);

            return(var.@int);
        }
示例#14
0
        [SerializeField] protected float comparer, comparer2; //min, max

        public override int CalculateScore(AISController ctrl)
        {
            if (comp <= Comparison.BetweenIn) return base.CalculateScore(ctrl);

            float t = toCompare - comparer / comparer2 - comparer;
            switch (comp)
            {
                case Comparison.LinearInterp: return (int)Mathf.Lerp(falseScore, trueScore, t);
                default:
                case Comparison.LinearInterpUnclamp: return (int)Mathf.LerpUnclamped(falseScore, trueScore, t);
            }
        }
示例#15
0
        public virtual void OnAction(AISController ctrl)
        {
            if (!controllers.Contains(ctrl))
            {
                return;
            }

            if (!following && follow != null)
            {
                follow(ctrl);
            }
        }
示例#16
0
        public override void OnActionExit(AISController ctrl)
        {
            base.OnActionExit(ctrl);

            if (!destiny.ContainsKey(ctrl))
            {
                return;
            }

            destiny.Remove(ctrl);
            ctrl.navAgent.destination = ctrl.transform.position;
        }
示例#17
0
        public override void OnAction(AISController ctrl)
        {
            base.OnAction(ctrl);

            if (!destiny.ContainsKey(ctrl) || ctrl.navAgent == null)
            {
                return;
            }

            ctrl.navAgent.stoppingDistance = stopDistance;
            ctrl.navAgent.destination      = destiny[ctrl].position;
        }
示例#18
0
        public override void OnActionEnter(AISController ctrl)
        {
            base.OnActionEnter(ctrl);

            Transform t = AISEditorUtil.GetSingleObject <Transform>(ctrl, destinyKey);

            if (!t)
            {
                return;
            }

            destiny.Add(ctrl, t);
        }
示例#19
0
 protected override bool Evaluate(AISController ctrl)
 {
     if (owner.parent.exe == AISAction.Execution.Parallel || owner.parent.children.Count == 1)
     {
         return(true);
     }
     else if (owner.parent.bestChild.ContainsKey(ctrl))
     {
         return(owner.parent.bestChild[ctrl] == owner);
     }
     else
     {
         return(false);
     }
 }
示例#20
0
        protected override bool Evaluate(AISController ctrl)
        {
            switch (comp)
            {
                case Comparison.BiggerEx:   return toCompare > comparer;
                case Comparison.BiggerIn:   return toCompare >= comparer;
                case Comparison.SmallerEx:  return toCompare < comparer;
                case Comparison.SmallerIn:  return toCompare <= comparer;
                case Comparison.Equal:      return toCompare == comparer;
                case Comparison.BetweenEx:  return toCompare > comparer && toCompare < comparer2;
                case Comparison.BetweenIn:  return toCompare >= comparer && toCompare <= comparer2;
            }

            return false;
        }
示例#21
0
        int GetBest(AISController ctrl, AISVarList l)
        {
            float maxPoints = float.MinValue;
            int   idx       = -1;

            for (int i = 0; i < [email protected]; ++i)
            {
                float s = Score(ctrl, l, i);
                if (s > maxPoints)
                {
                    idx = i; maxPoints = s;
                }
            }

            return(idx);
        }
示例#22
0
        public AISAction BestAction(AISController ctrl)
        {
            AISAction a        = null;
            int       maxScore = int.MinValue;

            for (int i = 0; i < children.Count; i++)
            {
                int s = children[i].Score(ctrl);

                if (s > maxScore)
                {
                    a        = children[i];
                    maxScore = s;
                }
            }
            return(a);
        }
示例#23
0
        public static List <T> GetListObject <T>(AISController ctrl, AISVariable key) where T : Object
        {
            if (!ctrl.ContainsKey(key))
            {
                return(null);
            }

            AISVarList vars = (AISVarList)ctrl.GetVar(key);

            List <T> list = [email protected](x => x is T).Select(x => (T)x).ToList();

            if (list == null || list.Count == 0)
            {
                return(null);
            }

            return(list);
        }
示例#24
0
        public void ChangeBest(AISController ctrl)
        {
            if (!controllers.Contains(ctrl))
            {
                return;
            }

            if (children.Count != 0)
            {
                AISAction best = BestAction(ctrl);
                if (best != bestChild[ctrl])
                {
                    bestChild[ctrl].OnActionExit(ctrl);
                    bestChild[ctrl] = best;
                    bestChild[ctrl].OnActionEnter(ctrl);
                }
            }
        }
示例#25
0
        public virtual void OnActionExit(AISController ctrl)
        {
            if (!controllers.Contains(ctrl))
            {
                return;
            }

            switch (exe)
            {
            case Execution.Parallel:
                foreach (AISAction c in children)
                {
                    c.OnActionExit(ctrl);
                }
                break;

            case Execution.Best_Score:
                foreach (AISScorer s in children.SelectMany(x => x.scorers))
                {
                    s.StopScoring(ctrl);
                }
                if (children.Count != 0)
                {
                    bestChild[ctrl].OnActionExit(ctrl);
                    bestChild.Remove(ctrl);
                }
                break;

            case Execution.Sequential: break;
            }

            if (!following)
            {
                ctrl.StopCoroutine(coroutines[ctrl]);
                coroutines.Remove(ctrl);
            }

            controllers.Remove(ctrl);

            if (controllers.Count == 0)
            {
                Final();
            }
        }
示例#26
0
        public int Score(AISController controller, Character character)
        {
            if (!character)
            {
                return(0);
            }

            switch (toComp)
            {
            case ToCompare.damage:              toCompare = character.damageable.Life.value; break;

            case ToCompare.damage_Percentage:   toCompare = (character.damageable.Life.value / character.damageable.Life.maxValue) * 100; break;

            case ToCompare.stamina:             toCompare = character.stamina.value; break;

            case ToCompare.stamina_Percentage:  toCompare = (character.stamina.value / character.stamina.maxValue) * 100; break;
            }

            return(base.CalculateScore(controller));
        }
示例#27
0
        public virtual void OnActionEnter(AISController ctrl)
        {
            if (!init)
            {
                Init();
            }

            switch (exe)
            {
            case Execution.Parallel:
                foreach (AISAction c in children)
                {
                    c.OnActionEnter(ctrl);
                }
                break;

            case Execution.Best_Score:
                if (children.Count != 0)
                {
                    foreach (AISScorer s in children.SelectMany(x => x.scorers))
                    {
                        s.StartScoring(ctrl);
                    }
                    bestChild.Add(ctrl, BestAction(ctrl));
                    bestChild[ctrl].OnActionEnter(ctrl);
                }
                break;

            case Execution.Sequential:

                break;
            }

            if (!following)
            {
                coroutines.Add(ctrl, ctrl.StartCoroutine(ActionCoroutine(ctrl)));
            }

            controllers.Add(ctrl);
        }
示例#28
0
 public T Get <T>(AISController ctrl, List <T> tList)
 {
     return(tList[controllers.IndexOf(ctrl)]);
 }
示例#29
0
 public override void OnAction(AISController controller)
 {
     base.OnAction(controller);
     //if (controller.motor.currentState != state) controller.motor.nextState = state;
 }
示例#30
0
 public override void OnActionEnter(AISController controller)
 {
     base.OnActionEnter(controller);
     //controller.motor.nextState = state;
 }