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