拼ui 一些业务逻辑x实现

This commit is contained in:
FloatGaming
2026-03-19 06:15:09 +08:00
parent f5c6f143c0
commit 49e45ac464
1118 changed files with 246518 additions and 5368 deletions
@@ -4986,7 +4986,7 @@ MonoBehaviour:
showLevel_prefab: {fileID: 775714823646948286, guid: 4c26aec0fc471c24d94487eff6821e14, type: 3}
store_prefab: {fileID: 3878406062860244594, guid: d94caf56bd6dff64fa606eeeb6e06fa9, type: 3}
settings_prefab: {fileID: 4801108313180107556, guid: 8db6dd820b152984980f7fd2124138c3, type: 3}
userInfo_prefab: {fileID: 0}
userInfo_prefab: {fileID: 5155954718781159675, guid: 18f4d2367ef2dff429599f1580fd6bad, type: 3}
email_prefab: {fileID: 3756075665884320709, guid: 41f4ea31b64f18d48aeef21b79930a6c, type: 3}
notice_prefab: {fileID: 8527835049849151044, guid: 06bb6d3a45697374ab4f5ff36356d138, type: 3}
back_navButton: {fileID: 0}
@@ -10,6 +10,11 @@ using Steamworks;
public class btmandtopController : MonoBehaviour, ICancelHandler
{
public static event System.Action<bool> GlobalSettingsVisibilityChanged;
public static bool CurrentSettingsVisible { get; private set; }
public event System.Action<bool> SettingsVisibilityChanged;
[Header("player unique so")]
public Player_SO player_SO;
public Text playerCoins_legacy;
@@ -98,6 +103,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
// cached reference to the settings instance to ensure only one exists
private GameObject settingsInstance;
private GameObject userInfoInstance;
private GameObject storeInstance;
private GameObject showLevelInstance;
private GameObject emailInstance;
@@ -106,6 +112,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
private Coroutine musicPicFade;
private bool musicPicVisible = true;
private bool navSceneLoading = false;
private bool lastSettingsVisibilityState;
private readonly Dictionary<string, int> guideIndexByScene = new Dictionary<string, int>();
private string currentGuideScene = string.Empty;
@@ -137,7 +144,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
}
}
instantiateSettings = () => ToggleSettingsPrefab();
instantiateUserInfo = () => { gNotice.recommendation.display("功能即将上线,敬请期待"); };
instantiateUserInfo = () => ToggleUserInfoPrefab();
instantiateStore = () => ShowStorePrefab();
instantiateShowLevel = () => { gNotice.error.display("功能即将下线,禁止访问"); };
// instantiateShowLevel = () => ShowLevelPrefab();
@@ -202,6 +209,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
{
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
EnsureSettingsEnterAnimator(settingsInstance);
EnsureSettingsLastSibling();
settingsInstance.SetActive(false);
// try to set canvas camera now as in previous behavior
@@ -225,10 +233,39 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
{
// ensure it's parented correctly under putPrefabsHere
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
EnsureSettingsLastSibling();
EnsureSettingsEnterAnimator(settingsInstance);
settingsInstance.SetActive(false);
}
}
if (userInfo_prefab != null && putPrefabsHere != null)
{
if (userInfoInstance == null)
{
var existing = GameObject.Find(userInfo_prefab.name + "(Clone)");
if (existing != null)
{
userInfoInstance = existing;
}
}
if (userInfoInstance == null)
{
userInfoInstance = Instantiate(userInfo_prefab, putPrefabsHere.transform);
TryAssignCanvasCamera(userInfoInstance);
PlacePanelBelowSettings(userInfoInstance);
userInfoInstance.SetActive(false);
}
else
{
userInfoInstance.transform.SetParent(putPrefabsHere.transform, false);
PlacePanelBelowSettings(userInfoInstance);
userInfoInstance.SetActive(false);
}
}
lastSettingsVisibilityState = IsSettingsPanelVisible;
}
@@ -240,6 +277,26 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
}
}
private void Update()
{
if (!IsUiUiSceneActive())
{
if (CurrentSettingsVisible)
{
BroadcastSettingsVisibility(false);
}
return;
}
bool visible = IsSettingsPanelVisible;
if (visible == lastSettingsVisibilityState)
{
return;
}
BroadcastSettingsVisibility(visible);
}
private void ToggleMusicPic()
@@ -581,6 +638,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
{
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
EnsureSettingsEnterAnimator(settingsInstance);
EnsureSettingsLastSibling();
// attempt to set canvas camera
try
@@ -600,43 +658,111 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
catch { }
settingsInstance.SetActive(true);
EnsureSettingsLastSibling();
BroadcastSettingsVisibility(true);
return;
}
EnsureSettingsEnterAnimator(settingsInstance);
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
EnsureSettingsLastSibling();
// Toggle active state
bool active = settingsInstance.activeSelf;
settingsInstance.SetActive(!active);
if (settingsInstance.activeSelf)
{
EnsureSettingsLastSibling();
}
BroadcastSettingsVisibility(settingsInstance.activeSelf);
}
public bool IsSettingsPanelVisible
{
get { return settingsInstance != null && settingsInstance.activeInHierarchy; }
}
private void ToggleUserInfoPrefab()
{
if (userInfo_prefab == null || putPrefabsHere == null) return;
if (userInfoInstance == null)
{
userInfoInstance = Instantiate(userInfo_prefab, putPrefabsHere.transform);
TryAssignCanvasCamera(userInfoInstance);
PlacePanelBelowSettings(userInfoInstance);
userInfoInstance.SetActive(true);
return;
}
userInfoInstance.transform.SetParent(putPrefabsHere.transform, false);
userInfoInstance.SetActive(!userInfoInstance.activeSelf);
if (userInfoInstance.activeSelf)
{
PlacePanelBelowSettings(userInfoInstance);
}
}
private void BroadcastSettingsVisibility(bool visible)
{
lastSettingsVisibilityState = visible;
if (CurrentSettingsVisible == visible)
{
SettingsVisibilityChanged?.Invoke(visible);
return;
}
CurrentSettingsVisible = visible;
SettingsVisibilityChanged?.Invoke(visible);
GlobalSettingsVisibilityChanged?.Invoke(visible);
}
private bool IsUiUiSceneActive()
{
string sceneName = SceneManager.GetActiveScene().name;
string targetScene = string.IsNullOrWhiteSpace(uiSceneName) ? "UI_UI" : uiSceneName;
return string.Equals(sceneName, targetScene, System.StringComparison.OrdinalIgnoreCase);
}
private void ShowLevelPrefab()
{
ShowPrefab(showLevel_prefab, ref showLevelInstance);
CloseInfoPanels(showLevelInstance);
bool opened = ShowPrefab(showLevel_prefab, ref showLevelInstance);
if (opened)
{
CloseInfoPanels(showLevelInstance);
}
}
private void ShowStorePrefab()
{
ShowPrefab(store_prefab, ref storeInstance);
CloseInfoPanels(storeInstance);
bool opened = ShowPrefab(store_prefab, ref storeInstance);
if (opened)
{
CloseInfoPanels(storeInstance);
}
}
private void ShowEmailPrefab()
{
ShowPrefab(email_prefab, ref emailInstance);
CloseInfoPanels(emailInstance);
bool opened = ShowPrefab(email_prefab, ref emailInstance);
if (opened)
{
CloseInfoPanels(emailInstance);
}
}
private void ShowNoticePrefab()
{
ShowPrefab(notice_prefab, ref noticeInstance);
CloseInfoPanels(noticeInstance);
bool opened = ShowPrefab(notice_prefab, ref noticeInstance);
if (opened)
{
CloseInfoPanels(noticeInstance);
}
}
private void ShowPrefab(GameObject prefab, ref GameObject instance)
private bool ShowPrefab(GameObject prefab, ref GameObject instance)
{
if (prefab == null || putPrefabsHere == null) return;
if (prefab == null || putPrefabsHere == null) return false;
if (instance == null)
{
@@ -652,8 +778,48 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
}
}
instance.SetActive(true);
instance.transform.SetAsLastSibling();
bool shouldOpen = !instance.activeSelf;
instance.SetActive(shouldOpen);
if (!shouldOpen)
{
return false;
}
PlacePanelBelowSettings(instance);
return true;
}
private void EnsureSettingsLastSibling()
{
if (settingsInstance == null || putPrefabsHere == null)
{
return;
}
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
settingsInstance.transform.SetAsLastSibling();
}
private void PlacePanelBelowSettings(GameObject instance)
{
if (instance == null || putPrefabsHere == null)
{
return;
}
instance.transform.SetParent(putPrefabsHere.transform, false);
if (settingsInstance == null || instance == settingsInstance)
{
instance.transform.SetAsLastSibling();
return;
}
EnsureSettingsLastSibling();
int settingsIndex = settingsInstance.transform.GetSiblingIndex();
int targetIndex = Mathf.Clamp(settingsIndex, 0, putPrefabsHere.transform.childCount - 1);
instance.transform.SetSiblingIndex(targetIndex);
EnsureSettingsLastSibling();
}
private void CloseInfoPanels(GameObject keep)
@@ -11,7 +11,12 @@ public class loadtopandbottomPrefab: MonoBehaviour
{
if (top_and_bottom_Panel != null && gameobject_to_Instantiate_below != null)
{
GameObject instantiated = Instantiate(top_and_bottom_Panel, gameobject_to_Instantiate_below.transform);
GameObject instantiated = FindExistingPanelInstance();
if (instantiated == null)
{
instantiated = Instantiate(top_and_bottom_Panel, gameobject_to_Instantiate_below.transform);
}
Canvas canvas = instantiated.GetComponent<Canvas>();
if (canvas != null)
{
@@ -30,6 +35,34 @@ public class loadtopandbottomPrefab: MonoBehaviour
}
}
GameObject FindExistingPanelInstance()
{
if (gameobject_to_Instantiate_below == null || top_and_bottom_Panel == null)
{
return null;
}
string prefabName = top_and_bottom_Panel.name;
Transform parent = gameobject_to_Instantiate_below.transform;
for (int i = 0; i < parent.childCount; i++)
{
Transform child = parent.GetChild(i);
if (child == null)
{
continue;
}
bool nameMatches = child.name == prefabName || child.name == prefabName + "(Clone)";
bool hasBars = child.Find("TOP") != null || child.Find("BTM") != null;
if (nameMatches && hasBars)
{
return child.gameObject;
}
}
return null;
}
void Bind_Main_Panel(GameObject instantiated)
{
if (instantiated == null)