コード例 #1
0
ファイル: JTweenTools.cs プロジェクト: OscarLeif/unity-jtween
 public static unsafe void CopyNativeArrayDirectlyToTweenLifetime(
     NativeArray <TweenLifetime> sourceArray,
     TweenLifetime[] destinationArray)
 {
     fixed(void *arrayPointer = destinationArray)
     {
         UnsafeUtility.MemCpy(
             arrayPointer,
             NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(sourceArray),
             sourceArray.Length * TweenLifetime.SizeOf());
     }
 }
コード例 #2
0
ファイル: JTweenTools.cs プロジェクト: OscarLeif/unity-jtween
 public static unsafe void CopyTweenLifetimeDirectlyToNativeArray(
     TweenLifetime[] sourceArray,
     NativeArray <TweenLifetime> destinationArray,
     int length)
 {
     fixed(void *arrayPointer = sourceArray)
     {
         UnsafeUtility.MemCpy(
             NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(destinationArray),
             arrayPointer,
             length * TweenLifetime.SizeOf());
     }
 }
コード例 #3
0
        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);
            }
        }