private static void ValidateBakeOptions(BakeOptions bakeOptions)
        {
            if (bakeOptions.RigDefinition == BlobAssetReference <RigDefinition> .Null ||
                bakeOptions.ClipConfiguration.Mask == 0 ||
                bakeOptions.SampleRate == 0)
            {
                return;
            }

            if (bakeOptions.SampleRate < 0)
            {
                throw new System.ArgumentOutOfRangeException("bakeOptions.SampleRate", bakeOptions.SampleRate, "SampleRate cannot be negative.");
            }
        }
        private static int ConvertSimpleDirectional2DBlendTree(BlendTree blendTree, Entity entity, EntityManager entityManager, BakeOptions bakeOptions)
        {
            if (!entityManager.HasComponent <BlendTree2DResource>(entity))
            {
                entityManager.AddBuffer <BlendTree2DResource>(entity);
            }

            if (!entityManager.HasComponent <BlendTree2DMotionData>(entity))
            {
                entityManager.AddBuffer <BlendTree2DMotionData>(entity);
            }

            var blendTreeResources  = entityManager.GetBuffer <BlendTree2DResource>(entity);
            var blendTreeMotionData = entityManager.GetBuffer <BlendTree2DMotionData>(entity);

            var blendTreeIndex = blendTreeResources.Length;

            blendTreeResources.Add(new BlendTree2DResource {
                MotionCount      = blendTree.children.Length,
                MotionStartIndex = blendTreeMotionData.Length
            });

            for (int i = 0; i < blendTree.children.Length; i++)
            {
                var motionData = new BlendTree2DMotionData {
                    MotionPosition = blendTree.children[i].position,
                    MotionSpeed    = blendTree.children[i].timeScale,
                };

                var clip = ClipBuilder.AnimationClipToDenseClip(blendTree.children[i].motion as AnimationClip);
                if (bakeOptions.NeedBaking)
                {
                    clip = UberClipNode.Bake(bakeOptions.RigDefinition, clip, bakeOptions.ClipConfiguration, bakeOptions.SampleRate);
                }

                motionData.Motion.Clip = clip;

                blendTreeMotionData.Add(motionData);
            }

            return(blendTreeIndex);
        }
        public static int Convert(BlendTree blendTree, Entity entity, EntityManager entityManager, BakeOptions bakeOptions = default)
        {
            AssertBlendTreeIsNotNested(blendTree);

            ValidateBakeOptions(bakeOptions);

            if (blendTree.blendType == BlendTreeType.Simple1D)
            {
                return(ConvertBlendTree1D(blendTree, entity, entityManager, bakeOptions));
            }
            else if (blendTree.blendType == BlendTreeType.SimpleDirectional2D)
            {
                return(ConvertSimpleDirectional2DBlendTree(blendTree, entity, entityManager, bakeOptions));
            }
            else
            {
                throw new System.ArgumentException($"Selected Blend Tree type is not supported.");
            }
        }