-
-
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 #12 from eviltwo/more-physics-action
Improved physical actions
- Loading branch information
Showing
132 changed files
with
14,193 additions
and
204 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
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
8 changes: 8 additions & 0 deletions
8
src/ActionGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/Effects.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
...onGameCore/Assets/CameraControls/Scripts/Runtime/Controllers/Effects/TPSCameraEffector.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,109 @@ | ||
using UnityEngine; | ||
|
||
namespace CameraControls.Controllers.Effects | ||
{ | ||
public class TPSCameraEffector : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
public TPSCameraController Controller = null; | ||
|
||
private Movement _movement; | ||
private Transform _target; | ||
private GameObject _handle; | ||
|
||
private void Reset() | ||
{ | ||
Controller = GetComponent<TPSCameraController>(); | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
if (Controller != null && _target != null) | ||
{ | ||
Controller.Target = _target; | ||
} | ||
if (_handle != null) | ||
{ | ||
Destroy(_handle); | ||
} | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (_movement != null) | ||
{ | ||
_movement.Update(Time.deltaTime); | ||
if (_movement.IsDone()) | ||
{ | ||
Controller.Target = _target; | ||
_target = null; | ||
_movement = null; | ||
} | ||
} | ||
} | ||
|
||
public void PlayLinearMove(float duration) | ||
{ | ||
if (_movement != null) | ||
{ | ||
return; | ||
} | ||
|
||
var handle = GetOrCreateHandle(); | ||
handle.transform.position = Controller.transform.position; | ||
handle.transform.rotation = Controller.transform.rotation; | ||
_target = Controller.Target; | ||
Controller.Target = handle.transform; | ||
_movement = new LinearMovement(_target, handle.transform, duration); | ||
} | ||
|
||
private GameObject GetOrCreateHandle() | ||
{ | ||
if (_handle == null) | ||
{ | ||
_handle = new GameObject("TPSCameraEffector Handle"); | ||
} | ||
return _handle; | ||
} | ||
|
||
private abstract class Movement | ||
{ | ||
protected Transform Target { get; } | ||
public Transform Handle { get; } | ||
public Movement(Transform target, Transform handle) | ||
{ | ||
Target = target; | ||
Handle = handle; | ||
} | ||
|
||
public abstract void Update(float deltaTime); | ||
|
||
public abstract bool IsDone(); | ||
} | ||
|
||
private class LinearMovement : Movement | ||
{ | ||
private readonly Vector3 _start; | ||
private readonly float _duration; | ||
private float _elapsedTime; | ||
public LinearMovement(Transform target, Transform handle, float duration) | ||
: base(target, handle) | ||
{ | ||
_start = target.position; | ||
_duration = duration; | ||
} | ||
|
||
public override void Update(float deltaTime) | ||
{ | ||
_elapsedTime += deltaTime; | ||
var t = _elapsedTime / _duration; | ||
Handle.position = Vector3.Lerp(_start, Target.position, t); | ||
} | ||
|
||
public override bool IsDone() | ||
{ | ||
return _elapsedTime > _duration; | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Runtime/Movements/IMoveController.cs.meta → ...rollers/Effects/TPSCameraEffector.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
8 changes: 8 additions & 0 deletions
8
src/ActionGameCore/Assets/CharacterControls/Scripts/Runtime/Movements/Animations.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
...CharacterControls/Scripts/Runtime/Movements/Animations/CharacterJumpAnimatorController.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,44 @@ | ||
using CharacterControls.Movements.Modules; | ||
using UnityEngine; | ||
|
||
namespace CharacterControls.Movements.Animations | ||
{ | ||
public class CharacterJumpAnimatorController : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
public Animator Animator = null; | ||
|
||
[SerializeField] | ||
public CharacterJumpModule JumpModule = null; | ||
|
||
[SerializeField] | ||
public string JumpAnimatorParameterTrigger = "OnJump"; | ||
|
||
private void Reset() | ||
{ | ||
Animator = GetComponentInChildren<Animator>(); | ||
JumpModule = GetComponentInParent<CharacterJumpModule>(); | ||
} | ||
|
||
private void Start() | ||
{ | ||
if (JumpModule != null) | ||
{ | ||
JumpModule.OnJump.AddListener(OnJump); | ||
} | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
if (JumpModule != null) | ||
{ | ||
JumpModule.OnJump.RemoveListener(OnJump); | ||
} | ||
} | ||
|
||
private void OnJump() | ||
{ | ||
Animator.SetTrigger(JumpAnimatorParameterTrigger); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...cterControls/Scripts/Runtime/Movements/Animations/CharacterJumpAnimatorController.cs.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.