Esempio n. 1
0
        /************************************************************************************************************************/

        private void DoAnimatorGUI()
        {
            var hasAnimator = AnimatorProperty.objectReferenceValue != null;

            var color = GUI.color;

            if (!hasAnimator)
            {
                GUI.color = AnimancerGUI.WarningFieldColor;
            }

            EditorGUILayout.PropertyField(AnimatorProperty);

            if (!hasAnimator)
            {
                GUI.color = color;

                EditorGUILayout.HelpBox("An Animator is required in order to play animations." +
                                        " Click here to search for one nearby.",
                                        MessageType.Warning);

                if (AnimancerGUI.TryUseClickEventInLastRect())
                {
                    Serialization.ForEachTarget(AnimatorProperty, (property) =>
                    {
                        var target = (IAnimancerComponent)property.serializedObject.targetObject;

                        var animator = AnimancerEditorUtilities.GetComponentInHierarchy <Animator>(target.gameObject);
                        if (animator == null)
                        {
                            Debug.Log("No Animator found on '" + target + "' or any of its parents or children." +
                                      " You must assign one manually.", target.gameObject);
                            return;
                        }

                        property.objectReferenceValue = animator;
                    });
                }
            }
        }
        /************************************************************************************************************************/

        private void DoAnimatorGUI(SerializedProperty property, GUIContent label)
        {
            var hasAnimator = property.objectReferenceValue != null;

            var color = GUI.color;

            if (!hasAnimator)
            {
                GUI.color = AnimancerGUI.WarningFieldColor;
            }

            EditorGUILayout.PropertyField(property, label);

            if (!hasAnimator)
            {
                GUI.color = color;

                EditorGUILayout.HelpBox($"An {nameof(Animator)} is required in order to play animations." +
                                        " Click here to search for one nearby.",
                                        MessageType.Warning);

                if (AnimancerGUI.TryUseClickEventInLastRect())
                {
                    Serialization.ForEachTarget(property, (targetProperty) =>
                    {
                        var target = (IAnimancerComponent)targetProperty.serializedObject.targetObject;

                        var animator = AnimancerEditorUtilities.GetComponentInHierarchy <Animator>(target.gameObject);
                        if (animator == null)
                        {
                            Debug.Log($"No {nameof(Animator)} found on '{target.gameObject.name}' or any of its parents or children." +
                                      " You must assign one manually.", target.gameObject);
                            return;
                        }

                        targetProperty.objectReferenceValue = animator;
                    });
                }
            }
            else if (property.objectReferenceValue is Animator animator)
            {
                if (animator.gameObject != Targets[0].gameObject)
                {
                    EditorGUILayout.HelpBox(
                        $"It is recommended that you keep this component on the same {nameof(GameObject)}" +
                        $" as its target {nameof(Animator)} so that they get enabled and disabled at the same time.",
                        MessageType.Info);
                }

                var initialUpdateMode = Targets[0].InitialUpdateMode;
                var updateMode        = animator.updateMode;
                if (AnimancerPlayable.HasChangedToOrFromAnimatePhysics(initialUpdateMode, updateMode))
                {
                    EditorGUILayout.HelpBox(
                        $"Changing to or from {nameof(AnimatorUpdateMode.AnimatePhysics)} mode at runtime has no effect" +
                        $" when using the Playables API. It will continue using the original mode it had on startup.",
                        MessageType.Warning);

                    if (AnimancerGUI.TryUseClickEventInLastRect())
                    {
                        EditorUtility.OpenWithDefaultApp(Strings.DocsURLs.UpdateModes);
                    }
                }
            }
        }