예제 #1
0
        /// <summary>
        /// Repeat an action a number of times (or until aborted)
        /// </summary>
        /// <param name="gameObject">This game object</param>
        /// <param name="seconds">Seconds before runs (unscaled)</param>
        /// <param name="callback">Callback action</param>
        /// <param name="parentPromise">Parent promise used for aborting (generally NULL)</param>
        /// <returns></returns>
        public static GmObjectEventPromise RepeatUnscaled(this GameObject gameObject, float seconds, int count, Action callback, GmObjectEventPromise parentPromise = null)
        {
            if (parentPromise == null)
            {
                parentPromise = new GmObjectEventPromise();
            }

            // All done
            if (count <= 0)
            {
                parentPromise.Done();
            }
            else
            {
                // Schedule the next one
                gameObject.GetEventBehaviour().ScheduleActionUnscaled(seconds, () =>
                {
                    if (!parentPromise.IsAborted && !parentPromise.IsDone)
                    {
                        callback();
                        // Schedule another one until aborted
                        gameObject.RepeatUnscaled(seconds, count - 1, callback, parentPromise);
                    }
                }, parentPromise);
            }

            return(parentPromise);
        }
        /// <summary>
        /// Add an event at the time scale/offset for this list
        /// </summary>
        /// <param name="scheduledTime">the scheduled time in the scale/offset for this list</param>
        /// <param name="action">The callback action</param>
        /// <returns>Scheduled Action (Promise)</returns>
        public GmObjectEventAction Add(float scheduledTime, Action action, GmObjectEventPromise parentPromise = null)
        {
            var newScheduledAction = new GmObjectEventAction(scheduledTime, action, parentPromise);

            Add(newScheduledAction.Key, newScheduledAction);
            return(newScheduledAction);
        }
예제 #3
0
 /// <summary>
 /// Construct a acheduled action
 /// </summary>
 /// <param name="scheduledTime">The scheduled time</param>
 /// <param name="action">The action callback</param>
 public GmObjectEventAction(float scheduledTime, Action action, GmObjectEventPromise parentPromise = null)
 {
     Key    = new GmObjectEventActionKey(scheduledTime);
     Action = action;
     if (parentPromise != null)
     {
         parentPromise.ChildPromise = this;
     }
 }
예제 #4
0
        /// <summary>
        /// Repeat an action forever (or until aborted)
        /// </summary>
        /// <param name="gameObject">This game object</param>
        /// <param name="seconds">Seconds before runs</param>
        /// <param name="callback">Callback action</param>
        /// <param name="parentPromise">Parent promise used for aborting (generally NULL)</param>
        /// <returns></returns>
        public static GmObjectEventPromise ForeverUnscaled(this GameObject gameObject, float seconds, Action callback, GmObjectEventPromise parentPromise = null)
        {
            if (parentPromise == null)
            {
                parentPromise = new GmObjectEventPromise();
            }

            // Schedule the next one
            gameObject.GetEventBehaviour().ScheduleActionUnscaled(seconds, () =>
            {
                if (!parentPromise.IsAborted && !parentPromise.IsDone)
                {
                    callback();
                    // Schedule another one until aborted
                    gameObject.ForeverUnscaled(seconds, callback, parentPromise);
                }
            }, parentPromise);

            return(parentPromise);
        }
 /// <summary>
 /// Schedule an action using unscaled time
 /// </summary>
 /// <param name="seconds">Seconds from now</param>
 /// <param name="callback">The callback action</param>
 /// <returns>Scheduled Action (Promise)</returns>
 internal GmObjectEventPromise ScheduleActionUnscaled(float seconds, Action callback, GmObjectEventPromise parentPromise = null)
 {
     //Debug.Log("Schedule for " + Mathf.Round((elapsedTimeUnscaled + seconds) * 10) / 10 + " unscaled");
     return(ActionListUnscaled.Add(elapsedTimeUnscaled + seconds, callback, parentPromise));
 }
예제 #6
0
 public GmObjectEventPromiseAwaiter(GmObjectEventPromise promise)
 {
     gmPromise = promise;
 }
예제 #7
0
 public static GmObjectEventPromiseAwaiter GetAwaiter(this GmObjectEventPromise promise)
 {
     return(new GmObjectEventPromiseAwaiter(promise));
 }