### Unity MonoBehaviour Singleton - GameManager Example Source: https://qf.readthedocs.io/zh-cn/latest/QFramework_v1.0_Guide/03_toolkits/09_singletonkit Provides a basic MonoBehaviour singleton implementation for GameManager using MonoSingleton. It demonstrates overriding OnSingletonInit, Awake, Start, and OnDestroy methods to log lifecycle events. ```csharp public class GameManager : MonoSingleton { public override void OnSingletonInit() { Debug.Log(name + ":" + "OnSingletonInit"); } private void Awake() { Debug.Log(name + ":" + "Awake"); } private void Start() { Debug.Log(name + ":" + "Start"); } protected override void OnDestroy() { base.OnDestroy(); Debug.Log(name + ":" + "OnDestroy"); } } var gameManager = GameManager.Instance; // GameManager:OnSingletonInit // GameManager:Awake // GameManager:Start // ——————— // GameManager:OnDestroy ``` -------------------------------- ### Examples of Using UIKit.OpenPanel in C# Source: https://qf.readthedocs.io/zh-cn/latest/QFramework_v1.0_Guide/03_toolkits/06_uikit Provides practical examples of calling the UIKit.OpenPanel method with different arguments. These examples illustrate how to specify UI level, pass initial data, and load panels using a specific prefab name. ```csharp // 在 Forward 层级打开 UIKit.OpenPanel(UILevel.Forward); // 传递初始数据给 UIHomePanel UIKit.OpenPanel(new UIHomePanelData() { Coin = 10 }); // 从 UIHomePanelTest.prefab 加载界面 UIKit.OpenPanel(prefabName: "UIBasicPanel"); ``` -------------------------------- ### Asynchronous Initialization for WebGL in C# Source: https://qf.readthedocs.io/zh-cn/latest/QFramework_v1.0_Guide/03_toolkits/05_reskit Provides examples of how to asynchronously initialize the ResKit on WebGL platforms. This is crucial for handling asset loading efficiently in a web environment. ```csharp StartCoroutine(ResKit.InitAsync()); // 或者 ResKit.InitAsync().ToAction().StartGlobal(); ``` -------------------------------- ### Unity MonoBehaviour Singleton - AudioManager Example Source: https://qf.readthedocs.io/zh-cn/latest/QFramework_v1.0_Guide/03_toolkits/09_singletonkit Implements a MonoBehaviour-based singleton for AudioManager in Unity. It utilizes QMonoSingletonProperty for instance management and provides methods for playing and stopping sounds. The OnSingletonInit method is called upon initialization. ```csharp namespace QFramework.Example { [MonoSingletonPath("[Audio]/AudioManager")] public class AudioManager : ManagerBase,ISingleton { public static AudioManager Instance { get { return QMonoSingletonProperty.Instance; } } public void OnSingletonInit() { } public void Dispose() { QMonoSingletonProperty.Dispose(); } public void PlaySound(string soundName) { } public void StopSound(string soundName) { } } } ``` -------------------------------- ### C# Singleton - GameDataManager Example Source: https://qf.readthedocs.io/zh-cn/latest/QFramework_v1.0_Guide/03_toolkits/09_singletonkit Demonstrates a non-MonoBehaviour C# singleton implementation for GameDataManager. It uses a base Singleton class and overrides OnSingletonInit for initialization logic. The example shows how to log messages with an incrementing index. ```csharp public class GameDataManager : Singleton { private static int mIndex = 0; private Class2Singleton() {} public override void OnSingletonInit() { mIndex++; } public void Log(string content) { Debug.Log(""GameDataManager"" + mIndex + ":" + content); } } GameDataManager.Instance.Log("Hello"); // GameDataManager1:OnSingletonInit:Hello GameDataManager.Instance.Log("Hello"); // GameDataManager1:OnSingletonInit:Hello GameDataManager.Instance.Dispose(); ``` -------------------------------- ### QFramework.cs Example: CounterAppController Source: https://qf.readthedocs.io/zh-cn/latest/QFramework_v1.0_Guide/01_introduction/01_introduction This C# code snippet demonstrates a typical controller implementation within the QFramework.cs architecture, specifically for a CounterApp. It shows how to get models, find UI components, handle button clicks by sending commands, and update the view based on model changes. It adheres to the IController interface and unregisters listeners when the GameObject is destroyed. ```csharp namespace QFramework.Exmaple { public class CounterAppController : MonoBehaviour , IController { // Viewprivate Button mBtnAdd; private Button mBtnSub; private Text mCountText; // Modelprivate ICounterAppModel mModel; void Start() { // 获取模型 mModel = this.GetModel(); // View 组件获取 mBtnAdd = transform.Find("BtnAdd").GetComponent