Skip to content

Commit

Permalink
Merge pull request #7 from eviltwo/merge-camera-packages
Browse files Browse the repository at this point in the history
Merge camera packages
  • Loading branch information
eviltwo authored Jun 28, 2024
2 parents d01a9c0 + fe74580 commit a3b74a2
Show file tree
Hide file tree
Showing 30 changed files with 378 additions and 394 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "TPSCameraControls",
"name": "CameraControls.Controllers",
"rootNamespace": "",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c",
Expand Down
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);
}
}
}
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);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "FPSCameraControls",
"name": "CameraControls.Inputs",
"rootNamespace": "",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:68bd7fdb68ef2684e982e8a9825b18a5"
"GUID:68bd7fdb68ef2684e982e8a9825b18a5",
"GUID:aeee1f7ffaac59745996d0fed47daca6"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a3b74a2

Please sign in to comment.