Example #1
0
        /// <summary>
        /// Fixes this shit: https://feedback.unity3d.com/suggestions/allow-retargeting-specific-animation-properties
        /// TODO: make this event-driven like <see cref="EditorApplication.hierarchyWindowChanged"/>
        /// </summary>
        private static void HandleUpdate()
        {
            AnimationClip clip = null;

            try
            {
                clip = AnimationWindowUtils.GetCurrentActiveAnimationClip();
            }
            catch (ArgumentNullException ex)
            {
                // Suppress until I figure out a way to not spam users (esp. animators)
            }
            if (clip != null)
            {
                RepairAnimationClipProperties(clip);
            }
        }
Example #2
0
 private static void HandleHierarchyObjectPathChanged(object sender, EditorHelper.HierarchyObjectPathChangedEventArgs args)
 {
     if (EnableStickyProperties)
     {
         object window = AnimationWindowUtils.GetAnimationWindow();
         // If the window is not null (i.e. if it has been made visible at least once)
         if (window != null)
         {
             object        editor = AnimationWindowUtils.GetAnimationEditor(window);
             object        state  = AnimationWindowUtils.GetAnimationWindowState(editor);
             AnimationClip clip   = AnimationWindowUtils.GetActiveAnimationClip(state);
             GameObject    root   = AnimationWindowUtils.GetRootGameObject(state);
             if (clip != null && root != null)
             {
                 string root_path      = AnimationUtility.CalculateTransformPath(root.transform, null);
                 int    trim_old_path  = Math.Min(args.OldPath.Length, root_path.Length + 1);
                 int    trim_new_path  = Math.Min(args.NewPath.Length, root_path.Length + 1);
                 string old_path_local = args.OldPath.Substring(trim_old_path);
                 string new_path_local = args.NewPath.Substring(trim_new_path);
                 var    bindings       = AnimationUtility.GetCurveBindings(clip);
                 for (int i = 0; i < bindings.Length; i++)
                 {
                     EditorCurveBinding binding = bindings[i];
                     if (binding.path == old_path_local)
                     {
                         // Remove curve from original binding (un-bind) and add updated binding (re-bind)
                         var curve = AnimationUtility.GetEditorCurve(clip, binding);
                         AnimationUtility.SetEditorCurve(clip, binding, null);
                         binding.path = new_path_local;
                         AnimationUtility.SetEditorCurve(clip, binding, curve);
                         EditorApplication.RepaintAnimationWindow();
                         Debug.Log("Updated property path: " + old_path_local + FTFY + new_path_local);
                         break;
                     }
                 }
             }
         }
     }
 }
Example #3
0
    void OnGUI()
    {
        if (GUILayout.Button("PrintMethods"))
        {
            AnimationWindowUtils.PrintMethods();
        }

        if (GUILayout.Button("ToggleRecord"))
        {
            AnimationWindowUtils.ToggleRecord();
        }

        if (GUILayout.Button("get_previewing"))
        {
            Debug.Log(AnimationWindowUtils.get_previewing());
        }

        if (GUILayout.Button("get_recording"))
        {
            Debug.Log(AnimationWindowUtils.get_recording());
        }
    }
Example #4
0
    private static void OnSceneGUI(SceneView sceneView)
    {
        Handles.BeginGUI();
        MonoBehaviour control = Selection.activeObject as Control;

        if (control == null)
        {
            var gameobject = Selection.activeObject as GameObject;
            if (gameobject != null)
            {
                control = gameobject.GetComponent <Control>();
                if (control == null)
                {
                    control = gameobject.GetComponent <Ik2D>();
                }
            }
        }

        if (AnimationWindowUtils.get_recording())
        {
            GUI.color = new Color(1, 0, 0, 0.8f);
            GUI.Box(new Rect(0, 0, sceneView.position.width, sceneView.position.height), GUIContent.none, EditorStyles.textArea);
        }

        if (control != null)
        {
            GUI.color = Color.black;
            GUI.Box(new Rect(0, 0, sceneView.position.width, 150), GUIContent.none, EditorStyles.textArea);
            var style = new GUIStyle();
            style.normal.textColor = Color.white;
            style.fontSize         = 100;
            GUI.color = Color.white;
            var message = string.Format("{0} ({1})", control.gameObject.name, Tools.current);
            GUI.Label(new Rect(0, 0, 100, sceneView.position.height), message, style);
        }

        Handles.EndGUI();
    }