Пример #1
0
        private void UpdateBinding(EditorBindingInfo aBindingInfo, EditorCurveBinding aBinding)
        {
            EditorCurveBinding bindingToUpdate = aBinding;
            AnimationCurve     curve           = AnimationUtility.GetEditorCurve(aBindingInfo.ClipInfo.Clip, bindingToUpdate);

            if (curve != null)
            {
                AnimationUtility.SetEditorCurve(aBindingInfo.ClipInfo.Clip, bindingToUpdate, null);
            }
            else
            {
                AnimationUtility.SetObjectReferenceCurve(aBindingInfo.ClipInfo.Clip, bindingToUpdate, null);
            }

            bindingToUpdate.path = aBindingInfo.NewPath;

            if (curve != null)
            {
                AnimationUtility.SetEditorCurve(aBindingInfo.ClipInfo.Clip, bindingToUpdate, curve);
            }
            else
            {
                ObjectReferenceKeyframe[] objectReferenceCurve = AnimationUtility.GetObjectReferenceCurve(aBindingInfo.ClipInfo.Clip, bindingToUpdate);
                AnimationUtility.SetObjectReferenceCurve(aBindingInfo.ClipInfo.Clip, bindingToUpdate, objectReferenceCurve);
            }
        }
Пример #2
0
        private void DrawAssociatedObjectReference(EditorBindingInfo aCurrentBindingInfo, EditorBindingInfo aAssociatedBindingInfo)
        {
            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Width(EditorGUIUtility.currentViewWidth / 1.25f));
            GUIContent label = new GUIContent("[" + aAssociatedBindingInfo.ClipInfo.Clip.name + "]", aAssociatedBindingInfo.ClipInfo.Clip.name);

            GUILayout.Label(label);

            GUILayout.FlexibleSpace();

            if (aAssociatedBindingInfo.HasPendingChanges && aAssociatedBindingInfo.NewPath.Equals(aCurrentBindingInfo.NewPath) == false)
            {
                GUILayout.Label("already has a different pending change!", EditorStyles.miniLabel);
            }
            else if (aAssociatedBindingInfo.ClipInfo.ContainsBinding(aCurrentBindingInfo.NewPath, aAssociatedBindingInfo))
            {
                GUILayout.Label("already has that binding or has it as a pending change!", EditorStyles.miniLabel);
            }
            else
            {
                bool set = GUILayout.Toggle(aAssociatedBindingInfo.HasPendingChanges, string.Empty);
                if (set)
                {
                    if (aAssociatedBindingInfo.HasPendingChanges == false)
                    {
                        aAssociatedBindingInfo.SetPendingUpdate(aCurrentBindingInfo.NewPath);
                        pendingChanges++;
                    }
                }
                else
                {
                    if (aAssociatedBindingInfo.HasPendingChanges)
                    {
                        aAssociatedBindingInfo.ClearPendingChanges();
                        pendingChanges--;
                    }
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.EndHorizontal();
        }
Пример #3
0
 /// <summary>
 /// Check to see if any of the editor bindings on the animation clip contains the path
 /// </summary>
 /// <param name="aBindingPath">Path to compare</param>
 /// <param name="aBindingToIgnore">If provided the function will ignore this specific binding when comparing the path</param>
 /// <returns></returns>
 public bool ContainsBinding(string aBindingPath, EditorBindingInfo aBindingToIgnore = null)
 {
     return(bindings.Find(b => b != aBindingToIgnore && (b.Path == aBindingPath || b.NewPath == aBindingPath)) != null);
 }
Пример #4
0
 /// <summary>
 /// Clear all pending changes from provided BindingInfo
 /// </summary>
 /// <param name="aBindingInfo">BindingInfo to update</param>
 private void ClearPendingChanges(EditorBindingInfo aBindingInfo)
 {
     aBindingInfo.ClearPendingChanges();
     pendingChanges--;
 }
Пример #5
0
        /// <summary>
        /// Draw the object reference's binding info (path and link to object)
        /// </summary>
        /// <param name="aClipInfo">AnimationClipInfo associated to the BindingInfo to draw</param>
        /// <param name="aBindingInfo">BindingInfo to draw</param>
        private void DrawObjectReference(EditorBindingInfo aBindingInfo, bool aIsInitialDraw)
        {
            GameObject objectReference = FindObjectInRoot(aBindingInfo.Path);

            // Cleanup references when drawing them for the first time (or switching which animation clip is being drawn)
            if (aIsInitialDraw)
            {
                aBindingInfo.ShowAssociatedBindings = false;
            }

            if (aBindingInfo.HasPendingChanges)
            {
                GUI.color = Color.yellow;
            }
            else if (objectReference == null)
            {
                GUI.color = Color.red;
            }

            GUILayout.BeginHorizontal(EditorStyles.helpBox);
            GUI.color = defaultColor;

            GUIContent label = new GUIContent(" Path: /" + aBindingInfo.Path, "/" + aBindingInfo.Path);

            GUILayout.Label(label, GUILayout.Width(150.0f));

            if (aBindingInfo.HasPendingChanges)
            {
                objectReference = FindObjectInRoot(aBindingInfo.NewPath);
            }

            // Draw the object field with the latest information and color it based on status. Red = invalid object (null), Yellow = pending change, Green = valid object
            GameObject newObjectReference = EditorGUILayout.ObjectField(objectReference, typeof(GameObject), true) as GameObject;

            // Update binding info's pending change data with new object reference
            if (newObjectReference != objectReference)
            {
                string newPath = GetPath(newObjectReference);

                if (aBindingInfo.ClipInfo.ContainsBinding(newPath))
                {
                    Debug.LogWarningFormat("[{0}] already has the binding with path [{1}] or has it in a pending change!", aBindingInfo.ClipInfo.Clip.name, newPath);
                }
                else
                {
                    if (aBindingInfo.HasPendingChanges == false)
                    {
                        pendingChanges++;
                    }

                    aBindingInfo.SetPendingUpdate(newPath);
                }
            }

            GUI.enabled = aBindingInfo.HasPendingChanges;

            // Draw apply button
            if (GUILayout.Button("Apply", EditorStyles.miniButtonLeft))
            {
                // Setup list of bindings to update base on the curently selected one as well as the current one's associated bindings
                List <EditorBindingInfo> bindings = new List <EditorBindingInfo>()
                {
                    aBindingInfo
                };
                foreach (EditorBindingInfo associatedBindingInfo in aBindingInfo.AssociatedBindings)
                {
                    if (associatedBindingInfo.HasPendingChanges && associatedBindingInfo.NewPath.Equals(aBindingInfo.NewPath))
                    {
                        bindings.Add(associatedBindingInfo);
                    }
                }

                ApplyPendingChanges(bindings.ToArray());
            }

            // Draw clear changes button
            if (GUILayout.Button("Clear", EditorStyles.miniButtonMid))
            {
                ClearPendingChanges(aBindingInfo);
            }

            GUI.enabled = (aBindingInfo.AssociatedBindings.Count > 0);

            // Diplay the show associated bindings button
            string     arrowUnicode  = (aBindingInfo.ShowAssociatedBindings) ? upArrowUnicode : downArrowUnicode;
            GUIContent expandContent = new GUIContent(arrowUnicode, "Expand to show associated bindings among the other animation clips on this animator");

            // Draw show associated bindings
            if (GUILayout.Button(expandContent, EditorStyles.miniButtonRight))
            {
                aBindingInfo.ShowAssociatedBindings = !aBindingInfo.ShowAssociatedBindings;
            }

            GUI.enabled = true;

            GUILayout.EndHorizontal();

            // Draw associated bindings
            if (EditorGUILayout.BeginFadeGroup(aBindingInfo.ShowAssociatedBindingsValue))
            {
                if (aBindingInfo.HasPendingChanges == false)
                {
                    EditorGUILayout.HelpBox("Can't modify associated bindings if the current one is not being modified.", MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("List of animations with this same binding. Check to associate changes across animations.", MessageType.Info);

                    foreach (EditorBindingInfo associatedBindingInfo in aBindingInfo.AssociatedBindings)
                    {
                        DrawAssociatedObjectReference(aBindingInfo, associatedBindingInfo);
                    }
                }
            }
            EditorGUILayout.EndFadeGroup();
        }