Exemplo n.º 1
0
        /// <summary>
        /// 创建一个UI
        /// </summary>
        /// <param name="_name"></param>
        /// <returns></returns>
        private UI_Base _createUIObject(String _name)
        {
            UnityEngine.Object prefab = null;
#if !GROOT_ASSETBUNDLE_SIMULATION && UNITY_EDITOR
            String path = String.Format("{0}/{1}.prefab", WeiqiApp.UI_PREFAB_ROOT_PATH, _name);
            prefab = AssetDatabase.LoadMainAssetAtPath(path);
            if (prefab == null)
            {
                Utility.Log.Error("[UIManager._create]ui: {0} 不存在!", path);
                return(null);
            }
#else
            Resource_Assetbundle bundle = ResourceManager.Instance.LoadAssetbundleSync(String.Concat("ui/", _name, ".ui"));
            if (bundle.Assetbundle == null)
            {
                Utility.Log.Error("[UIManager._create]ui: {0} 不存在!", _name);
                return(null);
            }
            prefab = bundle.Assetbundle.LoadAsset(_name);
            bundle.Unload(false);
            //prefab = ResourceManager.Instance.LoadUIObject( _name );
#endif
            GameObject ui_object = Instantiate(prefab) as GameObject;
            ui_object.SetActive(false);
            ui_object.name = _name;             //预制创建出来名字中会有(Clone)所以去掉

            // 放置ui到对应的层
            UI_Base ui_base = ui_object.GetComponent <UI_Base>();
            ui_object.transform.SetParent(m_layer_transforms[(Int32)ui_base.Layer], false);

            ui_base.OnLoaded();
            m_loaded_ui.Add(ui_base);
            return(ui_base);
        }