-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from eviltwo/merge-camera-packages
Merge camera packages
- Loading branch information
Showing
30 changed files
with
378 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
...ore/Assets/FPSCameraControls/CHANGELOG.md → ...meCore/Assets/CameraControls/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ionGameCore/Assets/TPSCameraControls.meta → ...Controls/Scripts/Runtime/Controllers.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../Scripts/Runtime/TPSCameraControls.asmdef → ...rollers/CameraControls.Controllers.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/FPSCameraController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using UnityEngine; | ||
|
||
namespace CameraControls.Controllers | ||
{ | ||
public interface ICameraController | ||
{ | ||
bool Enabled { get; } | ||
void SetDeltaAngles(Vector2 deltaAngles); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ctionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/ICameraController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/TPSCameraController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ore/Assets/TPSCameraControls/Scripts.meta → ...ameraControls/Scripts/Runtime/Inputs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
.../Scripts/Runtime/FPSCameraControls.asmdef → ...ntime/Inputs/CameraControls.Inputs.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pts/Runtime/TPSCameraControls.asmdef.meta → .../Inputs/CameraControls.Inputs.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.