Skip to content

Commit

Permalink
Improve switching between ROCamera and FreeflyCam (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermelhr committed Nov 29, 2020
1 parent fbbfaf9 commit 149673a
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions Assets/Scripts/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public static PathFindingManager PathFinding {
private Hashtable configs = new Hashtable();
private static string CFG_NAME = "config.txt";

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

private void Awake() {
if (Instance == null) {
Expand All @@ -57,6 +56,7 @@ private void Awake() {
void Start() {
MapRenderer.SoundsMixerGroup = soundsMixerGroup;
MapRenderer.WorldLight = worldLight;
roCamEnabled = MainCamera.GetComponent<ROCamera>().enabled;

LoadConfigs();
LoadGrf();
Expand All @@ -69,9 +69,16 @@ private void BuildMapSelector() {
selector.buildDropdown(mapDropdown);
Debug.Log($"Map list has {selector.GetMapList().Count} entries.");

if (!string.IsNullOrEmpty(mapname)) {
// do we have a map to load on startup
var preLoadMap = !string.IsNullOrEmpty(mapname);

// there is a map to load on startup: load it
if (preLoadMap) {
selector.ChangeMap(mapname);
}

// if a map is pre loaded, do not display map selector on startup
mapDropdown.gameObject.SetActive(!preLoadMap);
}

private void LoadGrf() {
Expand Down Expand Up @@ -114,39 +121,46 @@ void FixedUpdate() {
}

void Update() {
if (mapRenderer.Ready) {
mapRenderer.Render();
}

// is map selector enabled
var mapSelectorEnabled = mapDropdown.gameObject.activeSelf;

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

// toggle map selector
mapSelectorEnabled = !mapSelectorEnabled;
mapDropdown.gameObject.SetActive(mapSelectorEnabled);

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

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

// 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;
else if (Input.GetKeyDown(KeyCode.F1) && !mapSelectorEnabled) {

// switch cameras
roCamEnabled = !roCamEnabled;
MainCamera.GetComponent<ROCamera>().enabled = roCamEnabled;
MainCamera.GetComponent<FreeflyCam>().enabled = !roCamEnabled;

Cursor.lockState = isRoCamEnabled ? CursorLockMode.None : Cursor.lockState;
Cursor.visible = isRoCamEnabled;
// handle cursor
Cursor.lockState = roCamEnabled ? CursorLockMode.None : Cursor.lockState;
Cursor.visible = roCamEnabled;

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


if (mapRenderer.Ready) {
mapRenderer.Render();
}
}

public void OnPostRender() {
Expand Down

0 comments on commit 149673a

Please sign in to comment.