Skip to content

Commit

Permalink
Improve switching between ROCamera and FreeflyCam
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermelhr committed Nov 29, 2020
1 parent 970b17a commit fbbfaf9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
23 changes: 20 additions & 3 deletions Assets/Scripts/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public static PathFindingManager PathFinding {
private static string CFG_NAME = "config.txt";

private bool isMapSelectorEnabled = false;
private bool isRoCamEnabled = false;
private bool isRoCamEnabled = true;

private void Awake() {
if (Instance == null) {
Instance = this;
}

/**
/**
* Caching the camera as it's heavy to search for it
*/
if (MainCamera == null) {
Expand Down Expand Up @@ -114,16 +114,33 @@ void FixedUpdate() {
}

void Update() {
// ESC pressed: toggle map selector visiblity
if (Input.GetKeyDown(KeyCode.Escape)) {
isMapSelectorEnabled = !isMapSelectorEnabled;
mapDropdown.gameObject.SetActive(isMapSelectorEnabled);
} else if (Input.GetKeyDown(KeyCode.F1)) {

// disable cameras when map selector is visible
MainCamera.GetComponent<ROCamera>().enabled = !isMapSelectorEnabled && isRoCamEnabled;
MainCamera.GetComponent<FreeflyCam>().enabled = !isMapSelectorEnabled && !isRoCamEnabled;

// disable entity when map selector is visible
MainCamera.GetComponentInParent<Entity>().enabled = !isMapSelectorEnabled;
}

// F1 pressed and not on map selector: switch between ROCamera and FreeflyCam
if (Input.GetKeyDown(KeyCode.F1) && !isMapSelectorEnabled) {
isRoCamEnabled = !isRoCamEnabled;
MainCamera.GetComponent<ROCamera>().enabled = isRoCamEnabled;
MainCamera.GetComponent<FreeflyCam>().enabled = !isRoCamEnabled;

Cursor.lockState = isRoCamEnabled ? CursorLockMode.None : Cursor.lockState;
Cursor.visible = isRoCamEnabled;

// switched to ROCamera: updated it so we go from wherever
// freefly is to where ROCam should be
if (isRoCamEnabled) {
MainCamera.GetComponent<ROCamera>().Start();
}
}


Expand Down
9 changes: 0 additions & 9 deletions Assets/Scripts/FreeflyCam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ void Start() {
}

void Update() {
if(Input.GetKeyDown(KeyCode.End) || Input.GetKeyDown(KeyCode.Escape)) {
Cursor.lockState = (CursorLockMode.Locked != Cursor.lockState) ? CursorLockMode.Locked : CursorLockMode.None;
Cursor.visible = Cursor.lockState != CursorLockMode.Locked;
}

if(Cursor.lockState != CursorLockMode.Locked) {
return;
}

rotationX = rotationX + Input.GetAxis("Mouse X") * cameraSensitivity;
rotationY = rotationY + Input.GetAxis("Mouse Y") * cameraSensitivity;
rotationY = Mathf.Clamp(rotationY, -90, 90);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Renderer/ROCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum DIRECTION : int {
[SerializeField] private float rotation = 0f;
[SerializeField] private float angle;

private void Start() {
public void Start() {
HandleYawPitch();
HandleZoom();
}
Expand Down

0 comments on commit fbbfaf9

Please sign in to comment.