using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using UnityEngine;
|
|
/// <summary>
|
/// 扩展函数,主要为调用泛型方式做性能优化
|
/// </summary>
|
public static class ILExtension
|
{
|
|
#region 主项目相关
|
public static T GetWidgtEx<T>(this WidgetBehavior mono, string name) where T : Component
|
{
|
var cp = mono.GetWidgt(typeof(T), name);
|
return (T)cp;
|
}
|
|
//不能在preopen中调用,会是null
|
public static T GetILBehaviour<T>(this Component cp) where T : ILBehaviour
|
{
|
return cp.gameObject.GetILBehaviour<T>();
|
}
|
|
public static T GetILBehaviour<T>(this GameObject go) where T : ILBehaviour
|
{
|
var proxy = go.GetComponentEx<ILBehaviourProxy>();
|
if (proxy == null)
|
return default(T);
|
var type = typeof(T);
|
var bh = proxy.GetILBehaviour(type.FullName);
|
if (bh == null || !type.IsInstanceOfType(bh))
|
return default(T);
|
return (T)bh;
|
}
|
|
public static T GetModelEx<T>(this ModelCenter center) where T : Model
|
{
|
var model = center.GetModel(typeof(T));
|
return (T)model;
|
}
|
|
public static T GetEx<T>(this WindowCenter center) where T : Window
|
{
|
var win = center.Get(typeof(T).Name);
|
return (T)win;
|
}
|
|
public static void OpenFromLocalEx<T>(this WindowCenter center) where T : Window
|
{
|
center.OpenFromLocal(typeof(T).Name);
|
}
|
|
public static void OpenEx<T>(this WindowCenter center, bool forceSync = false, int functionOrder = 0) where T : Window
|
{
|
center.Open(typeof(T).Name, forceSync, functionOrder);
|
}
|
|
public static void OpenIL<T>(this WindowCenter center, bool forceSync = false, int functionOrder = 0) where T : ILWindow
|
{
|
center.Open(typeof(T).Name, forceSync, functionOrder);
|
}
|
|
public static void CloseIL<T>(this WindowCenter center) where T : ILWindow
|
{
|
center.Close(typeof(T).Name);
|
}
|
|
public static void CloseEx<T>(this WindowCenter center) where T : Window
|
{
|
center.Close(typeof(T).Name);
|
}
|
|
public static bool IsOpenEx<T>(this WindowCenter center) where T : Window
|
{
|
return center.IsOpen(typeof(T).Name);
|
}
|
|
#endregion
|
|
#region Unity 相关
|
|
public static T GetComponentEx<T>(this Component component) where T : Component
|
{
|
var cp = component.GetComponent(typeof(T));
|
return (T)cp;
|
}
|
|
public static T AddComponentEx<T>(this GameObject go) where T : Component
|
{
|
var cp = go.AddComponent(typeof(T));
|
return (T)cp;
|
}
|
|
public static T GetComponentEx<T>(this GameObject go) where T : Component
|
{
|
var cp = go.GetComponent(typeof(T));
|
return (T)cp;
|
}
|
|
public static T GetComponentInParentEx<T>(this Component component) where T : Component
|
{
|
var cp = component.GetComponentInParent(typeof(T));
|
return (T)cp;
|
}
|
|
public static T GetComponentInParentEx<T>(this GameObject go) where T : Component
|
{
|
var cp = go.GetComponentInParent(typeof(T));
|
return (T)cp;
|
}
|
|
public static T FindComponentEx<T>(this Component cp, string path) where T : Component
|
{
|
var child = cp.transform.Find(path);
|
var childCp = child.GetComponentEx<T>();
|
return (T)childCp;
|
}
|
|
//效果同c#底层的ComponentExtersion SetActive
|
public static void SetActiveIL(this Component cp, bool state)
|
{
|
if (cp == null) return;
|
|
if (cp.gameObject.activeSelf != state)
|
{
|
cp.gameObject.SetActive(state);
|
}
|
}
|
|
#endregion
|
|
}
|