fr.jeanf.universal.player 0.8.35 → 0.8.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,18 +24,23 @@ namespace jeanf.universalplayer
24
24
  bool isMoving;
25
25
  Vector2 moveValue;
26
26
 
27
+ // Cache camera transform to avoid Camera.main lookups
28
+ private Transform cameraTransform;
29
+ private const float INPUT_MULTIPLIER = 50f;
27
30
 
28
- private void OnEnable()
31
+ private void Awake()
29
32
  {
30
- fpsMoveAction.action.performed += ctx => SetMoveValue(ctx.ReadValue<Vector2>() * Time.smoothDeltaTime * 50f);
31
- fpsMoveAction.action.performed += ctx => SetIsMoving(true);
32
- xrMoveAction.action.performed += ctx => SetIsMoving(true);
33
- xrMoveAction.action.canceled += ctx => SetIsMoving(false);
34
- //xrMoveAction.action.performed += ctx => SetIsMoving(true);
35
- fpsMoveAction.action.canceled += ctx => SetMoveValue(ctx.ReadValue<Vector2>() * Time.smoothDeltaTime * 50);
36
- fpsMoveAction.action.canceled += ctx => SetIsMoving(false);
37
- //xrMoveAction.action.canceled += ctx => SetIsMoving(false);
33
+ // Cache the camera transform once
34
+ cameraTransform = Camera.main.transform;
35
+ }
38
36
 
37
+ private void OnEnable()
38
+ {
39
+ // Use proper method references instead of lambdas
40
+ fpsMoveAction.action.performed += OnFpsMovePerformed;
41
+ fpsMoveAction.action.canceled += OnFpsMoveCanceled;
42
+ xrMoveAction.action.performed += OnXrMovePerformed;
43
+ xrMoveAction.action.canceled += OnXrMoveCanceled;
39
44
  }
40
45
 
41
46
  private void OnDisable() => Unsubscribe();
@@ -43,15 +48,40 @@ namespace jeanf.universalplayer
43
48
 
44
49
  private void Unsubscribe()
45
50
  {
46
- fpsMoveAction.action.performed -= ctx => SetMoveValue(ctx.ReadValue<Vector2>() * Time.smoothDeltaTime * 50f);
47
- fpsMoveAction.action.performed -= ctx => SetIsMoving(true);
48
- xrMoveAction.action.performed -= ctx => SetIsMoving(true);
49
- xrMoveAction.action.canceled -= ctx => SetIsMoving(false);
50
- //xrMoveAction.action.performed -= ctx => SetIsMoving(false);
51
- fpsMoveAction.action.canceled -= ctx => SetMoveValue(ctx.ReadValue<Vector2>() * Time.smoothDeltaTime * 50f);
52
- fpsMoveAction.action.canceled -= ctx => SetIsMoving(false);
53
- //xrMoveAction.action.canceled -= ctx => SetIsMoving(false);
51
+ if (fpsMoveAction != null && fpsMoveAction.action != null)
52
+ {
53
+ fpsMoveAction.action.performed -= OnFpsMovePerformed;
54
+ fpsMoveAction.action.canceled -= OnFpsMoveCanceled;
55
+ }
56
+
57
+ if (xrMoveAction != null && xrMoveAction.action != null)
58
+ {
59
+ xrMoveAction.action.performed -= OnXrMovePerformed;
60
+ xrMoveAction.action.canceled -= OnXrMoveCanceled;
61
+ }
62
+ }
63
+
64
+ // Event handler methods
65
+ private void OnFpsMovePerformed(InputAction.CallbackContext ctx)
66
+ {
67
+ SetMoveValue(ctx.ReadValue<Vector2>() * Time.smoothDeltaTime * INPUT_MULTIPLIER);
68
+ SetIsMoving(true);
69
+ }
70
+
71
+ private void OnFpsMoveCanceled(InputAction.CallbackContext ctx)
72
+ {
73
+ SetMoveValue(Vector2.zero);
74
+ SetIsMoving(false);
75
+ }
76
+
77
+ private void OnXrMovePerformed(InputAction.CallbackContext ctx)
78
+ {
79
+ SetIsMoving(true);
80
+ }
54
81
 
82
+ private void OnXrMoveCanceled(InputAction.CallbackContext ctx)
83
+ {
84
+ SetIsMoving(false);
55
85
  }
56
86
 
57
87
  private void LateUpdate()
@@ -61,42 +91,35 @@ namespace jeanf.universalplayer
61
91
  Move(moveValue);
62
92
  }
63
93
 
64
-
65
94
  if (!controller.isGrounded)
66
95
  {
67
- controller.Move(new Vector3(0.0f, -gravity, 0.0f).normalized * Time.deltaTime * 10f);
96
+ controller.Move(Vector3.down * gravity * Time.deltaTime);
68
97
  }
69
-
70
98
  }
99
+
71
100
  private void SetMoveValue(Vector2 move)
72
101
  {
73
102
  moveValue = move;
74
-
75
103
  }
76
104
 
77
- private bool IsGrounded()
78
- {
79
- return Physics.Raycast(transform.position, -Vector3.up, distToGround);
80
- }
81
105
  private void Move(Vector2 move)
82
106
  {
107
+ // Use cached camera transform
108
+ Vector3 forward = cameraTransform.forward;
109
+ Vector3 right = cameraTransform.right;
83
110
 
111
+ // Calculate move direction on XZ plane only
112
+ Vector3 moveDirection = (forward * move.y) + (right * move.x);
113
+ moveDirection.y = 0f;
84
114
 
85
- Vector3 forward = Camera.main.transform.forward;
86
- Vector3 right = Camera.main.transform.right;
87
-
88
- Vector3 moveDirection = (forward * speed * move.y) + (right * speed * move.x);
89
-
90
-
91
-
92
- Vector3 finalMoveDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.z);
93
- controller.Move(finalMoveDirection.normalized * speed * Time.deltaTime);
115
+ // Move with normalized direction
116
+ controller.Move(moveDirection.normalized * speed * Time.deltaTime);
94
117
  }
95
118
 
96
119
  private void SetIsMoving(bool isMoving)
97
120
  {
98
121
  this.isMoving = isMoving;
99
- playerIsMovingEvent.RaiseEvent(isMoving);
122
+ playerIsMovingEvent?.RaiseEvent(isMoving);
100
123
  }
101
124
  }
102
- }
125
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fr.jeanf.universal.player",
3
3
 
4
- "version": "0.8.35",
4
+ "version": "0.8.36",
5
5
 
6
6
  "displayName": "Universal Player",
7
7
  "description": "This package contains a universal player working in URP & HDRP for Mouse+Keyboard or VR",