Example #1
0
        private static string GetSaveControllerPath(MultiStateImageUI target)
        {
            var defaultName = target.gameObject.name;
            var message     = string.Format("Create a new animator for the game object '{0}':", defaultName);

            return(EditorUtility.SaveFilePanelInProject("New Animation Contoller", defaultName, "controller", message));
        }
Example #2
0
        protected static UnityEditor.Animations.AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, MultiStateImageUI target)
        {
            if (target == null)
            {
                return(null);
            }

            // Where should we create the controller?
            var path = GetSaveControllerPath(target);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            // figure out clip names
            var normalName      = string.IsNullOrEmpty(animationTriggers.normalTrigger) ? "Normal" : animationTriggers.normalTrigger;
            var highlightedName = string.IsNullOrEmpty(animationTriggers.highlightedTrigger) ? "Highlighted" : animationTriggers.highlightedTrigger;
            var pressedName     = string.IsNullOrEmpty(animationTriggers.pressedTrigger) ? "Pressed" : animationTriggers.pressedTrigger;
            var disabledName    = string.IsNullOrEmpty(animationTriggers.disabledTrigger) ? "Disabled" : animationTriggers.disabledTrigger;

            // Create controller and hook up transitions.
            var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(path);

            GenerateTriggerableTransition(normalName, controller);
            GenerateTriggerableTransition(highlightedName, controller);
            GenerateTriggerableTransition(pressedName, controller);
            GenerateTriggerableTransition(disabledName, controller);

            AssetDatabase.ImportAsset(path);

            return(controller);
        }