You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace HJDFrameWork
|
|
{
|
|
public class ViewManager : MonoSingleton<ViewManager>
|
|
{
|
|
[Header("已注册窗口类")]
|
|
public List<string> _registerList=new List<string>();
|
|
[HideInInspector]
|
|
public ViewModel _viewModel;
|
|
|
|
private Dictionary<string, ViewBase> ViewDict = new Dictionary<string, ViewBase>();
|
|
|
|
public void Init()
|
|
{
|
|
//查找->初始化
|
|
ViewBase[] views = GameObject.FindObjectsOfType<ViewBase>();
|
|
for (int i = 0; i < views.Length; i++)
|
|
{
|
|
views[i].Init();
|
|
}
|
|
//_viewModel = ViewModel.Instance;
|
|
//_viewModel.Init();
|
|
}
|
|
|
|
public T GetViewWnd<T>() where T:ViewBase
|
|
{
|
|
ViewBase view= null;
|
|
if(ViewDict.TryGetValue(typeof(T).Name,out view))
|
|
{
|
|
return view as T;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError(typeof(T).Name + "获取失败!");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void Register(string WndName,ViewBase viewBase)
|
|
{
|
|
if (!ViewDict.ContainsKey(WndName))
|
|
{
|
|
ViewDict.Add(WndName, viewBase);
|
|
_registerList.Add(WndName);
|
|
Debug.Log(WndName + "注册成功");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log(WndName+"已注册,请勿重复注册");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|