Esempio n. 1
0
        private void OnEnable()
        {
            if (target == null)
            {
                return;
            }
            m_action           = (CharacterAction)target;
            m_action.hideFlags = HideFlags.HideInInspector;

            if (m_ActionSettingsHeader == null)
            {
                m_ActionSettingsHeader = new GUIContent()
                {
                    text    = "-- " + m_action.GetType().Name + " Settings --",
                    tooltip = "Settings for " + m_action.GetType().Name
                };
            }
            if (m_HeaderStyle == null)
            {
                m_HeaderStyle = new GUIStyle()
                {
                    font      = new GUIStyle(EditorStyles.label).font,
                    fontStyle = FontStyle.Bold,
                    //fontSize = 12,
                };
            }


            m_animatorMotion = serializedObject.FindProperty("m_animatorMotion");
            m_executeOnStart = serializedObject.FindProperty("m_executeOnStart");
            m_executeOnStop  = serializedObject.FindProperty("m_executeOnStop");
            enableDebug      = serializedObject.FindProperty("m_Debug");
        }
        protected void OnActionActive(CharacterAction action, bool activated)
        {
            int index = Array.IndexOf(m_Actions, action);

            if (action == m_Actions[index])
            {
                if (m_Actions[index].enabled)
                {
                    if (activated)
                    {
                        //Debug.LogFormat(" {0} is starting.", action.GetType().Name);
                        CharacterDebug.Log(action.GetType().Name, action.GetType());
                    }
                    else
                    {
                        CharacterDebug.Remove(action.GetType().Name);
                    }
                }
            }
        }
Esempio n. 3
0
        private void OnActionActive(CharacterAction action, bool activated)
        {
            if (activated)
            {
                //  There is currently an action running.
                if (m_activeStateAction != action && m_activeStateAction != null)
                {
                    //Debug.LogFormat("Stoppiong ActiveAction {0} |Starting Action ({1})", m_activeStateAction.GetType().Name,  action.GetType().Name);
                    m_controller.TryStopAction(m_activeStateAction, true);
                    m_activeStateAction = action;
                }
                //  If active action is the same as the incoming action.  This shoul;dn't happen.
                else if (m_activeStateAction == action)
                {
                    Debug.LogFormat("<color=yellow><b>[Warning]</color></b> ActiveAction is the same as incoming Action ({0})", action.GetType().Name);
                }
                //  there is no active action.
                else
                {
                    //Debug.LogFormat("ActiveAction is ({0})", action.GetType().Name);
                    m_activeStateAction = action;
                }

                //  If animator is matching target, stop it.
                if (m_animator.isMatchingTarget)
                {
                    m_animator.InterruptMatchTarget(false);
                }
            }
            else
            {
                if (m_activeStateAction == action)
                {
                    //Debug.LogFormat("ActiveAction {0} is now null.", m_activeStateAction.GetType().Name);
                    m_activeStateAction = null;

                    //  If animator is matching target, stop it.
                    if (m_animator.isMatchingTarget)
                    {
                        m_animator.InterruptMatchTarget(true);
                    }
                }
            }
        }
Esempio n. 4
0
        //private void LateUpdate()
        //{
        //    DetermineStates();

        //    DebugUI.DebugUI.Log(this, m_activeStateAction == null ? "null" : m_activeStateAction.ToString(), "ActiveAction", DebugUI.RichTextColor.Yellow);
        //    DebugUI.DebugUI.Log(this, m_animator.isMatchingTarget, "MatchingTarget", DebugUI.RichTextColor.Yellow);
        //}



        /// <summary>
        /// Changes the animator state.
        /// </summary>
        /// <param name="action">Action state to transition too.</param>
        /// <param name="layer">Which layer.</param>
        /// <param name="destinationState">Name of the state to transition too.</param>
        /// <param name="transitionDuration">The transition time.</param>
        /// <param name="normalizedTime">The normalized offset time.</param>
        /// <returns>Returns true if changing to new state.</returns>
        public bool ChangeAnimatorState(CharacterAction action, string destinationState, float transitionDuration = 0.2f, int layer = -1, float normalizedTime = 0f)
        {
            if (layer > -1 && layer <= m_animator.layerCount)
            {
                destinationState = m_animator.GetLayerName(layer) + "." + destinationState;
            }
            //string fullStateName = m_animator.GetLayerName(layer) + "." + destinationState;
            int stateHash = GetStateHash(destinationState);

            if (m_animator.HasState(layer, stateHash))
            {
                //  Set active action.
                m_previousStateAction = m_activeStateAction;
                m_activeStateAction   = action;
                //  CRossfade to new state.
                m_animator.CrossFade(stateHash, (transitionDuration > 0) ? transitionDuration : 0.01f, layer, normalizedTime);
                //m_animator.CrossFadeInFixedTime(fullStateName, (transitionDuration > 0) ? transitionDuration : 0.01f, layer, normalizedTime);
                if (debugStateChanges)
                {
                    Debug.LogFormat("<b><color=blue>[AnimatorMonitor]</color></b> Action \"<b><color=blue>{0}</color></b>\" is active.", action.GetType().Name);
                }
                return(true);
            }
            Debug.LogFormat("<b><color=red>[AnimatorMonitor]</color></b> Destination state <b><color=blue>\"{0}\"</color></b> does not exist.\nStateHAsh: {1} | AnimatorStateHash: {2}", destinationState, stateHash, Animator.StringToHash(destinationState));

            return(false);
        }
Esempio n. 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (k_drawDefault)
            {
                base.OnGUI(position, property, label);
                return;
            }

            element    = property;
            lineHeight = EditorGUIUtility.singleLineHeight;
            rect       = position;

            EditorGUI.BeginProperty(position, label, element);
            {
                serializedObject = new SerializedObject(element.objectReferenceValue);
                if (serializedObject != null)
                {
                    CharacterAction action = (CharacterAction)element.objectReferenceValue;
                    isActive    = serializedObject.FindProperty("m_isActive");
                    actionID    = serializedObject.FindProperty("m_actionID");
                    m_startType = serializedObject.FindProperty("m_startType");
                    m_stopType  = serializedObject.FindProperty("m_stopType");

                    var allocWidth = (rect.width - 20) / 5;
                    var enumWidth  = Mathf.Clamp(allocWidth, 75, float.MaxValue);
                    rect.y     += 2;
                    enabledRect = new Rect(rect.x, rect.y, 20, lineHeight);
                    labelRect   = new Rect(rect.x + 20, rect.y, allocWidth + 20, lineHeight);
                    //stateRect = new Rect(rect.x + allocWidth + 15, rect.y, allocWidth, lineHeight);
                    startTypeRect = new Rect((rect.x + enumWidth) + 36, rect.y, enumWidth, lineHeight);
                    stopTypeRect  = new Rect(startTypeRect.x + startTypeRect.width - 4, rect.y, enumWidth, lineHeight);
                    inputRect     = new Rect(stopTypeRect.x + stopTypeRect.width - 4, rect.y, allocWidth, lineHeight);

                    if (Application.isPlaying)
                    {
                        if (action.IsActive)
                        {
                            EditorGUI.DrawRect(position, activeActiopn);
                        }
                        //else EditorGUI.DrawRect(position, inactiveAction);
                    }

                    //  Enable toggle
                    action.enabled = EditorGUI.Toggle(enabledRect, action.enabled);
                    //  Action name.
                    EditorGUI.LabelField(labelRect, action.GetType().Name, action.IsActive? m_ActiveActionTextStyle : m_DefaultActionTextStyle);
                    //  StateName

                    //  StartType
                    action.StartType = (ActionStartType)EditorGUI.EnumPopup(startTypeRect, action.StartType);
                    //  StopType
                    action.StopType = (ActionStopType)EditorGUI.EnumPopup(stopTypeRect, action.StopType);
                    //  Input
                    EditorGUI.BeginDisabledGroup(!IsStartStopInput(action));
                    var m_inputKey = serializedObject.FindProperty("m_inputKey");
                    EditorGUI.PropertyField(inputRect, m_inputKey, GUIContent.none);
                    EditorGUI.EndDisabledGroup();


                    //stateName.stringValue = EditorGUI.TextField(rect, stateName.stringValue);



                    //  Action name.
                    //rect.width = position.width * 0.40f;
                    //if (action.IsActive) {
                    //    EditorGUI.LabelField(rect, string.Format("{0} ({1})", action.GetType().Name, "Active"), m_ActiveActionTextStyle);
                    //}
                    //else {
                    //    EditorGUI.LabelField(rect, action.GetType().Name, m_DefaultActionTextStyle);
                    //}


                    ////  Action state name.
                    //rect.x += position.width * 0.40f;
                    //rect.width = position.width * 0.36f;
                    //stateName.stringValue = EditorGUI.TextField(rect, stateName.stringValue);
                    ////  Action ID
                    ////rect.x = position.width * 0.85f;
                    //rect.x = position.width - 36;
                    //rect.width = 36;
                    //actionID.intValue = EditorGUI.IntField(rect, actionID.intValue);

                    ////  Toggle Enable
                    //rect.x = position.width + 12;
                    //rect.width = 36;
                    //action.enabled = EditorGUI.Toggle(rect, action.enabled);
                    ////isActive.boolValue = EditorGUI.Toggle(rect, isActive.boolValue);
                    ////isActive.boolValue = action.enabled;

                    serializedObject.ApplyModifiedProperties();
                }
            }



            EditorGUI.EndProperty();
        }