public void AddElement(OTActionTreeElement el) { string name = el.name.ToLower(); if (!elements.ContainsKey(name)) elements.Add(name,el); }
/// <summary> /// Adds a serial tree element /// </summary> /// <param name="name">Action name of this tree element</param> /// <param name="duration">Action duration in seconds</param> /// <returns>Added tree element</returns> public OTActionTreeElement FollowedBy(string name, float duration) { OTActionTreeElement el = new OTActionTreeElement(_tree, this, name, duration); _children.Add(el); return(el); }
/// <summary> /// Adds a first tree element to the tree /// </summary> /// <param name="name">Name of this tree element's action</param> /// <param name="duration">Duration override</param> /// <returns>The added tree element</returns> public OTActionTreeElement Action(string name, float duration) { OTActionTreeElement el = new OTActionTreeElement(this, null, name, duration); root.Add(el); return(el); }
/// <summary> /// Action tree element constructor /// </summary> /// <param name="tree">Tree of this element</param> /// <param name="parent">Parament tree element</param> /// <param name="name">Name of the action to use</param> /// <param name="duration">Duration of this action in seconds</param> public OTActionTreeElement(OTActionTree tree, OTActionTreeElement parent, string name, float duration) { _name = name; this._duration = duration; this.parent = parent; this._tree = tree; tree.AddElement(this); }
/// <summary> /// Adds a parallel tree element /// </summary> /// <param name="name">Action name of this tree element</param> /// <param name="duration">Action duration in seconds</param> /// <returns>Added tree element</returns> public OTActionTreeElement And(string name, float duration) { OTActionTreeElement el = new OTActionTreeElement(_tree, parent, name, duration); if (parent == null) _tree.Root(el); else parent._children.Add(el); return el; }
/// <summary> /// Action tree element constructor /// </summary> /// <param name="tree">Tree of this element</param> /// <param name="parent">Parament tree element</param> /// <param name="name">Name of the action to use</param> /// <param name="duration">Duration of this action in seconds</param> public OTActionTreeElement(OTActionTree tree, OTActionTreeElement parent, string name, float duration) { _name = name; this._duration = duration; this.parent = parent; this._tree = tree; tree.AddElement(this); }
public void AddElement(OTActionTreeElement el) { string name = el.name.ToLower(); if (!elements.ContainsKey(name)) { elements.Add(name, el); } }
/// <summary> /// Adds a parallel tree element /// </summary> /// <param name="name">Action name of this tree element</param> /// <param name="duration">Action duration in seconds</param> /// <returns>Added tree element</returns> public OTActionTreeElement And(string name, float duration) { OTActionTreeElement el = new OTActionTreeElement(_tree, parent, name, duration); if (parent == null) { _tree.Root(el); } else { parent._children.Add(el); } return(el); }
void RunTreeElements(List <OTActionTreeElement> elements) { for (int e = 0; e < elements.Count; e++) { OTActionTreeElement el = elements[e]; string name = el.name.ToLower(); if (actions.ContainsKey(name)) { if (runningActions.Contains(actions[name])) { actions[name].Stop(); if (onStopAction != null) { onStopAction(actions[name]); } runningActions.Remove(actions[name]); } if (el.duration > 0) { actions[name].duration = el.duration; } actions[name].speed = treeSpeed; actions[name].count = 1; actions[name].Start(); runningTreeActions.Add(actions[name]); runningTreeElements.Add(el); if (onStartAction != null) { onStartAction(actions[name]); } if (!CallBack("onStartAction", new object[] { actions[name] })) { CallBack("OnStartAction", new object[] { actions[name] }); } } } }
/// <summary> /// Adds a first tree element to the tree /// </summary> /// <param name="name">Name of this tree element's action</param> /// <param name="duration">Duration override</param> /// <returns>The added tree element</returns> public OTActionTreeElement Action(string name, float duration) { OTActionTreeElement el = new OTActionTreeElement(this, null, name, duration); root.Add(el); return el; }
/// <summary> /// Adds a tree element to the root of the tree /// </summary> /// <param name="el">Tree element to add</param> public void Root(OTActionTreeElement el) { root.Add(el); }
/// <summary> /// Adds the action tree of an tree element /// </summary> /// <param name="name">Action tree name</param> /// <param name="element">Action tree element</param> public void Add(string name, OTActionTreeElement element) { Add(name, element.tree); }
/// <summary> /// Adds a serial tree element /// </summary> /// <param name="name">Action name of this tree element</param> /// <param name="duration">Action duration in seconds</param> /// <returns>Added tree element</returns> public OTActionTreeElement FollowedBy(string name, float duration) { OTActionTreeElement el = new OTActionTreeElement(_tree, this, name, duration); _children.Add(el); return el; }
/// <summary> /// Adds a tree element to the root of the tree /// </summary> /// <param name="el">Tree element to add</param> public void Root(OTActionTreeElement el) { root.Add(el); }
protected override void Update() { base.Update(); int r = 0; // update single running actions if (runningActions.Count > 0) { r = 0; while (r < runningActions.Count) { OTAction a = runningActions[r]; if (a.Update(deltaTime)) { if (runningActions.Count == 0) { return; } if (a.count > 0) { a.count--; } if (a.count > 0 || a.count == -1) { a.Start(); } else { a.Stop(); if (onStopAction != null) { onStopAction(a); } if (!CallBack("onStopAction", new object[] { a })) { CallBack("OnStopAction", new object[] { a }); } runningActions.Remove(a); } } else { r++; } if (runningActions.Count == 0) { return; } } } // update running tree actions if (runningTreeActions.Count > 0) { string currentRuningTree = runningTree.name; r = 0; List <OTActionTreeElement> closedElements = new List <OTActionTreeElement>(); while (r < runningTreeActions.Count) { OTAction a = runningTreeActions[r]; if (a.Update(deltaTime)) { if (runningTree == null) { return; } if (runningTree.name != currentRuningTree || runningTreeActions.Count == 0) { return; } a.Stop(); if (onStopAction != null) { onStopAction(a); } if (!CallBack("onStopAction", new object[] { a })) { CallBack("OnStopAction", new object[] { a }); } closedElements.Add(runningTreeElements[r]); runningTreeActions.Remove(a); runningTreeElements.RemoveAt(r); } else { if (runningTree.name != currentRuningTree || runningTreeActions.Count == 0) { return; } r++; } } if (closedElements.Count > 0) { while (closedElements.Count > 0) { OTActionTreeElement el = closedElements[0]; if (el.children.Count > 0) { RunTreeElements(el.children); } closedElements.Remove(el); } } if (runningTreeActions.Count == 0) { // tree has ended if (treeCount > 1 || treeCount == -1) { if (treeCount > 1) { treeCount--; } RunTree(runningTree); } else { if (onStopTree != null) { onStopTree(runningTree); } runningTree = null; } } } else { if (runningTree != null && owner != null) { RunTree(runningTree); } } if (nextNames.Count != 0 && runningTreeActions.Count == 0 && runningActions.Count == 0 && owner != null) { Run(nextNames[0], nextSpeeds[0], nextCounts[0]); nextNames.RemoveAt(0); nextSpeeds.RemoveAt(0); nextCounts.RemoveAt(0); } }
/// <summary> /// Adds the action tree of an tree element /// </summary> /// <param name="name">Action tree name</param> /// <param name="element">Action tree element</param> public void Add(string name, OTActionTreeElement element) { Add(name, element.tree); }