Example #1
0
        /// <summary>
        /// Get an animation to play. This requires the use of action fields 0-3.
        /// </summary>
        /// <param name="title">Title of the action field.</param>
        /// <param name="actionParams">Action parameters.</param>
        /// <param name="actionFieldA">Action field.</param>
        /// <param name="actionFieldB">Action field.</param>
        /// <param name="actionFieldC">Action field.</param>
        /// <param name="paramType">Animation controller parameter type.</param>
        /// <param name="targetHeroObject">The target hero object.</param>
        public static void GetAnimation(string title, HeroActionParams actionParams, HeroActionField actionFieldA, HeroActionField actionFieldB, HeroActionField actionFieldC, AnimatorControllerParameterType paramType, HeroObject targetHeroObject)
        {
            if (title != "")
            {
                SimpleLayout.Label(title);
            }

            SimpleLayout.BeginVertical(Box.StyleB);

            if (targetHeroObject == null)
            {
                SimpleLayout.Label("Select a hero object to see its animation parameters.");
                SimpleLayout.EndVertical();
                return;
            }

            if (targetHeroObject.states.states == null || targetHeroObject.states.states.Count == 0)
            {
                SimpleLayout.Label("This hero object has no states.");
                SimpleLayout.EndVertical();
                return;
            }

            SimpleLayout.Label("The state that contains the animation controller:");
            int stateID = GetDropDownBField.BuildField("", actionParams, actionFieldA, new HeroField.StateListField(), targetHeroObject.states.states) - 1;

            if (stateID >= 0)
            {
                string paramTypeName = paramType.ToString();

                SimpleLayout.Label(paramTypeName + " assigned to the animation controller:");
                RuntimeAnimatorController animatorController = GetAnimationParameterField.BuildFieldA("", actionParams, actionFieldB, targetHeroObject, stateID, paramType);

                if (animatorController == null)
                {
                    SimpleLayout.BeginVertical(Box.StyleA);
                    SimpleLayout.Label("This state has no animation controller.\nIf you are 100% certain a specific animation controller\nwill be available at runtime, drag the prefab \nthat contains the controller here:");
                    GameObject prefab = GetPrefabValue.BuildField("", actionParams, actionFieldC);
                    if (prefab != null)
                    {
                        Animator animator = prefab.GetComponent <Animator>();
                        if (animator != null)
                        {
                            animatorController = animator.runtimeAnimatorController;
                            if (animatorController != null)
                            {
                                GetAnimationParameterField.BuildFieldB("", actionParams, actionFieldB, animatorController, paramType);
                            }
                        }
                    }

                    SimpleLayout.EndVertical();
                }
            }

            SimpleLayout.EndVertical();
        }
Example #2
0
 private void OnParametrizedValueGUIOverride(string name, SerializedProperty value, SerializedProperty valueParameter, SerializedProperty valueParameterActive, AnimatorControllerParameterType parameterType)
 {
     if (this.controllerContext != null)
     {
         EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
         if (valueParameterActive.boolValue)
         {
             List<string> list = this.CollectParameters(this.controllerContext, parameterType);
             if ((list.Count == 0) && valueParameterActive.boolValue)
             {
                 EditorGUILayout.HelpBox(string.Format("Must have at least one Parameter of type {0} in the AnimatorController", parameterType.ToString()), MessageType.Error);
             }
             else
             {
                 if ((valueParameterActive.boolValue && (valueParameter.stringValue == "")) && (list.Count > 0))
                 {
                     valueParameter.stringValue = list[0];
                 }
                 EditorGUI.BeginChangeCheck();
                 string str = EditorGUILayout.TextFieldDropDown(new GUIContent(name), valueParameter.stringValue, list.ToArray());
                 if (EditorGUI.EndChangeCheck())
                 {
                     valueParameter.stringValue = str;
                 }
             }
         }
         else
         {
             EditorGUILayout.PropertyField(value, new GUILayoutOption[0]);
         }
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(100f) };
         valueParameterActive.boolValue = EditorGUILayout.ToggleLeft(new GUIContent("Parameter", "Override this constant value with an AnimatorController's parameter to animate this property at runtime."), valueParameterActive.boolValue, options);
         EditorGUILayout.EndHorizontal();
     }
     else
     {
         EditorGUILayout.PropertyField(value, new GUILayoutOption[0]);
     }
 }
Example #3
0
 private void OnParametrizedValueGUI(string name, SerializedProperty value, SerializedProperty valueParameter, SerializedProperty valueParameterActive, AnimatorControllerParameterType parameterType)
 {
     EditorGUILayout.PropertyField(value, new GUILayoutOption[0]);
     if (this.controllerContext != null)
     {
         EditorGUI.indentLevel++;
         EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
         List<string> list = this.CollectParameters(this.controllerContext, parameterType);
         if ((list.Count == 0) && valueParameterActive.boolValue)
         {
             EditorGUILayout.HelpBox(string.Format("Must have at least one Parameter of type {0} in the AnimatorController", parameterType.ToString()), MessageType.Error);
         }
         else
         {
             if ((valueParameterActive.boolValue && (valueParameter.stringValue == "")) && (list.Count > 0))
             {
                 valueParameter.stringValue = list[0];
             }
             using (new EditorGUI.DisabledScope(!valueParameterActive.boolValue))
             {
                 EditorGUI.BeginChangeCheck();
                 string str = EditorGUILayout.TextFieldDropDown(new GUIContent("Multiplier", "Parameter used as multiplier for speed."), valueParameter.stringValue, list.ToArray());
                 if (EditorGUI.EndChangeCheck())
                 {
                     valueParameter.stringValue = str;
                 }
             }
         }
         EditorGUI.indentLevel--;
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(100f) };
         valueParameterActive.boolValue = EditorGUILayout.ToggleLeft(new GUIContent("Parameter", "Use an AnimatorController's parameter to modulate this property at runtime."), valueParameterActive.boolValue, options);
         EditorGUILayout.EndHorizontal();
     }
 }
Example #4
0
 private void OnParametrizedValueGUIOverride(string name, SerializedProperty value, SerializedProperty valueParameter, SerializedProperty valueParameterActive, AnimatorControllerParameterType parameterType)
 {
     if (this.controllerContext != null)
     {
         EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
         if (valueParameterActive.boolValue)
         {
             List <string> list = this.CollectParameters(this.controllerContext, parameterType);
             if (list.Count == 0 && valueParameterActive.boolValue)
             {
                 EditorGUILayout.HelpBox(string.Format("Must have at least one Parameter of type {0} in the AnimatorController", parameterType.ToString()), MessageType.Error);
             }
             else
             {
                 if (valueParameterActive.boolValue && valueParameter.stringValue == string.Empty && list.Count > 0)
                 {
                     valueParameter.stringValue = list[0];
                 }
                 EditorGUI.BeginChangeCheck();
                 string stringValue = EditorGUILayout.TextFieldDropDown(new GUIContent(name), valueParameter.stringValue, list.ToArray());
                 if (EditorGUI.EndChangeCheck())
                 {
                     valueParameter.stringValue = stringValue;
                 }
             }
         }
         else
         {
             EditorGUILayout.PropertyField(value, new GUILayoutOption[0]);
         }
         valueParameterActive.boolValue = EditorGUILayout.ToggleLeft(new GUIContent("Parameter", "Override this constant value with an AnimatorController's parameter to animate this property at runtime."), valueParameterActive.boolValue, new GUILayoutOption[]
         {
             GUILayout.MaxWidth(100f)
         });
         EditorGUILayout.EndHorizontal();
     }
     else
     {
         EditorGUILayout.PropertyField(value, new GUILayoutOption[0]);
     }
 }
Example #5
0
 private void OnParametrizedValueGUI(string name, SerializedProperty value, SerializedProperty valueParameter, SerializedProperty valueParameterActive, AnimatorControllerParameterType parameterType)
 {
     EditorGUILayout.PropertyField(value, new GUILayoutOption[0]);
     if (this.controllerContext != null)
     {
         EditorGUI.indentLevel++;
         EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
         List <string> list = this.CollectParameters(this.controllerContext, parameterType);
         if (list.Count == 0 && valueParameterActive.boolValue)
         {
             EditorGUILayout.HelpBox(string.Format("Must have at least one Parameter of type {0} in the AnimatorController", parameterType.ToString()), MessageType.Error);
         }
         else
         {
             if (valueParameterActive.boolValue && valueParameter.stringValue == string.Empty && list.Count > 0)
             {
                 valueParameter.stringValue = list[0];
             }
             using (new EditorGUI.DisabledScope(!valueParameterActive.boolValue))
             {
                 EditorGUI.BeginChangeCheck();
                 string stringValue = EditorGUILayout.TextFieldDropDown(new GUIContent("Multiplier", "Parameter used as multiplier for speed."), valueParameter.stringValue, list.ToArray());
                 if (EditorGUI.EndChangeCheck())
                 {
                     valueParameter.stringValue = stringValue;
                 }
             }
         }
         EditorGUI.indentLevel--;
         valueParameterActive.boolValue = EditorGUILayout.ToggleLeft(new GUIContent("Parameter", "Use an AnimatorController's parameter to modulate this property at runtime."), valueParameterActive.boolValue, new GUILayoutOption[]
         {
             GUILayout.MaxWidth(100f)
         });
         EditorGUILayout.EndHorizontal();
     }
 }
Example #6
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        SerializedProperty parameterMode = property.FindPropertyRelative("_syncMode");
        SerializedProperty parameterName = property.FindPropertyRelative("_parameterName");
        SerializedProperty parameterType = property.FindPropertyRelative("_parameterType");
        int indexEnumValue = parameterType.intValue;
        AnimatorControllerParameterType paramaterTypeName = (AnimatorControllerParameterType)indexEnumValue;

        EditorGUI.PropertyField(position, parameterMode, new GUIContent($"n: {parameterName.stringValue} | t: {paramaterTypeName.ToString()}"));
    }