-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: decouple input logic from rotate
- Loading branch information
Showing
8 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.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,46 @@ | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
|
||
namespace ReadyPlayerMe.AvatarCreator | ||
{ | ||
public class AvatarMouseRotation: MonoBehaviour | ||
{ | ||
private const int MOUSE_BUTTON_INDEX = 0; | ||
|
||
[SerializeField] private float speed = 50; | ||
|
||
private IMouseInput mouseInput; | ||
private float lastPosX; | ||
private bool rotate; | ||
|
||
private void Awake() | ||
{ | ||
mouseInput = GetComponent<IMouseInput>(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (EventSystem.current.IsPointerOverGameObject() && !rotate) | ||
{ | ||
return; | ||
} | ||
|
||
if (mouseInput.GetButtonDown(MOUSE_BUTTON_INDEX)) | ||
{ | ||
lastPosX = Input.mousePosition.x; | ||
rotate = true; | ||
} | ||
|
||
if (mouseInput.GetButtonUp(MOUSE_BUTTON_INDEX)) | ||
{ | ||
rotate = false; | ||
} | ||
|
||
if (mouseInput.GetButtonPressed(MOUSE_BUTTON_INDEX)) | ||
{ | ||
transform.Rotate(Vector3.up, (lastPosX - Input.mousePosition.x) * (Time.deltaTime * speed)); | ||
lastPosX = Input.mousePosition.x; | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ReadyPlayerMe.AvatarCreator | ||
{ | ||
public interface IMouseInput | ||
{ | ||
bool GetButtonDown(int index); | ||
bool GetButtonUp(int index); | ||
bool GetButtonPressed(int index); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using UnityEngine; | ||
|
||
namespace ReadyPlayerMe.AvatarCreator | ||
{ | ||
public class MouseInput: MonoBehaviour, IMouseInput | ||
{ | ||
public bool GetButtonDown(int index) | ||
{ | ||
return Input.GetMouseButtonDown(index); | ||
} | ||
|
||
public bool GetButtonUp(int index) | ||
{ | ||
return Input.GetMouseButtonUp(index); | ||
} | ||
|
||
public bool GetButtonPressed(int index) | ||
{ | ||
return Input.GetMouseButton(index); | ||
} | ||
} | ||
} |
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