/// <summary> /// 创建VIEW /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent">父节点,当创建子View的时候为必填</param> /// <returns></returns> public BaseUIView CreateView <T>(Transform parent) { BaseUIView uiView = Activator.CreateInstance(typeof(T)) as BaseUIView; //获取UIViewDataAttribute特性 var attr = (UIViewDataAttribute)typeof(T).GetCustomAttributes(typeof(UIViewDataAttribute), true).FirstOrDefault(); if (attr != null) { GameObject uiGameObject = uiGameObject = parent.Find(attr.loadPath).gameObject; if (uiGameObject == null) { LWDebug.LogError("没有找到这个UI对象" + attr.loadPath); } //初始化UI uiView.CreateView(uiGameObject); } else { LWDebug.Log("没有找到UIViewDataAttribute这个特性"); } LWDebug.Log("UIManager:" + typeof(T).ToString()); return(uiView); }
/// <summary> /// 创建一个VIEW /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public BaseUIView CreateView <T>() { BaseUIView uiView = Activator.CreateInstance(typeof(T)) as BaseUIView; //获取UIViewDataAttribute特性 var attr = (UIViewDataAttribute)typeof(T).GetCustomAttributes(typeof(UIViewDataAttribute), true).FirstOrDefault(); if (attr != null) { GameObject uiGameObject = null; //创建UI对象 uiGameObject = UIUtility.Instance.CreateViewEntity(attr.loadPath); Transform parent = GetParent(attr.findType, attr.param); if (uiGameObject == null) { LWDebug.LogError("没有找到这个UI对象" + attr.loadPath); } if (parent == null) { LWDebug.LogError("没有找到这个UI父节点" + attr.param); } if (parent != null) { uiGameObject.transform.SetParent(parent, false); } //初始化UI uiView.CreateView(uiGameObject); } else { LWDebug.Log("没有找到UIViewDataAttribute这个特性"); } LWDebug.Log("UIManager:" + typeof(T).ToString()); return(uiView); }