Skip to content

Commit

Permalink
Update to work lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurihaia committed Jun 1, 2020
1 parent 22c6b08 commit 441df4b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
62 changes: 54 additions & 8 deletions src/FrameCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;
using UnityEngine.UI;
using GlobalEnums;
using System.Collections;

namespace FrameDisplay
{
Expand All @@ -10,30 +11,66 @@ public class FrameCount : MonoBehaviour
private int frame = 0;
private bool timerActive = false;

private Text display;
private string goalRoom = null;

private Text frameDisplay;
private Text goalDisplay;

public void ShowDisplay()
{
Modding.Logger.Log("[FrameDisplay] Creating display");
GameObject go = CanvasUtil.CreateCanvas(UnityEngine.RenderMode.ScreenSpaceOverlay, 100);
CanvasUtil.CreateFonts();
CanvasUtil.RectData rd = new CanvasUtil.RectData(
CanvasUtil.RectData timerRd = new CanvasUtil.RectData(
new Vector2(400, 100),
new Vector2(0.5f, 0.5f),
new Vector2(0.15f, 0.1f),
new Vector2(0.15f, 0.1f)
);
display = CanvasUtil.CreateTextPanel(go, "test", 40, TextAnchor.LowerLeft, rd).GetComponent<Text>();
display.text = "0";
CanvasUtil.RectData goalRd = new CanvasUtil.RectData(
new Vector2(800, 100),
new Vector2(0.5f, 0.5f),
new Vector2(0.7f, 0.1f),
new Vector2(0.7f, 0.1f)
);
frameDisplay = CanvasUtil.CreateTextPanel(go, "0", 40, TextAnchor.LowerLeft, timerRd).GetComponent<Text>();
goalDisplay = CanvasUtil.CreateTextPanel(go, "None", 25, TextAnchor.LowerRight, goalRd).GetComponent<Text>();
Object.DontDestroyOnLoad(go);
StartCoroutine(Tick());
}

public IEnumerator Tick()
{
Modding.Logger.Log("[FrameDisplay] Starting Coroutine");
while (true)
{
if (GameManager.instance.gameState != GameState.LOADING && timerActive)
{
frame += 1;
}
yield return new WaitForSecondsRealtime(0.02f);
}
}

public void Update()
{
GameState state = GameManager.instance.gameState;
if (state != GameState.LOADING && timerActive)
if (GameManager.instance.gameState != GameState.LOADING)
{
frame += 1;
if (Input.GetKeyDown(FrameDisplay.Instance.settings.SetGoal))
{
if (goalRoom == GameManager.instance.sceneName)
{
goalRoom = null;
}
else
{
goalRoom = GameManager.instance.sceneName;
}
}
if (goalRoom != null && goalRoom == GameManager.instance.sceneName)
{
timerActive = false;
}
}
if (Input.GetKeyDown(FrameDisplay.Instance.settings.Pause))
{
Expand All @@ -42,8 +79,17 @@ public void Update()
if (Input.GetKeyDown(FrameDisplay.Instance.settings.Reset))
{
frame = 0;
timerActive = false;
}
frameDisplay.text = frame.ToString();
if (goalRoom == null)
{
goalDisplay.text = "No Goal";
}
else
{
goalDisplay.text = goalRoom;
}
display.text = frame.ToString();
}
}
}
6 changes: 6 additions & 0 deletions src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ public string Reset
get => GetString("f11");
set => SetString(value);
}

public string SetGoal
{
get => GetString("f12");
set => SetString(value);
}
}
}

0 comments on commit 441df4b

Please sign in to comment.