public override void Draw()
        {
            // Variable name
            EditorGUILayout.BeginHorizontal();
            FieldValue.Name = EditorGUILayout.TextField(new GUIContent("Name", ""), FieldValue.Name);
            EditorGUILayout.EndHorizontal();


            AnimatorVariableType prevType = FieldValue.Type.Copy();

            EditorGUILayout.BeginHorizontal();
            FieldValue.Type = (AnimatorVariableType)EditorGUILayout.EnumPopup("Type", FieldValue.Type);
            EditorGUILayout.EndHorizontal();

            // Handle type changing
            if (prevType != FieldValue.Type)
            {
                if (prevType == AnimatorVariableType.FLOAT && FieldValue.Type == AnimatorVariableType.INT)
                {
                    FieldValue.StoredValue = ((int)FieldValue.GetValueAs <float>()).ToString();
                }
                else if (prevType == AnimatorVariableType.INT && FieldValue.Type == AnimatorVariableType.FLOAT)
                {
                    FieldValue.StoredValue = ((float)FieldValue.GetValueAs <int>()).ToString();
                }
                else
                {
                    FieldValue.StoredValue = null;
                }
            }

            // Field value
            EditorGUILayout.BeginHorizontal();
            switch (FieldValue.Type)
            {
            case AnimatorVariableType.FLOAT:
                FieldValue.StoredValue = (EditorGUILayout.FloatField(FieldName, FieldValue.GetValueAs <float>())).ToString();
                break;

            case AnimatorVariableType.INT:
                FieldValue.StoredValue = (EditorGUILayout.IntField(FieldName, FieldValue.GetValueAs <int>())).ToString();
                break;

            case AnimatorVariableType.BOOL:
                FieldValue.StoredValue = (EditorGUILayout.Toggle(FieldName, FieldValue.GetValueAs <bool>())).ToString();
                break;

            default:     // Trigger
                EditorGUILayout.LabelField("Will call the trigger.");
                break;
            }
            EditorGUILayout.EndHorizontal();
        }
Exemple #2
0
        /// <summary>
        /// Returns that the type of the specified variable corresponds to this <see cref="AnimatorVariableType"/>.
        /// </summary>
        /// <param name="var"></param>
        /// <param name="other">The type to check.</param>
        /// <returns>Returns that the type of the specified variable corresponds to this <see cref="AnimatorVariableType"/>.</returns>
        public static bool Correspond(this AnimatorVariableType var, VariableType other)
        {
            switch (var)
            {
            case AnimatorVariableType.FLOAT:
                return(other == VariableType.FLOAT);

            case AnimatorVariableType.INT:
                return(other == VariableType.INT);

            case AnimatorVariableType.TRIGGER:
            case AnimatorVariableType.BOOL:
            default:
                return(false);
            }
        }
Exemple #3
0
        public static AnimatorVariableType Copy(this AnimatorVariableType var)
        {
            switch (var)
            {
            case AnimatorVariableType.FLOAT:
                return(AnimatorVariableType.FLOAT);

            case AnimatorVariableType.INT:
                return(AnimatorVariableType.INT);

            case AnimatorVariableType.BOOL:
                return(AnimatorVariableType.BOOL);

            default:
                return(AnimatorVariableType.TRIGGER);
            }
        }