void Convert(AnimationClip clip)
        {
            if (clip == null)
            {
                return;
            }

            var entity = TryGetPrimaryEntity(clip);

            if (entity == Entity.Null)
            {
                throw new Exception($"Something went wrong while creating an Entity for animation clip: {clip.name}");
            }

            if (DstEntityManager.HasComponent <BakedAnimationClip>(entity))
            {
                return; // Already converted
            }
            ConversionUtils.WarnAboutUnsupportedFeatures(clip);

            var floatCurvesInfo = ConvertFloatCurves(clip);
            var pPtrCurvesInfo  = ConvertPPtrCurves(clip);

            DstEntityManager.AddComponentData(entity, new BakedAnimationClip
            {
                FloatCurvesInfo = floatCurvesInfo,
                PPtrCurvesInfo  = pPtrCurvesInfo,
                ClipHash        = TinyAnimation.StringToHash(clip.name)
            });
        }
예제 #2
0
        internal static bool ValidateGameObjectAndWarn([NotNull] GameObject gameObject)
        {
            if (!k_GameObjectValidityMap.ContainsKey(gameObject))
            {
                k_GameObjectValidityMap.Add(gameObject, ConversionUtils.ValidateGameObjectAndWarn(gameObject));
            }

            return(k_GameObjectValidityMap[gameObject]);
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.Animation animationComponent) =>
            {
                if (!TinyAnimationConversionState.ValidateGameObjectAndWarn(animationComponent.gameObject))
                {
                    return;
                }

                var animationClips = TinyAnimationConversionState.GetAllAnimationClips(animationComponent);
                if (animationClips.Length == 0)
                {
                    return;
                }

                ConversionUtils.WarnAboutUnsupportedFeatures(animationComponent);

                foreach (var clip in animationClips)
                {
                    Convert(clip);
                }
            });

            Entities.ForEach((TinyAnimationAuthoring animationComponent) =>
            {
                if (!TinyAnimationConversionState.ValidateGameObjectAndWarn(animationComponent.gameObject))
                {
                    return;
                }

                var animationClips = TinyAnimationConversionState.GetAllAnimationClips(animationComponent);
                if (animationClips.Length == 0)
                {
                    return;
                }

                ConversionUtils.WarnAboutUnsupportedFeatures(animationComponent.GetComponent <Animator>());

                foreach (var clip in animationClips)
                {
                    Convert(clip);
                }
            });
        }
        void Convert(GameObject rootGameObject, AnimationClip clip, Entity gameObjectEntity)
        {
            if (clip == null)
            {
                return;
            }

            var clipName = clip.name;

            var clipInfoEntity = TryGetPrimaryEntity(clip);

            if (clipInfoEntity == Entity.Null || !DstEntityManager.HasComponent <BakedAnimationClip>(clipInfoEntity))
            {
                throw new Exception($"Something went wrong while retrieving the Entity for animation clip: {clipName}");
            }

            var bakedAnimationClip = DstEntityManager.GetComponentData <BakedAnimationClip>(clipInfoEntity);
            var floatCurvesInfo    = bakedAnimationClip.FloatCurvesInfo;
            var pPtrCurvesInfo     = bakedAnimationClip.PPtrCurvesInfo;

            var hasFloatCurves = floatCurvesInfo != BlobAssetReference <CurvesInfo> .Null;
            var hasPPtrCurves  = pPtrCurvesInfo != BlobAssetReference <CurvesInfo> .Null;

            var clipEntity = CreateAdditionalEntity(rootGameObject);

            DstEntityManager.SetName(clipEntity, $"{clipName} ({rootGameObject.name})");

            // With pruning, it's possible that nothing remains to be animated
            var anythingToAnimate = false;

            if (hasFloatCurves)
            {
                anythingToAnimate |= ConvertFloatCurves(rootGameObject, clipEntity, floatCurvesInfo, clipName);
            }

            if (hasPPtrCurves)
            {
                anythingToAnimate |= ConvertPPtrCurves(rootGameObject, clipEntity, pPtrCurvesInfo, clipName);
            }

            if ((hasFloatCurves || hasPPtrCurves) && !anythingToAnimate)
            {
                Debug.LogWarning($"Due to the pruning of invalid bindings, the animation clip {clipName} has become empty.");
            }

            var wrapMode    = ConversionUtils.GetWrapMode(clip);
            var cycleOffset = ConversionUtils.GetCycleOffset(clip);

            DstEntityManager.AddComponentData(
                clipEntity, new TinyAnimationPlaybackInfo
            {
                Duration    = clip.length,
                CycleOffset = cycleOffset,
                WrapMode    = wrapMode
            });

            var initialTime = (wrapMode == WrapMode.Loop || wrapMode == WrapMode.PingPong) ? cycleOffset * clip.length : 0.0f;

            DstEntityManager.AddComponentData(
                clipEntity, new TinyAnimationTime
            {
                InternalWorkTime = initialTime,
                Value            = initialTime
            });

            var clipReferences = DstEntityManager.GetBuffer <TinyAnimationClipRef>(gameObjectEntity);

            clipReferences.Add(new TinyAnimationClipRef {
                Value = clipEntity, Hash = bakedAnimationClip.ClipHash
            });
        }