少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 11997ece0dc4980eba3dd8889d37adb8376e14cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//--------------------------------------------------------
//    [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);
        }
 
    }
 
}