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); } } } }
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); } } } }
public void TryStopAction(CharacterAction action) { if (action == null) { return; } if (action.CanStopAction()) { int index = Array.IndexOf(m_Actions, action); if (m_ActiveAction == action) { m_ActiveAction = null; } action.StopAction(); ActionStopped(); } }
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(); }
protected override void FixedUpdate() { if (m_TimeScale == 0) { return; } m_DeltaTime = fixedDeltaTime; m_Move = true; m_CheckGround = true; m_CheckMovement = true; m_SetPhysicsMaterial = true; m_UpdateRotation = true; m_UpdateMovement = true; m_UpdateAnimator = true; for (int i = 0; i < m_Actions.Length; i++) { if (m_Actions[i].enabled == false) { continue; } CharacterAction charAction = m_Actions[i]; if (charAction.IsActive) { // Move charatcer based on input values. if (m_Move) { m_Move = charAction.Move(); } // Perform checks to determine if the character is on the ground. if (m_CheckGround) { m_CheckGround = charAction.CheckGround(); } // Ensure the current movement direction is valid. if (m_CheckMovement) { m_CheckMovement = charAction.CheckMovement(); } // Update the rotation forces. if (m_UpdateRotation) { m_UpdateRotation = charAction.UpdateRotation(); } // Apply any movement. if (m_UpdateMovement) { m_UpdateMovement = charAction.UpdateMovement(); } // Update the Animator. if (m_UpdateAnimator) { m_UpdateAnimator = charAction.UpdateAnimator(); } } } // end of for loop // Moves the character according to the input. if (m_Move) { Move(); } // Perform checks to determine if the character is on the ground. if (m_CheckGround) { CheckGround(); } // Ensure the current movement direction is valid. if (m_CheckMovement) { CheckMovement(); } // Set the physic material based on the grounded and stepping state if (m_SetPhysicsMaterial) { SetPhysicsMaterial(); } // Update the rotation forces. if (m_UpdateRotation) { UpdateRotation(); } // Apply any movement. if (m_UpdateMovement) { UpdateMovement(); } // Update the Animator. if (m_UpdateAnimator) { UpdateAnimator(); } }
protected void StopStartAction(CharacterAction charAction) { // First, check if current Action can Start or Stop. // Current Action is Active. if (charAction.enabled && charAction.IsActive) { // Check if can stop Action is StopType is NOT Manual. if (charAction.StopType != ActionStopType.Manual) { if (charAction.CanStopAction()) { // Start the Action and update the animator. charAction.StopAction(); // Reset Active Action. if (m_ActiveAction = charAction) { m_ActiveAction = null; } // Move on to the next Action. return; } } } // Current Action is NOT Active. else { // Check if can start Action is StartType is NOT Manual. if (charAction.enabled && charAction.StartType != ActionStartType.Manual) { if (m_ActiveAction == null) { if (charAction.CanStartAction()) { // Start the Action and update the animator. charAction.StartAction(); //charAction.UpdateAnimator(); // Set active Action if not concurrent. if (charAction.IsConcurrentAction() == false) { m_ActiveAction = charAction; } // Move onto the next Action. return; } } else if (charAction.IsConcurrentAction()) { if (charAction.CanStartAction()) { // Start the Action and update the animator. charAction.StartAction(); //charAction.UpdateAnimator(); // Move onto the next Action. return; } } else { return; } } } }