/// <summary> /// Add a new child to the Selector, creating a PriorityNode. /// </summary> /// <param name='child'>Child.</param> /// <param name="prio">The assigned priority</param> /// <returns>A reference to the PriorityNode.</returns> public void AddChild(Node child, double prio = 1.0) { if (prio <= 0) throw new ArgumentException("prio must be positive: " + prio); PriorityNode pn = new PriorityNode(child,prio); children_.Add(pn); prioTotal += pn.Prio; }
// Use this for initialization void Start() { mate = buddy.transform; speed = 1.1f; direction = mate.position - transform.position; root = new SequenceSelector(); redSeq = new SequenceSelector(); colors = new PrioritySelector(); movement = new PrioritySelector(); close = new Condition(() => Mathf.Abs(Vector3.Distance(transform.position, mate.position)) < kindaClose); red = new Action(Red); green = new Action(Green); toward = new Action(Toward); away = new Action(Away); root.AddChild(colors, movement); colors.AddChild(redSeq,1.0); colors.AddChild(green); redSeq.AddChild(close,red); movement.AddChild(away,farAway); towardPrio = movement.AddChild(toward); toward.name = "toward"; }
/// <summary> /// Add a new child to the Selector, creating a PriorityNode. /// Take care to always save the return value as that is the only way to change its priority! /// </summary> /// <param name='child'>Child.</param> /// <param name="prio">The assigned priority</param> /// <returns>A reference to the PriorityNode.</returns> public PriorityNode AddChild(Node child, double prio = 1.0) { PriorityNode pn = new PriorityNode(child,prio); children_.Add(pn); return pn; }
// Use this for initialization void Start() { mate = buddy.transform; updatespeed = 0.05f; root = new PrioritySelector(); redder = new Action(Redder); bluer = new Action(Bluer); redder.name = "redder"; bluer.name = "bluer"; redPrio = root.AddChild(redder,0.0); bluePrio = root.AddChild(bluer,100.0); close = new ConditionDecorator(root, () => Mathf.Abs(Vector3.Distance(transform.position, mate.position)) > kindaClose); //InvokeRepeating("MyUpdate", .01f,updatespeed); }