成就系统 巨大修改 新的ui 黑白效果 等一堆
This commit is contained in:
@@ -31,9 +31,12 @@ public class btmandtopController : MonoBehaviour
|
||||
private UnityAction instantiateEmail;
|
||||
private UnityAction instantiateNotice;
|
||||
|
||||
// cached reference to the settings instance to ensure only one exists
|
||||
private GameObject settingsInstance;
|
||||
|
||||
void Start()
|
||||
{
|
||||
instantiateSettings = () => InstantiatePrefab(settings_prefab);
|
||||
instantiateSettings = () => ToggleSettingsPrefab();
|
||||
instantiateUserInfo = () => InstantiatePrefab(userInfo_prefab);
|
||||
instantiateStore = () => InstantiatePrefab(store_prefab);
|
||||
instantiateShowLevel = () => InstantiatePrefab(showLevel_prefab);
|
||||
@@ -52,6 +55,49 @@ public class btmandtopController : MonoBehaviour
|
||||
email_display.onClick.AddListener(instantiateEmail);
|
||||
if (notice_display != null)
|
||||
notice_display.onClick.AddListener(instantiateNotice);
|
||||
|
||||
// Pre-instantiate settings prefab and keep it inactive, ensuring only one exists
|
||||
if (settings_prefab != null && putPrefabsHere != null)
|
||||
{
|
||||
// Try to find existing one in scene first
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
var existing = GameObject.Find(settings_prefab.name + "(Clone)");
|
||||
if (existing != null)
|
||||
{
|
||||
settingsInstance = existing;
|
||||
}
|
||||
}
|
||||
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
|
||||
settingsInstance.SetActive(false);
|
||||
|
||||
// try to set canvas camera now as in previous behavior
|
||||
try
|
||||
{
|
||||
Canvas c = settingsInstance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = GameObject.FindObjectsOfType<Camera>();
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
}
|
||||
cams = null;
|
||||
c = null;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else
|
||||
{
|
||||
// ensure it's parented correctly under putPrefabsHere
|
||||
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
settingsInstance.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
@@ -70,11 +116,47 @@ public class btmandtopController : MonoBehaviour
|
||||
notice_display.onClick.RemoveListener(instantiateNotice);
|
||||
}
|
||||
|
||||
private void ToggleSettingsPrefab()
|
||||
{
|
||||
if (settings_prefab == null || putPrefabsHere == null) return;
|
||||
|
||||
// If we don't have an instance (it may have been destroyed), instantiate one
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
|
||||
|
||||
// attempt to set canvas camera
|
||||
try
|
||||
{
|
||||
Canvas c = settingsInstance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = GameObject.FindObjectsOfType<Camera>();
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
}
|
||||
cams = null;
|
||||
c = null;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
settingsInstance.SetActive(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Toggle active state
|
||||
bool active = settingsInstance.activeSelf;
|
||||
settingsInstance.SetActive(!active);
|
||||
}
|
||||
|
||||
private void InstantiatePrefab(GameObject prefab)
|
||||
{
|
||||
if (prefab != null && putPrefabsHere != null)
|
||||
{
|
||||
Instantiate(prefab, putPrefabsHere.transform);
|
||||
GameObject instance = Instantiate(prefab, putPrefabsHere.transform);
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user