框架启动模式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class UIFrameFacade {
public void FrameStart() {
UIAssets.instance.LoadPanel("MainPanel");
UIManager.instance.PushPanel("MainPanel");
}
}public class UIAssets {
public static readonly UIAssets instance=new UIAssets();
private UIAssets() { }
public void LoadPanel(string panelName) {
Debug.Log(panelName+"资源已经加载完成!");
}
}public class UIManager {
public static readonly UIManager instance = new UIManager();
private UIManager() { }
public void PushPanel(string panelName) {
Debug.Log("已经打开窗口"+panelName);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class FacadeConsole : MonoBehaviour {
// Use this for initialization
void Start () {
//框架启动
UIFrameFacade facade = new UIFrameFacade();
facade.FrameStart();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;public class DemoWindowFacade : MonoBehaviour {
private Button[] buttons;
private void Awake()
{
buttons = GetComponentsInChildren<Button>();
}
public void BindEvent(UnityAction unityAction) {
for (int i=0;i<buttons.Length;i++) {
buttons[i].onClick.AddListener(unityAction);
}
}
}