private static string GetSaveControllerPath(Unselectable 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));
    }
    private static void SetDefaultColorTransitionValues(Unselectable slider)
    {
        ColorBlock colors = slider.colors;

        colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f);
        colors.pressedColor     = new Color(0.698f, 0.698f, 0.698f);
        colors.disabledColor    = new Color(0.521f, 0.521f, 0.521f);
    }
    private static string BuildAnimationPath(Unselectable target)
    {
        // if no target don't hook up any curves.
        var highlight = target.targetGraphic;

        if (highlight == null)
        {
            return(string.Empty);
        }

        var startGo  = highlight.gameObject;
        var toFindGo = target.gameObject;

        var pathComponents = new Stack <string>();

        while (toFindGo != startGo)
        {
            pathComponents.Push(startGo.name);

            // didn't exist in hierarchy!
            if (startGo.transform.parent == null)
            {
                return(string.Empty);
            }

            startGo = startGo.transform.parent.gameObject;
        }

        // calculate path
        var animPath = new StringBuilder();

        if (pathComponents.Count > 0)
        {
            animPath.Append(pathComponents.Pop());
        }

        while (pathComponents.Count > 0)
        {
            animPath.Append("/").Append(pathComponents.Pop());
        }

        return(animPath.ToString());
    }
    private static UnityEditor.Animations.AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, Unselectable 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 selectedName    = string.IsNullOrEmpty(animationTriggers.selectedTrigger) ? "Selected" : animationTriggers.selectedTrigger;
        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(selectedName, controller);
        GenerateTriggerableTransition(disabledName, controller);

        AssetDatabase.ImportAsset(path);

        return(controller);
    }