超大量的更新 修复很多问题,gameplay特效初步
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class btmandtopController : MonoBehaviour
|
||||
{
|
||||
@@ -31,12 +33,22 @@ public class btmandtopController : MonoBehaviour
|
||||
public GameObject email_prefab;
|
||||
public GameObject notice_prefab;
|
||||
|
||||
[Header("New Back Buttons")]
|
||||
[SerializeField] private Button back_navButton;
|
||||
[SerializeField] private Button home_navButton;
|
||||
[SerializeField] private Button settings_navButton;
|
||||
[SerializeField] private string homeSceneName = "UI_UI";
|
||||
[SerializeField] private string backFallbackSceneName = "Main_main";
|
||||
|
||||
private UnityAction instantiateSettings;
|
||||
private UnityAction instantiateUserInfo;
|
||||
private UnityAction instantiateStore;
|
||||
private UnityAction instantiateShowLevel;
|
||||
private UnityAction instantiateEmail;
|
||||
private UnityAction instantiateNotice;
|
||||
private UnityAction navBackAction;
|
||||
private UnityAction navHomeAction;
|
||||
private UnityAction navSettingsAction;
|
||||
|
||||
// cached reference to the settings instance to ensure only one exists
|
||||
private GameObject settingsInstance;
|
||||
@@ -46,10 +58,16 @@ public class btmandtopController : MonoBehaviour
|
||||
private CanvasGroup musicPicGroup;
|
||||
private Coroutine musicPicFade;
|
||||
private bool musicPicVisible = true;
|
||||
private bool navSceneLoading = false;
|
||||
|
||||
private static readonly List<string> sceneHistory = new List<string>();
|
||||
private static bool sceneHistoryHooked = false;
|
||||
private static string trackedCurrentScene = string.Empty;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
EnsureMusicPicRoot();
|
||||
InitializeSceneHistoryIfNeeded();
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -85,6 +103,8 @@ public class btmandtopController : MonoBehaviour
|
||||
if (notice_display != null)
|
||||
notice_display.onClick.AddListener(instantiateNotice);
|
||||
|
||||
BindNewBackButtons();
|
||||
|
||||
EnsureMusicPicRoot();
|
||||
SetupMusicPicDefault();
|
||||
if (button_Music != null)
|
||||
@@ -112,6 +132,7 @@ public class btmandtopController : MonoBehaviour
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
settingsInstance.SetActive(false);
|
||||
|
||||
// try to set canvas camera now as in previous behavior
|
||||
@@ -135,6 +156,7 @@ public class btmandtopController : MonoBehaviour
|
||||
{
|
||||
// ensure it's parented correctly under putPrefabsHere
|
||||
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
settingsInstance.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -309,6 +331,13 @@ public class btmandtopController : MonoBehaviour
|
||||
|
||||
if (button_Music != null)
|
||||
button_Music.onClick.RemoveListener(ToggleMusicPicLocal);
|
||||
|
||||
if (back_navButton != null && navBackAction != null)
|
||||
back_navButton.onClick.RemoveListener(navBackAction);
|
||||
if (home_navButton != null && navHomeAction != null)
|
||||
home_navButton.onClick.RemoveListener(navHomeAction);
|
||||
if (settings_navButton != null && navSettingsAction != null)
|
||||
settings_navButton.onClick.RemoveListener(navSettingsAction);
|
||||
}
|
||||
|
||||
private void ToggleSettingsPrefab()
|
||||
@@ -319,6 +348,7 @@ public class btmandtopController : MonoBehaviour
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
|
||||
// attempt to set canvas camera
|
||||
try
|
||||
@@ -341,6 +371,8 @@ public class btmandtopController : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
|
||||
// Toggle active state
|
||||
bool active = settingsInstance.activeSelf;
|
||||
settingsInstance.SetActive(!active);
|
||||
@@ -445,4 +477,174 @@ public class btmandtopController : MonoBehaviour
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureSettingsEnterAnimator(GameObject instance)
|
||||
{
|
||||
if (instance == null) return;
|
||||
|
||||
UI_SettingsPanelEnterAnim anim = instance.GetComponent<UI_SettingsPanelEnterAnim>();
|
||||
if (anim == null)
|
||||
anim = instance.AddComponent<UI_SettingsPanelEnterAnim>();
|
||||
anim.enabled = true;
|
||||
}
|
||||
|
||||
private void BindNewBackButtons()
|
||||
{
|
||||
ResolveNewBackButtons();
|
||||
|
||||
navBackAction = OnBackNavClicked;
|
||||
navHomeAction = OnHomeNavClicked;
|
||||
navSettingsAction = OnSettingsNavClicked;
|
||||
|
||||
if (back_navButton != null)
|
||||
{
|
||||
back_navButton.onClick.RemoveListener(navBackAction);
|
||||
back_navButton.onClick.AddListener(navBackAction);
|
||||
}
|
||||
|
||||
if (home_navButton != null)
|
||||
{
|
||||
home_navButton.onClick.RemoveListener(navHomeAction);
|
||||
home_navButton.onClick.AddListener(navHomeAction);
|
||||
}
|
||||
|
||||
if (settings_navButton != null)
|
||||
{
|
||||
settings_navButton.onClick.RemoveListener(navSettingsAction);
|
||||
settings_navButton.onClick.AddListener(navSettingsAction);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResolveNewBackButtons()
|
||||
{
|
||||
Transform navRoot = FindChildRecursive(transform, "New back");
|
||||
if (navRoot == null)
|
||||
{
|
||||
GameObject sceneRoot = FindByName("New back");
|
||||
if (sceneRoot != null)
|
||||
navRoot = sceneRoot.transform;
|
||||
}
|
||||
|
||||
if (back_navButton == null)
|
||||
back_navButton = FindButtonByName(navRoot, "back");
|
||||
if (home_navButton == null)
|
||||
home_navButton = FindButtonByName(navRoot, "home");
|
||||
if (settings_navButton == null)
|
||||
settings_navButton = FindButtonByName(navRoot, "settings");
|
||||
}
|
||||
|
||||
private static Transform FindChildRecursive(Transform root, string childName)
|
||||
{
|
||||
if (root == null || string.IsNullOrEmpty(childName)) return null;
|
||||
if (root.name == childName) return root;
|
||||
|
||||
for (int i = 0; i < root.childCount; i++)
|
||||
{
|
||||
Transform child = root.GetChild(i);
|
||||
Transform found = FindChildRecursive(child, childName);
|
||||
if (found != null) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Button FindButtonByName(Transform root, string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return null;
|
||||
|
||||
if (root != null)
|
||||
{
|
||||
Button[] buttons = root.GetComponentsInChildren<Button>(true);
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
Button btn = buttons[i];
|
||||
if (btn != null && string.Equals(btn.gameObject.name, name, System.StringComparison.OrdinalIgnoreCase))
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void InitializeSceneHistoryIfNeeded()
|
||||
{
|
||||
if (sceneHistoryHooked) return;
|
||||
sceneHistoryHooked = true;
|
||||
trackedCurrentScene = SceneManager.GetActiveScene().name ?? string.Empty;
|
||||
SceneManager.sceneLoaded += OnSceneLoadedTrackHistory;
|
||||
}
|
||||
|
||||
private static void OnSceneLoadedTrackHistory(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
string incoming = scene.name ?? string.Empty;
|
||||
if (!string.IsNullOrEmpty(trackedCurrentScene) &&
|
||||
!string.Equals(trackedCurrentScene, incoming, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (sceneHistory.Count == 0 ||
|
||||
!string.Equals(sceneHistory[sceneHistory.Count - 1], trackedCurrentScene, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
sceneHistory.Add(trackedCurrentScene);
|
||||
if (sceneHistory.Count > 24) sceneHistory.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
trackedCurrentScene = incoming;
|
||||
}
|
||||
|
||||
private static string PopPreviousSceneName(string currentScene)
|
||||
{
|
||||
for (int i = sceneHistory.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string candidate = sceneHistory[i];
|
||||
sceneHistory.RemoveAt(i);
|
||||
if (string.IsNullOrEmpty(candidate)) continue;
|
||||
if (string.Equals(candidate, currentScene, System.StringComparison.OrdinalIgnoreCase)) continue;
|
||||
return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void OnBackNavClicked()
|
||||
{
|
||||
if (navSceneLoading) return;
|
||||
InitializeSceneHistoryIfNeeded();
|
||||
|
||||
string current = SceneManager.GetActiveScene().name ?? string.Empty;
|
||||
string target = PopPreviousSceneName(current);
|
||||
if (string.IsNullOrEmpty(target))
|
||||
{
|
||||
target = string.IsNullOrEmpty(backFallbackSceneName) ? "Main_main" : backFallbackSceneName;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(target) &&
|
||||
!string.Equals(target, current, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
StartCoroutine(LoadNavSceneAsync(target));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHomeNavClicked()
|
||||
{
|
||||
if (navSceneLoading) return;
|
||||
string target = string.IsNullOrEmpty(homeSceneName) ? "UI_UI" : homeSceneName;
|
||||
StartCoroutine(LoadNavSceneAsync(target));
|
||||
}
|
||||
|
||||
private void OnSettingsNavClicked()
|
||||
{
|
||||
ToggleSettingsPrefab();
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator LoadNavSceneAsync(string sceneName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sceneName)) yield break;
|
||||
if (navSceneLoading) yield break;
|
||||
|
||||
navSceneLoading = true;
|
||||
Time.timeScale = 1f;
|
||||
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
|
||||
while (op != null && !op.isDone)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
navSceneLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user