/** * Perform multiple actions when binding to an ActionAcceptor */ public void Bind(IBinder binder) { IActionPerformer performer = binder as IActionPerformer; PerformableActions performable = performer.PerformableActions; AcceptableActions acceptable = binder.BoundAcceptor.AcceptableActions; performable.RefreshEnabledActions(); acceptable.Bind(performer); acceptable.RefreshEnabledActions(); PerformerAction matching = null; foreach (var action in performable.EnabledActions) { AcceptorAction acceptorAction; if (acceptable.EnabledActions.TryGetValue(action.Key, out acceptorAction)) { PerformerAction performerAction = action.Value; performerAction.Bind(acceptorAction.AcceptCondition); matching = performerAction; break; } } StartCoroutine(PerformActions(binder, matching)); }
IEnumerator Perform(PerformerAction action) { float time = action.Duration; float eTime = 0; while (eTime < time) { eTime += Time.deltaTime; action.Perform(eTime / time); yield return(null); } action.End(); }
IEnumerator PerformActions(IBinder binder, PerformerAction action) { if (action != null) { yield return(StartCoroutine(Perform(action))); Bind(binder); } else { IActionPerformer performer = binder as IActionPerformer; performer.PerformableActions.RefreshEnabledActions(); binder.OnEndActions(); } }
/** * Perform a single action */ public void StartAction(PerformerAction action) { StartCoroutine(Perform(action)); }