Ejemplo n.º 1
0
        /** Helper constructor to create an array of sequenceable actions.
         *
         * @return An autoreleased Sequence object.
         */
        public Sequence(params FiniteTimeAction[] actions)
            : base(0)
        {
            int count = actions.Length;

            if (count == 0)
            {
                Debug.Assert(false, "actions can't be empty");
                _actions [0] = new ExtraAction();
                _actions [1] = new ExtraAction();
            }
            else
            {
                _actions [0] = actions [0];
                if (count == 1)
                {
                    _actions [1] = new ExtraAction();
                }
                else
                {
                    // else size > 1
                    for (int i = 1; i < count - 1; ++i)
                    {
                        _actions [0] = new Sequence(_actions [0], actions [i]);
                    }
                    _actions [1] = actions [count - 1];
                }
            }
            _duration = _actions [0].duration + _actions [1].duration;
        }
Ejemplo n.º 2
0
        /** Helper constructor to create an array of spawned actions given an array.
         *
         * @param arrayOfActions    An array of spawned actions.
         * @return  An autoreleased Spawn object.
         */
        public Spawn(params FiniteTimeAction[] actions)
            : base(0)
        {
            int count = actions.Length;

            if (count == 0)
            {
                Debug.Assert(false, "actions can't be empty");
                _one = new ExtraAction();
                _two = new ExtraAction();
            }
            else
            {
                _one = actions [0];
                if (count == 1)
                {
                    _two = new DelayTime(_one.duration);
                }
                else
                {
                    // else size > 1
                    for (int i = 1; i < count - 1; ++i)
                    {
                        _one = new Spawn(_one, actions [i]);
                    }
                    _two = actions [count - 1];

                    float delta = _one.duration - _two.duration;
                    if (delta > 0)
                    {
                        _two = new Sequence(_two, new DelayTime(delta));
                    }
                    else if (delta < 0)
                    {
                        _one = new Sequence(_one, new DelayTime(-delta));
                    }
                }
            }
            _duration = Mathf.Max(_one.duration, _two.duration);
        }