Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Packages/com.styly.styly-xr-rig/Runtime/STYLY XR Rig.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GameObject:
- component: {fileID: 2907708859642309068}
- component: {fileID: 1901460064738478333}
- component: {fileID: 4321886860393714057}
- component: {fileID: 129172355910230854}
m_Layer: 0
m_Name: STYLY XR RigManager
m_TagString: Untagged
Expand Down Expand Up @@ -233,6 +234,21 @@ MonoBehaviour:
m_EditorClassIdentifier:
xriActions: {fileID: -944628639613478452, guid: c348712bda248c246b8c49b3db54643f,
type: 3}
--- !u!114 &129172355910230854
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1591456111131864104}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0ad7d9ccec2bb44c4b0797d02ca2e0f3, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 932545197216251794}
moveSpeed: 5
lookSensitivity: 8
--- !u!1001 &1313010322738206687
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using UnityEngine;
using UnityEngine.InputSystem;

namespace Styly.XRRig
{
/// <summary>
/// Controller for operating local avatar in the editor
/// </summary>
#if UNITY_EDITOR
public class EditorPlayerController : MonoBehaviour
{
[Header("Target")] [SerializeField] private Transform target;

[Header("Movement Settings")] [SerializeField]
private float moveSpeed = 5f;

[Header("Look Settings")] [SerializeField]
private float lookSensitivity = 8f;

private Transform controlTarget;
private float rotationX = 0f;
private float rotationY = 0f;

void Start()
{
// Set control target (use self if target is null)
controlTarget = target != null ? target : transform;

// Preserve current rotation
rotationY = controlTarget.eulerAngles.y;
rotationX = controlTarget.eulerAngles.x;
}

void Update()
{
HandleMovement();
HandleRotation();
}

/// <summary>
/// Movement handling with WASD (XZ plane) and EQ (Y axis)
/// </summary>
private void HandleMovement()
{
Vector3 moveDirection = Vector3.zero;
Keyboard keyboard = Keyboard.current;

if (keyboard == null) return;

// XZ plane movement (WASD)
if (keyboard.wKey.isPressed)
moveDirection += controlTarget.forward;
if (keyboard.sKey.isPressed)
moveDirection -= controlTarget.forward;
if (keyboard.aKey.isPressed)
moveDirection -= controlTarget.right;
if (keyboard.dKey.isPressed)
moveDirection += controlTarget.right;

// Y axis movement (E/Q)
if (keyboard.eKey.isPressed)
moveDirection += Vector3.up;
if (keyboard.qKey.isPressed)
moveDirection -= Vector3.up;

// Apply movement
if (moveDirection.magnitude > 0)
{
moveDirection.Normalize();
controlTarget.position += moveDirection * moveSpeed * Time.deltaTime;
}
}

/// <summary>
/// View rotation handling with right mouse button drag
/// </summary>
private void HandleRotation()
{
Mouse mouse = Mouse.current;
if (mouse == null) return;

// Rotate only while right-clicking
if (mouse.rightButton.isPressed)
{
Vector2 mouseDelta = mouse.delta.ReadValue() * lookSensitivity * 0.1f;
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 0.1f should be extracted to a named constant or configurable field to make the sensitivity scaling more transparent and maintainable.

Suggested change
Vector2 mouseDelta = mouse.delta.ReadValue() * lookSensitivity * 0.1f;
Vector2 mouseDelta = mouse.delta.ReadValue() * lookSensitivity * mouseSensitivityScale;

Copilot uses AI. Check for mistakes.

rotationY += mouseDelta.x;
rotationX -= mouseDelta.y;

// Vertical angle limit
rotationX = Mathf.Clamp(rotationX, -90f, 90f);
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vertical rotation limits (-90f, 90f) should be extracted to configurable fields or constants to allow customization of the look angle constraints.

Suggested change
rotationX = Mathf.Clamp(rotationX, -90f, 90f);
rotationX = Mathf.Clamp(rotationX, minVerticalAngle, maxVerticalAngle);

Copilot uses AI. Check for mistakes.

controlTarget.rotation = Quaternion.Euler(rotationX, rotationY, 0);
}
}
}
#else
public class EditorPlayerController : MonoBehaviour
{
// Do nothing outside the editor
}
#endif
}

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