主界面添加,许多bug修复。祝贺黑盒1如期开始
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -6,6 +6,9 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
public class pressStart : MonoBehaviour
|
||||
{
|
||||
@@ -24,6 +27,28 @@ public class pressStart : MonoBehaviour
|
||||
// UI text to show status
|
||||
public Text statusText;
|
||||
public Text warningText;
|
||||
|
||||
[Header("New UI Buttons")]
|
||||
public Button startButton;
|
||||
public Button helpButton;
|
||||
public Button closeButton;
|
||||
public Button exitButton;
|
||||
public GameObject helpContentObject;
|
||||
|
||||
[Header("Fade Settings")]
|
||||
public CanvasGroup mainCanvasGroup;
|
||||
public float fadeDelay = 0f;
|
||||
public float fadeDuration = 1f;
|
||||
|
||||
[Header("TMP Flashing Settings")]
|
||||
public TextMeshProUGUI flashingText;
|
||||
public float flashInterval = 0.5f;
|
||||
|
||||
[Header("Start Sequence Settings")]
|
||||
public Volume globalVolume;
|
||||
public Image fadeOutImage;
|
||||
public float startButtonDelay = 6f; // 6秒后才允许点击 Start
|
||||
|
||||
// polling
|
||||
private Coroutine pollCoroutine;
|
||||
private float pollInterval = 3f;
|
||||
@@ -40,6 +65,147 @@ public class pressStart : MonoBehaviour
|
||||
|
||||
// Ensure status text shows idle
|
||||
UpdateStatus("Press Enter to continue.", Color.green);
|
||||
|
||||
// Bind buttons
|
||||
if (startButton != null)
|
||||
{
|
||||
startButton.onClick.AddListener(OnStartButtonClick);
|
||||
}
|
||||
if (helpButton != null)
|
||||
{
|
||||
helpButton.onClick.AddListener(OnHelpButtonClick);
|
||||
}
|
||||
if (closeButton != null)
|
||||
{
|
||||
closeButton.onClick.AddListener(OnCloseButtonClick);
|
||||
}
|
||||
if (exitButton != null)
|
||||
{
|
||||
exitButton.onClick.AddListener(OnExitButtonClick);
|
||||
}
|
||||
if (helpContentObject != null)
|
||||
{
|
||||
helpContentObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Initialize fadeOutImage
|
||||
if (fadeOutImage != null)
|
||||
{
|
||||
Color c = fadeOutImage.color;
|
||||
c.a = 0f;
|
||||
fadeOutImage.color = c;
|
||||
fadeOutImage.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Initialize Global Volume Bloom intensity to 0
|
||||
if (globalVolume != null && globalVolume.profile.TryGet<Bloom>(out var bloom))
|
||||
{
|
||||
bloom.intensity.Override(0f);
|
||||
}
|
||||
|
||||
// Initialize CanvasGroup and start fade-in
|
||||
if (mainCanvasGroup != null)
|
||||
{
|
||||
mainCanvasGroup.alpha = 0f;
|
||||
StartCoroutine(FadeInMainCanvasGroup());
|
||||
}
|
||||
|
||||
// Start flashing logic
|
||||
if (flashingText != null)
|
||||
{
|
||||
StartCoroutine(FlashTMPText());
|
||||
}
|
||||
|
||||
// Start button delay logic
|
||||
if (startButton != null)
|
||||
{
|
||||
StartCoroutine(StartButtonActivationDelay());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator StartButtonActivationDelay()
|
||||
{
|
||||
if (startButton == null) yield break;
|
||||
|
||||
// 初始禁用按钮
|
||||
startButton.interactable = false;
|
||||
|
||||
// 等待指定时间 (使用 unscaledTime 以防 timeScale 为 0)
|
||||
yield return new WaitForSecondsRealtime(startButtonDelay);
|
||||
|
||||
// 启用按钮
|
||||
startButton.interactable = true;
|
||||
Debug.Log("[pressStart] Start button is now active.");
|
||||
}
|
||||
|
||||
private IEnumerator FlashTMPText()
|
||||
{
|
||||
if (flashingText == null) yield break;
|
||||
|
||||
float elapsed = 0f;
|
||||
while (true)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
// 使用 Mathf.PingPong 在 0 到 1 之间往复
|
||||
// 除以 flashInterval 可以控制循环的速度
|
||||
float alpha = Mathf.PingPong(elapsed / flashInterval, 1f);
|
||||
|
||||
Color color = flashingText.color;
|
||||
color.a = alpha;
|
||||
flashingText.color = color;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FadeInMainCanvasGroup()
|
||||
{
|
||||
if (fadeDelay > 0)
|
||||
yield return new WaitForSeconds(fadeDelay);
|
||||
|
||||
float elapsed = 0f;
|
||||
while (elapsed < fadeDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
mainCanvasGroup.alpha = Mathf.Lerp(0f, 1f, elapsed / fadeDuration);
|
||||
yield return null;
|
||||
}
|
||||
mainCanvasGroup.alpha = 1f;
|
||||
}
|
||||
|
||||
private void OnStartButtonClick()
|
||||
{
|
||||
Debug.Log("[pressStart] Start button clicked.");
|
||||
HandleGameStartLogic();
|
||||
}
|
||||
|
||||
private void OnHelpButtonClick()
|
||||
{
|
||||
if (helpContentObject != null)
|
||||
{
|
||||
bool isActive = helpContentObject.activeSelf;
|
||||
helpContentObject.SetActive(!isActive);
|
||||
Debug.Log("[pressStart] Help button clicked. Help content active: " + !isActive);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCloseButtonClick()
|
||||
{
|
||||
if (helpContentObject != null)
|
||||
{
|
||||
helpContentObject.SetActive(false);
|
||||
Debug.Log("[pressStart] Close button clicked. Help content hidden.");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExitButtonClick()
|
||||
{
|
||||
Debug.Log("[pressStart] Exit button clicked. Application quitting.");
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -51,32 +217,82 @@ public class pressStart : MonoBehaviour
|
||||
if (!(Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
|
||||
return;
|
||||
|
||||
// 如果按钮未激活 (还在倒计时),不允许通过键盘进入
|
||||
if (startButton != null && !startButton.interactable)
|
||||
{
|
||||
Debug.Log("[pressStart] Start request ignored. Button is not active yet.");
|
||||
return;
|
||||
}
|
||||
|
||||
HandleGameStartLogic();
|
||||
}
|
||||
|
||||
private void HandleGameStartLogic()
|
||||
{
|
||||
bool requestTestMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
||||
if (requestTestMode)
|
||||
{
|
||||
Debug.Log("[pressStart] Enter+Shift detected, starting test mode polling.");
|
||||
Debug.Log("[pressStart] Enter+Shift or button start requested, starting test mode polling.");
|
||||
GameConfig.testMode = true;
|
||||
if (pollCoroutine != null) StopCoroutine(pollCoroutine);
|
||||
pollCoroutine = StartCoroutine(PollForBanflagAndProceed());
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_enterNextScene)
|
||||
{
|
||||
Debug.Log("[pressStart] Second input detected, loading UI_UI scene. Forcing Time.timeScale = 1.");
|
||||
Time.timeScale = 1f; // Ensure time is running for next scene
|
||||
SceneManager.LoadScene("UI_UI");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("[pressStart] First input detected, setting check_enterNextScene = true");
|
||||
// 修改为点击一次即可开始进入游戏序列
|
||||
Debug.Log("[pressStart] Start requested, initiating transition sequence.");
|
||||
GameConfig.testMode = false;
|
||||
|
||||
if (warningText != null)
|
||||
{
|
||||
warningText.gameObject.SetActive(true);
|
||||
warningText.text = WARNING_TEXT_CONTENT;
|
||||
}
|
||||
check_enterNextScene = true;
|
||||
|
||||
// 启动进入游戏的异步序列
|
||||
StartCoroutine(StartGameTransitionSequence());
|
||||
}
|
||||
|
||||
private IEnumerator StartGameTransitionSequence()
|
||||
{
|
||||
// 1. 0.5秒内将 Global Volume 的 Bloom Intensity 从 0 变到 3
|
||||
if (globalVolume != null && globalVolume.profile.TryGet<Bloom>(out var bloom))
|
||||
{
|
||||
float elapsed = 0f;
|
||||
float duration = 0.5f;
|
||||
float startVal = bloom.intensity.value;
|
||||
float targetVal = 3f;
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
bloom.intensity.Override(Mathf.Lerp(startVal, targetVal, elapsed / duration));
|
||||
yield return null;
|
||||
}
|
||||
bloom.intensity.Override(targetVal);
|
||||
}
|
||||
|
||||
// 2. 结束变 3 后,将 Image 的不透明度在 0.5 秒内从 0 变到 255 (alpha = 1)
|
||||
if (fadeOutImage != null)
|
||||
{
|
||||
fadeOutImage.gameObject.SetActive(true);
|
||||
float elapsed = 0f;
|
||||
float duration = 0.5f;
|
||||
Color color = fadeOutImage.color;
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
color.a = Mathf.Lerp(0f, 1f, elapsed / duration);
|
||||
fadeOutImage.color = color;
|
||||
yield return null;
|
||||
}
|
||||
color.a = 1f;
|
||||
fadeOutImage.color = color;
|
||||
}
|
||||
|
||||
// 3. 切换场景
|
||||
Debug.Log("[pressStart] Transition sequence complete. Loading UI_UI scene.");
|
||||
Time.timeScale = 1f;
|
||||
SceneManager.LoadScene("UI_UI");
|
||||
}
|
||||
|
||||
private IEnumerator PollForBanflagAndProceed()
|
||||
|
||||
Reference in New Issue
Block a user