public static void FixAnimationsHideFlags(List <AnimatorOverrideController> overrideControllers, HideFlags hideFlags)
        {
            int fixCount = 0;

            foreach (var overrideController in overrideControllers)
            {
#if !(UNITY_5_5 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4)
                List <AnimationClip> clips = AnimatorOverrideControllerInspector.GetIncludeAnimations(overrideController);
                foreach (AnimationClip clip in clips)
                {
                    if (clip.hideFlags == hideFlags)
                    {
                        continue;
                    }
                    clip.hideFlags = hideFlags;
                    EditorUtility.SetDirty(clip);
                    fixCount++;
                }
#endif
            }

            if (fixCount > 0)
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                UIControllerDebugger.LogMessage(3, fixCount + " override animations Hide Flags is set to " + hideFlags + ".");
            }
        }
        public static void SetupController(AnimatorOverrideController overrideController, RuntimeAnimatorController controller = null)
        {
            if (controller != null)
            {
                overrideController.runtimeAnimatorController = controller;
            }

            foreach (AnimationClipPair clipPair in overrideController.clips)
            {
                string overrideClipName = clipPair.originalClip.name.Replace("Original", "");

                List <AnimationClip> clips = AnimatorOverrideControllerInspector.GetIncludeAnimations(overrideController);
                foreach (AnimationClip clip in clips)
                {
                    if (clip.name == overrideClipName)
                    {
                        overrideController[clipPair.originalClip] = clip;
                        break;
                    }
                }

                if (overrideController[clipPair.originalClip] == clipPair.originalClip)
                {
                    AnimationClip overrideClip = new AnimationClip();
                    EditorUtility.CopySerialized(clipPair.originalClip, overrideClip);
                    overrideClip.name      = overrideClipName;
                    overrideClip.hideFlags = HideFlags.HideInHierarchy;
                    AssetDatabase.AddObjectToAsset(overrideClip, overrideController);
                    overrideController[clipPair.originalClip] = overrideClip;
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        private static void FixAnimationsNotSet(List <AnimatorOverrideController> overrideControllers)
        {
            int fixCount = 0;

            foreach (var overrideController in overrideControllers)
            {
                bool isFix     = false;
                var  overrides = overrideController.GetOverridesUnite();
                foreach (var clipPair in overrides)
                {
                    if (clipPair.Key == clipPair.Value)
                    {
                        AnimatorOverrideControllerInspector.SetupController(overrideController);
                        isFix = true;
                        break;
                    }
                }
                fixCount += isFix ? 1 : 0;
            }

            if (fixCount > 0)
            {
                UIControllerDebugger.LogMessage(2, fixCount + " override controllers no override animation is fix.");
            }
        }
Exemple #4
0
        private static void FixAnimationsHide(List <AnimatorOverrideController> overrideControllers)
        {
            int fixCount = 0;

            foreach (var overrideController in overrideControllers)
            {
#if !(UNITY_5_5 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4)
                List <AnimationClip> clips = AnimatorOverrideControllerInspector.GetIncludeAnimations(overrideController);
                foreach (AnimationClip clip in clips)
                {
                    if (clip.hideFlags == HideFlags.None)
                    {
                        continue;
                    }
                    clip.hideFlags = HideFlags.None;
                    EditorUtility.SetDirty(clip);
                    fixCount++;
                }
#endif
            }

            if (fixCount > 0)
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                UIControllerDebugger.LogWarning(3, fixCount + " Override Controllers is Fix.");
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            var overrideController = this.target as AnimatorOverrideController;

            List <AnimationClip> clips = AnimatorOverrideControllerInspector.GetIncludeAnimations(overrideController);

            if (clips.Count > 0)
            {
                string names = clips[0].name;
                for (int i = 1; i < clips.Count; i++)
                {
                    names += ", " + clips[i].name;
                }
                GUILayout.Label("Include Animations: " + names);
            }

            foreach (var controller in UIControllerSetting.instance.controllers)
            {
                if (GUILayout.Button("Setup " + controller.name.Replace("_", "->")))
                {
                    AnimatorOverrideControllerInspector.SetupController(overrideController, controller);
                }
            }
            GUILayout.Label("");

            List <AnimationClip> unusedClips = AnimatorOverrideControllerInspector.GetUnusedAnimations(overrideController);

            GUI.enabled = unusedClips.Count > 0;
            if (GUILayout.Button("Delete Unused Animations (" + unusedClips.Count + ")"))
            {
                foreach (AnimationClip clip in unusedClips)
                {
                    Object.DestroyImmediate(clip, true);
                }
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
            GUI.enabled = true;

            GUI.enabled = overrideController.runtimeAnimatorController != null;
            if (GUILayout.Button("Export to Animator"))
            {
                AnimatorOverrideControllerInspector.ExportController(overrideController);
            }
            GUI.enabled = true;
        }
        private static List <AnimationClip> GetUnusedAnimations(AnimatorOverrideController controller)
        {
            List <AnimationClip> unusedClips = new List <AnimationClip> ();

            List <AnimationClip> includeClips = AnimatorOverrideControllerInspector.GetIncludeAnimations(controller);

            foreach (AnimationClip includeClip in includeClips)
            {
                if (!new List <AnimationClip> (controller.animationClips).Contains(includeClip))
                {
                    unusedClips.Add(includeClip);
                }
            }

            return(unusedClips);
        }
        public static void FixAllOverrideControllers(UIControllerSetting setting)
        {
            int fixCount = 0;
            List <AnimatorOverrideController> all = FindAllOverrideControllers(setting);

            foreach (var a in all)
            {
                foreach (AnimationClipPair clipPair in a.clips)
                {
                    if (clipPair.originalClip == clipPair.overrideClip)
                    {
                        AnimatorOverrideControllerInspector.SetupController(a);
                        fixCount++;
                        break;
                    }
                }
            }
            if (fixCount > 0)
            {
                Debug.LogWarning("UIController: " + fixCount + " Override Controllers is Fix. (Error 2)");
            }
        }