Пример #1
0
        //  ==============================================================
        public GameObject instantiatePrefab(PrefbasAssets.PrefabAssetsConstant prefabAssetsConstant, bool isCachePrefabObj)
        {
            GameObject tempGo = null;

            //  先从缓存池中拿 一般窗体的 prefabGameobj 都是不缓存的,获取后,内存直接管理 instane 不需要重复实例化
            tempGo = getGoFromCachePool(prefabAssetsConstant);

            //  没有缓存过
            if (tempGo == null)
            {
                //  配置文件中是否有这个路径
                if (_prefabMapping.ContainsKey(prefabAssetsConstant))
                {
                    string prefabPath = _prefabMapping[prefabAssetsConstant];

                    //  加载prefabGameobj
                    tempGo = Resources.Load <GameObject>(prefabPath);

                    if (tempGo == null)
                    {
                        throw new System.Exception("prefabPath = " + prefabPath + ", is null!");
                    }

                    //  缓存
                    if (isCachePrefabObj)
                    {
                        _cachedGameObjByPrefabClazzMapping[prefabAssetsConstant] = tempGo;
                    }
                }
            }

            return(tempGo == null ? null : GameObject.Instantiate(tempGo) as GameObject);
        }
Пример #2
0
 private GameObject getGoFromCachePool(PrefbasAssets.PrefabAssetsConstant prefabAssetsConstant)
 {
     if (_cachedGameObjByPrefabClazzMapping.ContainsKey(prefabAssetsConstant))
     {
         return(_cachedGameObjByPrefabClazzMapping[prefabAssetsConstant]);
     }
     return(null);
 }
Пример #3
0
        public void Start()
        {
            BMC.getObserverBehaviour().registerMsg(this);

            RectTransform canvasRt = uiCanvas.GetComponent <RectTransform>();

            Array uiLayerEnumArr = Enum.GetValues(typeof(UIConstant.UILayerType));     // ? 这个类 需要自动生成

            PrefbasAssets.PrefabAssetsConstant uiEmptyContainer = PrefbasAssets.PrefabAssetsConstant.UI_EMPTY_CONTAINER;

            foreach (UIConstant.UILayerType item in uiLayerEnumArr)
            {
                GameObject windowContainer = BMC.getPrefabsBehaviour().instantiatePrefab(uiEmptyContainer, true);

                RectTransform windowRectTransfrom = windowContainer.GetComponent <RectTransform>();
                windowRectTransfrom.name = item.ToString();
                windowRectTransfrom.SetParent(canvasRt);

                string emptyContainerPrefabPath = BMC.getPrefabsBehaviour().getPrefabPath(uiEmptyContainer);
                windowContainer.AddComponent <RectTransfromResetComponent>().reSetRectTransformInfo(emptyContainerPrefabPath);

                _layerContainerMapping[item] = windowContainer;
            }
        }
Пример #4
0
 public string getPrefabPath(PrefbasAssets.PrefabAssetsConstant prefabAssetsConstant)
 {
     return(_prefabMapping[prefabAssetsConstant]);
 }