技能主要更新,修复卡顿并加入动画,以及各种其他更新。
This commit is contained in:
@@ -16,6 +16,13 @@ public class btmandtopController : MonoBehaviour
|
||||
public Button email_display;
|
||||
public Button notice_display;
|
||||
|
||||
public Button button_Music;
|
||||
[Header("MusicPic")]
|
||||
public RectTransform musicPicRoot;
|
||||
public bool showMusicPicInUI = false;
|
||||
public string uiSceneName = "UI_UI";
|
||||
public float musicPicFadeTime = 0.25f;
|
||||
|
||||
[Header("sig prefabs")]
|
||||
public GameObject showLevel_prefab;
|
||||
public GameObject store_prefab;
|
||||
@@ -33,15 +40,37 @@ public class btmandtopController : MonoBehaviour
|
||||
|
||||
// cached reference to the settings instance to ensure only one exists
|
||||
private GameObject settingsInstance;
|
||||
private GameObject showLevelInstance;
|
||||
private GameObject emailInstance;
|
||||
private GameObject noticeInstance;
|
||||
private CanvasGroup musicPicGroup;
|
||||
private Coroutine musicPicFade;
|
||||
private bool musicPicVisible = true;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
EnsureMusicPicRoot();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (button_Music == null)
|
||||
{
|
||||
var btn = transform.Find("Button_Music") as RectTransform;
|
||||
if (btn != null)
|
||||
button_Music = btn.GetComponent<Button>();
|
||||
if (button_Music == null)
|
||||
{
|
||||
var any = FindByName("Button_Music");
|
||||
if (any != null) button_Music = any.GetComponent<Button>();
|
||||
}
|
||||
}
|
||||
instantiateSettings = () => ToggleSettingsPrefab();
|
||||
instantiateUserInfo = () => InstantiatePrefab(userInfo_prefab);
|
||||
instantiateStore = () => InstantiatePrefab(store_prefab);
|
||||
instantiateShowLevel = () => InstantiatePrefab(showLevel_prefab);
|
||||
instantiateEmail = () => InstantiatePrefab(email_prefab);
|
||||
instantiateNotice = () => InstantiatePrefab(notice_prefab);
|
||||
instantiateShowLevel = () => ShowLevelPrefab();
|
||||
instantiateEmail = () => ShowEmailPrefab();
|
||||
instantiateNotice = () => ShowNoticePrefab();
|
||||
|
||||
if (settings_launch != null)
|
||||
settings_launch.onClick.AddListener(instantiateSettings);
|
||||
@@ -56,6 +85,17 @@ public class btmandtopController : MonoBehaviour
|
||||
if (notice_display != null)
|
||||
notice_display.onClick.AddListener(instantiateNotice);
|
||||
|
||||
EnsureMusicPicRoot();
|
||||
SetupMusicPicDefault();
|
||||
if (button_Music != null)
|
||||
button_Music.onClick.AddListener(ToggleMusicPicLocal);
|
||||
|
||||
var binder = BgmUiBinder.Instance != null ? BgmUiBinder.Instance : Object.FindAnyObjectByType<BgmUiBinder>();
|
||||
if (binder != null && musicPicRoot != null)
|
||||
{
|
||||
binder.SetMusicRoot(musicPicRoot);
|
||||
}
|
||||
|
||||
// Pre-instantiate settings prefab and keep it inactive, ensuring only one exists
|
||||
if (settings_prefab != null && putPrefabsHere != null)
|
||||
{
|
||||
@@ -80,7 +120,7 @@ public class btmandtopController : MonoBehaviour
|
||||
Canvas c = settingsInstance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = GameObject.FindObjectsOfType<Camera>();
|
||||
Camera[] cams = Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
@@ -100,8 +140,160 @@ public class btmandtopController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
//ToggleSettingsPrefab();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ToggleMusicPic()
|
||||
{
|
||||
var binder = BgmUiBinder.Instance != null ? BgmUiBinder.Instance : Object.FindAnyObjectByType<BgmUiBinder>();
|
||||
if (binder != null)
|
||||
{
|
||||
binder.ToggleMusicPic();
|
||||
var spectrum = binder.GetSpectrumRoot();
|
||||
if (spectrum != null && binder.transform != null)
|
||||
{
|
||||
spectrum.localRotation = binder.transform.localRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureMusicPicRoot()
|
||||
{
|
||||
if (musicPicRoot != null)
|
||||
return;
|
||||
var child = transform.Find("MusicPic");
|
||||
if (child != null)
|
||||
{
|
||||
musicPicRoot = child as RectTransform;
|
||||
return;
|
||||
}
|
||||
var sceneMusic = GameObject.Find("MusicPic");
|
||||
if (sceneMusic != null)
|
||||
{
|
||||
musicPicRoot = sceneMusic.GetComponent<RectTransform>();
|
||||
if (musicPicRoot != null)
|
||||
{
|
||||
musicPicRoot.SetParent(transform, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupMusicPicDefault()
|
||||
{
|
||||
if (musicPicRoot == null)
|
||||
return;
|
||||
EnsureMusicPicGroup();
|
||||
SetMusicPicVisible(false, true);
|
||||
}
|
||||
|
||||
private void EnsureMusicPicGroup()
|
||||
{
|
||||
if (musicPicRoot == null)
|
||||
return;
|
||||
if (musicPicGroup == null)
|
||||
musicPicGroup = musicPicRoot.GetComponent<CanvasGroup>();
|
||||
if (musicPicGroup == null)
|
||||
musicPicGroup = musicPicRoot.gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
private void ToggleMusicPicLocal()
|
||||
{
|
||||
EnsureMusicPicRoot();
|
||||
var binder = BgmUiBinder.Instance != null ? BgmUiBinder.Instance : Object.FindAnyObjectByType<BgmUiBinder>();
|
||||
if (musicPicRoot == null)
|
||||
{
|
||||
if (binder != null)
|
||||
binder.ToggleMusicPic();
|
||||
return;
|
||||
}
|
||||
|
||||
SetMusicPicVisible(!musicPicVisible, false);
|
||||
}
|
||||
|
||||
private void SetMusicPicVisible(bool visible, bool instant)
|
||||
{
|
||||
if (musicPicRoot == null)
|
||||
return;
|
||||
EnsureMusicPicGroup();
|
||||
musicPicVisible = visible;
|
||||
|
||||
if (musicPicFade != null)
|
||||
{
|
||||
StopCoroutine(musicPicFade);
|
||||
musicPicFade = null;
|
||||
}
|
||||
|
||||
if (instant)
|
||||
{
|
||||
musicPicGroup.alpha = visible ? 1f : 0f;
|
||||
musicPicGroup.interactable = visible;
|
||||
musicPicGroup.blocksRaycasts = visible;
|
||||
musicPicRoot.gameObject.SetActive(visible);
|
||||
return;
|
||||
}
|
||||
|
||||
musicPicRoot.gameObject.SetActive(true);
|
||||
musicPicFade = StartCoroutine(FadeMusicPic(visible));
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator FadeMusicPic(bool visibleAtEnd)
|
||||
{
|
||||
EnsureMusicPicGroup();
|
||||
if (musicPicGroup == null)
|
||||
yield break;
|
||||
float start = musicPicGroup != null ? musicPicGroup.alpha : 0f;
|
||||
float target = visibleAtEnd ? 1f : 0f;
|
||||
float t = 0f;
|
||||
while (t < 1f)
|
||||
{
|
||||
if (musicPicGroup == null || musicPicRoot == null)
|
||||
yield break;
|
||||
t += Time.unscaledDeltaTime / Mathf.Max(0.0001f, musicPicFadeTime);
|
||||
float eased = Mathf.SmoothStep(0f, 1f, t);
|
||||
musicPicGroup.alpha = Mathf.LerpUnclamped(start, target, eased);
|
||||
yield return null;
|
||||
}
|
||||
if (musicPicGroup != null)
|
||||
{
|
||||
musicPicGroup.alpha = target;
|
||||
musicPicGroup.interactable = visibleAtEnd;
|
||||
musicPicGroup.blocksRaycasts = visibleAtEnd;
|
||||
}
|
||||
if (!visibleAtEnd && musicPicRoot != null)
|
||||
{
|
||||
musicPicRoot.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
GameObject FindByName(string name)
|
||||
{
|
||||
var all = Resources.FindObjectsOfTypeAll<Transform>();
|
||||
for (int i = 0; i < all.Length; i++)
|
||||
{
|
||||
var t = all[i];
|
||||
if (t == null) continue;
|
||||
if (!t.gameObject.scene.IsValid() || !t.gameObject.scene.isLoaded) continue;
|
||||
if (t.name == name) return t.gameObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (musicPicFade != null)
|
||||
{
|
||||
StopCoroutine(musicPicFade);
|
||||
musicPicFade = null;
|
||||
}
|
||||
musicPicGroup = null;
|
||||
if (settings_launch != null)
|
||||
settings_launch.onClick.RemoveListener(instantiateSettings);
|
||||
if (userInfo_launch != null)
|
||||
@@ -114,6 +306,9 @@ public class btmandtopController : MonoBehaviour
|
||||
email_display.onClick.RemoveListener(instantiateEmail);
|
||||
if (notice_display != null)
|
||||
notice_display.onClick.RemoveListener(instantiateNotice);
|
||||
|
||||
if (button_Music != null)
|
||||
button_Music.onClick.RemoveListener(ToggleMusicPicLocal);
|
||||
}
|
||||
|
||||
private void ToggleSettingsPrefab()
|
||||
@@ -131,7 +326,7 @@ public class btmandtopController : MonoBehaviour
|
||||
Canvas c = settingsInstance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = GameObject.FindObjectsOfType<Camera>();
|
||||
Camera[] cams = Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
@@ -151,6 +346,97 @@ public class btmandtopController : MonoBehaviour
|
||||
settingsInstance.SetActive(!active);
|
||||
}
|
||||
|
||||
private void ShowLevelPrefab()
|
||||
{
|
||||
ShowPrefab(showLevel_prefab, ref showLevelInstance);
|
||||
CloseInfoPanels(showLevelInstance);
|
||||
}
|
||||
|
||||
private void ShowEmailPrefab()
|
||||
{
|
||||
ShowPrefab(email_prefab, ref emailInstance);
|
||||
CloseInfoPanels(emailInstance);
|
||||
}
|
||||
|
||||
private void ShowNoticePrefab()
|
||||
{
|
||||
ShowPrefab(notice_prefab, ref noticeInstance);
|
||||
CloseInfoPanels(noticeInstance);
|
||||
}
|
||||
|
||||
private void ShowPrefab(GameObject prefab, ref GameObject instance)
|
||||
{
|
||||
if (prefab == null || putPrefabsHere == null) return;
|
||||
|
||||
if (instance == null)
|
||||
{
|
||||
instance = FindExistingInstance(prefab);
|
||||
if (instance == null)
|
||||
{
|
||||
instance = Instantiate(prefab, putPrefabsHere.transform);
|
||||
TryAssignCanvasCamera(instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
}
|
||||
}
|
||||
|
||||
instance.SetActive(true);
|
||||
instance.transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
private void CloseInfoPanels(GameObject keep)
|
||||
{
|
||||
CloseInstance(ref showLevelInstance, keep);
|
||||
CloseInstance(ref emailInstance, keep);
|
||||
CloseInstance(ref noticeInstance, keep);
|
||||
}
|
||||
|
||||
private void CloseInstance(ref GameObject instance, GameObject keep)
|
||||
{
|
||||
if (instance == null || instance == keep) return;
|
||||
instance.SetActive(false);
|
||||
}
|
||||
|
||||
private GameObject FindExistingInstance(GameObject prefab)
|
||||
{
|
||||
if (prefab == null || putPrefabsHere == null) return null;
|
||||
|
||||
Transform parent = putPrefabsHere.transform;
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
Transform child = parent.GetChild(i);
|
||||
if (child == null) continue;
|
||||
if (child.name == prefab.name || child.name == prefab.name + "(Clone)")
|
||||
{
|
||||
return child.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
GameObject existing = GameObject.Find(prefab.name + "(Clone)");
|
||||
return existing;
|
||||
}
|
||||
|
||||
private void TryAssignCanvasCamera(GameObject instance)
|
||||
{
|
||||
if (instance == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
Canvas c = instance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void InstantiatePrefab(GameObject prefab)
|
||||
{
|
||||
if (prefab != null && putPrefabsHere != null)
|
||||
|
||||
Reference in New Issue
Block a user