Example #1
0
        public static UI_Item CreateUIItem <UI_Item>(Transform parent) where UI_Item : UIItem
        {
            var type      = typeof(UI_Item);
            var container = UIPrefabDic[type];

            ABLoader.LoadAB(container);
            if (container.Bundle == null)
            {
                throw new NullReferenceException(string.Format("该路径下没有AB包: [{0}]", container.ABName));
            }
            var prefab = container.Bundle.LoadAsset <GameObject>(type.Name);

            if (prefab == null)
            {
                throw new NullReferenceException(string.Format("AB包中没有预制体:[{0}]", type.Name));
            }
            var itemObj = GameObject.Instantiate <GameObject>(prefab, parent, false);
            var ret     = itemObj.AddComponent <UI_Item>();

            UIObjectList.Add(ret);

            return(ret);
        }
Example #2
0
        public static UIItem CreateUIItem(Type type, Transform parent)
        {
//			if (!(type is UIItem))
//				throw new Exception("必须继承语UIItem");
            var container = UIPrefabDic[type];

            ABLoader.LoadAB(container);
            if (container.Bundle == null)
            {
                throw new NullReferenceException(string.Format("该路径下没有AB包: [{0}]", container.ABName));
            }
            var prefab = container.Bundle.LoadAsset <GameObject>(type.Name);

            if (prefab == null)
            {
                throw new NullReferenceException(string.Format("AB包中没有预制体:[{0}]", type.Name));
            }
            var itemObj = GameObject.Instantiate <GameObject>(prefab, parent, false);
            var ret     = itemObj.AddComponent(type) as UIItem;

            UIObjectList.Add(ret);

            return(ret);
        }