/// 创建面板 IEnumerator StartCreatePanel(string name, AssetBundle bundle, LuaFunction func = null) { name += "Panel"; GameObject prefab = Util.LoadAsset(bundle, name); yield return(new WaitForEndOfFrame()); if (Parent.FindChild(name) != null || prefab == null) { yield break; } GameObject go = Instantiate(prefab) as GameObject; go.name = name; go.layer = LayerMask.NameToLayer("Default"); go.transform.parent = Parent; go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; yield return(new WaitForEndOfFrame()); go.AddComponent <LuaBehaviour>().OnInit(bundle); if (func != null) { func.Call(go); } Debug.Log("StartCreatePanel------>>>>" + name); }
internal string PreLoadObject(string prefabName, bool isLocal = false, int poolSize = 1) { isLocal = true; GameObject tmp = null; string key = prefabName.Split('/')[prefabName.Split('/').Length - 1]; //if (!m_GameObjectPools.ContainsKey(key)) if (m_spawnPool.prefabs.ContainsKey(key) == false) { if (GameStart.Instance.IsDebug || isLocal) { tmp = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/" + prefabName + ".prefab", typeof(GameObject)) as GameObject; //tmp = Resources.Load<GameObject>(prefabName); } else { AssetBundle bundle = ResManager.LoadBundle(key); tmp = Util.LoadAsset(bundle, key); } if (tmp == null) { Debug.LogError("资源:" + prefabName + " 加载为空"); } else if (!prefabName.StartsWith("Prefabs/FirstPackage") && !prefabName.StartsWith("Prefabs/SecondPackage")) { CreatePrefabPool(tmp.transform); //CreatePool(key, poolSize, 10, tmp); } } return(key); }
/// <summary> /// 获取一个GameObject资源 /// </summary> /// <param name="name"></param> public GameObject LoadAsset(string name) { if (bundle == null) { return(null); } return(Util.LoadAsset(bundle, name)); }