public override void OnAction(AISController ctrl) { base.OnAction(ctrl); AISVarList l = (AISVarList)ctrl.GetVar(listKey); l.PassToSingle((AISVarSingle)ctrl.GetVar(best), GetBest(ctrl, l)); }
public IEnumerator ActionCoroutine(AISController ctrl) { while (true) { OnAction(ctrl); yield return(new WaitForSeconds(updateTime)); } }
IEnumerator ScoreCoroutine(AISController ctrl) { while (true) { Score(ctrl); yield return(new WaitForSeconds(updateTime)); } }
public void InitComponent(AISController ctrl) { mb = ctrl.GetComponent(type); if (!mb) { ic = ctrl.GetComponent <ItemHolder>().item.GetComponent(type); } }
public override int CalculateScore(AISController ai) { if (Evaluate(ai)) { return(trueScore); } else { return(falseScore); } }
float Score(AISController ctrl, AISVarList l, int idx) { float scor = 0; foreach (var v in varScorers) { scor += v.Score(ctrl, l, idx); } return(scor); }
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); }
public int Score(AISController ctrl) { int s = 0; for (int i = 0; i < scorers.Count; i++) { s += scorers[i].GetScore(ctrl); } return(s); }
public static List <Vector3> GetListVector3(AISController ctrl, AISVariable key) { if (!ctrl.ContainsKey(key)) { return(null); } AISVarList vars = (AISVarList)ctrl.GetVar(key); return(vars.vector3); }
public static Vector3 GetSingleVector3(AISController ctrl, AISVariable key) { if (!ctrl.ContainsKey(key)) { return(Vector3.zero); } AISVarSingle var = (AISVarSingle)ctrl.GetVar(key); return(var.vector3); }
public static List <float> GetListFloat(AISController ctrl, AISVariable key) { if (!ctrl.ContainsKey(key)) { return(null); } AISVarList vars = (AISVarList)ctrl.GetVar(key); return(vars.@float); }
public static float GetSingleFloat(AISController ctrl, AISVariable key) { if (!ctrl.ContainsKey(key)) { return(0); } AISVarSingle var = (AISVarSingle)ctrl.GetVar(key); return(var.@float); }
public static int GetSingleInt <T>(AISController ctrl, AISVariable key) { if (!ctrl.ContainsKey(key)) { return(0); } AISVarSingle var = (AISVarSingle)ctrl.GetVar(key); return(var.@int); }
[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); } }
public virtual void OnAction(AISController ctrl) { if (!controllers.Contains(ctrl)) { return; } if (!following && follow != null) { follow(ctrl); } }
public override void OnActionExit(AISController ctrl) { base.OnActionExit(ctrl); if (!destiny.ContainsKey(ctrl)) { return; } destiny.Remove(ctrl); ctrl.navAgent.destination = ctrl.transform.position; }
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; }
public override void OnActionEnter(AISController ctrl) { base.OnActionEnter(ctrl); Transform t = AISEditorUtil.GetSingleObject <Transform>(ctrl, destinyKey); if (!t) { return; } destiny.Add(ctrl, t); }
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); } }
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; }
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); }
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); }
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); }
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); } } }
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(); } }
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)); }
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); }
public T Get <T>(AISController ctrl, List <T> tList) { return(tList[controllers.IndexOf(ctrl)]); }
public override void OnAction(AISController controller) { base.OnAction(controller); //if (controller.motor.currentState != state) controller.motor.nextState = state; }
public override void OnActionEnter(AISController controller) { base.OnActionEnter(controller); //controller.motor.nextState = state; }