//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, March 19, 2019
|
//--------------------------------------------------------
|
using UnityEngine;
|
|
[ExecuteAlways]
|
[RequireComponent(typeof(RectTransform))]
|
public class UIPrefabLoader : MonoBehaviour
|
{
|
[SerializeField] protected string m_PrefabName;
|
public virtual string prefabName { get { return m_PrefabName; } }
|
|
protected GameObject instance;
|
|
[ExecuteAlways]
|
private void Awake()
|
{
|
Create();
|
}
|
public void Reload()
|
{
|
instance = null;
|
this.transform.ClearAllChilds();
|
Create();
|
}
|
|
[ContextMenu("Create")]
|
public virtual void Create()
|
{
|
if (instance != null)
|
return;
|
|
if (string.IsNullOrEmpty(prefabName))
|
return;
|
|
var find = this.transform.Find(prefabName);
|
if (find)
|
{
|
instance = find.gameObject;
|
return;
|
}
|
instance = UIUtility.CreateWidget(prefabName, prefabName);
|
instance.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
|
}
|