Exemple #1
0
		public Sequence (params FiniteTimeAction[] actions) : base ()
		{

			Actions = new FiniteTimeAction[2];

			var prev = actions [0];

			// Can't call base(duration) because we need to calculate duration here
			float combinedDuration = 0.0f;
			foreach (FiniteTimeAction action in actions)
			{
				combinedDuration += action.Duration;
			}
			Duration = combinedDuration;

			if (actions.Length == 1)
			{
				InitSequence (prev, new ExtraAction ());
			}
			else
			{
				// Basically what we are doing here is creating a whole bunch of 
				// nested Sequences from the actions.
				for (int i = 1; i < actions.Length - 1; i++)
				{
					prev = new Sequence (prev, actions [i]);
				}

				InitSequence (prev, actions [actions.Length - 1]);
			}

		}
Exemple #2
0
		public SequenceState (Sequence action, Node target)
			: base (action, target)
		{ 
			actionSequences = action.Actions;
			hasInfiniteAction = (actionSequences [0] is RepeatForever) || (actionSequences [1] is RepeatForever);
			split = actionSequences [0].Duration / Duration;
			last = -1;

		}
Exemple #3
0
        /// <summary>
        /// Runs an Action that can be awaited.
        /// </summary>
        /// <param name="action">A FiniteTimeAction.</param>
        public Task<ActionState> RunActionsAsync(FiniteTimeAction action)
        {
            var tcs = new TaskCompletionSource<ActionState>();

            ActionState state = null;
            var completion = new CallFunc(() => tcs.TrySetResult(state));

            var asyncAction = new Sequence(action, completion);

            state = Application.Current.ActionManager.AddAction(asyncAction, this);
            return tcs.Task;
        }
Exemple #4
0
		private void InitSpawn (FiniteTimeAction action1, FiniteTimeAction action2)
		{
			Debug.Assert (action1 != null);
			Debug.Assert (action2 != null);

			float d1 = action1.Duration;
			float d2 = action2.Duration;

			ActionOne = action1;
			ActionTwo = action2;

			if (d1 > d2)
			{
				ActionTwo = new Sequence (action2, new DelayTime (d1 - d2));
			}
			else if (d1 < d2)
			{
				ActionOne = new Sequence (action1, new DelayTime (d2 - d1));
			}
		}
Exemple #5
0
		public Parallel (params FiniteTimeAction[] actions) : base ()
		{
			// Can't call base(duration) because max action duration needs to be determined here
			float maxDuration = 0.0f;
			foreach (FiniteTimeAction action in actions)
			{
				if (action.Duration > maxDuration)
				{
					maxDuration = action.Duration;
				}
			}
			Duration = maxDuration;

			Actions = actions;

			for (int i = 0; i < Actions.Length; i++)
			{
				var actionDuration = Actions [i].Duration;
				if (actionDuration < Duration)
				{
					Actions [i] = new Sequence (Actions [i], new DelayTime (Duration - actionDuration));
				}
			}
		}