主界面添加,许多bug修复。祝贺黑盒1如期开始
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public static class UISystemBootstrap
|
||||
{
|
||||
private const string defaultConfigPath = "UISoundConfig_Default";
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||||
static void Init()
|
||||
{
|
||||
CreateRouterIfNeeded();
|
||||
RegisterAll();
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
RegisterAll();
|
||||
}
|
||||
|
||||
static void CreateRouterIfNeeded()
|
||||
{
|
||||
UISoundRouter router;
|
||||
if (UISoundRouter.Instance != null)
|
||||
{
|
||||
router = UISoundRouter.Instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject go = new GameObject("UISoundRouter");
|
||||
router = go.AddComponent<UISoundRouter>();
|
||||
Object.DontDestroyOnLoad(go);
|
||||
}
|
||||
|
||||
var config = Resources.Load<UISoundConfig>(defaultConfigPath);
|
||||
if (config != null)
|
||||
{
|
||||
router.SetConfig(config);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("UISoundConfig not found in Resources at: " + defaultConfigPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterAll()
|
||||
{
|
||||
Debug.Log("RegisterButtons Called");
|
||||
|
||||
// Find all Selectable objects (includes Button, Toggle, Slider, etc.)
|
||||
Selectable[] selectables = Object.FindObjectsOfType<Selectable>(true);
|
||||
|
||||
foreach (var sel in selectables)
|
||||
{
|
||||
Register(sel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterHierarchy(GameObject root)
|
||||
{
|
||||
if (root == null) return;
|
||||
Selectable[] selectables = root.GetComponentsInChildren<Selectable>(true);
|
||||
foreach (var sel in selectables)
|
||||
{
|
||||
Register(sel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Register(Selectable sel)
|
||||
{
|
||||
if (sel == null) return;
|
||||
if (sel.GetComponent<UIButtonInteraction>() == null)
|
||||
{
|
||||
sel.gameObject.AddComponent<UIButtonInteraction>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user