예제 #1
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;
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 private void HandleHierarchyObjectPathChanged(
     object sender,
     EditorHelper.HierarchyObjectPathChangedEventArgs args)
 {
     // If the change had anything to do with the subject, notify
     // control groups of the changes to the subject descendants
     if (!String.IsNullOrEmpty(SubjectPathAbs))
     {
         // Subject root was affected
         bool root_affected =
             SubjectPathAbs == args.NewPath ||
             SubjectPathAbs == args.OldPath;
         // Subject descendants affected
         bool descendants_affected =
             Paths.IsSubPath(SubjectPathAbs, args.NewPath) ||
             Paths.IsSubPath(SubjectPathAbs, args.OldPath);
         if (root_affected)
         {
             // If the subject is not null (destroyed), set the subject
             if (args.GameObject != null)
             {
                 Subject = args.GameObject;
             }
         }
         if (descendants_affected)
         {
             // Handle invalidation
             if (!PathChangeHandledOnceThisUpdate)
             {
                 CachedSubjectDescendantsAndPaths = GetSubjectDescendants();
                 NotifyControlGroupsOfSubjectDescendants();
                 PathChangeHandledOnceThisUpdate = true;
                 GroupedTargets = GetAllGroupedTargets();
             }
         }
     }
 }