/// <summary> /// Updates the motion over time. This is called by the controller /// every update cycle so animations and stages can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> public override void Update(float rDeltaTime, int rUpdateIndex) { mMovement = Vector3.zero; mRotation = Quaternion.identity; // Determine if the view rotation is active mForceRotationToCamera = false; if (mMotionController._InputSource.IsPressed(_RotateActionAlias)) { if (mMotionController._CameraTransform != null) { mForceRotationToCamera = true; } } // Grab the state info float lInputMax = (IsRunActive ? 1f : 0.5f); MotionState lState = mMotionController.State; // Convert the input to radial so we deal with keyboard and gamepad input the same. float lInputX = (mMotionController._InputSource.IsPressed(_StrafeLeftActionAlias) ? -1f : 0f); lInputX = lInputX + (mMotionController._InputSource.IsPressed(_StrafeRightActionAlias) ? 1f : 0f); if (mForceRotationToCamera && lInputX == 0f) { lInputX = lState.InputX; } float lInputMagnitude = Mathf.Sqrt((lInputX * lInputX) + (lState.InputY * lState.InputY)); lInputX = Mathf.Clamp(lInputX, -lInputMax, lInputMax); float lInputY = Mathf.Clamp(lState.InputY, -lInputMax, lInputMax); lInputMagnitude = Mathf.Clamp(lInputMagnitude, 0f, lInputMax); InputManagerHelper.ConvertToRadialInput(ref lInputX, ref lInputY, ref lInputMagnitude); // Smooth the input mInputX.Add(lInputX); mInputY.Add(lInputY); mInputMagnitude.Add(lInputMagnitude); // Modify the input values to add some lag mMotionController.State.InputX = mInputX.Average; mMotionController.State.InputY = mInputY.Average; mMotionController.State.InputMagnitudeTrend.Replace(mInputMagnitude.Average); // If we're meant to rotate with the camera (and OnCameraUpdate isn't already attached), do it here if (_RotateWithCamera && !(mMotionController.CameraRig is BaseCameraRig)) { OnCameraUpdated(rDeltaTime, rUpdateIndex, null); } // If we're not rotating with the camera, rotate with the input if (_RotateWithInput && !mForceRotationToCamera) { RotateUsingInput(rDeltaTime, ref mRotation); } }
/// <summary> /// Test if we need to setup input manager entries /// </summary> /// <returns></returns> private bool TestInputManagerSettings() { if (!InputManagerHelper.IsDefined("Combatant Toggle Lock")) { return(false); } return(true); }
/// <summary> /// If the input manager entries don't exist, create them /// </summary> private void CreateInputManagerSettings() { if (!InputManagerHelper.IsDefined("Inventory Toggle")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Inventory Toggle"; lEntry.PositiveButton = "0"; lEntry.Gravity = 100; lEntry.Dead = 0.3f; lEntry.Sensitivity = 100; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("Inventory Shift")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Inventory Shift"; lEntry.NegativeButton = "-"; lEntry.PositiveButton = "="; lEntry.Gravity = 100; lEntry.Dead = 0.3f; lEntry.Sensitivity = 100; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry = new InputManagerEntry(); lEntry.Name = "Inventory Shift"; lEntry.PositiveButton = "joystick button 7"; lEntry.NegativeButton = "joystick button 8"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #else lEntry = new InputManagerEntry(); lEntry.Name = "Inventory Shift"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 6; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #endif } }
/// <summary> /// Test if we need to setup input manager entries /// </summary> /// <returns></returns> private bool TestInputManagerSettings() { if (!InputManagerHelper.IsDefined("Inventory Toggle")) { return(false); } if (!InputManagerHelper.IsDefined("Inventory Shift")) { return(false); } return(true); }
/// <summary> /// Updates the motion over time. This is called by the controller /// every update cycle so animations and stages can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> public override void Update(float rDeltaTime, int rUpdateIndex) { mMovement = Vector3.zero; mRotation = Quaternion.identity; // Test if we stop sneak due to a change in stance. We do this here to transition if (mMotionController.State.AnimatorStates[mMotionLayer._AnimatorLayerIndex].MotionPhase == 0 && mMotionController._InputSource != null && mMotionController._InputSource.IsEnabled) { //if (mMotionController._InputSource.IsJustPressed(_ActionAlias)) if (mMotionController._InputSource.IsReleased(_ActionAlias)) { // We have to use the forced value our we'll change the current blend value as we transition mMotionController.ForcedInput.x = mInputX.Average; mMotionController.ForcedInput.y = mInputY.Average; mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_END, 0, true); } } // Grab the state info MotionState lState = mMotionController.State; // Convert the input to radial so we deal with keyboard and gamepad input the same. float lInputX = lState.InputX; float lInputY = lState.InputY; float lInputMagnitude = lState.InputMagnitudeTrend.Value; InputManagerHelper.ConvertToRadialInput(ref lInputX, ref lInputY, ref lInputMagnitude, 0.5f); // Smooth the input mInputX.Add(lInputX); mInputY.Add(lInputY); mInputMagnitude.Add(lInputMagnitude); // Use the smoothed values for input mMotionController.State.InputX = mInputX.Average; mMotionController.State.InputY = mInputY.Average; mMotionController.State.InputMagnitudeTrend.Replace(mInputMagnitude.Average); // If we're not dealing with an ootii camera rig, we need to rotate to the camera here if (_RotateWithCamera && !(mMotionController.CameraRig is BaseCameraRig)) { OnCameraUpdated(rDeltaTime, rUpdateIndex, null); } // Rotate as needed if (!_RotateWithCamera && _RotateWithInput) { RotateUsingInput(rDeltaTime, ref mRotation); } }
// ************************************************************************************************** // Following properties and function only valid while editing // ************************************************************************************************** #if UNITY_EDITOR /// <summary> /// Creates input settings in the Unity Input Manager /// </summary> public override void CreateInputManagerSettings() { if (!InputManagerHelper.IsDefined(_ActionAlias)) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = _ActionAlias; lEntry.PositiveButton = "t"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry = new InputManagerEntry(); lEntry.Name = _ActionAlias; lEntry.PositiveButton = "joystick button 11"; // Left stick click lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #else lEntry = new InputManagerEntry(); lEntry.Name = _ActionAlias; lEntry.PositiveButton = "joystick button 8"; // Left stick click lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #endif } }
/// <summary> /// (Internal) Create the Input Manager entry for keys, mouse buttons, and joystick buttons /// Defaults to Gravity = 1000; Dead = 0.001; Sensitivity = 1000 /// </summary> /// <param name="rName">Name of the Input Manager setting (input alias)</param> /// <param name="rKey">The primary key</param> /// <param name="rAltKey">The alternate key (or mouse button)</param> /// <param name="rJoystickButton">(Optional) The joystick button</param> private static void CreateInputSetting_Internal(string rName, string rKey, string rAltKey, int rJoystickButton = -1) { if (InputManagerHelper.IsDefined(rName)) { return; } // Keyboard and/or mouse button InputManagerEntry lEntry = new InputManagerEntry { Name = rName, PositiveButton = rKey, AltPositiveButton = rAltKey, Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = InputManagerEntryType.KEY_MOUSE_BUTTON, Axis = 0, JoyNum = 0 }; InputManagerHelper.AddEntry(lEntry, true); // Joystick button if (rJoystickButton <= -1) { return; } lEntry = new InputManagerEntry { Name = rName, Gravity = 1000, Dead = 0.001f, Sensitivity = 1000, Type = InputManagerEntryType.KEY_MOUSE_BUTTON, Axis = 0, JoyNum = 0, PositiveButton = "joystick button " + rJoystickButton }; InputManagerHelper.AddEntry(lEntry, true); }
/// <summary> /// Removes entries from the input manager /// </summary> private void ClearInputManagerEntries() { InputManagerHelper.RemoveEntry("WXButton0"); InputManagerHelper.RemoveEntry("WXButton1"); InputManagerHelper.RemoveEntry("WXButton2"); InputManagerHelper.RemoveEntry("WXButton3"); InputManagerHelper.RemoveEntry("WXLeftStickX"); InputManagerHelper.RemoveEntry("WXLeftStickY"); InputManagerHelper.RemoveEntry("WXLeftStickButton"); InputManagerHelper.RemoveEntry("WXRightStickX"); InputManagerHelper.RemoveEntry("WXRightStickY"); InputManagerHelper.RemoveEntry("WXRightStickButton"); InputManagerHelper.RemoveEntry("WXLeftTrigger"); InputManagerHelper.RemoveEntry("WXRightTrigger"); InputManagerHelper.RemoveEntry("WXDPadX"); InputManagerHelper.RemoveEntry("WXDPadY"); InputManagerHelper.RemoveEntry("WXLeftBumper"); InputManagerHelper.RemoveEntry("WXRightBumper"); InputManagerHelper.RemoveEntry("WXBack"); InputManagerHelper.RemoveEntry("WXStart"); InputManagerHelper.RemoveEntry("MXButton0"); InputManagerHelper.RemoveEntry("MXButton1"); InputManagerHelper.RemoveEntry("MXButton2"); InputManagerHelper.RemoveEntry("MXButton3"); InputManagerHelper.RemoveEntry("MXLeftStickX"); InputManagerHelper.RemoveEntry("MXLeftStickY"); InputManagerHelper.RemoveEntry("MXLeftStickButton"); InputManagerHelper.RemoveEntry("MXRightStickX"); InputManagerHelper.RemoveEntry("MXRightStickY"); InputManagerHelper.RemoveEntry("MXRightStickButton"); InputManagerHelper.RemoveEntry("MXLeftTrigger"); InputManagerHelper.RemoveEntry("MXRightTrigger"); InputManagerHelper.RemoveEntry("MXDPadX"); InputManagerHelper.RemoveEntry("MXDPadY"); InputManagerHelper.RemoveEntry("MXLeftBumper"); InputManagerHelper.RemoveEntry("MXRightBumper"); InputManagerHelper.RemoveEntry("MXBack"); InputManagerHelper.RemoveEntry("MXStart"); }
/// <summary> /// If the input manager entries don't exist, create them /// </summary> private void CreateInputManagerSettings() { if (!InputManagerHelper.IsDefined("Combatant Toggle Lock")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Combatant Toggle Lock"; lEntry.PositiveButton = "t"; lEntry.Gravity = 100; lEntry.Dead = 0.3f; lEntry.Sensitivity = 100; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry = new InputManagerEntry(); lEntry.Name = "Combatant Toggle Lock"; lEntry.PositiveButton = "joystick button 12"; lEntry.Gravity = 100; lEntry.Dead = 0.3f; lEntry.Sensitivity = 100; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #else lEntry = new InputManagerEntry(); lEntry.Name = "Combatant Toggle Lock"; lEntry.PositiveButton = "joystick button 9"; lEntry.Gravity = 100; lEntry.Dead = 0.3f; lEntry.Sensitivity = 100; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); #endif } }
/// <summary> /// Create a new Input Manager setting for a joystick axis. /// Defaults to Gravity = 1; Dead = 0.3; Sensitivity = 1 /// </summary> /// <param name="rName">Name of the Input Manager setting (input alias)</param> /// <param name="rAxis">Index of the joystick axis</param> /// <param name="rJoystickNum">(optional) Which joystick?</param> public static void CreateAxisInputSetting(string rName, int rAxis, int rJoystickNum = 0) { if (InputManagerHelper.IsDefined(rName)) { return; } InputManagerEntry lEntry = new InputManagerEntry { Name = rName, PositiveButton = string.Empty, AltPositiveButton = string.Empty, Gravity = 1, Dead = 0.3f, Sensitivity = 1, Type = InputManagerEntryType.JOYSTICK_AXIS, Axis = rAxis, JoyNum = rJoystickNum }; InputManagerHelper.AddEntry(lEntry, true); }
/// <summary> /// We smooth the input so that we don't start and stop immediately in the blend tree. That can create pops. /// </summary> protected void SmoothInput() { MotionState lState = mMotionController.State; // Convert the input to radial so we deal with keyboard and gamepad input the same. float lInputMax = (IsRunActive ? 1f : 0.5f); float lInputX = Mathf.Clamp(lState.InputX, -lInputMax, lInputMax); float lInputY = Mathf.Clamp(lState.InputY, -lInputMax, lInputMax); float lInputMagnitude = Mathf.Clamp(lState.InputMagnitudeTrend.Value, 0f, lInputMax); InputManagerHelper.ConvertToRadialInput(ref lInputX, ref lInputY, ref lInputMagnitude); // Smooth the input mInputX.Add(lInputX); mInputY.Add(lInputY); mInputMagnitude.Add(lInputMagnitude); // Modify the input values to add some lag mMotionController.State.InputX = mInputX.Average; mMotionController.State.InputY = mInputY.Average; mMotionController.State.InputMagnitudeTrend.Replace(mInputMagnitude.Average); }
/// <summary> /// Updates the motion over time. This is called by the controller /// every update cycle so animations and stages can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> public override void Update(float rDeltaTime, int rUpdateIndex) { mMovement = Vector3.zero; mRotation = Quaternion.identity; // Grab the state info MotionState lState = mMotionController.State; // Convert the input to radial so we deal with keyboard and gamepad input the same. float lInputMax = (IsRunActive ? 1f : 0.5f); float lInputX = Mathf.Clamp(lState.InputX, -lInputMax, lInputMax); float lInputY = Mathf.Clamp(lState.InputY, -lInputMax, lInputMax); float lInputMagnitude = Mathf.Clamp(lState.InputMagnitudeTrend.Value, 0f, lInputMax); InputManagerHelper.ConvertToRadialInput(ref lInputX, ref lInputY, ref lInputMagnitude); // Smooth the input mInputX.Add(lInputX); mInputY.Add(lInputY); mInputMagnitude.Add(lInputMagnitude); // Modify the input values to add some lag mMotionController.State.InputX = mInputX.Average; mMotionController.State.InputY = mInputY.Average; mMotionController.State.InputMagnitudeTrend.Replace(mInputMagnitude.Average); // If we're not dealing with an ootii camera rig, we need to rotate to the camera here if (_RotateWithCamera && !(mMotionController.CameraRig is BaseCameraRig)) { OnCameraUpdated(rDeltaTime, rUpdateIndex, null); } if (!_RotateWithCamera && _RotateWithInput) { RotateUsingInput(rDeltaTime, ref mRotation); } }
/// <summary> /// Called when the inspector needs to draw /// </summary> public override void OnInspectorGUI() { // Pulls variables from runtime so we have the latest values. mTargetSO.Update(); GUILayout.Space(5); EditorHelper.DrawInspectorTitle("ootii Easy Input Source"); EditorHelper.DrawInspectorDescription("Input solution that leverages ootii's advanced 'Easy Input' asset. There should only be one per scene.", MessageType.None); GUILayout.Space(5); if (!InputManagerHelper.IsDefined("WXLeftStickX")) { Color lGUIColor = GUI.color; GUI.color = new Color(1f, 0.7f, 0.7f, 1f); EditorGUILayout.HelpBox("Required Unity Input Manager entries not created. To create the entries, press the 'Reset Input Entries' button below.", MessageType.Warning); GUI.color = lGUIColor; GUILayout.Space(5); } EditorGUILayout.BeginVertical(EditorHelper.Box); EditorGUILayout.HelpBox("Reset required Unity Input Manager entries.", MessageType.None); if (GUILayout.Button("Reset Input Entries", EditorStyles.miniButton)) { ClearInputManagerEntries(); CreateInputManagerEntries(); } EditorGUILayout.EndVertical(); GUILayout.Space(5); bool lNewIsPlayerInputEnabled = EditorGUILayout.Toggle(new GUIContent("Is Input Enabled", "Determines if this component will return user input. This is NOT a global setting and does NOT effect the static 'Input Manager' from returning input."), mTarget.IsEnabled); if (lNewIsPlayerInputEnabled != mTarget.IsEnabled) { mIsDirty = true; mTarget.IsEnabled = lNewIsPlayerInputEnabled; } bool lNewIsXboxControllerEnabled = EditorGUILayout.Toggle(new GUIContent("Is Xbox Enabled", "Determines we can use the Xbox controller for input. This is a global setting that effects the static 'Input Manager'."), mTarget.IsXboxControllerEnabled); if (lNewIsXboxControllerEnabled != mTarget.IsXboxControllerEnabled) { mIsDirty = true; mTarget.IsXboxControllerEnabled = lNewIsXboxControllerEnabled; // Ensure our input manager entries exist if (mTarget.IsXboxControllerEnabled) { CreateInputManagerEntries(); } } GUILayout.Space(5); float lNewViewSensativity = EditorGUILayout.FloatField(new GUIContent("View Sensativity", "Sets how quickly the view rotates (while using the mouse)"), mTarget.ViewSensativity); if (lNewViewSensativity != mTarget.ViewSensativity) { mIsDirty = true; mTarget.ViewSensativity = lNewViewSensativity; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("View Activator", "Determines what button enables viewing."), GUILayout.Width(EditorGUIUtility.labelWidth)); int lNewViewActivator = EditorGUILayout.Popup(mTarget.ViewActivator, mActivators); if (lNewViewActivator != mTarget.ViewActivator) { mIsDirty = true; mTarget.ViewActivator = lNewViewActivator; } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorHelper.DrawLine(); GUILayout.Space(5f); // Show the aliases GUILayout.BeginVertical(EditorHelper.GroupBox); mAliasList.DoLayoutList(); GUILayout.EndVertical(); if (mAliasList.index >= 0) { EditorGUILayout.BeginVertical(EditorHelper.Box); InputAlias lAlias = mTarget.DefaultActionAliases[mAliasList.index]; bool lListIsDirty = DrawAliasDetailItem(ref lAlias); if (lListIsDirty) { mIsDirty = true; mTarget.DefaultActionAliases[mAliasList.index] = lAlias; } EditorGUILayout.EndVertical(); } GUILayout.Space(5); // If there is a change... update. if (mIsDirty) { // Flag the object as needing to be saved EditorUtility.SetDirty(mTarget); #if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 EditorApplication.MarkSceneDirty(); #else if (!EditorApplication.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } #endif // Pushes the values back to the runtime so it has the changes mTargetSO.ApplyModifiedProperties(); // Clear out the dirty flag mIsDirty = false; } }
/// <summary> /// If the input manager entries don't exist, create them /// </summary> private void CreateInputManagerEntries() { if (!InputManagerHelper.IsDefined("WXButton0")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXButton0"; lEntry.PositiveButton = "joystick button 0"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXButton1")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXButton1"; lEntry.PositiveButton = "joystick button 1"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightStickX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightStickX"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 4; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightStickY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightStickY"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Invert = true; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 5; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightStickX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightStickX"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 3; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightStickY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightStickY"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Invert = true; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 4; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } }
/// <summary> /// Updates the motion over time. This is called by the controller /// every update cycle so animations and stages can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> public override void Update(float rDeltaTime, int rUpdateIndex) { mMovement = Vector3.zero; mRotation = Quaternion.identity; mNoInputElapsed = mNoInputElapsed + rDeltaTime; // If we're at the surface and grounded, we can't be going fast bool lAllowRunning = (!mSwimmerInfo.IsInShallowWater(mActorController.GroundingLayers)) && IsRunning; // Grab the state info MotionState lState = mMotionController.State; // Convert the input to radial so we deal with keyboard and gamepad input the same. float lInputX = lState.InputX; float lInputY = lState.InputY; float lInputMagnitude = lState.InputMagnitudeTrend.Value; InputManagerHelper.ConvertToRadialInput(ref lInputX, ref lInputY, ref lInputMagnitude, (lAllowRunning ? 1f : 0.5f)); // If input stops, we're going to keep our current value // and have the motion come to a smooth stop as needed if (lInputMagnitude > 0f) { mInputX.Add(lInputX); mInputY.Add(lInputY); mInputMagnitude.Add(lInputMagnitude); mNoInputElapsed = 0f; } // Use the averaged values for input lState.InputX = mInputX.Average; lState.InputY = mInputY.Average; lState.InputMagnitudeTrend.Replace(mInputMagnitude.Average); mMotionController.State = lState; // Determine how we'll stop based on the direction if (mMotionLayer._AnimatorStateID == STATE_SwimTree && mNoInputElapsed > 0.15f) { mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_STOP_SWIM, 0, true); } // We do this so we can re-enter the movement if needed if (mMotionLayer._AnimatorTransitionID == TRANS_SwimTree_TreadIdlePose) { mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, 0, 0, true); } // Do a surface check to see if we're exiting the water float lWaterMovement = mSwimmerInfo.WaterSurface.position.y - mSwimmerInfo.WaterSurfaceLastPosition.y; if (mSwimmerInfo.TestExitWater(lWaterMovement)) { mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_STOP_IDLE, 0, true); return; } // If we're at the surface, we may need to move with the surface if (mSwimmerInfo.IsAtWaterSurface(0.5f)) { mMovement.y = mMovement.y + lWaterMovement; mSwimmerInfo.CreateRipples(mMotionController._Transform.position); } else { mSwimmerInfo.CreateUnderwaterEffect(mMotionController.Animator, HumanBodyBones.Head); } mSwimmerInfo.WaterSurfaceLastPosition = mSwimmerInfo.WaterSurface.position; // Move based on the buoyancy mMovement = mMovement + mSwimmerInfo.GetBuoyancy(rDeltaTime); // Move vertically float lAngle = 0f; if (mMotionController._InputSource != null) { float lUpSpeed = mMotionController._InputSource.GetValue(_UpAlias) * _VerticalSpeed; if (lUpSpeed != 0f) { lAngle = _MaxPitch; } if (mSwimmerInfo.IsAtWaterSurface(0f)) { lUpSpeed = 0f; } float lDownSpeed = mMotionController._InputSource.GetValue(_DownAlias) * -_VerticalSpeed; if (lDownSpeed != 0f) { lAngle = -_MaxPitch; } if (mActorController.IsGrounded) { lDownSpeed = 0f; } mMovement.y = mMovement.y + ((lUpSpeed + lDownSpeed) * rDeltaTime); } // If we're not using the keys, we may use the mouse if (_DiveWithCamera && lAngle == 0f) { float lUpSpeed = 0f; float lDownSpeed = 0f; float lAdjustedMaxPitch = _MaxPitch - 5f; float lCameraAngle = NumberHelper.GetHorizontalAngle(mMotionController._CameraTransform.forward, mMotionController._Transform.forward, mMotionController._CameraTransform.right); if (lCameraAngle > 5f) { lCameraAngle = lCameraAngle - 5f; lUpSpeed = (Mathf.Min(lCameraAngle, lAdjustedMaxPitch) / lAdjustedMaxPitch) * _VerticalSpeed; if (mSwimmerInfo.IsAtWaterSurface(0f)) { lUpSpeed = 0f; lCameraAngle = 0f; } } else if (lCameraAngle < -5f) { lCameraAngle = lCameraAngle + 5f; lDownSpeed = (Mathf.Max(lCameraAngle, -lAdjustedMaxPitch) / -lAdjustedMaxPitch) * -_VerticalSpeed; if (mActorController.IsGrounded) { lDownSpeed = 0f; lCameraAngle = 0f; } } if (lCameraAngle != 0f) { lAngle = Mathf.Clamp(lAngle + lCameraAngle, -_MaxPitch, _MaxPitch); mMovement.y = mMovement.y + ((lUpSpeed + lDownSpeed) * rDeltaTime); } } //Utilities.Debug.Log.ScreenWrite("Angle:" + lAngle.ToString("f3"), 14); // Rotate the body if we can RotateBody(-lAngle); // If we're not dealing with an ootii camera rig, we need to rotate to the camera here if (_RotateWithCamera && !(mMotionController.CameraRig is BaseCameraRig)) { OnCameraUpdated(rDeltaTime, rUpdateIndex, null); } // Rotate as needed if (!_RotateWithCamera && _RotateWithInput) { RotateUsingInput(rDeltaTime, ref mRotation); } }
/// <summary> /// Displays the properties for the advanced tab /// </summary> /// <returns></returns> private bool OnAdvancedInspector() { bool lIsDirty = false; EditorGUILayout.BeginVertical(Box); GUILayout.Space(5); bool lNewIsInternalUpdateEnabled = EditorGUILayout.Toggle(new GUIContent("Force Update", "Determines if we allow the camera rig to update itself or if something like the Actor Controller will tell the camera when to update."), mTarget.IsInternalUpdateEnabled); if (lNewIsInternalUpdateEnabled != mTarget.IsInternalUpdateEnabled) { mIsDirty = true; mTarget.IsInternalUpdateEnabled = lNewIsInternalUpdateEnabled; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); GUILayout.Space(5); float lNewOrbitSmoothing = EditorGUILayout.FloatField(new GUIContent("Rotation Smoothing", "Power of the smoothing function to ease rotations. (0=none, 1=lots)"), mTarget.OrbitSmoothing); if (lNewOrbitSmoothing != mTarget.OrbitSmoothing) { mIsDirty = true; mTarget.OrbitSmoothing = lNewOrbitSmoothing; } GUILayout.Space(5); float lNewMinDistance = EditorGUILayout.FloatField(new GUIContent("Min Distance", "Minimum distance the camera can get to the anchor."), mTarget.MinDistance); if (lNewMinDistance != mTarget.MinDistance) { mIsDirty = true; mTarget.MinDistance = lNewMinDistance; } float lNewMaxDistance = EditorGUILayout.FloatField(new GUIContent("Max Distance", "Maximum distance the camera can get from the anchor."), mTarget.MaxDistance); if (lNewMaxDistance != mTarget.MaxDistance) { mIsDirty = true; mTarget.MaxDistance = lNewMaxDistance; } GUILayout.Space(5); float lNewMinPitch = EditorGUILayout.FloatField(new GUIContent("Min Pitch", "Minimum pitch the camera can get to. Pitch values are from -87 to 87 to prevent flipping."), mTarget.MinPitch); if (lNewMinPitch != mTarget.MinPitch) { mIsDirty = true; mTarget.MinPitch = lNewMinPitch; } float lNewMaxPitch = EditorGUILayout.FloatField(new GUIContent("Max Pitch", "Maximum pitch the camera can get to. Pitch values are from -87 to 87 to prevent flipping."), mTarget.MaxPitch); if (lNewMaxPitch != mTarget.MaxPitch) { mIsDirty = true; mTarget.MaxPitch = lNewMaxPitch; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); GUILayout.Space(5); Transform lNewAnchor = EditorGUILayout.ObjectField(new GUIContent("Anchor", "Transform the camera is meant to follow."), mTarget.Anchor, typeof(Transform), true) as Transform; if (lNewAnchor != mTarget.Anchor) { lIsDirty = true; mTarget.Anchor = lNewAnchor; } Vector3 lNewAnchorOffset = EditorGUILayout.Vector3Field(new GUIContent("Anchor Offset", "Offset from the transform that represents the true anchor."), mTarget.AnchorOffset); if (lNewAnchorOffset != mTarget.AnchorOffset) { lIsDirty = true; mTarget.AnchorOffset = lNewAnchorOffset; } float lNewAnchorDistance = EditorGUILayout.FloatField(new GUIContent("Anchor Distance", "Orbit distance from the anchor."), mTarget.AnchorDistance); if (lNewAnchorDistance != mTarget.AnchorDistance) { lIsDirty = true; mTarget.AnchorDistance = lNewAnchorDistance; } bool lNewAnchorOrbitsCamera = EditorGUILayout.Toggle(new GUIContent("Anchor Orbits Camera", "Determines if the player walks around the camera."), mTarget.AnchorOrbitsCamera); if (lNewAnchorOrbitsCamera != mTarget.AnchorOrbitsCamera) { mIsDirty = true; mTarget.AnchorOrbitsCamera = lNewAnchorOrbitsCamera; } float lNewAnchorTime = EditorGUILayout.FloatField(new GUIContent("Transition Time", "Time (in seconds) to transition to this mode."), mTarget.AnchorTime); if (lNewAnchorTime != mTarget.AnchorTime) { mIsDirty = true; mTarget.AnchorTime = lNewAnchorTime; } float lNewYawSpeed = EditorGUILayout.FloatField(new GUIContent("Yaw Speed", "Degrees per second the camera orbits the anchor."), mTarget.YawSpeed); if (lNewYawSpeed != mTarget.YawSpeed) { mIsDirty = true; mTarget.YawSpeed = lNewYawSpeed; } float lNewPitchSpeed = EditorGUILayout.FloatField(new GUIContent("Pitch Speed", "Degrees per second the camera orbits the anchor."), mTarget.PitchSpeed); if (lNewPitchSpeed != mTarget.PitchSpeed) { mIsDirty = true; mTarget.PitchSpeed = lNewPitchSpeed; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); EditorHelper.DrawSmallTitle("Targeting Mode Properties"); bool lNewIsAltModeEnabled = EditorGUILayout.Toggle(new GUIContent("Is Targeting Enabled", "Determines if the player can use the alternate targeting mode."), mTarget.IsAltModeEnabled); if (lNewIsAltModeEnabled != mTarget.IsAltModeEnabled) { mIsDirty = true; mTarget.IsAltModeEnabled = lNewIsAltModeEnabled; } string lNewAltActionAlias = EditorGUILayout.TextField(new GUIContent("Targeting Alias", "Input used to activate the alternate targeting mode."), mTarget.AltActionAlias); if (lNewAltActionAlias != mTarget.AltActionAlias) { mIsDirty = true; mTarget.AltActionAlias = lNewAltActionAlias; } bool lNewAltActionAliasAsToggle = EditorGUILayout.Toggle(new GUIContent("Targeting As Toggle", "Determines if the alias works as a toggle or needs to be held for the alternate targeting mode"), mTarget.AltActionAliasAsToggle); if (lNewAltActionAliasAsToggle != mTarget.AltActionAliasAsToggle) { mIsDirty = true; mTarget.AltActionAliasAsToggle = lNewAltActionAliasAsToggle; } Vector3 lNewAltAnchorOffset = EditorGUILayout.Vector3Field(new GUIContent("Targeting Anchor Offset", "Position of the camera relative to the anchor."), mTarget.AltAnchorOffset); if (lNewAltAnchorOffset != mTarget.AltAnchorOffset) { mIsDirty = true; mTarget.AltAnchorOffset = lNewAltAnchorOffset; } float lNewAltAnchorDistance = EditorGUILayout.FloatField(new GUIContent("Targeting Anchor Distance", "Distance from the anchor."), mTarget.AltAnchorDistance); if (lNewAltAnchorDistance != mTarget.AltAnchorDistance) { mIsDirty = true; mTarget.AltAnchorDistance = lNewAltAnchorDistance; } float lNewAltPitchSpeed = EditorGUILayout.FloatField(new GUIContent("Pitch Speed", "Degrees per second the view pitches while targeting."), mTarget.AltPitchSpeed); if (lNewAltPitchSpeed != mTarget.AltPitchSpeed) { mIsDirty = true; mTarget.AltPitchSpeed = lNewAltPitchSpeed; } float lNewAltAnchorTime = EditorGUILayout.FloatField(new GUIContent("Transition Time", "Time (in seconds) to transition to this mode."), mTarget.AltAnchorTime); if (lNewAltAnchorTime != mTarget.AltAnchorTime) { mIsDirty = true; mTarget.AltAnchorTime = lNewAltAnchorTime; } bool lNewAltForceActorToView = EditorGUILayout.Toggle(new GUIContent("Start Actor at View", "Determines if we rotate the actor to look at our current view when targeting starts."), mTarget.AltForceActorToView); if (lNewAltForceActorToView != mTarget.AltForceActorToView) { mIsDirty = true; mTarget.AltForceActorToView = lNewAltForceActorToView; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); EditorHelper.DrawSmallTitle("Collision Properties"); if ((mTarget.IsCollisionsEnabled && mTarget.IsObstructionsEnabled) || (mTarget.IsAltCollisionsEnabled && mTarget.IsAltObstructionsEnabled)) { EditorGUILayout.HelpBox("Having both collisions and line-of-sight testing enabled could cause some popping.", MessageType.Warning); } bool lNewTestCollisions = EditorGUILayout.Toggle(new GUIContent("Is Collision Enabled", "Deterines if we can collide with obstacles in the normal mode."), mTarget.IsCollisionsEnabled); if (lNewTestCollisions != mTarget.IsCollisionsEnabled) { mIsDirty = true; mTarget.IsCollisionsEnabled = lNewTestCollisions; } bool lNewAltTestCollisions = EditorGUILayout.Toggle(new GUIContent("Is Targeting Collision Enabled", "Determines if we can collide with obstacles in the targeting mode."), mTarget.IsAltCollisionsEnabled); if (lNewAltTestCollisions != mTarget.IsAltCollisionsEnabled) { mIsDirty = true; mTarget.IsAltCollisionsEnabled = lNewAltTestCollisions; } bool lNewAutoCollisionRadius = EditorGUILayout.Toggle(new GUIContent("Auto Collision Radius", "Automatically sets the collider radius to cover the camera's near plane."), mTarget.AutoCollisionRadius); if (lNewAutoCollisionRadius != mTarget.AutoCollisionRadius) { mIsDirty = true; mTarget.AutoCollisionRadius = lNewAutoCollisionRadius; } if (lNewAutoCollisionRadius) { float lNewAutoCollisionRadiusFactor = EditorGUILayout.FloatField(new GUIContent("Auto Radius Factor", "Multiplier to use when automatically setting the collider radius."), mTarget.AutoCollisionRadiusFactor); if (lNewAutoCollisionRadiusFactor != mTarget.AutoCollisionRadiusFactor) { mIsDirty = true; mTarget.AutoCollisionRadiusFactor = lNewAutoCollisionRadiusFactor; } } else { float lNewCollisionRadius = EditorGUILayout.FloatField(new GUIContent("Collision Radius", "Radius of the collider used by the camera."), mTarget.CollisionRadius); if (lNewCollisionRadius != mTarget.CollisionRadius) { mIsDirty = true; mTarget.CollisionRadius = lNewCollisionRadius; } } GUILayout.Space(5); bool lNewTestObstructions = EditorGUILayout.Toggle(new GUIContent("Is LOS Enabled", "Deterines if we use line-of-sight test for objects blocing the view in the normal mode."), mTarget.IsObstructionsEnabled); if (lNewTestObstructions != mTarget.IsObstructionsEnabled) { mIsDirty = true; mTarget.IsObstructionsEnabled = lNewTestObstructions; } bool lNewAltTestObstructions = EditorGUILayout.Toggle(new GUIContent("Is Targeting LOS Enabled", "Determines if we test for objects blocking the view in the targeting mode."), mTarget.IsAltObstructionsEnabled); if (lNewAltTestObstructions != mTarget.IsAltObstructionsEnabled) { mIsDirty = true; mTarget.IsAltObstructionsEnabled = lNewAltTestObstructions; } bool lNewAutoObstructionRadius = EditorGUILayout.Toggle(new GUIContent("Auto LOS Radius", "Automatically sets the obstruction radius to cover the camera's near plane."), mTarget.AutoObstructionRadius); if (lNewAutoObstructionRadius != mTarget.AutoObstructionRadius) { mIsDirty = true; mTarget.AutoObstructionRadius = lNewAutoObstructionRadius; } if (lNewAutoObstructionRadius) { float lNewAutoCollisionRadiusFactor = EditorGUILayout.FloatField(new GUIContent("Auto Radius Factor", "Multiplier to use when automatically setting the obstruction radius."), mTarget.AutoCollisionRadiusFactor); if (lNewAutoCollisionRadiusFactor != mTarget.AutoCollisionRadiusFactor) { mIsDirty = true; mTarget.AutoCollisionRadiusFactor = lNewAutoCollisionRadiusFactor; } } else { float lNewObstructionRadius = EditorGUILayout.FloatField(new GUIContent("LOS Radius", "Radius of the collider used by the camera."), mTarget.ObstructionRadius); if (lNewObstructionRadius != mTarget.ObstructionRadius) { mIsDirty = true; mTarget.ObstructionRadius = lNewObstructionRadius; } } float lNewRecoveryDelay = EditorGUILayout.FloatField(new GUIContent("LOS Recovery Delay", "After a collision, the number of seconds before we head back to our desired distance."), mTarget.RecoveryDelay); if (lNewRecoveryDelay != mTarget.RecoveryDelay) { mIsDirty = true; mTarget.RecoveryDelay = lNewRecoveryDelay; } GUILayout.Space(5); int lNewCollisionLayers = EditorHelper.LayerMaskField(new GUIContent("Collision Layers", "Layers that identies objects the camera will collide with."), mTarget.CollisionLayers); if (lNewCollisionLayers != mTarget.CollisionLayers) { mIsDirty = true; mTarget.CollisionLayers = lNewCollisionLayers; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); EditorHelper.DrawSmallTitle("Fade Properties"); if ((mTarget.IsFadeEnabed)) { EditorGUILayout.HelpBox("True fading requires character shaders to use transparency." + (mTarget.DisableRenderers ? "" : "Disabling renderers works with opaque or transparent shaders."), MessageType.Warning); } bool lNewIsFadeEnabled = EditorGUILayout.Toggle(new GUIContent("Is Fade Enabled", "Determines if we fade the anchor when the camera is too close. This requires the anchor shaders to use transparencies."), mTarget.IsFadeEnabed); if (lNewIsFadeEnabled != mTarget.IsFadeEnabed) { mIsDirty = true; mTarget.IsFadeEnabed = lNewIsFadeEnabled; } float lNewFadeDistance = EditorGUILayout.FloatField(new GUIContent("Fade Distance", "Distance between the anchor and camera where we start fading out."), mTarget.FadeDistance); if (lNewFadeDistance != mTarget.FadeDistance) { mIsDirty = true; mTarget.FadeDistance = lNewFadeDistance; } float lNewFadeSpeed = EditorGUILayout.FloatField(new GUIContent("Fade Speed", "Time (in seconds) to fade the anchor in and out."), mTarget.FadeSpeed); if (lNewFadeSpeed != mTarget.FadeSpeed) { mIsDirty = true; mTarget.FadeSpeed = lNewFadeSpeed; } bool lNewDisableRenderers = EditorGUILayout.Toggle(new GUIContent("Disable Renderers", "Determines if the anchor's renderers are disabled when fading is complete. This works for non-transparent shaders too."), mTarget.DisableRenderers); if (lNewDisableRenderers != mTarget.DisableRenderers) { mIsDirty = true; mTarget.DisableRenderers = lNewDisableRenderers; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); EditorHelper.DrawSmallTitle("Zoom Properties"); bool lNewIsFieldOfViewEnabled = EditorGUILayout.Toggle(new GUIContent("Is FOV Enabled", "Determines if we allow changing the field-of-view while in normal mode."), mTarget.IsFieldOfViewEnabled); if (lNewIsFieldOfViewEnabled != mTarget.IsFieldOfViewEnabled) { mIsDirty = true; mTarget.IsFieldOfViewEnabled = lNewIsFieldOfViewEnabled; } bool lNewIsAltFieldOfViewEnabled = EditorGUILayout.Toggle(new GUIContent("Is Targeting FOV Enabled", "Determines if we allow changing the field-of-view while in targeting mode."), mTarget.IsAltFieldOfViewEnabled); if (lNewIsAltFieldOfViewEnabled != mTarget.IsAltFieldOfViewEnabled) { mIsDirty = true; mTarget.IsAltFieldOfViewEnabled = lNewIsAltFieldOfViewEnabled; } string lNewFieldOfViewActionAlias = EditorGUILayout.TextField(new GUIContent("FOV Action Alias", "Input alias used to get the field-of-view delta each frame."), mTarget.FieldOfViewActionAlias); if (lNewFieldOfViewActionAlias != mTarget.FieldOfViewActionAlias) { mIsDirty = true; mTarget.FieldOfViewActionAlias = lNewFieldOfViewActionAlias; } if (lNewFieldOfViewActionAlias == "Camera FOV") { if (!InputManagerHelper.IsDefined("Camera FOV")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Camera FOV"; lEntry.Gravity = 0f; lEntry.Dead = 0f; lEntry.Sensitivity = 0.1f; lEntry.Type = InputManagerEntryType.MOUSE_MOVEMENT; lEntry.Axis = 3; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); lEntry = new InputManagerEntry(); lEntry.Name = "Camera FOV"; lEntry.Gravity = 1f; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1f; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry.Axis = 6; #else lEntry.Axis = 10; #endif lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); } } float lNewMinFieldOfView = EditorGUILayout.FloatField(new GUIContent("Min FOV", "Minimum field of view (tightest zoom) allowed."), mTarget.MinFieldOfView); if (lNewMinFieldOfView != mTarget.MinFieldOfView) { mIsDirty = true; mTarget.MinFieldOfView = lNewMinFieldOfView; } float lNewFieldOfViewSpeed = EditorGUILayout.FloatField(new GUIContent("FOV Speed", "Speed (in seconds) at which we change the field-of-view."), mTarget.FieldOfViewSpeed); if (lNewFieldOfViewSpeed != mTarget.FieldOfViewSpeed) { mIsDirty = true; mTarget.FieldOfViewSpeed = lNewFieldOfViewSpeed; } float lNewFieldOfViewSmoothing = EditorGUILayout.FloatField(new GUIContent("FOV Smoothing", "Smoothing applied to field-of-view changes. (0=none, 1=lots)"), mTarget.FieldOfViewSmoothing); if (lNewFieldOfViewSmoothing != mTarget.FieldOfViewSmoothing) { mIsDirty = true; mTarget.FieldOfViewSmoothing = lNewFieldOfViewSmoothing; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUILayout.BeginVertical(Box); EditorHelper.DrawSmallTitle("Camera Shake Properties"); // Determine how gravity is applied AnimationCurve lNewShakeStrength = EditorGUILayout.CurveField(new GUIContent("Shake Strength", "Determines how strong the shake is over the duration. (0 = none, 1 = 100%)"), mTarget.ShakeStrength); if (lNewShakeStrength != mTarget.ShakeStrength) { mIsDirty = true; mTarget.ShakeStrength = lNewShakeStrength; } GUILayout.Space(3); EditorGUILayout.EndVertical(); GUILayout.Space(5); //float lNewDistanceEnd = EditorGUILayout.FloatField(new GUIContent("Distance End", ""), mTarget.mDistanceEnd); //if (lNewDistanceEnd != mTarget.mDistanceEnd) //{ // mIsDirty = true; // mTarget.mDistanceEnd = lNewDistanceEnd; //} //float lNewLocalYaw = EditorGUILayout.FloatField(new GUIContent("Local Yaw", ""), mTarget.LocalYaw); //if (lNewLocalYaw != mTarget.LocalYaw) //{ // mIsDirty = true; // mTarget.LocalYaw = lNewLocalYaw; //} //float lNewLocalPitch = EditorGUILayout.FloatField(new GUIContent("Local Pitch", ""), mTarget.LocalPitch); //if (lNewLocalPitch != mTarget.LocalPitch) //{ // mIsDirty = true; // mTarget.LocalPitch = lNewLocalPitch; //} return(lIsDirty); }
/// <summary> /// Draws the inspector for the pack /// </summary> /// <returns></returns> public static bool OnPackInspector(MotionController rMotionController) { EditorHelper.DrawSmallTitle(GroupName()); EditorHelper.DrawLink("Mixamo Pro Magic Pack Animations", "http://www.ootii.com/Unity/MotionPacks/SpellCasting/SpellCastingUsersGuide.pdf"); GUILayout.Space(5f); EditorGUILayout.LabelField("See included documentation:", EditorHelper.SmallBoldLabel); EditorGUILayout.LabelField("1. Download and import animations.", EditorHelper.SmallLabel); EditorGUILayout.LabelField("2. Unzip and replace animation meta files.", EditorHelper.SmallLabel); EditorGUILayout.LabelField("3. Select options and create motions.", EditorHelper.SmallLabel); EditorHelper.DrawLine(); EditorHelper.BoolField("Create Mecanim States", "Determines if we create/override the existing sub-state machine", sCreateSubStateMachines); sCreateSubStateMachines = EditorHelper.FieldBoolValue; EditorHelper.BoolField("Create Input Aliases", "Determines if we create input aliases", sCreateInputAliases); sCreateInputAliases = EditorHelper.FieldBoolValue; EditorHelper.BoolField("Create Inventory", "Determines if we create/override the existing inventory", sCreateInventory); sCreateInventory = EditorHelper.FieldBoolValue; EditorHelper.BoolField("Create Attributes", "Determines if we create/override the existing attributes", sCreateAttributes); sCreateAttributes = EditorHelper.FieldBoolValue; EditorHelper.BoolField("Create Spell Inventory", "Create the spell inventory for the caster", sCreateSpellInventory); sCreateSpellInventory = EditorHelper.FieldBoolValue; EditorHelper.BoolField("Create Combatant", "Determines if we create/override the existing core", sCreateCore); sCreateCore = EditorHelper.FieldBoolValue; EditorHelper.BoolField("Create Motions", "Determines if we create the archery motions", sCreateMotions); sCreateMotions = EditorHelper.FieldBoolValue; GUILayout.Space(5f); if (GUILayout.Button(new GUIContent("Setup Pack", "Create and setup the motion pack."), EditorStyles.miniButton)) { if (sCreateInventory) { BasicInventory lInventory = rMotionController.gameObject.GetComponent <BasicInventory>(); if (lInventory == null) { lInventory = rMotionController.gameObject.AddComponent <BasicInventory>(); } BasicInventoryItem lItem = lInventory.GetInventoryItem("Spell_01"); if (lItem != null) { lInventory.Items.Remove(lItem); } lInventory.Items.Add(new BasicInventoryItem()); lInventory.Items[lInventory.Items.Count - 1].ID = "Spell_01"; lInventory.Items[lInventory.Items.Count - 1].EquipMotion = "PMP_EquipSpell"; lInventory.Items[lInventory.Items.Count - 1].StoreMotion = "PMP_StoreSpell"; BasicInventorySlot lSlot = lInventory.GetInventorySlot("RIGHT_HAND"); if (lSlot == null) { lInventory.Slots.Add(new BasicInventorySlot()); lInventory.Slots[lInventory.Slots.Count - 1].ID = "RIGHT_HAND"; lInventory.Slots[lInventory.Slots.Count - 1].ItemID = ""; } if (lInventory.GetInventorySlot("LEFT_HAND") == null) { lInventory.Slots.Add(new BasicInventorySlot()); lInventory.Slots[lInventory.Slots.Count - 1].ID = "LEFT_HAND"; lInventory.Slots[lInventory.Slots.Count - 1].ItemID = ""; } lSlot = lInventory.GetInventorySlot("LEFT_LOWER_ARM"); if (lSlot == null) { lInventory.Slots.Add(new BasicInventorySlot()); lInventory.Slots[lInventory.Slots.Count - 1].ID = "LEFT_LOWER_ARM"; lInventory.Slots[lInventory.Slots.Count - 1].ItemID = ""; } if (lInventory.GetInventorySlot("READY_PROJECTILE") == null) { lInventory.Slots.Add(new BasicInventorySlot()); lInventory.Slots[lInventory.Slots.Count - 1].ID = "READY_PROJECTILE"; lInventory.Slots[lInventory.Slots.Count - 1].ItemID = ""; } BasicInventorySet lWeaponSet = lInventory.GetWeaponSet("Spell Casting"); if (lWeaponSet != null) { lInventory.WeaponSets.Remove(lWeaponSet); } lWeaponSet = new BasicInventorySet(); lWeaponSet.ID = "Spell Casting"; BasicInventorySetItem lWeaponSetItem = new BasicInventorySetItem(); lWeaponSetItem.ItemID = ""; lWeaponSetItem.SlotID = "LEFT_HAND"; lWeaponSetItem.Instantiate = true; lWeaponSet.Items.Add(lWeaponSetItem); lWeaponSetItem = new BasicInventorySetItem(); lWeaponSetItem.ItemID = ""; lWeaponSetItem.SlotID = "READY_PROJECTILE"; lWeaponSetItem.Instantiate = false; lWeaponSet.Items.Add(lWeaponSetItem); lWeaponSetItem = new BasicInventorySetItem(); lWeaponSetItem.ItemID = "Spell_01"; lWeaponSetItem.SlotID = "RIGHT_HAND"; lWeaponSetItem.Instantiate = false; lWeaponSet.Items.Add(lWeaponSetItem); lWeaponSetItem = new BasicInventorySetItem(); lWeaponSetItem.ItemID = ""; lWeaponSetItem.SlotID = "LEFT_LOWER_ARM"; lWeaponSetItem.Instantiate = false; lWeaponSet.Items.Add(lWeaponSetItem); if (lInventory.WeaponSets.Count == 0) { BasicInventorySet lFirstWeaponSet = new BasicInventorySet(); lFirstWeaponSet.ID = "Sword and Shield"; lInventory.WeaponSets.Add(lFirstWeaponSet); } if (lInventory.WeaponSets.Count == 1) { BasicInventorySet lSecondWeaponSet = new BasicInventorySet(); lSecondWeaponSet.ID = "Longbow"; lInventory.WeaponSets.Add(lSecondWeaponSet); } lInventory.WeaponSets.Insert(2, lWeaponSet); } if (sCreateAttributes) { BasicAttributes lAttributes = rMotionController.gameObject.GetComponent <BasicAttributes>(); if (lAttributes == null) { lAttributes = rMotionController.gameObject.AddComponent <BasicAttributes>(); } BasicAttribute lAttribute = lAttributes.GetAttribute("Health"); if (lAttribute != null) { lAttributes.Items.Remove(lAttribute); } lAttributes.Items.Add(new BasicAttribute()); lAttributes.Items[lAttributes.Items.Count - 1].ID = "Health"; lAttributes.Items[lAttributes.Items.Count - 1].SetValue <float>(100f); } if (sCreateSpellInventory) { SpellInventory lAttributes = rMotionController.gameObject.GetComponent <SpellInventory>(); if (lAttributes == null) { lAttributes = rMotionController.gameObject.AddComponent <SpellInventory>(); } } if (sCreateCore) { Combatant lCombatant = rMotionController.gameObject.GetComponent <Combatant>(); if (lCombatant == null) { lCombatant = rMotionController.gameObject.AddComponent <Combatant>(); } if (rMotionController._ActorController == null || !rMotionController._ActorController.UseTransformPosition) { lCombatant.IsLockingEnabled = true; lCombatant.TargetLockedIcon = AssetDatabase.LoadAssetAtPath <Texture>("Assets/ootii/Framework_v1/Content/Textures/UI/TargetIcon_2.png"); } ActorCore lCore = rMotionController.gameObject.GetComponent <ActorCore>(); if (lCore == null) { lCore = rMotionController.gameObject.AddComponent <ActorCore>(); } lCore.IsAlive = true; } if (sCreateInputAliases) { // Sheathe if (!InputManagerHelper.IsDefined("Spell Casting Equip")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Equip"; lEntry.PositiveButton = "3"; // "3" key lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Equip"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.JoyNum = 0; #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry.PositiveButton = "joystick button 8"; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; // D-pad Y lEntry.Axis = 0; #else lEntry.PositiveButton = ""; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; // D-pad Y lEntry.Axis = 7; #endif InputManagerHelper.AddEntry(lEntry, true); } // Fire if (!InputManagerHelper.IsDefined("Spell Casting Cast")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Cast"; lEntry.PositiveButton = "left ctrl"; lEntry.AltPositiveButton = "mouse 0"; // Left mouse button lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Cast"; #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry.PositiveButton = "joystick button 16"; // Green A #else lEntry.PositiveButton = "joystick button 0"; // Green A #endif lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); } // Continue if (!InputManagerHelper.IsDefined("Spell Casting Continue")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Continue"; lEntry.PositiveButton = "left ctrl"; lEntry.AltPositiveButton = "mouse 0"; // Left mouse button lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Continue"; #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry.PositiveButton = "joystick button 16"; // Green A #else lEntry.PositiveButton = "joystick button 0"; // Green A #endif lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); } // Cancel if (!InputManagerHelper.IsDefined("Spell Casting Cancel")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Cancel"; lEntry.PositiveButton = "escape"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); lEntry = new InputManagerEntry(); lEntry.Name = "Spell Casting Cancel"; #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX lEntry.PositiveButton = "joystick button 19"; // Yellow Y #else lEntry.PositiveButton = "joystick button 3"; // Yellow Y #endif lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); } // Move Up if (!InputManagerHelper.IsDefined("Move Up")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Move Up"; lEntry.PositiveButton = "e"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); } // Move down if (!InputManagerHelper.IsDefined("Move Down")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "Move Down"; lEntry.PositiveButton = "q"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry, true); } } if (sCreateMotions || sCreateSubStateMachines) { IBaseCameraRig lCameraRig = rMotionController.CameraRig; if (lCameraRig == null) { lCameraRig = rMotionController.ExtractCameraRig(rMotionController.CameraTransform); } if (rMotionController.MotionLayers.Count == 0) { MotionControllerLayer lMotionLayer = new MotionControllerLayer(); rMotionController.MotionLayers.Add(lMotionLayer); } PMP_Idle lIdle = rMotionController.GetMotion <PMP_Idle>(); if (lIdle == null) { lIdle = rMotionController.CreateMotion <PMP_Idle>(0); } PMP_EquipSpell lEquip = rMotionController.GetMotion <PMP_EquipSpell>(0); if (lEquip == null) { lEquip = rMotionController.CreateMotion <PMP_EquipSpell>(0); } PMP_StoreSpell lStore = rMotionController.GetMotion <PMP_StoreSpell>(0); if (lStore == null) { lStore = rMotionController.CreateMotion <PMP_StoreSpell>(0); } PMP_WalkRunPivot lPivot = rMotionController.GetMotion <PMP_WalkRunPivot>(0); if (lPivot == null) { lPivot = rMotionController.CreateMotion <PMP_WalkRunPivot>(0); } PMP_WalkRunStrafe lStrafe = rMotionController.GetMotion <PMP_WalkRunStrafe>(0); if (lStrafe == null) { lStrafe = rMotionController.CreateMotion <PMP_WalkRunStrafe>(0); } PMP_BasicSpellCastings lCast = rMotionController.GetMotion <PMP_BasicSpellCastings>(0); if (lCast == null) { lCast = rMotionController.CreateMotion <PMP_BasicSpellCastings>(0); } Cower lCower = rMotionController.GetMotion <Cower>(0); if (lCower == null) { lCower = rMotionController.CreateMotion <Cower>(0); } Death lDeath = rMotionController.GetMotion <Death>(0); if (lDeath == null) { lDeath = rMotionController.CreateMotion <Death>(0); } Damaged lDamaged = rMotionController.GetMotion <Damaged>(0); if (lDamaged == null) { lDamaged = rMotionController.CreateMotion <Damaged>(0); } Frozen lFrozen = rMotionController.GetMotion <Frozen>(0); if (lFrozen == null) { lFrozen = rMotionController.CreateMotion <Frozen>(0); } KnockedDown lKnockedDown = rMotionController.GetMotion <KnockedDown>(0); if (lKnockedDown == null) { lKnockedDown = rMotionController.CreateMotion <KnockedDown>(0); } Levitate lLevitate = rMotionController.GetMotion <Levitate>(0); if (lLevitate == null) { lLevitate = rMotionController.CreateMotion <Levitate>(0); } PushedBack lPushedBack = rMotionController.GetMotion <PushedBack>(0); if (lPushedBack == null) { lPushedBack = rMotionController.CreateMotion <PushedBack>(0); } Sleep lSleep = rMotionController.GetMotion <Sleep>(0); if (lSleep == null) { lSleep = rMotionController.CreateMotion <Sleep>(0); } Stunned lStunned = rMotionController.GetMotion <Stunned>(0); if (lStunned == null) { lStunned = rMotionController.CreateMotion <Stunned>(0); } if (sCreateSubStateMachines) { Animator lAnimator = rMotionController.Animator; if (lAnimator == null) { lAnimator = rMotionController.gameObject.GetComponent <Animator>(); } if (lAnimator != null) { UnityEditor.Animations.AnimatorController lAnimatorController = lAnimator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; lIdle.CreateStateMachine(lAnimatorController); lEquip.CreateStateMachine(lAnimatorController); lPivot.CreateStateMachine(lAnimatorController); lStrafe.CreateStateMachine(lAnimatorController); lCast.CreateStateMachine(lAnimatorController); lDeath.CreateStateMachine(lAnimatorController); lLevitate.CreateStateMachine(lAnimatorController); } } } EditorUtility.DisplayDialog("Motion Pack: " + GroupName(), "Motion pack imported.", "ok"); return(true); } return(false); }
/// <summary> /// Check if the default Motion Controller Input Manager settings have been applied /// </summary> /// <returns></returns> public static bool HasDefaultInputSettings() { return(InputManagerHelper.IsDefined("ActivateRotation")); }
/// <summary> /// Updates the motion over time. This is called by the controller /// every update cycle so animations and stages can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> public override void Update(float rDeltaTime, int rUpdateIndex) { mRotation = Quaternion.identity; // Grab the state info MotionState lState = mMotionController.State; // Convert the input to radial so we deal with keyboard and gamepad input the same. float lInputX = lState.InputX; float lInputY = lState.InputY; float lInputMag = lState.InputMagnitudeTrend.Value; InputManagerHelper.ConvertToRadialInput(ref lInputX, ref lInputY, ref lInputMag); //, (IsRunActive ? 1f : 0.5f)); // Ensure we support the stop delay. This way, we can get out // of the blend tree with a nice transition if (lState.InputMagnitudeTrend.Value < 0.4f) { // Only set the timer if it's not set yet if (mStopTime == 0f) { mStopInput.x = mInputX.Average; mStopInput.y = mInputY.Average; mStopTime = Time.time + _StopDelay; mInputX.Clear(mStopInput.x); mInputY.Clear(mStopInput.y); mInputMagnitude.Clear(Mathf.Sqrt((mInputX.Value * mInputX.Value) + (mInputY.Value * mInputY.Value))); } } // Clear the timer else { mStopTime = 0f; } // When we're processing normally, update all the input values if (mStopTime == 0f) { mInputX.Add(lInputX); mInputY.Add(lInputY); mInputMagnitude.Add(lInputMag); } // If we've reached our stop time, it's time to stop else if (Time.time > mStopTime) { // Determine how we'll stop based on the direction if (!(mMotionLayer._AnimatorStateID == STATE_IdlePoseOut)) { mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_STOP, 0, true); } // If we're already stopping, we can clear our movement info. We don't want // to clear the movement before the transition our our blend tree will drop to idle else { mStopTime = 0f; mInputX.Clear(); mInputY.Clear(); mInputMagnitude.Clear(); lState.AnimatorStates[mMotionLayer._AnimatorLayerIndex].MotionPhase = 0; lState.AnimatorStates[mMotionLayer._AnimatorLayerIndex].MotionParameter = 0; } } // Modify the input values to add some lag lState.InputX = mInputX.Average; lState.InputY = mInputY.Average; lState.InputMagnitudeTrend.Replace(mInputMagnitude.Average); // Finally, set the state value mMotionController.State = lState; // If we're not dealing with an ootii camera rig, we need to rotate to the camera here if (_RotateWithCamera && !(mMotionController.CameraRig is BaseCameraRig)) { OnCameraUpdated(rDeltaTime, rUpdateIndex, null); } if (!_RotateWithCamera && _RotateWithInput) { RotateUsingInput(rDeltaTime, ref mRotation); } // Allow the base class to render debug info base.Update(rDeltaTime, rUpdateIndex); }
/// <summary> /// Updates the motor over time. This is called by the controller /// every update cycle so movement can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> /// <param name="rTiltAngle">Amount of tilting the camera needs to do to match the anchor</param> public override CameraTransform RigLateUpdate(float rDeltaTime, int rUpdateIndex, float rTiltAngle = 0f) { bool lSmooth = true; bool lContinue = true; Vector3 lMovement = Vector3.zero; IInputSource lInputSource = RigController.InputSource; // Camera rotation we'll use to modify the input Quaternion lCameraYaw = Quaternion.Euler(0f, RigController._Transform.rotation.eulerAngles.y, 0f); // Follow anchor logic if (_FollowAnchor && Anchor != null && lMovement.sqrMagnitude == 0f) { if (!_AllowDisconnect) { mIsFollowConnected = true; } else if (_FollowAlias.Length == 0) { mIsFollowConnected = true; } else if (_FollowAlias.Length > 0 && lInputSource != null && lInputSource.IsPressed(_FollowAlias)) { mIsFollowConnected = true; } if (mIsFollowConnected) { lSmooth = false; lContinue = false; //Vector3 lCameraPosition = RigController._Transform.position; Vector3 lAnchorPosition = AnchorPosition; if (_FollowFromView) { //float lAngle = 90f - RigController._Transform.eulerAngles.x; //float lDistance = _MaxDistance / Mathf.Cos(lAngle * Mathf.Deg2Rad); Vector3 lLastPositionTarget = mPositionTarget; mPositionTarget = lAnchorPosition - (RigController._Transform.forward * _MaxDistance); //lMovement = lNewCameraPosition - lCameraPosition; if (!_FollowElevation) { mPositionTarget.y = lLastPositionTarget.y; } } else { lMovement.x = lAnchorPosition.x - RigController._Transform.position.x; lMovement.y = (_FollowElevation ? lAnchorPosition.y - RigController._Transform.position.y : 0f); lMovement.z = lAnchorPosition.z - RigController._Transform.position.z; } } } else { mPositionTarget = RigController._Transform.position; } // Grip logic if (_GripPan && lInputSource != null && lMovement.sqrMagnitude == 0f) { if (_GripAlias.Length == 0 || lInputSource.IsPressed(_GripAlias)) { if (lInputSource.ViewX != 0f || lInputSource.ViewY != 0f) { mIsFollowConnected = false; if (lContinue) { lContinue = false; lMovement.x = lInputSource.ViewX * -mGripUnitsPerTick; lMovement.z = lInputSource.ViewY * -mGripUnitsPerTick; lMovement = lCameraYaw * lMovement; } } } } // Input logic if (_InputPan && lInputSource != null && lMovement.sqrMagnitude == 0f) { float lZ = (_ForwardAlias.Length > 0 && lInputSource.IsPressed(_ForwardAlias) ? 1f : 0f); lZ = lZ - (_BackAlias.Length > 0 && lInputSource.IsPressed(_BackAlias) ? 1f : 0f); float lX = (_RightAlias.Length > 0 && lInputSource.IsPressed(_RightAlias) ? 1f : 0f); lX = lX - (_LeftAlias.Length > 0 && lInputSource.IsPressed(_LeftAlias) ? 1f : 0f); if (lX != 0f || lZ != 0f) { mIsFollowConnected = false; if (lContinue) { float lMagnitude = 1f; InputManagerHelper.ConvertToRadialInput(ref lX, ref lZ, ref lMagnitude); lContinue = false; lMovement.x = lX; lMovement.z = lZ; lMovement = (lCameraYaw * lMovement) * mInputUnitsPerTick; } } } // Edge logic if (_EdgePan && lMovement.sqrMagnitude == 0f) { Vector3 lEdgeMovement = Vector3.zero; float lScreenWidth = Screen.width; float lScreenHeight = Screen.height; Vector3 lMousePosition = UnityEngine.Input.mousePosition; lMousePosition.x = Mathf.Clamp(lMousePosition.x, 0f, lScreenWidth - 1f); lMousePosition.y = Mathf.Clamp(lMousePosition.y, 0f, lScreenHeight - 1f); float lEdgePanBorder = (_EdgePanBorder > 1f ? _EdgePanBorder : 1f); if (lMousePosition.x < lEdgePanBorder) { float lPercent = (lEdgePanBorder - lMousePosition.x) / lEdgePanBorder; lEdgeMovement.x = -mEdgeUnitsPerTick * lPercent; } else if (lMousePosition.x >= lScreenWidth - _EdgePanBorder) { float lPercent = (lEdgePanBorder - (lScreenWidth - 1f - lMousePosition.x)) / lEdgePanBorder; lEdgeMovement.x = mEdgeUnitsPerTick * lPercent; } if (lMousePosition.y < _EdgePanBorder) { float lPercent = (lEdgePanBorder - lMousePosition.y) / lEdgePanBorder; lEdgeMovement.z = -mEdgeUnitsPerTick * lPercent; } else if (lMousePosition.y >= lScreenHeight - _EdgePanBorder) { float lPercent = (lEdgePanBorder - (lScreenHeight - 1f - lMousePosition.y)) / lEdgePanBorder; lEdgeMovement.z = mEdgeUnitsPerTick * lPercent; } if (lEdgeMovement.sqrMagnitude > 0f) { mIsFollowConnected = false; if (lContinue) { lContinue = false; lMovement.x = lEdgeMovement.x; lMovement.z = lEdgeMovement.z; lMovement = lCameraYaw * lMovement; } } } // Set the final results and apply any bounds //Vector3 lNewPosition = mRigTransform.Position + lMovement; mPositionTarget = mPositionTarget + lMovement; if (_MinBounds.x != 0f || _MaxBounds.x != 0f) { mPositionTarget.x = Mathf.Clamp(mPositionTarget.x, _MinBounds.x, _MaxBounds.x); } if (_MaxBounds.y != 0f || _MaxBounds.y != 0f) { mPositionTarget.z = Mathf.Clamp(mPositionTarget.z, _MinBounds.y, _MaxBounds.y); } lMovement = (!lSmooth ? mPositionTarget : Vector3.SmoothDamp(RigController._Transform.position, mPositionTarget, ref mPositionVelocity, rDeltaTime)) - RigController._Transform.position; mRigTransform.Position = RigController._Transform.position + lMovement; mRigTransform.Rotation = RigController._Transform.rotation; return(mRigTransform); }
/// <summary> /// If the input manager entries don't exist, create them /// </summary> private void CreateInputManagerEntries() { if (!InputManagerHelper.IsDefined("WXButton0")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXButton0"; lEntry.PositiveButton = "joystick button 0"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXButton1")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXButton1"; lEntry.PositiveButton = "joystick button 1"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXButton2")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXButton2"; lEntry.PositiveButton = "joystick button 2"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXButton3")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXButton3"; lEntry.PositiveButton = "joystick button 3"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXLeftStickX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXLeftStickX"; lEntry.Gravity = 1; lEntry.Dead = 0.1f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXLeftStickY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXLeftStickY"; lEntry.Gravity = 1; lEntry.Dead = 0.1f; lEntry.Sensitivity = 1; lEntry.Invert = true; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 2; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXLeftStickButton")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXLeftStickButton"; lEntry.PositiveButton = "joystick button 8"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightStickX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightStickX"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 4; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightStickY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightStickY"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Invert = true; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 5; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightStickButton")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightStickButton"; lEntry.PositiveButton = "joystick button 9"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXLeftTrigger")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXLeftTrigger"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 9; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightTrigger")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightTrigger"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 10; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXDPadX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXDPadX"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 6; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXDPadY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXDPadY"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 7; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXLeftBumper")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXLeftBumper"; lEntry.PositiveButton = "joystick button 4"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXRightBumper")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXRightBumper"; lEntry.PositiveButton = "joystick button 5"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXBack")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXBack"; lEntry.PositiveButton = "joystick button 6"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("WXStart")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "WXStart"; lEntry.PositiveButton = "joystick button 7"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXButton0")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXButton0"; lEntry.PositiveButton = "joystick button 16"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXButton1")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXButton1"; lEntry.PositiveButton = "joystick button 17"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXButton2")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXButton2"; lEntry.PositiveButton = "joystick button 18"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXButton3")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXButton3"; lEntry.PositiveButton = "joystick button 19"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXLeftStickX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXLeftStickX"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 1; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXLeftStickY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXLeftStickY"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Invert = true; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 2; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXLeftStickButton")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXLeftStickButton"; lEntry.PositiveButton = "joystick button 11"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightStickX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightStickX"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 3; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightStickY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightStickY"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Invert = true; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 4; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightStickButton")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightStickButton"; lEntry.PositiveButton = "joystick button 12"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXLeftTrigger")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXLeftTrigger"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 5; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightTrigger")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightTrigger"; lEntry.Gravity = 1; lEntry.Dead = 0.3f; lEntry.Sensitivity = 1; lEntry.Type = InputManagerEntryType.JOYSTICK_AXIS; lEntry.Axis = 6; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXDPadX")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXDPadX"; lEntry.PositiveButton = "joystick button 7"; lEntry.NegativeButton = "joystick button 8"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXDPadY")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXDPadY"; lEntry.PositiveButton = "joystick button 6"; lEntry.NegativeButton = "joystick button 5"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXLeftBumper")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXLeftBumper"; lEntry.PositiveButton = "joystick button 13"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXRightBumper")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXRightBumper"; lEntry.PositiveButton = "joystick button 14"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXBack")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXBack"; lEntry.PositiveButton = "joystick button 10"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } if (!InputManagerHelper.IsDefined("MXStart")) { InputManagerEntry lEntry = new InputManagerEntry(); lEntry.Name = "MXStart"; lEntry.PositiveButton = "joystick button 9"; lEntry.Gravity = 1000; lEntry.Dead = 0.001f; lEntry.Sensitivity = 1000; lEntry.Type = InputManagerEntryType.KEY_MOUSE_BUTTON; lEntry.Axis = 0; lEntry.JoyNum = 0; InputManagerHelper.AddEntry(lEntry); } }