diff --git a/README.md b/README.md index 605c325..e6b8629 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,10 @@ https://github.com/eviltwo/ActionGameCore.git?path=src/ActionGameCore/Assets/CharacterControls ``` -### FPSCameraControls v1.3.0 -FPS視点のカメラ。 +### CameraControls v1.4.0 +FPSとTPS視点のカメラ。 ``` -https://github.com/eviltwo/ActionGameCore.git?path=src/ActionGameCore/Assets/FPSCameraControls -``` - -### TPSCameraControls v1.3.0 -TPS視点のカメラ。 -``` -https://github.com/eviltwo/ActionGameCore.git?path=src/ActionGameCore/Assets/TPSCameraControls +https://github.com/eviltwo/ActionGameCore.git?path=src/ActionGameCore/Assets/CameraControls ``` ### Interactions v0.5.1 diff --git a/src/ActionGameCore/Assets/FPSCameraControls.meta b/src/ActionGameCore/Assets/CameraControls.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls.meta rename to src/ActionGameCore/Assets/CameraControls.meta diff --git a/src/ActionGameCore/Assets/FPSCameraControls/CHANGELOG.md b/src/ActionGameCore/Assets/CameraControls/CHANGELOG.md similarity index 78% rename from src/ActionGameCore/Assets/FPSCameraControls/CHANGELOG.md rename to src/ActionGameCore/Assets/CameraControls/CHANGELOG.md index e301bfc..14553be 100644 --- a/src/ActionGameCore/Assets/FPSCameraControls/CHANGELOG.md +++ b/src/ActionGameCore/Assets/CameraControls/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [1.4.0] - 2024-06-28 +### Changed +- Merged with TPS package. +- Renamed namespace to CameraControls. +- Separated script to Controller and Input. + ## [1.3.0] - 2024-06-28 ### Changed - Support SteamInput. diff --git a/src/ActionGameCore/Assets/FPSCameraControls/CHANGELOG.md.meta b/src/ActionGameCore/Assets/CameraControls/CHANGELOG.md.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls/CHANGELOG.md.meta rename to src/ActionGameCore/Assets/CameraControls/CHANGELOG.md.meta diff --git a/src/ActionGameCore/Assets/FPSCameraControls/Scripts.meta b/src/ActionGameCore/Assets/CameraControls/Scripts.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls/Scripts.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts.meta diff --git a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime.meta diff --git a/src/ActionGameCore/Assets/TPSCameraControls.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers.meta similarity index 77% rename from src/ActionGameCore/Assets/TPSCameraControls.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers.meta index aa15edf..77a7a3f 100644 --- a/src/ActionGameCore/Assets/TPSCameraControls.meta +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9e0965cb6b7cd0344ba2f60031488d70 +guid: 3972ca2c6fb8dcf4abc232361747390c folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraControls.asmdef b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/CameraControls.Controllers.asmdef similarity index 94% rename from src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraControls.asmdef rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/CameraControls.Controllers.asmdef index 8bb8aeb..9b231d5 100644 --- a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraControls.asmdef +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/CameraControls.Controllers.asmdef @@ -1,5 +1,5 @@ { - "name": "TPSCameraControls", + "name": "CameraControls.Controllers", "rootNamespace": "", "references": [ "GUID:75469ad4d38634e559750d17036d5f7c", diff --git a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraControls.asmdef.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/CameraControls.Controllers.asmdef.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraControls.asmdef.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/CameraControls.Controllers.asmdef.meta diff --git a/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/FPSCameraController.cs b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/FPSCameraController.cs new file mode 100644 index 0000000..2e19614 --- /dev/null +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/FPSCameraController.cs @@ -0,0 +1,63 @@ +using UnityEngine; + +namespace CameraControls.Controllers +{ + public class FPSCameraController : MonoBehaviour, ICameraController + { + [SerializeField] + public Transform Target = null; + + [SerializeField] + public float OffsetY = 1.5f; + + [SerializeField] + public float Sensitivity = 1.0f; + + [SerializeField] + public float AngleMin = -90.0f; + + [SerializeField] + public float AngleMax = 90.0f; + + [SerializeField] + public int SmoothingFrameCount = 2; + + [SerializeField] + private bool _lockAndHideCursor = true; + + private Vector2 _deltaAngles; + private Vector3 _lookAngles; + + public bool Enabled => enabled; + + public void SetDeltaAngles(Vector2 deltaAngles) + { + _deltaAngles = deltaAngles; + } + + private void Start() + { + if (_lockAndHideCursor) + { + Cursor.visible = false; + Cursor.lockState = CursorLockMode.Locked; + } + } + + private void LateUpdate() + { + if (Target == null) + { + return; + } + + var position = Target.position + new Vector3(0, OffsetY, 0); + + _lookAngles.x = Mathf.Clamp(_lookAngles.x - _deltaAngles.y * Sensitivity, -AngleMax, -AngleMin); // Look up and down + _lookAngles.y = (_lookAngles.y + _deltaAngles.x * Sensitivity) % 360; // Look left and right + var rotation = Quaternion.Euler(_lookAngles); + + transform.SetPositionAndRotation(position, rotation); + } + } +} diff --git a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraController.cs.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/FPSCameraController.cs.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraController.cs.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/FPSCameraController.cs.meta diff --git a/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs new file mode 100644 index 0000000..9d768f4 --- /dev/null +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace CameraControls.Controllers +{ + public interface ICameraController + { + bool Enabled { get; } + void SetDeltaAngles(Vector2 deltaAngles); + } +} diff --git a/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs.meta new file mode 100644 index 0000000..a2be8fe --- /dev/null +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b2f20405bcbb41d4fbeceec67aa11680 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/TPSCameraController.cs b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/TPSCameraController.cs new file mode 100644 index 0000000..e93c1fc --- /dev/null +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/TPSCameraController.cs @@ -0,0 +1,92 @@ +using UnityEngine; + +namespace CameraControls.Controllers +{ + public class TPSCameraController : MonoBehaviour, ICameraController + { + public enum OffsetRotationType + { + FullRotation = 0, + HorizontalRotation = 1, + } + + [SerializeField] + public Transform Target = null; + + [SerializeField] + public Vector3 Offset = Vector3.zero; + + [SerializeField] + public OffsetRotationType OffsetRotation = OffsetRotationType.HorizontalRotation; + + [SerializeField] + public float Distance = 5.0f; + + [SerializeField] + public float Sensitivity = 1.0f; + + [SerializeField] + public float AngleMin = -90.0f; + + [SerializeField] + public float AngleMax = 90.0f; + + [SerializeField] + public bool IsCheckWall = true; + + [SerializeField] + public LayerMask WallLayerMask = ~0; + + [SerializeField] + public int SmoothingFrameCount = 2; + + [SerializeField] + private bool _lockAndHideCursor = true; + + private Vector2 _deltaAngles; + private Vector3 _lookAngles; + + public bool Enabled => enabled; + + public void SetDeltaAngles(Vector2 deltaAngles) + { + _deltaAngles = deltaAngles; + } + + private void Start() + { + if (_lockAndHideCursor) + { + Cursor.visible = false; + Cursor.lockState = CursorLockMode.Locked; + } + } + + private void LateUpdate() + { + if (Target == null) + { + return; + } + + _lookAngles.x = Mathf.Clamp(_lookAngles.x - _deltaAngles.y * Sensitivity, -AngleMax, -AngleMin); // Look up and down + _lookAngles.y = (_lookAngles.y + _deltaAngles.x * Sensitivity) % 360; // Look left and right + var rotation = Quaternion.Euler(_lookAngles); + + var offsetRotation = OffsetRotation == OffsetRotationType.FullRotation ? rotation : Quaternion.AngleAxis(_lookAngles.y, Vector3.up); + var pivot = Target.position + offsetRotation * Offset; + + var distance = Distance; + if (IsCheckWall) + { + var ray = new Ray(pivot, rotation * Vector3.back); + if (Physics.Raycast(ray, out var hit, Distance, WallLayerMask)) + { + distance = hit.distance; + } + } + + transform.SetPositionAndRotation(pivot + rotation * Vector3.back * distance, rotation); + } + } +} diff --git a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraController.cs.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/TPSCameraController.cs.meta similarity index 100% rename from src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraController.cs.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/TPSCameraController.cs.meta diff --git a/src/ActionGameCore/Assets/TPSCameraControls/Scripts.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs.meta similarity index 77% rename from src/ActionGameCore/Assets/TPSCameraControls/Scripts.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs.meta index ecfd8a2..45660fa 100644 --- a/src/ActionGameCore/Assets/TPSCameraControls/Scripts.meta +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7b2d31485f23ea048a760dcf5dfe7c28 +guid: 48e066460b7844d48a72c284947a750c folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraControls.asmdef b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraControls.Inputs.asmdef similarity index 83% rename from src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraControls.asmdef rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraControls.Inputs.asmdef index 05c9004..f5494ca 100644 --- a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraControls.asmdef +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraControls.Inputs.asmdef @@ -1,9 +1,10 @@ { - "name": "FPSCameraControls", + "name": "CameraControls.Inputs", "rootNamespace": "", "references": [ "GUID:75469ad4d38634e559750d17036d5f7c", - "GUID:68bd7fdb68ef2684e982e8a9825b18a5" + "GUID:68bd7fdb68ef2684e982e8a9825b18a5", + "GUID:aeee1f7ffaac59745996d0fed47daca6" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraControls.asmdef.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraControls.Inputs.asmdef.meta similarity index 76% rename from src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraControls.asmdef.meta rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraControls.Inputs.asmdef.meta index ceae6e4..02ec111 100644 --- a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraControls.asmdef.meta +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraControls.Inputs.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bd05ab0e5cf3eac4fb241abe2a6779ea +guid: 146db588204ef4944978d48d8c59d2ba AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraController.cs b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraInput.cs similarity index 50% rename from src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraController.cs rename to src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraInput.cs index 4e13e21..d7488f6 100644 --- a/src/ActionGameCore/Assets/FPSCameraControls/Scripts/Runtime/FPSCameraController.cs +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraInput.cs @@ -1,39 +1,20 @@ -using System.Collections.Generic; +using CameraControls.Controllers; using UnityEngine; #if SUPPORT_INPUTSYSTEM using UnityEngine.InputSystem; -#endif +using System.Collections.Generic; + +#endif #if SUPPORT_STEAMWORKS && !DISABLESTEAMWORKS using Steamworks; #endif -namespace FPSCameraControls +namespace CameraControls.Inputs { - public class FPSCameraController : MonoBehaviour + public class CameraInput : MonoBehaviour { - [SerializeField] - public Transform Target = null; - - [SerializeField] - public float OffsetY = 1.5f; - - [SerializeField] - public float Sensitivity = 1.0f; - - [SerializeField] - public float AngleMin = -90.0f; - - [SerializeField] - public float AngleMax = 90.0f; - - [SerializeField] - public int SmoothingFrameCount = 2; - - [SerializeField] - private bool _lockAndHideCursor = true; - #if SUPPORT_INPUTSYSTEM [Header("InputSystem")] [SerializeField] @@ -55,12 +36,13 @@ public class FPSCameraController : MonoBehaviour private InputHandle_t[] _connectedControllerInputHandles = new InputHandle_t[Constants.STEAM_INPUT_MAX_COUNT]; #endif - private Vector3 _lookAngles; - private List _deltaPositions = new List(); - private List _deltaTimes = new List(); + private ICameraController _cameraController; + private List _cameraControllerBuffer = new List(); private void Start() { + _cameraController = GetComponent(); + #if SUPPORT_INPUTSYSTEM _deltaActionReference?.action.Enable(); _continuousActionreference?.action.Enable(); @@ -80,32 +62,56 @@ private void Start() Debug.LogError($"Failed to initialize Steam Input: {e.Message}"); } #endif - - if (_lockAndHideCursor) - { - Cursor.visible = false; - Cursor.lockState = CursorLockMode.Locked; - } } - private void LateUpdate() + private void Update() { - if (Target == null) + if (_cameraController == null || !_cameraController.Enabled) { + GetComponents(_cameraControllerBuffer); + foreach (var controller in _cameraControllerBuffer) + { + if (controller.Enabled) + { + _cameraController = controller; + break; + } + } return; } - var position = Target.position + new Vector3(0, OffsetY, 0); - var deltaAngle = Vector2.zero; - var deltaPosition = Vector2.zero; + // Digital input + { + var deltaPixels = GetDeltaPixels(); + const float DpiAverage = 96; + var dpi = Screen.dpi == 0 ? DpiAverage : Screen.dpi; + const float InchForTurn = 13; + var v = deltaPixels / dpi / InchForTurn * 180; + deltaAngle = v.sqrMagnitude > deltaAngle.sqrMagnitude ? v : deltaAngle; + } + + // Analog input + { + var analogValues = GetAnalogValues(); + const float SecondsForTurn = 1.0f; + var v = analogValues * Time.deltaTime / SecondsForTurn * 180; + deltaAngle = v.sqrMagnitude > deltaAngle.sqrMagnitude ? v : deltaAngle; + } + + _cameraController.SetDeltaAngles(deltaAngle); + } + + private Vector2 GetDeltaPixels() + { + var value = Vector2.zero; #if SUPPORT_INPUTSYSTEM if (_deltaActionReference != null) { var v = _deltaActionReference.action.ReadValue(); - deltaPosition = v.sqrMagnitude > deltaPosition.sqrMagnitude ? v : deltaPosition; + value = v.sqrMagnitude > value.sqrMagnitude ? v : value; } #endif @@ -118,66 +124,28 @@ private void LateUpdate() var inputHandle = _connectedControllerInputHandles[i]; var data = SteamInput.GetAnalogActionData(inputHandle, _steamCameraActionHandle); var v = new Vector2(data.x, -data.y); - deltaPosition = v.sqrMagnitude > deltaPosition.sqrMagnitude ? v : deltaPosition; + value = v.sqrMagnitude > value.sqrMagnitude ? v : value; } } #endif - { - _deltaPositions.Add(deltaPosition); - _deltaTimes.Add(Time.deltaTime); - SmoothingFrameCount = Mathf.Max(1, SmoothingFrameCount); - if (_deltaPositions.Count > SmoothingFrameCount) - { - _deltaPositions.RemoveRange(0, _deltaPositions.Count - SmoothingFrameCount); - _deltaTimes.RemoveRange(0, _deltaTimes.Count - SmoothingFrameCount); - } - var totalPosition = Vector2.zero; - var totalTime = 0f; - for (int i = 0; i < _deltaPositions.Count; i++) - { - totalPosition += _deltaPositions[i]; - totalTime += _deltaTimes[i]; - } - var deltaPositionAverage = totalPosition / totalTime; - var smoothDeltaPosition = deltaPositionAverage * Time.deltaTime; + return value; + } - const float DpiAverage = 96; - var dpi = Screen.dpi == 0 ? DpiAverage : Screen.dpi; - const float InchForTurn = 13; - var v = smoothDeltaPosition / dpi / InchForTurn * 180; - deltaAngle = v.sqrMagnitude > deltaAngle.sqrMagnitude ? v : deltaAngle; - } + private Vector2 GetAnalogValues() + { + var value = Vector2.zero; #if SUPPORT_INPUTSYSTEM if (_continuousActionreference != null) { const float SecondsForTurn = 1.0f; - var v = _continuousActionreference.action.ReadValue() * Time.deltaTime / SecondsForTurn * 180; - deltaAngle = v.sqrMagnitude > deltaAngle.sqrMagnitude ? v : deltaAngle; + var v = _continuousActionreference.action.ReadValue(); + value = v.sqrMagnitude > value.sqrMagnitude ? v : value; } #endif - _lookAngles.x = Mathf.Clamp(_lookAngles.x - deltaAngle.y * Sensitivity, -AngleMax, -AngleMin); // Look up and down - _lookAngles.y = (_lookAngles.y + deltaAngle.x * Sensitivity) % 360; // Look left and right - var rotation = Quaternion.Euler(_lookAngles); - transform.SetPositionAndRotation(position, rotation); - } - - private void OnDrawGizmos() - { - if (!Application.isPlaying) - { - return; - } - - Gizmos.color = Color.red; - for (int i = 0; i < _deltaPositions.Count; i++) - { - var d = _deltaPositions[i].x; - var basePos = new Vector3(i * 0.1f, 1, 0); - Gizmos.DrawLine(basePos, basePos + Vector3.up * d); - } + return value; } } } diff --git a/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraInput.cs.meta b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraInput.cs.meta new file mode 100644 index 0000000..af1b8a4 --- /dev/null +++ b/src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Inputs/CameraInput.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: df57dca951846c8418748accb8bd0568 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/ActionGameCore/Assets/FPSCameraControls/package.json b/src/ActionGameCore/Assets/CameraControls/package.json similarity index 57% rename from src/ActionGameCore/Assets/FPSCameraControls/package.json rename to src/ActionGameCore/Assets/CameraControls/package.json index 6c20aef..a2f131d 100644 --- a/src/ActionGameCore/Assets/FPSCameraControls/package.json +++ b/src/ActionGameCore/Assets/CameraControls/package.json @@ -1,9 +1,9 @@ { - "name": "com.eviltwo.fps-camera-controls", - "displayName": "FPS Camera Controls", - "version": "1.3.0", + "name": "com.eviltwo.camera-controls", + "displayName": "Camera Controls", + "version": "1.4.0", "unity": "2022.3", - "description": "Camera movements for FPS.", + "description": "Camera movements for FPS and TPS.", "author": { "name": "DAIKI(eviltwo)", "url": "https://github.com/eviltwo" diff --git a/src/ActionGameCore/Assets/FPSCameraControls/package.json.meta b/src/ActionGameCore/Assets/CameraControls/package.json.meta similarity index 100% rename from src/ActionGameCore/Assets/FPSCameraControls/package.json.meta rename to src/ActionGameCore/Assets/CameraControls/package.json.meta diff --git a/src/ActionGameCore/Assets/Samples/Scenes/SampleScene.unity b/src/ActionGameCore/Assets/Samples/Scenes/SampleScene.unity index ca0b574..e25af8b 100644 --- a/src/ActionGameCore/Assets/Samples/Scenes/SampleScene.unity +++ b/src/ActionGameCore/Assets/Samples/Scenes/SampleScene.unity @@ -178,7 +178,7 @@ CapsuleCollider: m_ProvidesContacts: 0 m_Enabled: 1 serializedVersion: 2 - m_Radius: 0.5 + m_Radius: 0.2 m_Height: 2 m_Direction: 1 m_Center: {x: 0, y: 1, z: 0} @@ -245,7 +245,6 @@ MonoBehaviour: m_EditorClassIdentifier: _moveActionReference: {fileID: -1680190386980627800, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} _jumpActionReference: {fileID: 1120369429361536294, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} - _steamActionSetName: InGameControls _steamMoveActionName: Move _steamJumpActionName: Jump --- !u!1 &209071631 @@ -1268,6 +1267,7 @@ GameObject: - component: {fileID: 963194228} - component: {fileID: 963194227} - component: {fileID: 963194226} + - component: {fileID: 963194231} - component: {fileID: 963194229} - component: {fileID: 963194230} m_Layer: 0 @@ -1316,7 +1316,7 @@ Camera: y: 0 width: 1 height: 1 - near clip plane: 0.3 + near clip plane: 0.1 far clip plane: 1000 field of view: 60 orthographic: 0 @@ -1363,8 +1363,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 76bea717eafe0f14188a4b53c3696b73, type: 3} m_Name: m_EditorClassIdentifier: - _deltaActionReference: {fileID: -5630151704836100654, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} - _continuousActionreference: {fileID: 4073854690803581126, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} Target: {fileID: 177208273} OffsetY: 1.5 Sensitivity: 1 @@ -1384,8 +1382,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 555f5af3ecd5c7a47862ada8aded246a, type: 3} m_Name: m_EditorClassIdentifier: - _deltaActionReference: {fileID: -5630151704836100654, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} - _continuousActionreference: {fileID: 4073854690803581126, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} Target: {fileID: 177208273} Offset: {x: 0, y: 1.5, z: 0} OffsetRotation: 1 @@ -1399,6 +1395,21 @@ MonoBehaviour: m_Bits: 4294967295 SmoothingFrameCount: 2 _lockAndHideCursor: 1 +--- !u!114 &963194231 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 963194225} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: df57dca951846c8418748accb8bd0568, type: 3} + m_Name: + m_EditorClassIdentifier: + _deltaActionReference: {fileID: -5630151704836100654, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} + _continuousActionreference: {fileID: 4073854690803581126, guid: d050cea4568e2be47bc9a4f2c136ccf9, type: 3} + _steamCameraActionName: Camera --- !u!1 &970461546 GameObject: m_ObjectHideFlags: 0 diff --git a/src/ActionGameCore/Assets/TPSCameraControls/CHANGELOG.md b/src/ActionGameCore/Assets/TPSCameraControls/CHANGELOG.md deleted file mode 100644 index 6a5555b..0000000 --- a/src/ActionGameCore/Assets/TPSCameraControls/CHANGELOG.md +++ /dev/null @@ -1,24 +0,0 @@ -# Changelog - -## [1.3.0] - 2024-06-28 -### Changed -- Support SteamInput. - -## [1.2.0] - 2024-05-16 -### Changed -- Match camera sensitivity of mouse and controller. - - Rename and add serialized field for input action reference. - - Change default sensitivity to 1.0 - - Change calculation of camera angle. - -## [1.1.0] - 2024-03-06 -### Fixed -- Change parameter type of input to InputActionReference. - -## [1.0.1] - 2024-03-04 -### Fixed -- Show input action name to inspector. - -## [1.0.0] - 2024-03-03 -### Added -- Add camera rotation and wall check. diff --git a/src/ActionGameCore/Assets/TPSCameraControls/CHANGELOG.md.meta b/src/ActionGameCore/Assets/TPSCameraControls/CHANGELOG.md.meta deleted file mode 100644 index 2861ddf..0000000 --- a/src/ActionGameCore/Assets/TPSCameraControls/CHANGELOG.md.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: e13ef1822b65d0d45a9c23a978c76a6d -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime.meta b/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime.meta deleted file mode 100644 index 4c4ba53..0000000 --- a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 51185baaf78d46d42944ceef40d80954 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraController.cs b/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraController.cs deleted file mode 100644 index a557b6a..0000000 --- a/src/ActionGameCore/Assets/TPSCameraControls/Scripts/Runtime/TPSCameraController.cs +++ /dev/null @@ -1,197 +0,0 @@ -using System.Collections.Generic; -using Steamworks; -using UnityEngine; - -#if SUPPORT_INPUTSYSTEM -using UnityEngine.InputSystem; -#endif - -#if SUPPORT_STEAMWORKS && !DISABLESTEAMWORKS -#endif - -namespace FPSCameraControls -{ - public class TPSCameraController : MonoBehaviour - { - public enum OffsetRotationType - { - FullRotation = 0, - HorizontalRotation = 1, - } - - [SerializeField] - public Transform Target = null; - - [SerializeField] - public Vector3 Offset = Vector3.zero; - - [SerializeField] - public OffsetRotationType OffsetRotation = OffsetRotationType.HorizontalRotation; - - [SerializeField] - public float Distance = 5.0f; - - [SerializeField] - public float Sensitivity = 1.0f; - - [SerializeField] - public float AngleMin = -90.0f; - - [SerializeField] - public float AngleMax = 90.0f; - - [SerializeField] - public bool IsCheckWall = true; - - [SerializeField] - public LayerMask WallLayerMask = ~0; - - [SerializeField] - public int SmoothingFrameCount = 2; - - [SerializeField] - private bool _lockAndHideCursor = true; - -#if SUPPORT_INPUTSYSTEM - [Header("InputSystem")] - [SerializeField] - private InputActionReference _deltaActionReference = null; - - [SerializeField] - private InputActionReference _continuousActionreference = null; -#endif - -#if SUPPORT_STEAMWORKS - [Header("SteamInput")] - [SerializeField] - private string _steamCameraActionName = "Camera"; -#endif - -#if SUPPORT_STEAMWORKS && !DISABLESTEAMWORKS - private bool _steamInitialized; - private InputAnalogActionHandle_t _steamCameraActionHandle; - private InputHandle_t[] _connectedControllerInputHandles = new InputHandle_t[Constants.STEAM_INPUT_MAX_COUNT]; -#endif - - private Vector3 _lookAngles; - private List _deltaPositions = new List(); - private List _deltaTimes = new List(); - - private void Start() - { -#if SUPPORT_INPUTSYSTEM - _deltaActionReference?.action.Enable(); - _continuousActionreference?.action.Enable(); -#endif - -#if SUPPORT_STEAMWORKS && !DISABLESTEAMWORKS - try - { - if (!string.IsNullOrEmpty(_steamCameraActionName)) - { - _steamCameraActionHandle = SteamInput.GetAnalogActionHandle(_steamCameraActionName); - } - _steamInitialized = true; - } - catch (System.Exception e) - { - Debug.LogError($"Failed to initialize Steam Input: {e.Message}"); - } -#endif - - if (_lockAndHideCursor) - { - Cursor.visible = false; - Cursor.lockState = CursorLockMode.Locked; - } - } - - private void LateUpdate() - { - if (Target == null) - { - return; - } - - var deltaAngle = Vector2.zero; - - var deltaPosition = Vector2.zero; - -#if SUPPORT_INPUTSYSTEM - if (_deltaActionReference != null) - { - var v = _deltaActionReference.action.ReadValue(); - deltaPosition = v.sqrMagnitude > deltaPosition.sqrMagnitude ? v : deltaPosition; - } -#endif - -#if SUPPORT_STEAMWORKS && !DISABLESTEAMWORKS - if (_steamInitialized && _steamCameraActionHandle != null) - { - var controllerCount = SteamInput.GetConnectedControllers(_connectedControllerInputHandles); - for (int i = 0; i < controllerCount; i++) - { - var inputHandle = _connectedControllerInputHandles[i]; - var data = SteamInput.GetAnalogActionData(inputHandle, _steamCameraActionHandle); - var v = new Vector2(data.x, -data.y); - deltaPosition = v.sqrMagnitude > deltaPosition.sqrMagnitude ? v : deltaPosition; - } - } -#endif - - { - _deltaPositions.Add(deltaPosition); - _deltaTimes.Add(Time.deltaTime); - SmoothingFrameCount = Mathf.Max(1, SmoothingFrameCount); - if (_deltaPositions.Count > SmoothingFrameCount) - { - _deltaPositions.RemoveRange(0, _deltaPositions.Count - SmoothingFrameCount); - _deltaTimes.RemoveRange(0, _deltaTimes.Count - SmoothingFrameCount); - } - var totalPosition = Vector2.zero; - var totalTime = 0f; - for (int i = 0; i < _deltaPositions.Count; i++) - { - totalPosition += _deltaPositions[i]; - totalTime += _deltaTimes[i]; - } - var deltaPositionAverage = totalPosition / totalTime; - var smoothDeltaPosition = deltaPositionAverage * Time.deltaTime; - - const float DpiAverage = 96; - var dpi = Screen.dpi == 0 ? DpiAverage : Screen.dpi; - const float InchForTurn = 13; - var v = smoothDeltaPosition / dpi / InchForTurn * 180; - deltaAngle = v.sqrMagnitude > deltaAngle.sqrMagnitude ? v : deltaAngle; - } - -#if SUPPORT_INPUTSYSTEM - if (_continuousActionreference != null) - { - const float SecondsForTurn = 1.0f; - var v = _continuousActionreference.action.ReadValue() * Time.deltaTime / SecondsForTurn * 180; - deltaAngle = v.sqrMagnitude > deltaAngle.sqrMagnitude ? v : deltaAngle; - } -#endif - - _lookAngles.x = Mathf.Clamp(_lookAngles.x - deltaAngle.y * Sensitivity, -AngleMax, -AngleMin); // Look up and down - _lookAngles.y = (_lookAngles.y + deltaAngle.x * Sensitivity) % 360; // Look left and right - var rotation = Quaternion.Euler(_lookAngles); - - var offsetRotation = OffsetRotation == OffsetRotationType.FullRotation ? rotation : Quaternion.AngleAxis(_lookAngles.y, Vector3.up); - var pivot = Target.position + offsetRotation * Offset; - - var distance = Distance; - if (IsCheckWall) - { - var ray = new Ray(pivot, rotation * Vector3.back); - if (Physics.Raycast(ray, out var hit, Distance, WallLayerMask)) - { - distance = hit.distance; - } - } - - transform.SetPositionAndRotation(pivot + rotation * Vector3.back * distance, rotation); - } - } -} diff --git a/src/ActionGameCore/Assets/TPSCameraControls/package.json b/src/ActionGameCore/Assets/TPSCameraControls/package.json deleted file mode 100644 index 6b72067..0000000 --- a/src/ActionGameCore/Assets/TPSCameraControls/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "com.eviltwo.tps-camera-controls", - "displayName": "TPS Camera Controls", - "version": "1.3.0", - "unity": "2022.3", - "description": "Camera movements for TPS.", - "author": { - "name": "DAIKI(eviltwo)", - "url": "https://github.com/eviltwo" - }, - - "keywords": [ - "Action", - "TPS", - "Camera" - ], - - "dependencies": { - } -} \ No newline at end of file diff --git a/src/ActionGameCore/Assets/TPSCameraControls/package.json.meta b/src/ActionGameCore/Assets/TPSCameraControls/package.json.meta deleted file mode 100644 index 969f929..0000000 --- a/src/ActionGameCore/Assets/TPSCameraControls/package.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 232e6a4f0af961b4897c6c07c06ed4ef -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/ActionGameCore/ProjectSettings/QualitySettings.asset b/src/ActionGameCore/ProjectSettings/QualitySettings.asset index 7b7658d..e00aac0 100644 --- a/src/ActionGameCore/ProjectSettings/QualitySettings.asset +++ b/src/ActionGameCore/ProjectSettings/QualitySettings.asset @@ -6,7 +6,7 @@ QualitySettings: serializedVersion: 5 m_CurrentQuality: 5 m_QualitySettings: - - serializedVersion: 2 + - serializedVersion: 3 name: Very Low pixelLightCount: 0 shadows: 0 @@ -18,17 +18,20 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - blendWeights: 1 - textureQuality: 1 + skinWeights: 1 + globalTextureMipmapLimit: 1 + textureMipmapLimitSettings: [] anisotropicTextures: 0 antiAliasing: 0 softParticles: 0 softVegetation: 0 realtimeReflectionProbes: 0 billboardsFaceCameraPosition: 0 + useLegacyDetailDistribution: 1 vSyncCount: 0 lodBias: 0.3 maximumLODLevel: 0 + enableLODCrossFade: 1 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -40,8 +43,18 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] - - serializedVersion: 2 + - serializedVersion: 3 name: Low pixelLightCount: 0 shadows: 0 @@ -53,17 +66,20 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - blendWeights: 2 - textureQuality: 0 + skinWeights: 2 + globalTextureMipmapLimit: 0 + textureMipmapLimitSettings: [] anisotropicTextures: 0 antiAliasing: 0 softParticles: 0 softVegetation: 0 realtimeReflectionProbes: 0 billboardsFaceCameraPosition: 0 + useLegacyDetailDistribution: 1 vSyncCount: 0 lodBias: 0.4 maximumLODLevel: 0 + enableLODCrossFade: 1 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -75,8 +91,18 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] - - serializedVersion: 2 + - serializedVersion: 3 name: Medium pixelLightCount: 1 shadows: 1 @@ -88,17 +114,20 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - blendWeights: 2 - textureQuality: 0 + skinWeights: 2 + globalTextureMipmapLimit: 0 + textureMipmapLimitSettings: [] anisotropicTextures: 1 antiAliasing: 0 softParticles: 0 softVegetation: 0 realtimeReflectionProbes: 0 billboardsFaceCameraPosition: 0 + useLegacyDetailDistribution: 1 vSyncCount: 1 lodBias: 0.7 maximumLODLevel: 0 + enableLODCrossFade: 1 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -110,8 +139,18 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] - - serializedVersion: 2 + - serializedVersion: 3 name: High pixelLightCount: 2 shadows: 2 @@ -123,17 +162,20 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 1 - blendWeights: 2 - textureQuality: 0 + skinWeights: 2 + globalTextureMipmapLimit: 0 + textureMipmapLimitSettings: [] anisotropicTextures: 1 antiAliasing: 0 softParticles: 0 softVegetation: 1 realtimeReflectionProbes: 1 billboardsFaceCameraPosition: 1 + useLegacyDetailDistribution: 1 vSyncCount: 1 lodBias: 1 maximumLODLevel: 0 + enableLODCrossFade: 1 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -145,8 +187,18 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] - - serializedVersion: 2 + - serializedVersion: 3 name: Very High pixelLightCount: 3 shadows: 2 @@ -158,17 +210,20 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 1 - blendWeights: 4 - textureQuality: 0 + skinWeights: 4 + globalTextureMipmapLimit: 0 + textureMipmapLimitSettings: [] anisotropicTextures: 2 antiAliasing: 2 softParticles: 1 softVegetation: 1 realtimeReflectionProbes: 1 billboardsFaceCameraPosition: 1 + useLegacyDetailDistribution: 1 vSyncCount: 1 lodBias: 1.5 maximumLODLevel: 0 + enableLODCrossFade: 1 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -180,8 +235,18 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] - - serializedVersion: 2 + - serializedVersion: 3 name: Ultra pixelLightCount: 4 shadows: 2 @@ -193,17 +258,20 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 1 - blendWeights: 4 - textureQuality: 0 + skinWeights: 4 + globalTextureMipmapLimit: 0 + textureMipmapLimitSettings: [] anisotropicTextures: 2 antiAliasing: 2 softParticles: 1 softVegetation: 1 realtimeReflectionProbes: 1 billboardsFaceCameraPosition: 1 + useLegacyDetailDistribution: 1 vSyncCount: 1 lodBias: 2 maximumLODLevel: 0 + enableLODCrossFade: 1 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -215,7 +283,18 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] + m_TextureMipmapLimitGroupNames: [] m_PerPlatformDefaultQuality: Android: 2 Lumin: 5 @@ -223,6 +302,7 @@ QualitySettings: Nintendo Switch: 5 PS4: 5 PSP2: 2 + Server: 0 Stadia: 5 Standalone: 5 WebGL: 3