5argon / NotchSolution

A set of components and tools to solve notched/cutout phones layout problems for Unity.
http://exceed7.com/notch-solution
MIT License
671 stars 90 forks source link

Use AnimationMode somehow with the adaptation component #28

Closed 5argon closed 5 years ago

5argon commented 5 years ago

Currently the adapted/animated fields got modified for real and dirty the game object. This is annoying on prefabs since it cause bolded override even though you just want to preview the changes.

We maybe able to emulate the Timeline package's approach where it also use Animation Playables API but it is revertable. The entry point to that should be AnimationMode. How to collect to-revert property from clips could be like in PropertyCollector.cs of Timeline package.

        public void AddFromClips(GameObject obj, IEnumerable<AnimationClip> clips)
        {
            if (Application.isPlaying)
                return;

            // Add RootMotion TR property in animation mode snapshot as well if animator bindings didn't do it.
            var animator = obj.GetComponent<Animator>();
            bool addRoot = (animator != null && !animator.isHuman && !animator.applyRootMotion);

            m_CurveBindingSet.Clear();
            foreach (var c in clips)
            {
                addRoot |= c.hasRootCurves | c.hasMotionCurves | c.hasRootMotion;

                m_CurveBindingSet.UnionWith(AnimationClipCurveCache.Instance.GetCurveInfo(c).rawBindings);
                m_CurveBindingSet.UnionWith(AnimationClipCurveCache.Instance.GetCurveInfo(c).objectBindings);
            }
            m_CurveBindingSet.UnionWith(m_AnimatorCache.GetAnimatorBindings(obj));

            foreach (var binding in m_CurveBindingSet)
            {
                if (binding.type != typeof(Animator) && !IsEulerHint(binding))
                    AnimationMode.AddEditorCurveBinding(obj, binding);
            }

            if (addRoot)
                AnimationMode.AddTransformTR(obj, string.Empty);
        }
5argon commented 5 years ago

It seems to working that way now? Maybe I was misunderstanding something..