/// <summary> /// Walks through the tree, and calls the handler for each node. /// </summary> /// <param name="handler">The method to be called for each nodes</param> public void Walk(WalkHandler handler) { List <Element> ancestors = new List <Element>(); handler?.Invoke(this, ancestors); Walk(this, ancestors, handler); }
//Steps are inclusive, meaning that steps=10 runs from [0, 10], and they have to be > 0 public void walk(int steps, WalkHandler handler) { if (steps <= 0) return; float resolution = 1f / (float)steps; for (int i = 0; i <= steps; i++) { float t = resolution * i; handler(t, i, getPosition(t)); } }
private void Walk(Element parent, List <Element> ancestors, WalkHandler handler) { if (parent.children != null) { List <Element> _ancestors = new List <Element>(ancestors) { parent }; foreach (Element child in parent.children) { handler?.Invoke(child, _ancestors); Walk(child, _ancestors, handler); } } }
// Start is called before the first frame update void Start() { // state = GetComponent<CharacterState>(); jump = GetComponent <JumpHandler>(); walk = GetComponent <WalkHandler>(); }