1.2.0
This commit is contained in:
1 parent
c3bb8d1a9e
commit
fd0312270b
26 files changed
+3310
-87
No files matched your search
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
|
||||
// 熱身做完、平均 FPS 太低時的提示 (v1.2.0) : 只提醒,不擋錄製
|
||||
// 由 BotSpawner 在第一個正式回合生成之前呼叫,這時沒有回合在進行,所以不會吃到回合時間,也不會記成回合內的暫停
|
||||
// 掛在場景裡一直啟用的物件上 (例如 HUD 的 Canvas),提示視窗本身平常隱藏
|
||||
public class FpsWarning : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("提示視窗 (Panel),平常隱藏")]
|
||||
public GameObject panel;
|
||||
|
||||
[Tooltip("提示文字 Text (TMP)")]
|
||||
public TextMeshProUGUI messageText;
|
||||
|
||||
[Tooltip("繼續 Button")]
|
||||
public Button continueButton;
|
||||
|
||||
[Tooltip("回主選單 Button")]
|
||||
public Button menuButton;
|
||||
|
||||
[Header("場景")]
|
||||
public string startSceneName = "StartUI";
|
||||
|
||||
private Action onContinue;
|
||||
private bool wired;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (panel != null && onContinue == null) panel.SetActive(false);
|
||||
WireButtons();
|
||||
}
|
||||
|
||||
// 掛的物件沒啟用時 Start() 不會跑,所以 Show() 也會呼叫一次
|
||||
void WireButtons()
|
||||
{
|
||||
if (wired) return;
|
||||
wired = true;
|
||||
if (continueButton != null) continueButton.onClick.AddListener(OnContinueClicked);
|
||||
if (menuButton != null) menuButton.onClick.AddListener(OnMenuClicked);
|
||||
}
|
||||
|
||||
// 給 BotSpawner 找場景裡的提示 (提示視窗可能是隱藏的,所以也找未啟用的物件)
|
||||
public static FpsWarning FindInScene()
|
||||
{
|
||||
return FindAnyObjectByType<FpsWarning>(FindObjectsInactive.Include);
|
||||
}
|
||||
|
||||
// 顯示提示並暫停 (不顯示暫停視窗) ; 按「繼續」後呼叫 continueAction
|
||||
// 顯示不出來 (沒接 Panel 或場景沒有 PauseMenu) 時回傳 false,呼叫端直接繼續
|
||||
public bool Show(float fps, Action continueAction)
|
||||
{
|
||||
if (panel == null) return false;
|
||||
if (!PauseMenu.PauseForPrompt()) return false;
|
||||
|
||||
WireButtons();
|
||||
onContinue = continueAction;
|
||||
if (messageText != null)
|
||||
{
|
||||
messageText.text = $"目前平均 FPS 是 {fps:F0},目標是 {SessionPlan.TargetFps}。\n" +
|
||||
"建議關掉其他程式,或回主選單勾選「低畫質」。\n" +
|
||||
"也可以直接繼續。";
|
||||
}
|
||||
panel.SetActive(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnContinueClicked()
|
||||
{
|
||||
if (panel != null) panel.SetActive(false);
|
||||
PauseMenu.ResumeFromPrompt();
|
||||
|
||||
Action action = onContinue;
|
||||
onContinue = null;
|
||||
action?.Invoke();
|
||||
}
|
||||
|
||||
// 回主選單 : 排程進度照舊 (再進來從第一個正式回合開始,熱身不用重做)
|
||||
void OnMenuClicked()
|
||||
{
|
||||
onContinue = null;
|
||||
Time.timeScale = 1f;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
SceneManager.LoadScene(startSceneName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user