예제 #1
0
        /************************************************************************************************************************/

        private AnimationClip GetTargetClip(out AnimationType type)
        {
            var clip = (AnimationClip)target;

            type = AnimationBindings.GetAnimationType(clip);
            return(clip);
        }
예제 #2
0
        /************************************************************************************************************************/

        private static ObjectReferenceKeyframe[] GetSpriteReferences(AnimationClip clip)
        {
            var bindings = AnimationBindings.GetBindings(clip);

            for (int i = 0; i < bindings.Length; i++)
            {
                var binding = bindings[i];
                if (binding.path == "" &&
                    binding.type == typeof(SpriteRenderer) &&
                    binding.propertyName == "m_Sprite")
                {
                    return(AnimationUtility.GetObjectReferenceCurve(clip, binding));
                }
            }

            return(null);
        }
            /************************************************************************************************************************/

            private static Transform TrySelectBestModel(HashSet<AnimationClip> clips, List<GameObject> models)
            {
                var animatableBindings = new HashSet<EditorCurveBinding>[models.Count];

                for (int i = 0; i < models.Count; i++)
                {
                    animatableBindings[i] = AnimationBindings.GetBindings(models[i]).ObjectBindings;
                }

                var bestMatchIndex = -1;
                var bestMatchCount = 0;
                foreach (var clip in clips)
                {
                    var clipBindings = AnimationBindings.GetBindings(clip);

                    for (int iModel = animatableBindings.Length - 1; iModel >= 0; iModel--)
                    {
                        var modelBindings = animatableBindings[iModel];
                        var matches = 0;

                        for (int iBinding = 0; iBinding < clipBindings.Length; iBinding++)
                        {
                            if (modelBindings.Contains(clipBindings[iBinding]))
                                matches++;
                        }

                        if (bestMatchCount < matches && matches > clipBindings.Length / 2)
                        {
                            bestMatchCount = matches;
                            bestMatchIndex = iModel;

                            // If it matches all bindings, use it.
                            if (bestMatchCount == clipBindings.Length)
                                goto FoundBestMatch;
                        }
                    }
                }

                FoundBestMatch:
                if (bestMatchIndex >= 0)
                    return models[bestMatchIndex].transform;
                else
                    return null;
            }
            /************************************************************************************************************************/

            /// <summary>
            /// Tries to choose the most appropriate model to use based on the properties animated by the target
            /// <see cref="Transition"/>.
            /// </summary>
            public static Transform TrySelectBestModel()
            {
                var transition = Transition;
                if (transition == null)
                    return null;

                using (ObjectPool.Disposable.AcquireSet<AnimationClip>(out var clips))
                {
                    clips.GatherFromSource(transition);
                    if (clips.Count == 0)
                        return null;

                    var model = TrySelectBestModel(clips, TemporarySettings.PreviewModels);
                    if (model != null)
                        return model;

                    model = TrySelectBestModel(clips, Models);
                    if (model != null)
                        return model;

                    foreach (var clip in clips)
                    {
                        var type = AnimationBindings.GetAnimationType(clip);
                        switch (type)
                        {
                            case AnimationType.Humanoid:
                                return DefaultHumanoid.transform;

                            case AnimationType.Sprite:
                                return DefaultSprite.transform;
                        }
                    }

                    return null;
                }
            }
예제 #5
0
            /************************************************************************************************************************/

            /// <summary>Gathers the bindings from the <see cref="AnimationModifierPanel.Animation"/>.</summary>
            private void GatherBindings()
            {
                if (!_OldBindingPathsAreDirty)
                {
                    return;
                }

                _OldBindingPathsAreDirty = false;

                BindingGroups.Clear();
                OldBindingPaths.Clear();

                if (Animation == null)
                {
                    _NewBindingPaths.Clear();
                    return;
                }

                var isHumanoid = Animation.humanMotion;

                AnimationBindings.OnAnimationChanged(Animation);
                var bindings = AnimationBindings.GetBindings(Animation);

                Array.Sort(bindings, (a, b) =>
                {
                    var result = EditorUtility.NaturalCompare(a.path, b.path);
                    if (result != 0)
                    {
                        return(result);
                    }

                    return(EditorUtility.NaturalCompare(a.propertyName, b.propertyName));
                });

                string previousPath = null;
                List <EditorCurveBinding> previousGroup = null;

                for (int i = 0; i < bindings.Length; i++)
                {
                    var binding = bindings[i];
                    if (isHumanoid &&
                        string.IsNullOrEmpty(binding.path) &&
                        IsHumanoidBinding(binding.propertyName))
                    {
                        continue;
                    }

                    var path = binding.path;
                    if (path == previousPath)
                    {
                        previousGroup.Add(binding);
                        continue;
                    }

                    previousPath  = path;
                    previousGroup = new List <EditorCurveBinding> {
                        binding
                    };

                    BindingGroups.Add(previousGroup);

                    OldBindingPaths.Add(path);
                    if (_NewBindingPaths.Count < OldBindingPaths.Count)
                    {
                        _NewBindingPaths.Add(path);
                    }
                }

                if (_NewBindingPaths.Count > OldBindingPaths.Count)
                {
                    _NewBindingPaths.RemoveRange(OldBindingPaths.Count, _NewBindingPaths.Count - OldBindingPaths.Count);
                }
            }