protected void CopyNativeCollectionsToManaged() { JTweenTools.CopyNativeArrayDirectlyToTweenState(_nativeTweenStates, _tweenStates.buffer); JTweenTools.CopyNativeArrayDirectlyToTweenLifetime(_nativePositionLifetimes, _tweenPositionLifetimes.buffer); JTweenTools.CopyNativeArrayDirectlyToTweenLifetime(_nativeRotationLifetimes, _tweenRotationLifetimes.buffer); JTweenTools.CopyNativeArrayDirectlyToTweenLifetime(_nativeScaleLifetimes, _tweenScaleLifetimes.buffer); }
protected override void LateUpdateTweens() { Profiler.BeginSample(LATE_UPDATE_PROFILE); if (!_isJobScheduled) { Profiler.EndSample(); return; } _isJobScheduled = false; // Complete the batch process job _processBatchJobHandle.Complete(); JTweenTools.CopyNativeArrayDirectlyToTweenBatch(_nativeTweenBatches, _tweenBatches.buffer); JTweenTools.CopyNativeArrayDirectlyToTweenLifetime(_nativeTweenBatchLifetimes, _tweenBatchLifetimes.buffer); // Complete the tween job and any dependencies applyTweenUpdates.Complete(); // Get the data we need back from the native collections or if tween completed remove it. CopyNativeCollectionsToManaged(); // Sort batches from earliest index to latest, check for any completed batches, // and then remove en masse tweens where their batch is complete. for (var i = _tweenBatches.Length - 1; i >= 0; i--) { var batch = _tweenBatches.buffer[i]; if (_tweenBatchHandles.buffer[i] != null) { _tweenBatchHandles.buffer[i].state = batch.state; } if (batch.IsCompleted()) { if (batch.JustEnded()) { batch.state &= ~TweenStateType.JustEnded; _tweenBatches.buffer[i] = batch; if (_tweenBatchHandles.buffer[i] != null) { _tweenBatchHandles.buffer[i].state = batch.state; _tweenHandleCallbackEventQueue.Enqueue(_tweenBatchHandles.buffer[i]); } } if (batch.RequiresRecycling()) { var index = (int)batch.startIndex; var length = (int)batch.length; // We don't have a great option here for removing a range of transforms from this // specific native collection type. for (var j = index + length - 1; j >= index; j--) { Profiler.BeginSample(TRANSFORM_ACCESS_ARRAY_REMOVE_PROFILE); _transformAccessArray.RemoveAtSwapBack(j); Profiler.EndSample(); } Profiler.BeginSample(FAST_LIST_REMOVE_RANGE); _transforms.RemoveRange(index, length); _tweenStates.RemoveRange(index, length); _tweenPositions.RemoveRange(index, length); _tweenRotations.RemoveRange(index, length); _tweenScales.RemoveRange(index, length); _tweenPositionLifetimes.RemoveRange(index, length); _tweenRotationLifetimes.RemoveRange(index, length); _tweenScaleLifetimes.RemoveRange(index, length); // Shuffle all batches ahead of the current one so that their start indexes are adjusted back // based on the length of the batch we are removing. for (var j = i + 1; j < _tweenBatches.Length; j++) { var laterTweenBatch = _tweenBatches.buffer[j]; laterTweenBatch.startIndex -= batch.length; _tweenBatches.buffer[j] = laterTweenBatch; } _tweenBatches.RemoveAt(i); _tweenBatchLifetimes.RemoveAt(i); _tweenBatchHandles.RemoveAt(i); Profiler.EndSample(); } } } // Properly dispose of the native collections DisposeNativeTransformCollections(); _nativeTweenBatches.Dispose(); _nativeTweenBatchLifetimes.Dispose(); Profiler.EndSample(); Profiler.BeginSample(EVENT_COMPLETED_PROFILE); // After all sensitive native work has completed, kick out any and all completed events while (_tweenHandleCallbackEventQueue.Count > 0) { var tweenHandle = _tweenHandleCallbackEventQueue.Dequeue(); _tweenHandlePool.AddLast(tweenHandle); tweenHandle.Completed?.Invoke(); } Profiler.EndSample(); }