Пример #1
0
 /// <summary>
 /// Creates a batch of movement tweens for the <see cref="Transform"/>[] <paramref name="targets"/>.
 /// </summary>
 /// <param name="targets">The <see cref="Transform"/>[] that are the targets of this tween batch.</param>
 /// <param name="fromArray">The <see cref="Vector3"/>[] where the move from position should be assigned from.</param>
 /// <param name="toArray">The <see cref="Vector3"/>[] where the move to position should be assigned from.</param>
 /// <param name="duration">The length of time in seconds that the tween batch should take to complete or one pass if looping.</param>
 /// <param name="tweenHandle">The <see cref="ITweenHandle"/> instance that will be initialized for this tween.</param>
 /// <param name="spaceType">The coordinate system the tween batch should operate in (default is World).</param>
 /// <param name="easeType">The type of easing the tween batch should use while playing (default is Linear).</param>
 /// <param name="loopType">The type of looping that should be used (default is None).</param>
 /// <param name="loopCount">If looping, the number of loops that should occur before completing. If set to -1, the tween will loop infinitely. (default is zero)</param>
 public void BatchMove(
     Transform[] targets,
     Vector3[] fromArray,
     Vector3[] toArray,
     float duration,
     out ITweenHandle tweenHandle,
     SpaceType spaceType = SpaceType.World,
     EaseType easeType   = EaseType.Linear,
     LoopType loopType   = LoopType.None,
     int loopCount       = 0)
 {
     _batchTransformTweener.BatchMove(
         targets,
         fromArray,
         toArray,
         0,
         targets.Length,
         duration,
         spaceType,
         easeType,
         loopType,
         loopCount,
         null,
         null,
         true,
         out tweenHandle);
 }
Пример #2
0
 /// <summary>
 /// Creates a batch of rotation tweens for a slice from <see cref="Transform"/>[] <paramref name="targets"/>
 /// starting at <paramref name="startIndex"/> to <paramref name="length"/>.
 /// </summary>
 /// <param name="targets">The <see cref="Transform"/>[] that are the targets of this tween batch.</param>
 /// <param name="fromArray">The <see cref="Quaternion"/>[] where the from rotation should be assigned from.</param>
 /// <param name="toArray">The <see cref="Quaternion"/>[] where the to rotation should be assigned from.</param>
 /// <param name="startIndex">The index where the slice should start from in the parameter arrays.</param>
 /// <param name="length">The length from which values should copied in the parameter arrays starting from the <paramref name="startIndex"/>.</param>
 /// <param name="duration">The length of time in seconds that the tween batch should take to complete or one pass if looping.</param>
 /// <param name="tweenHandle">The <see cref="ITweenHandle"/> instance that will be initialized for this tween.</param>
 /// <param name="spaceType">The coordinate system the tween batch should operate in (default is World).</param>
 /// <param name="easeType">The type of easing the tween batch should use while playing (default is Linear).</param>
 /// <param name="loopType">The type of looping that should be used (default is None).</param>
 /// <param name="loopCount">If looping, the number of loops that should occur before completing. If set to -1, the tween will loop infinitely. (default is zero)</param>
 public void BatchRotateSlice(
     Transform[] targets,
     Quaternion[] fromArray,
     Quaternion[] toArray,
     int startIndex,
     int length,
     float duration,
     out ITweenHandle tweenHandle,
     SpaceType spaceType = SpaceType.World,
     EaseType easeType   = EaseType.Linear,
     LoopType loopType   = LoopType.None,
     int loopCount       = 0)
 {
     _batchTransformTweener.BatchRotate(
         targets,
         fromArray,
         toArray,
         startIndex,
         length,
         duration,
         spaceType,
         easeType,
         loopType,
         loopCount,
         null,
         null,
         true,
         out tweenHandle);
 }
Пример #3
0
 /// <summary>
 /// Creates a batch of tweens animating movement, rotation, and scaling for the <see cref="Transform"/>[] <paramref name="targets"/>.
 /// </summary>
 /// <param name="targets">The <see cref="Transform"/>[] that are the targets of this tween batch.</param>
 /// <param name="fromPosArray">The <see cref="Vector3"/>[] where the from position should be assigned from.</param>
 /// <param name="toPosArray">The <see cref="Vector3"/>[] where the from position should be assigned from.</param>
 /// <param name="fromRotArray">The <see cref="Quaternion"/>[] where the from rotation should be assigned from.</param>
 /// <param name="toRotArray">The <see cref="Quaternion"/>[] where the to rotation should be assigned from.</param>
 /// <param name="fromScaleArray">The <see cref="Vector3"/>[] where the from scale should be assigned from.</param>
 /// <param name="toScaleArray">The <see cref="Vector3"/>[] where the to scale should be assigned from.</param>
 /// <param name="duration">The length of time in seconds that the tween batch should take to complete or one pass if looping.</param>
 /// <param name="tweenHandle">The <see cref="ITweenHandle"/> instance that will be initialized for this tween.</param>
 /// <param name="spaceType">The coordinate system the tween batch should operate in (default is World).</param>
 /// <param name="easeType">The type of easing the tween batch should use while playing (default is Linear).</param>
 /// <param name="loopType">The type of looping that should be used (default is None).</param>
 /// <param name="loopCount">If looping, the number of loops that should occur before completing. If set to -1, the tween will loop infinitely. (default is zero)</param>
 public void BatchUpdateTransforms(
     Transform[] targets,
     Vector3[] fromPosArray,
     Vector3[] toPosArray,
     Quaternion[] fromRotArray,
     Quaternion[] toRotArray,
     Vector3[] fromScaleArray,
     Vector3[] toScaleArray,
     float duration,
     out ITweenHandle tweenHandle,
     SpaceType spaceType = SpaceType.World,
     EaseType easeType   = EaseType.Linear,
     LoopType loopType   = LoopType.None,
     int loopCount       = 0)
 {
     _batchTransformTweener.BatchUpdateTransforms(
         targets,
         fromPosArray,
         toPosArray,
         fromRotArray,
         toRotArray,
         fromScaleArray,
         toScaleArray,
         0,
         targets.Length,
         duration,
         spaceType,
         easeType,
         loopType,
         loopCount,
         null,
         null,
         true,
         out tweenHandle);
 }
 /// <summary>
 /// Moves the <see cref="Transform"/> <paramref name="target"/>.
 /// </summary>
 /// <param name="target">The <see cref="Transform"/> that is the target of this tween.</param>
 /// <param name="from">The position the <see cref="Transform"/> will be moved from.</param>
 /// <param name="to">The position the <see cref="Transform"/> will be moved to.</param>
 /// <param name="duration">The length of time in seconds that the tween should take to complete or one pass if looping.</param>
 /// <param name="tweenHandle">The <see cref="ITweenHandle"/> instance that will be initialized for this tween.</param>
 /// <param name="spaceType">The coordinate system the tween should operate in (default is World).</param>
 /// <param name="easeType">The type of easing the tween should use while playing (default is Linear).</param>
 /// <param name="loopType">The type of looping that should be used (default is None).</param>
 /// <param name="loopCount">If looping, the number of loops that should occur before completing. If set to -1, the tween will loop infinitely. (default is zero)</param>
 public void Move(
     Transform target,
     Vector3 from,
     Vector3 to,
     float duration,
     out ITweenHandle tweenHandle,
     SpaceType spaceType = SpaceType.World,
     EaseType easeType   = EaseType.Linear,
     LoopType loopType   = LoopType.None,
     int loopCount       = 0)
 {
     _singleTransformTweener.Move(
         target,
         from,
         to,
         duration,
         spaceType,
         easeType,
         loopType,
         loopCount,
         null,
         null,
         true,
         out tweenHandle);
 }
 /// <summary>
 /// Rotates the <see cref="Transform"/> <paramref name="target"/> around the the specified axis
 /// (RotateMode.XYZ is an invalid value and will cause an assertion).
 /// </summary>
 /// <param name="target">The <see cref="Transform"/> that is the target of this tween.</param>
 /// <param name="angle"></param>
 /// <param name="duration">The length of time in seconds that the tween should take to complete or one pass if looping.</param>
 /// <param name="rotateMode"></param>
 /// <param name="tweenHandle">The <see cref="ITweenHandle"/> instance that will be initialized for this tween.</param>
 /// <param name="spaceType">The coordinate system the tween should operate in (default is World).</param>
 /// <param name="easeType">The type of easing the tween should use while playing (default is Linear).</param>
 /// <param name="loopType">The type of looping that should be used (default is None).</param>
 /// <param name="loopCount">If looping, the number of loops that should occur before completing. If set to -1, the tween will loop infinitely. (default is zero)</param>
 public void RotateOnAxis(
     Transform target,
     float angle,
     float duration,
     RotateMode rotateMode,
     out ITweenHandle tweenHandle,
     SpaceType spaceType = SpaceType.World,
     EaseType easeType   = EaseType.Linear,
     LoopType loopType   = LoopType.None,
     int loopCount       = 0)
 {
     _singleTransformTweener.RotateOnAxis(
         target,
         angle,
         duration,
         rotateMode,
         spaceType,
         easeType,
         loopType,
         loopCount,
         null,
         null,
         true,
         out tweenHandle);
 }
Пример #6
0
        public override void Add(ITweenHandle tweenHandle)
        {
            tweenHandle.AddOnStartedListener(OnTweenStarted);
            tweenHandle.AddOnCompletedListener(OnTweenCompleted);

            _tweenList.Add((TweenHandle)tweenHandle);
        }
Пример #7
0
 private void OnRecycleButtonClicked()
 {
     if (_tweenHandle != null)
     {
         _tweenHandle.Recycle();
         _tweenHandle = null;
     }
     else
     {
         Debug.Log("Tween needs to be created first via Play button before trying to recycle it.");
     }
 }
Пример #8
0
 // Abstract methods for collections.
 public abstract void Add(ITweenHandle tweenHandle);
        public void BatchUpdateTransforms(
            Transform[] targets,
            Vector3[] fromPosArray,
            Vector3[] toPosArray,
            Quaternion[] fromRotArray,
            Quaternion[] toRotArray,
            Vector3[] fromScaleArray,
            Vector3[] toScaleArray,
            int startIndex,
            int length,
            float duration,
            SpaceType spaceType,
            EaseType easeType,
            LoopType loopType,
            int loopCount,
            Action onStart,
            Action onComplete,
            bool useTweenHandle,
            out ITweenHandle tweenHandle)
        {
            // Ensure that our arrays are non-null and have sufficient capacity for the intended slice.
            Assert.IsNotNull(targets);
            Assert.IsNotNull(fromRotArray);
            Assert.IsNotNull(toRotArray);
            Assert.IsTrue(targets.Length >= startIndex + length &&
                          fromPosArray.Length >= startIndex + length &&
                          toPosArray.Length >= startIndex + length &&
                          fromRotArray.Length >= startIndex + length &&
                          toRotArray.Length >= startIndex + length &&
                          fromScaleArray.Length >= startIndex + length &&
                          toScaleArray.Length >= startIndex + length);

            tweenHandle = null;

            var batchIndex  = _transforms.Length;
            var batchLength = length;

            _tweenBatches.Add(new TweenTransformBatchState
            {
                state      = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START,
                startIndex = (uint)batchIndex,
                length     = (uint)batchLength
            });
            _tweenBatchLifetimes.Add(new TweenLifetime
            {
                duration          = Mathf.Max(0, duration),
                easeType          = easeType,
                loopType          = loopType,
                loopCount         = (short)Mathf.Clamp(loopCount, -1, short.MaxValue),
                originalLoopCount = (short)Mathf.Clamp(loopCount, -1, short.MaxValue)
            });
            var hasEvents = onStart != null || onComplete != null;

            if (useTweenHandle || hasEvents)
            {
                var availableTweenHandle = GetNextAvailableTweenHandle();
                availableTweenHandle.state = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START;
                if (onStart != null)
                {
                    availableTweenHandle.AddOnStartedListener(onStart);
                }

                if (onComplete != null)
                {
                    availableTweenHandle.AddOnCompletedListener(onComplete);
                }

                _tweenBatchHandles.Add(availableTweenHandle);

                // Only populate the out parameter if explicitly called out for.
                if (useTweenHandle)
                {
                    tweenHandle = availableTweenHandle;
                }
            }
            else
            {
                _tweenBatchHandles.Add(null);
            }

            _transforms.AddRange(targets, startIndex, length);
            for (var i = 0; i < batchLength; i++)
            {
                var normalizedIndex      = startIndex + i;
                var normalizedBatchIndex = batchIndex + i;
                _transformAccessArray.Add(_transforms.buffer[normalizedBatchIndex]);
                _tweenStates.Add(new TweenTransformState
                {
                    state         = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START,
                    transformType = TweenTransformType.Movement |
                                    TweenTransformType.Rotation |
                                    TweenTransformType.Scaling,
                    spaceType = spaceType == SpaceType.World
                                                ? TweenSpaceType.WorldMovement | TweenSpaceType.WorldRotation
                                                : TweenSpaceType.LocalMovement | TweenSpaceType.LocalRotation
                });
                _tweenPositions.Add(new TweenFloat3 {
                    from = fromPosArray[normalizedIndex], to = toPosArray[normalizedIndex]
                });
                _tweenRotations.Add(new TweenRotation {
                    from = fromRotArray[normalizedIndex], to = toRotArray[normalizedIndex]
                });
                _tweenScales.Add(new TweenFloat3 {
                    from = fromScaleArray[normalizedIndex], to = toScaleArray[normalizedIndex]
                });

                var lifetime = new TweenLifetime
                {
                    duration          = Mathf.Max(0, duration),
                    easeType          = easeType,
                    loopType          = loopType,
                    loopCount         = (short)Mathf.Clamp(loopCount, -1, short.MaxValue),
                    originalLoopCount = (short)Mathf.Clamp(loopCount, -1, short.MaxValue)
                };
                _tweenPositionLifetimes.Add(lifetime);
                _tweenRotationLifetimes.Add(lifetime);
                _tweenScaleLifetimes.Add(lifetime);
            }
        }
        public void Scale(
            Transform target,
            Vector3 from,
            Vector3 to,
            float duration,
            EaseType easeType,
            LoopType loopType,
            int loopCount,
            Action onStart,
            Action onComplete,
            bool useTweenHandle,
            out ITweenHandle tweenHandle)
        {
            tweenHandle = null;

            _transforms.Add(target);
            _transformAccessArray.Add(target);
            _tweenStates.Add(new TweenTransformState
            {
                state         = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START,
                transformType = TweenTransformType.Scaling
            });
            _tweenPositions.Add(new TweenFloat3());
            _tweenRotations.Add(new TweenRotation());
            _tweenScales.Add(new TweenFloat3 {
                from = from, to = to
            });
            _tweenPositionLifetimes.Add(new TweenLifetime());
            _tweenRotationLifetimes.Add(new TweenLifetime());
            _tweenScaleLifetimes.Add(new TweenLifetime
            {
                duration          = Mathf.Max(0, duration),
                easeType          = easeType,
                loopType          = loopType,
                loopCount         = (short)Mathf.Clamp(loopCount, -1, short.MaxValue),
                originalLoopCount = (short)Mathf.Clamp(loopCount, -1, short.MaxValue)
            });
            var hasEvents = onStart != null || onComplete != null;

            if (useTweenHandle || hasEvents)
            {
                var availableTweenHandle = GetNextAvailableTweenHandle();
                availableTweenHandle.state = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START;
                if (onStart != null)
                {
                    availableTweenHandle.AddOnStartedListener(onStart);
                }

                if (onComplete != null)
                {
                    availableTweenHandle.AddOnCompletedListener(onComplete);
                }

                _tweenHandles.Add(availableTweenHandle);

                // Only populate the out parameter if explicitly called out for.
                if (useTweenHandle)
                {
                    tweenHandle = availableTweenHandle;
                }
            }
            else
            {
                _tweenHandles.Add(null);
            }
        }
        internal void RotateOnAxis(
            Transform target,
            float angle,
            float duration,
            RotateMode rotateMode,
            SpaceType spaceType,
            EaseType easeType,
            LoopType loopType,
            int loopCount,
            Action onStart,
            Action onComplete,
            bool useTweenHandle,
            out ITweenHandle tweenHandle)
        {
            Assert.IsTrue(rotateMode != RotateMode.XYZ, RuntimeConstants.INVALID_ROTATE_MODE);

            tweenHandle = null;

            _transforms.Add(target);
            _transformAccessArray.Add(target);

            var rotateType = JTweenTools.GetTweenSpaceTypeFromRotateMode(rotateMode);

            _tweenStates.Add(new TweenTransformState
            {
                state         = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START,
                transformType = TweenTransformType.Rotation,
                spaceType     = spaceType == SpaceType.World
                                        ? TweenSpaceType.WorldRotation | rotateType
                                        : TweenSpaceType.LocalRotation | rotateType
            });
            _tweenPositions.Add(new TweenFloat3());

            var eulerAngles = spaceType == SpaceType.World
                                ? target.eulerAngles
                                : target.localEulerAngles;

            _tweenRotations.Add(new TweenRotation
            {
                from  = new quaternion(eulerAngles.x, eulerAngles.y, eulerAngles.z, 0),
                angle = angle
            });
            _tweenScales.Add(new TweenFloat3());
            _tweenPositionLifetimes.Add(new TweenLifetime());
            _tweenRotationLifetimes.Add(new TweenLifetime
            {
                duration          = Mathf.Max(0, duration),
                easeType          = easeType,
                loopType          = loopType,
                loopCount         = (short)Mathf.Clamp(loopCount, -1, short.MaxValue),
                originalLoopCount = (short)Mathf.Clamp(loopCount, -1, short.MaxValue)
            });
            _tweenScaleLifetimes.Add(new TweenLifetime());
            var hasEvents = onStart != null || onComplete != null;

            if (useTweenHandle || hasEvents)
            {
                var availableTweenHandle = GetNextAvailableTweenHandle();
                availableTweenHandle.state = useTweenHandle ? HANDLE_START_PAUSED : NO_HANDLE_START;
                if (onStart != null)
                {
                    availableTweenHandle.AddOnStartedListener(onStart);
                }

                if (onComplete != null)
                {
                    availableTweenHandle.AddOnCompletedListener(onComplete);
                }

                _tweenHandles.Add(availableTweenHandle);

                // Only populate the out parameter if explicitly called out for.
                if (useTweenHandle)
                {
                    tweenHandle = availableTweenHandle;
                }
            }
            else
            {
                _tweenHandles.Add(null);
            }
        }