UI换了很多,spine主视觉停用
This commit is contained in:
@@ -49,6 +49,8 @@ public class BgmUiBinder : MonoBehaviour
|
||||
public string gameplaySceneName = "gamePlay_gamePlay";
|
||||
[Tooltip("Main menu scene name where spectrum should be hidden.")]
|
||||
public string mainSceneName = "Main_main";
|
||||
[Tooltip("Startup/EULA scene name where spectrum should be hidden.")]
|
||||
public string beforeEverythingSceneName = "beforeEverything";
|
||||
public bool hideSpectrumInMainScene = true;
|
||||
public float musicPicFadeDuration = 0.3f;
|
||||
public bool useUnscaledTime = true;
|
||||
@@ -93,15 +95,15 @@ public class BgmUiBinder : MonoBehaviour
|
||||
}
|
||||
|
||||
private string _cachedGameplaySceneName;
|
||||
private bool _isGameplayScene;
|
||||
private bool _spectrumHiddenInGameplay = false;
|
||||
private bool _shouldHideSpectrumForCurrentScene;
|
||||
private bool _spectrumHiddenForCurrentScene = false;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
_cachedGameplaySceneName = gameplaySceneName;
|
||||
_isGameplayScene = SceneManager.GetActiveScene().name == _cachedGameplaySceneName;
|
||||
_spectrumHiddenInGameplay = false;
|
||||
_shouldHideSpectrumForCurrentScene = ShouldHideSpectrumInScene(SceneManager.GetActiveScene().name);
|
||||
_spectrumHiddenForCurrentScene = false;
|
||||
_buttonsBound = false;
|
||||
Bind();
|
||||
ApplyDefaultMusicPicVisibility(SceneManager.GetActiveScene().name);
|
||||
@@ -109,7 +111,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
{
|
||||
var mgr = BgmPlaybackManager.EnsureInstance();
|
||||
if (outputMixerGroup != null)
|
||||
mgr.outputMixerGroup = outputMixerGroup;
|
||||
mgr.SetOutputMixerGroup(outputMixerGroup);
|
||||
mgr.EnsurePlaying();
|
||||
}
|
||||
}
|
||||
@@ -121,8 +123,8 @@ public class BgmUiBinder : MonoBehaviour
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
_isGameplayScene = scene.name == _cachedGameplaySceneName;
|
||||
_spectrumHiddenInGameplay = false;
|
||||
_shouldHideSpectrumForCurrentScene = ShouldHideSpectrumInScene(scene.name);
|
||||
_spectrumHiddenForCurrentScene = false;
|
||||
_buttonsBound = false;
|
||||
Bind();
|
||||
ApplyDefaultMusicPicVisibility(scene.name);
|
||||
@@ -134,10 +136,15 @@ public class BgmUiBinder : MonoBehaviour
|
||||
hasExplicitMusicRoot = false;
|
||||
|
||||
Canvas sceneCanvas = FindSceneCanvas();
|
||||
var controller = Object.FindAnyObjectByType<btmandtopController>();
|
||||
var controller = SceneObjectLookupCache.FindAny<btmandtopController>();
|
||||
if (controller != null && controller.bgmMixerGroup != null)
|
||||
{
|
||||
outputMixerGroup = controller.bgmMixerGroup;
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
var mgr = BgmPlaybackManager.Instance ?? BgmPlaybackManager.EnsureInstance();
|
||||
mgr.SetOutputMixerGroup(outputMixerGroup);
|
||||
}
|
||||
}
|
||||
|
||||
if (controller != null && controller.musicPicRoot != null)
|
||||
@@ -146,7 +153,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
RectTransform persistentMusic = null;
|
||||
var persistentCanvasGo = GameObject.Find(musicPicCanvasName);
|
||||
var persistentCanvasGo = SceneObjectLookupCache.Find(musicPicCanvasName);
|
||||
if (!keepMusicPicAcrossScenes && persistentCanvasGo != null)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
@@ -202,7 +209,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
|
||||
if (musicRoot == null)
|
||||
{
|
||||
var canvas = Object.FindAnyObjectByType<Canvas>();
|
||||
var canvas = SceneObjectLookupCache.FindAny<Canvas>();
|
||||
if (canvas != null)
|
||||
musicRoot = canvas.GetComponent<RectTransform>();
|
||||
}
|
||||
@@ -332,7 +339,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
}
|
||||
if (timeRoot == null)
|
||||
{
|
||||
var timeGo = GameObject.Find(timeRootName);
|
||||
var timeGo = SceneObjectLookupCache.Find(timeRootName);
|
||||
if (timeGo != null) timeRoot = timeGo.transform;
|
||||
}
|
||||
|
||||
@@ -385,16 +392,17 @@ public class BgmUiBinder : MonoBehaviour
|
||||
}
|
||||
|
||||
private bool _buttonsBound = false;
|
||||
private string _cachedMusicRootNameNormalized;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
return;
|
||||
|
||||
if (_isGameplayScene && !_spectrumHiddenInGameplay)
|
||||
if (_shouldHideSpectrumForCurrentScene && !_spectrumHiddenForCurrentScene)
|
||||
{
|
||||
HideSpectrumInGameplay(_cachedGameplaySceneName);
|
||||
_spectrumHiddenInGameplay = true;
|
||||
HideSpectrumInGameplay(SceneManager.GetActiveScene().name);
|
||||
_spectrumHiddenForCurrentScene = true;
|
||||
}
|
||||
|
||||
if (!_buttonsBound)
|
||||
@@ -583,6 +591,9 @@ public class BgmUiBinder : MonoBehaviour
|
||||
private GameObject FindByNameContains(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return null;
|
||||
string target = name.Replace(" ", "");
|
||||
var exact = SceneObjectLookupCache.Find(name);
|
||||
if (exact != null) return exact;
|
||||
var all = Object.FindObjectsByType<Transform>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
for (int i = 0; i < all.Length; i++)
|
||||
{
|
||||
@@ -590,7 +601,6 @@ public class BgmUiBinder : MonoBehaviour
|
||||
if (t == null) continue;
|
||||
if (!t.gameObject.scene.IsValid() || !t.gameObject.scene.isLoaded) continue;
|
||||
var n = t.name.Replace(" ", "");
|
||||
var target = name.Replace(" ", "");
|
||||
if (n.Contains(target))
|
||||
return t.gameObject;
|
||||
}
|
||||
@@ -693,7 +703,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
return;
|
||||
|
||||
var currentCanvas = musicRoot.GetComponentInParent<Canvas>();
|
||||
var persistent = GameObject.Find(musicPicCanvasName);
|
||||
var persistent = SceneObjectLookupCache.Find(musicPicCanvasName);
|
||||
Canvas persistentCanvas = null;
|
||||
if (persistent == null)
|
||||
{
|
||||
@@ -774,7 +784,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
if (musicRoot != null && hasExplicitMusicRoot)
|
||||
SetMusicPicVisible(shouldShow, true);
|
||||
|
||||
if (sceneName == "gamePlay_gamePlay")
|
||||
if (ShouldHideSpectrumInScene(sceneName))
|
||||
{
|
||||
CleanupSpectrumRoots(true);
|
||||
HideSpectrumInGameplay(sceneName);
|
||||
@@ -884,8 +894,7 @@ public class BgmUiBinder : MonoBehaviour
|
||||
|
||||
private void HideSpectrumInGameplay(string sceneName)
|
||||
{
|
||||
bool shouldHide = sceneName == gameplaySceneName ||
|
||||
(hideSpectrumInMainScene && sceneName == mainSceneName);
|
||||
bool shouldHide = ShouldHideSpectrumInScene(sceneName);
|
||||
if (!shouldHide) return;
|
||||
|
||||
var all = Resources.FindObjectsOfTypeAll<RectTransform>();
|
||||
@@ -908,6 +917,23 @@ public class BgmUiBinder : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldHideSpectrumInScene(string sceneName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sceneName))
|
||||
return false;
|
||||
|
||||
if (string.Equals(sceneName, gameplaySceneName, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
|
||||
if (hideSpectrumInMainScene && string.Equals(sceneName, mainSceneName, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
|
||||
if (string.Equals(sceneName, beforeEverythingSceneName, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator ShowLobbyMusicPicNextFrame()
|
||||
{
|
||||
int tries = 0;
|
||||
@@ -956,3 +982,4 @@ public class BgmUiBinder : MonoBehaviour
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user