/// <summary> /// Adds an action to this action controller /// </summary> /// <param name="name">Action name</param> /// <param name="action">Action object</param> public void Add(string name, OTAction action) { name = name.ToLower(); if (!actions.ContainsKey(name)) { actions.Add(name, action); actionList.Add(action); actionNames.Add(name); action.SetOwner(owner, name); } }
void RunAction(OTAction action) { if (!runningTreeActions.Contains(action)) { action.Start(); if (!runningActions.Contains(action)) { runningActions.Add(action); } if (onStartAction != null) { onStartAction(action); } if (!CallBack("onStartAction", new object[] { action })) { CallBack("OnStartAction", new object[] { action }); } } }
void RunTree(OTActionTree tree) { if (runningTree != null) { while (runningTreeActions.Count > 0) { OTAction a = runningTreeActions[0]; a.Complete(); if (onStopAction != null) { onStopAction(a); } runningTreeActions.Remove(a); } if (onStopTree != null) { onStopTree(runningTree); } if (!CallBack("onStopTree", new object[] { runningTree })) { CallBack("OnStopTree", new object[] { runningTree }); } runningTreeElements.Clear(); } runningTree = tree; if (onStartTree != null) { onStartTree(runningTree); } if (!CallBack("onStartTree", new object[] { runningTree })) { CallBack("OnStartTree", new object[] { runningTree }); } if (owner != null) { RunTreeElements(tree.rootElements); } }
void RunAction(OTAction action) { if (!runningTreeActions.Contains(action)) { action.Start(); if (!runningActions.Contains(action)) runningActions.Add(action); if (onStartAction != null) onStartAction(action); if (!CallBack("onStartAction", new object[] { action })) CallBack("OnStartAction", new object[] { action }); } }
/// <summary> /// Adds an action to this action controller /// </summary> /// <param name="name">Action name</param> /// <param name="action">Action object</param> public void Add(string name, OTAction action) { name = name.ToLower(); if (!actions.ContainsKey(name)) { actions.Add(name, action); actionList.Add(action); actionNames.Add(name); action.SetOwner(owner, name); } }
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); } }