diff --git a/Runtime/AvatarCreator/Utils/Rotation.meta b/Runtime/AvatarCreator/Utils/Rotation.meta new file mode 100644 index 00000000..d2b71172 --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f0c01b6b2472477aa73c08ac14cb44be +timeCreated: 1701243945 \ No newline at end of file diff --git a/Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.cs b/Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.cs new file mode 100644 index 00000000..5dbf9c93 --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.cs @@ -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(); + } + + 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; + } + } + } +} diff --git a/Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.cs.meta b/Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.cs.meta new file mode 100644 index 00000000..7cc70745 --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation/AvatarMouseRotation.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 740b98666dec44e5bb949b172ef49d6a +timeCreated: 1701243283 \ No newline at end of file diff --git a/Runtime/AvatarCreator/Utils/Rotation/IMouseInput.cs b/Runtime/AvatarCreator/Utils/Rotation/IMouseInput.cs new file mode 100644 index 00000000..97ce7bd0 --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation/IMouseInput.cs @@ -0,0 +1,9 @@ +namespace ReadyPlayerMe.AvatarCreator +{ + public interface IMouseInput + { + bool GetButtonDown(int index); + bool GetButtonUp(int index); + bool GetButtonPressed(int index); + } +} diff --git a/Runtime/AvatarCreator/Utils/Rotation/IMouseInput.cs.meta b/Runtime/AvatarCreator/Utils/Rotation/IMouseInput.cs.meta new file mode 100644 index 00000000..f2c80f73 --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation/IMouseInput.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b5f339ed8b554c13b0be184e09a9cd9c +timeCreated: 1701243930 \ No newline at end of file diff --git a/Runtime/AvatarCreator/Utils/Rotation/MouseInput.cs b/Runtime/AvatarCreator/Utils/Rotation/MouseInput.cs new file mode 100644 index 00000000..4d8e346a --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation/MouseInput.cs @@ -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); + } + } +} diff --git a/Runtime/AvatarCreator/Utils/Rotation/MouseInput.cs.meta b/Runtime/AvatarCreator/Utils/Rotation/MouseInput.cs.meta new file mode 100644 index 00000000..bf76b49e --- /dev/null +++ b/Runtime/AvatarCreator/Utils/Rotation/MouseInput.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: aa24cb1a34344a70836591c2b0bde98c +timeCreated: 1701244125 \ No newline at end of file diff --git a/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs b/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs index 0392025b..88e0d9e3 100644 --- a/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs +++ b/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs @@ -302,7 +302,8 @@ private void ProcessAvatar(GameObject avatar) avatar.GetComponent().runtimeAnimatorController = animator; } avatar.transform.rotation = lastRotation; - avatar.AddComponent(); + avatar.AddComponent(); + avatar.AddComponent(); } public void Dispose()