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.

61 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Level05;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace HJDFrameWork
{
/// <summary>
/// 此类用来获取到各个窗口的UI控件通过窗口类和控件名的函数
/// </summary>
public class ViewModel : MonoSingleton<ViewModel>
{
//将各UI字段写在这暴露在Unity方便使用
//public Image testImg;
public Text countDownTimeTxt;
public Button demo1OpenBtn;
public void Init()
{
//GetUI函数给UI字段赋值
//testImg=GetUI<TestWnd,Image>("Img02");
countDownTimeTxt = GetUI<ProjectTitle, Text>("timeTxt");
demo1OpenBtn = GetUI<Level05.CtrlWnd, Button>("OpenBtn");
}
//private void UIActionRgister()
//{
// ButtonAddlisten(demo1OpenBtn)
//}
/// <summary>
/// 获取UI控件的方法
/// </summary>
/// <typeparam name="T1">窗口类</typeparam>
/// <typeparam name="T2">控件类型</typeparam>
/// <param name="UIName">控件名</param>
/// <returns></returns>
private T2 GetUI<T1, T2>(string UIName) where T1 : ViewBase where T2 : UIBehaviour
{
T2 ui = ViewManager.Instance.GetViewWnd<T1>().GetViewData<T2>(UIName);
if (ui != null) return ui;
else
{
Debug.Log("获取" + typeof(T1).Name + "窗口的" + UIName + "失败");
return null;
}
}
}
}