using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/**
* 单例类,创建或者销毁窗体
*/
public class UIWindowManager {
private static UIWindowManager windowMag;
private static Dictionary<string, GameObject> windowCache = new Dictionary<string, GameObject>();
public static UIWindowManager GetInstance() {
if (windowMag == null) {
windowMag = new UIWindowManager();
}
return windowMag;
}
public GameObject OpenWindow(string windowName) {
if (windowCache.ContainsKey(windowName)) {
CloseWindow(windowName);
return null;
}
GameObject windowObject = Resources.Load(windowName) as GameObject;
GameObject prefabClone = GameObject.Instantiate(windowObject);
prefabClone.transform.parent = UIRoot.list[0].transform;
prefabClone.transform.localPosition = Vector3.zero;
prefabClone.transform.localScale = Vector3.one;
windowCache.Add(windowName, prefabClone);
return prefabClone;
}
public void CloseWindow(string windowName) {
if (windowCache.ContainsKey(windowName)) {
// Debug.Log(windowName);
GameObject.Destroy(windowCache[windowName]);
windowCache.Remove(windowName);
}
}
}