Esempio n. 1
0
        /// <summary>
        /// Updates a given parameter in the character animator
        /// </summary>
        /// <param name="characterAnimator"></param>
        public void Update(StratusCharacterAnimator characterAnimator)
        {
            switch (parameterType)
            {
            case AnimatorControllerParameterType.Float:
                characterAnimator.SetFloat(parameterName, member.Get <float>());
                break;

            case AnimatorControllerParameterType.Int:
                characterAnimator.SetInteger(parameterName, member.Get <int>());
                break;

            case AnimatorControllerParameterType.Bool:
                characterAnimator.SetBoolean(parameterName, member.Get <bool>());
                break;
            }
        }
        protected override void OnDrawProperty(Rect position, SerializedProperty property)
        {
            // Special case if it's being used by the character animator
            StratusCharacterAnimator characterAnimator = this.target as StratusCharacterAnimator;
            bool hasParameters = characterAnimator != null && characterAnimator.animator != null && characterAnimator.hasParameters;

            // Member
            SerializedProperty memberProperty = property.FindPropertyRelative(nameof(StratusAnimatorParameterHook.member));

            DrawProperty(ref position, memberProperty);

            // Parameter
            SerializedProperty parameterNameProperty = property.FindPropertyRelative(nameof(StratusAnimatorParameterHook.parameterName));

            if (hasParameters)
            {
                SerializedProperty parameterTypeProperty      = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.parameterType));
                AnimatorControllerParameterType parameterType = (AnimatorControllerParameterType)parameterTypeProperty.intValue;
                string[] parameters = null;
                switch (parameterType)
                {
                case AnimatorControllerParameterType.Float:
                    parameters = characterAnimator.floatParameters;
                    break;

                case AnimatorControllerParameterType.Int:
                    parameters = characterAnimator.intParameters;
                    break;

                case AnimatorControllerParameterType.Bool:
                    parameters = characterAnimator.boolParameters;
                    break;

                case AnimatorControllerParameterType.Trigger:
                    parameters = characterAnimator.triggerParameters;
                    break;
                }
                DrawPopup(ref position, parameterNameProperty, parameters);
            }
            else
            {
                DrawProperty(ref position, parameterNameProperty);
            }
        }
Esempio n. 3
0
        public void Play(StratusCharacterAnimator ca)
        {
            switch (parameterType)
            {
            case AnimatorControllerParameterType.Float:
                ca.SetFloat(parameter.name, floatValue);
                break;

            case AnimatorControllerParameterType.Int:
                ca.SetInteger(parameter.name, intValue);
                break;

            case AnimatorControllerParameterType.Bool:
                ca.SetBoolean(parameter.name, boolValue);
                break;

            case AnimatorControllerParameterType.Trigger:
                ca.SetTrigger(parameter.name);
                break;
            }
        }
        protected override void OnDrawProperty(Rect position, SerializedProperty property)
        {
            // Special case if it's being used by the character animator
            StratusCharacterAnimator characterAnimator = this.target as StratusCharacterAnimator;
            bool hasParameters = characterAnimator != null && characterAnimator.animator != null && characterAnimator.hasParameters;

            // Event
            SerializedProperty onEventProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.onEvent));

            DrawProperty(ref position, onEventProperty);

            // Parameter: Type
            SerializedProperty parameterTypeProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.parameterType));

            // Paramater: Name, Value
            SerializedProperty parameterNameProperty      = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.parameterName));
            SerializedProperty parameterValueProperty     = null;
            AnimatorControllerParameterType parameterType = (AnimatorControllerParameterType)parameterTypeProperty.intValue;

            if (hasParameters)
            {
                string[] parameters = null;
                switch (parameterType)
                {
                case AnimatorControllerParameterType.Float:
                    parameterValueProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.floatValue));
                    parameters             = characterAnimator.floatParameters;
                    break;

                case AnimatorControllerParameterType.Int:
                    parameterValueProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.intValue));
                    parameters             = characterAnimator.intParameters;
                    break;

                case AnimatorControllerParameterType.Bool:
                    parameterValueProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.boolValue));
                    parameters             = characterAnimator.boolParameters;
                    break;

                case AnimatorControllerParameterType.Trigger:
                    parameters = characterAnimator.triggerParameters;
                    break;
                }

                // Draw parameters in a single line
                DrawCommand drawType = new DrawCommand(parameterTypeProperty);
                DrawCommand drawName = new DrawPopUp(parameterNameProperty, parameters);
                switch (parameterType)
                {
                case AnimatorControllerParameterType.Float:
                case AnimatorControllerParameterType.Int:
                case AnimatorControllerParameterType.Bool:
                    DrawPropertiesHorizontal(ref position, new DrawCommand[] { drawType, drawName, new DrawCommand(parameterValueProperty) });
                    break;

                case AnimatorControllerParameterType.Trigger:
                    DrawPropertiesHorizontal(ref position, new DrawCommand[] { drawType, drawName });
                    break;
                }
            }
            else
            {
                switch (parameterType)
                {
                case AnimatorControllerParameterType.Float:
                    parameterValueProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.floatValue));
                    break;

                case AnimatorControllerParameterType.Int:
                    parameterValueProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.intValue));
                    break;

                case AnimatorControllerParameterType.Bool:
                    parameterValueProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.boolValue));
                    break;
                }

                switch (parameterType)
                {
                case AnimatorControllerParameterType.Float:
                case AnimatorControllerParameterType.Int:
                case AnimatorControllerParameterType.Bool:
                    DrawPropertiesHorizontal(ref position, parameterTypeProperty, parameterNameProperty, parameterValueProperty);
                    break;

                case AnimatorControllerParameterType.Trigger:
                    DrawPropertiesHorizontal(ref position, parameterTypeProperty, parameterNameProperty);
                    break;
                }
            }
        }
Esempio n. 5
0
        protected override void OnDrawProperty(Rect position, SerializedProperty property)
        {
            // Special case if it's being used by the character animator
            StratusCharacterAnimator characterAnimator = target as StratusCharacterAnimator;
            bool hasParameters = characterAnimator != null && characterAnimator.animator != null && characterAnimator.hasParameters;

            // Member
            SerializedProperty memberProperty = property.FindPropertyRelative(nameof(StratusAnimatorParameterHook.member));

            EditorGUI.PropertyField(position, memberProperty);
            position.y += lineHeight * 2f;

            // Parameter
            SerializedProperty parameterNameProperty = property.FindPropertyRelative(nameof(StratusAnimatorParameterHook.parameterName));

            if (hasParameters)
            {
                SerializedProperty parameterTypeProperty = property.FindPropertyRelative(nameof(StratusAnimatorEventHook.parameterType));
                //AnimatorControllerParameterType parameterType = GetEnumValue<AnimatorControllerParameterType>(parameterTypeProperty);
                AnimatorControllerParameterType parameterType = (AnimatorControllerParameterType)parameterTypeProperty.intValue;
                string[] parameters = null;
                switch (parameterType)
                {
                case AnimatorControllerParameterType.Float:
                    parameters = characterAnimator.floatParameters;
                    break;

                case AnimatorControllerParameterType.Int:
                    parameters = characterAnimator.intParameters;
                    break;

                case AnimatorControllerParameterType.Bool:
                    parameters = characterAnimator.boolParameters;
                    break;

                case AnimatorControllerParameterType.Trigger:
                    parameters = characterAnimator.triggerParameters;
                    break;
                }
                DrawPopup(position, parameterNameProperty, parameters);
            }
            else
            {
                EditorGUI.PropertyField(position, parameterNameProperty);
            }


            //// Parameter
            ////AnimatorControllerParameterType parameterType = (AnimatorControllerParameterType)parameterTypeProperty.intValue;
            //if (hasParameters)
            //{
            //  DrawPopup(position, parameterNameProperty, characterAnimator.animatorParameterNames);
            //  //int index = characterAnimator.animatorParameterNames.FindIndex(parameterNameProperty.stringValue);
            //  //index = EditorGUI.Popup(position, index, characterAnimator.animatorParameterNames);
            //  //parameterNameProperty.stringValue = characterAnimator.animatorParameterNames.AtIndexOrDefault(index, string.Empty);
            //}
            //else
            //{
            //  EditorGUI.PropertyField(position, parameterNameProperty);
            //}
        }