Skip to content

Commit dbe7e3b

Browse files
committed
refactor(scripts): resolve optimization suggestions
1 parent a06f502 commit dbe7e3b

File tree

2 files changed

+79
-69
lines changed

2 files changed

+79
-69
lines changed
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
using UnityEngine;
22
using UnityEngine.InputSystem;
3-
4-
public class FlyCamera : MonoBehaviour {
5-
6-
private float mainSpeed = 5.0f; //regular speed
7-
private float camSens = 0.25f; //How sensitive it with mouse
3+
4+
public class FlyCamera : MonoBehaviour
5+
{
6+
7+
private readonly float mainSpeed = 5.0f; //regular speed
8+
private readonly float camSens = 0.25f; //How sensitive it with mouse
89
private Vector2 p;
910
private Vector3 lastMouse;
1011
private bool activateCam = false;
1112

1213
public GameObject DroneObject;
1314

14-
public void onMove(InputAction.CallbackContext value){
15+
public void onMove(InputAction.CallbackContext value)
16+
{
1517
p = -value.ReadValue<Vector2>();
16-
p = p * mainSpeed * Time.deltaTime;
18+
p = mainSpeed * Time.deltaTime * p;
1719
}
1820

1921
// TODO: Camera flips when the X angle is either max or min. Needs to be clipped
20-
public void onMouse(InputAction.CallbackContext value){
22+
public void onMouse(InputAction.CallbackContext value)
23+
{
2124
lastMouse = value.ReadValue<Vector2>();
2225
lastMouse = new Vector2(lastMouse.y * camSens, lastMouse.x * camSens);
2326
lastMouse = new Vector2(transform.eulerAngles.x + lastMouse.x, transform.eulerAngles.y + lastMouse.y);
2427
}
2528

26-
public void onCameraActivate(InputAction.CallbackContext value){
29+
public void onCameraActivate(InputAction.CallbackContext value)
30+
{
2731
activateCam = !value.canceled;
2832
}
2933

30-
void LateUpdate(){
31-
DroneObject.transform.Translate(new Vector3(p.x,0,p.y));
32-
if (activateCam){transform.eulerAngles = lastMouse;}
34+
void LateUpdate()
35+
{
36+
DroneObject.transform.Translate(new Vector3(p.x, 0, p.y));
37+
if (activateCam) { transform.eulerAngles = lastMouse; }
3338
}
3439
}
Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
using UnityEngine;
2-
using UnityEngine.EventSystems;
3-
using Valve.VR.Extras;
4-
5-
public class SteamVRLaserWrapper : MonoBehaviour
6-
{
7-
/**
8-
This script lets the SteamVR laser interact with Unity Buttons using Box Colliders
9-
Offered up by a gracious soul on the Unity Forums
10-
TODO: Find original author
11-
**/
12-
13-
private SteamVR_LaserPointer steamVrLaserPointer;
14-
15-
private void Awake()
16-
{
17-
steamVrLaserPointer = gameObject.GetComponent<SteamVR_LaserPointer>();
18-
steamVrLaserPointer.PointerIn += OnPointerIn;
19-
steamVrLaserPointer.PointerOut += OnPointerOut;
20-
steamVrLaserPointer.PointerClick += OnPointerClick;
21-
}
22-
23-
private void OnPointerClick(object sender, PointerEventArgs e)
24-
{
25-
Debug.Log(e.target.name);
26-
IPointerClickHandler clickHandler = e.target.GetComponent<IPointerClickHandler>();
27-
if (clickHandler == null)
28-
{
29-
return;
30-
}
31-
32-
33-
clickHandler.OnPointerClick(new PointerEventData(EventSystem.current));
34-
}
35-
36-
private void OnPointerOut(object sender, PointerEventArgs e)
37-
{
38-
IPointerExitHandler pointerExitHandler = e.target.GetComponent<IPointerExitHandler>();
39-
if (pointerExitHandler == null)
40-
{
41-
return;
42-
}
43-
44-
pointerExitHandler.OnPointerExit(new PointerEventData(EventSystem.current));
45-
}
46-
47-
private void OnPointerIn(object sender, PointerEventArgs e)
48-
{
49-
IPointerEnterHandler pointerEnterHandler = e.target.GetComponent<IPointerEnterHandler>();
50-
if (pointerEnterHandler == null)
51-
{
52-
return;
53-
}
54-
55-
pointerEnterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
56-
}
57-
}
1+
using UnityEngine;
2+
using UnityEngine.EventSystems;
3+
using Valve.VR.Extras;
4+
5+
public class SteamVRLaserWrapper : MonoBehaviour
6+
{
7+
/**
8+
This script lets the SteamVR laser interact with Unity Buttons using Box Colliders
9+
Offered up by a gracious soul on the Unity Forums
10+
TODO: Find original author
11+
**/
12+
13+
private SteamVR_LaserPointer steamVrLaserPointer;
14+
15+
private void Awake()
16+
{
17+
steamVrLaserPointer = gameObject.GetComponent<SteamVR_LaserPointer>();
18+
steamVrLaserPointer.PointerIn += OnPointerIn;
19+
steamVrLaserPointer.PointerOut += OnPointerOut;
20+
steamVrLaserPointer.PointerClick += OnPointerClick;
21+
}
22+
23+
private void OnPointerClick(object sender, PointerEventArgs e)
24+
{
25+
if (e.target.TryGetComponent<IPointerClickHandler>(out var clickHandler))
26+
{
27+
if (clickHandler == null)
28+
{
29+
return;
30+
}
31+
clickHandler.OnPointerClick(new PointerEventData(EventSystem.current));
32+
}
33+
}
34+
35+
private void OnPointerOut(object sender, PointerEventArgs e)
36+
{
37+
if (e.target.TryGetComponent<IPointerExitHandler>(out var pointerExitHandler))
38+
{
39+
40+
41+
if (pointerExitHandler == null)
42+
{
43+
return;
44+
}
45+
46+
pointerExitHandler.OnPointerExit(new PointerEventData(EventSystem.current));
47+
}
48+
}
49+
50+
private void OnPointerIn(object sender, PointerEventArgs e)
51+
{
52+
if (e.target.TryGetComponent<IPointerEnterHandler>(out var pointerEnterHandler))
53+
{
54+
if (pointerEnterHandler == null)
55+
{
56+
return;
57+
}
58+
59+
pointerEnterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)