public static bool Init() { s_uiRoot = GameObject.Find("UIRoot/UICanvas").transform; if (null == s_uiRoot) { return(false); } s_sceneRoot = GameObject.Find("SceneRoot/SceneCanvas").transform; if (null == s_sceneRoot) { return(false); } GameObject abGo = GameObject.Find("AssetMgr").gameObject; if (null == abGo) { return(false); } s_AssetMgr = abGo.GetComponent <AssetMgr>(); if (null == s_AssetMgr) { return(false); } GameObject.DontDestroyOnLoad(abGo); return(true); }
public override void getObj(string name, Action <Sprite, string> callBack, bool forceRemove = false) { //bundle池有 if (AssetMgr.has(resName)) { PackAsset pab = AssetMgr.get(resName); pab.getObj <Sprite>(name, callBack); } else { if (forceRemove) { Debug.LogError("加载资源失败 path " + resName); } else { if (!handler.ContainsKey(name)) { handler.Add(name, new List <Action <Sprite, string> >()); } handler[name].Add(callBack); LoadItemMgr.add(resName, resPath, loadFinish); } } }
static public Asset Load(string name) { Asset asset = AssetMgr.Load(name); if (asset == null) { return(null); } asset.OnAssetLoaded = delegate(Object obj) { if (uiRoot == null) { uiRoot = NGUITools.CreateUI(false); GameObject.DontDestroyOnLoad(uiRoot.gameObject); //uiRoot.camera.audio.enabled = false; AudioListener al = (AudioListener)uiRoot.GetComponentInChildren <AudioListener>(); al.enabled = false; } GameObject go = NGUITools.AddChild(uiRoot.gameObject, obj as GameObject); go.name = go.name.Replace("(Clone)", ""); }; return(asset); }
public MyJson.IJsonNode Parser(Component com, NeedList list) { MeshRenderer t = com as MeshRenderer; var json = new MyJson.JsonNode_Object(); json["castShadows"] = new MyJson.JsonNode_ValueNumber(t.castShadows); json["receiveShadows"] = new MyJson.JsonNode_ValueNumber(t.receiveShadows); json["useLightProbes"] = new MyJson.JsonNode_ValueNumber(t.useLightProbes); int meshcount = t.sharedMaterials.Length; json["materials"] = new MyJson.JsonNode_Array(); foreach (var m in t.sharedMaterials) { MyJson.JsonNode_Object matobj = new MyJson.JsonNode_Object(); json["materials"].AddArrayValue(matobj); matobj.SetDictValue("name", m.name); matobj.SetDictValue("shader", m.shader.name); matobj.SetDictValue("shaderkeyword", new MyJson.JsonNode_Array()); foreach (var shaderkey in m.shaderKeywords) { matobj["shaderkeyword"].AddArrayValue(shaderkey); } if (m.mainTexture != null) { string name = AssetMgr.SaveTexture(m.mainTexture, System.IO.Path.Combine(Application.streamingAssetsPath, "texture")); matobj.SetDictValue("maintex", name); list.AddDependTexture(name); } } return(json); }
private void setSpSprite(Image img, string name, SpriteRenderer renderer = null) { if (atlasCfg.ContainsKey(name)) { string bundleName = atlasCfg[name]; if (AssetMgr.isHave(bundleName)) { TBundle tb = AssetMgr.getBundle(bundleName); if (img != null) { img.sprite = tb.Ab.LoadAsset <Sprite>(name); } if (renderer != null) { renderer.sprite = tb.Ab.LoadAsset <Sprite>(name); } } else { //需要加载ab index++; SpriteTask spTask = new SpriteTask(index, name, bundleName, img, renderer); dictTask.Add(index, spTask); } } else { Debug.LogError("请导出图集配置"); } }
public void onInit() { for (int i = 0; i < depends.Count; i++) { AssetMgr.addRef(depends[i], 1); } AssetMgr.addRef(url, 1); }
public MyJson.IJsonNode Parser(Component com, NeedList list) { MeshFilter t = com as MeshFilter; var json = new MyJson.JsonNode_Object(); var name = AssetMgr.SaveMesh(t.sharedMesh, System.IO.Path.Combine(Application.streamingAssetsPath, "mesh")); list.AddDependMesh(name); json["mesh"] = new MyJson.JsonNode_ValueString(name); return(json); }
static public void Destroy(string name) { GameObject obj = FindControl(name); if (obj != null) { obj.transform.parent = null; GameObject.Destroy(obj); AssetMgr.UnLoad(name); } }
public void onDispose() { for (int i = 0; i < depends.Count; i++) { AssetMgr.releaseRef(depends[i], 1); } AssetMgr.releaseRef(url, 1); Obj = null; depends = null; url = null; }
void Start() { FrameMgr.GetInstance(); TimerMgr.GetInstance(); PathMgr.GetInstance(); ConfigMgr.GetInstance(); AssetMgr.GetInstance(); UIMgr.GetInstance(); SoundMgr.GetInstance(); LoadSceneMgr.LoadSence("test"); }
public static MyJson.IJsonNode Parser(GameObject obj, NeedList needList = null) { AssetMgr.Reset(); MyJson.JsonNode_Object json = new MyJson.JsonNode_Object(); Debug.Log("ParserObj:" + obj.name); var comps = obj.GetComponents <Component>(); MyJson.JsonNode_Array jsoncs = new MyJson.JsonNode_Array(); json["name"] = new MyJson.JsonNode_ValueString(obj.name); json["active"] = new MyJson.JsonNode_ValueNumber(obj.activeSelf); json["_id"] = new MyJson.JsonNode_ValueNumber(ObjToID(obj)); json["coms"] = jsoncs; foreach (var c in comps) { if (c == null) { Debug.LogWarning("--组件丢失"); } else { Type type = c.GetType(); var pp = ComponentParser.Instance.GetParser(type); if (pp != null) { MyJson.JsonNode_Object jsonc = new MyJson.JsonNode_Object(); jsonc["type"] = new MyJson.JsonNode_ValueString(type.ToString()); if (c is Behaviour) { jsonc["enabled"] = new MyJson.JsonNode_ValueNumber((c as Behaviour).enabled); } jsonc["param"] = pp.Parser(c, needList); Debug.Log("--" + c.name + "<" + type.ToString() + ">:" + jsonc["param"].ToString()); jsoncs.Add(jsonc); } else { Debug.LogWarning("--" + c.name + "<" + type.ToString() + ">" + "没有处理器"); } } } if (obj.transform.childCount > 0) { MyJson.JsonNode_Array jsonsubarray = new MyJson.JsonNode_Array(); json["child"] = jsonsubarray; foreach (Transform t in obj.transform) { jsonsubarray.Add(Parser(t.gameObject, needList)); } } Debug.Log("ParserObjFinish:" + obj.name); AssetMgr.Reset(); return(json); }
static public void DestroyAll() { UIPanel[] panel = uiRoot.GetComponentsInChildren <UIPanel>(); for (int i = 0, imax = panel.Length; i < imax; ++i) { AssetMgr.UnLoad(panel[i].name); } GameObject.Destroy(uiRoot.gameObject); GameObject rt = GameObject.Find("_RealTime"); GameObject.Destroy(rt); }
/// <summary> /// 移除一个正在加载的任务 /// 上层的创建一个gameobject的时候 很有可能调了创建 马上又销毁(这个时候unload掉) /// </summary> /// <param name="resName"></param> /// <param name="callBack"></param> public void unLoad(string resName, Action <GameObject> callBack) { resName = resName.ToLower(); if (pools.ContainsKey(resName)) { pools[resName].removeHandler(callBack); } if (AssetMgr.has(resName)) { PackAsset pka = AssetMgr.get(resName); pka.remove(callBack); } }
public MyJson.IJsonNode Parser(Component com, NeedList list) { MeshCollider t = com as MeshCollider; var json = new MyJson.JsonNode_Object(); json["isTrigger"] = new MyJson.JsonNode_ValueNumber(t.isTrigger); var name = AssetMgr.SaveMesh(t.sharedMesh, System.IO.Path.Combine(Application.streamingAssetsPath, "mesh")); list.AddDependMesh(name); json.SetDictValue("mesh", name); json.SetDictValue("convex", t.convex); json.SetDictValue("smoothSphereCollisions", t.smoothSphereCollisions); return(json); }
private void insObj(Action <GameObject> callBack) { GameObject go = GameObject.Instantiate(this.obj) as GameObject; GameObject.DontDestroyOnLoad(go); PoolObj po = go.AddComponent <PoolObj>(); po.resName = resName; for (int i = 0; i < deps.Count; i++) { AssetMgr.addRef(deps[i]); } AssetMgr.addRef(resName); callBack.Invoke(go); }
//异步加载 public IEnumerator doLoad() { status = E_LoadStatus.Loading; AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(resPath); while (!req.isDone) { yield return(new WaitForEndOfFrame()); } AssetMgr.add(new PackAsset(resName, resPath, req.assetBundle)); for (int i = 0; i < handler.Count; i++) { handler[i].Invoke(resName); } status = E_LoadStatus.Finish; }
public void Awake() { DataMgr.SetLog(this); Commander.SetLog(this); UIMgr.SetLog(this); //>======================== Starter.Initialized(this); AssetMgr.Initialized(LevelMgr); AssetBundleMgr.Initialized(LevelMgr, AssetBundleExtension); UIMgr.Initialized(AssetMgr, AssetBundleMgr); StageMgr.SetUpdateInterval(StageUpdateInterval); DontDestroyOnLoad(gameObject); Starter.RegisterOptionObject(gameObject); Starter.RegisterOptionByChildren(gameObject); Instance = GetComponent <IGameInstance>(); }
//预加载 public virtual void preLoad(Action <string> preLoad, int preLoadCount = 0) { this.preLoadCount = preLoadCount; this.preLoadHandler = preLoad; if (!AssetMgr.has(resName)) { if (cacheLst != null && cacheLst.Count > 0) { Debug.LogError("预创建错误 gameobject池子有缓存 但是assetbundle已经不存在(可能造成预设资源丢失)"); } LoadItemMgr.add(resName, resPath, onPerCreate); } else { onPerCreate(resName); } }
//销毁池 public virtual void onDispose() { LoadItemMgr.remove(resName, loadFinish); if (cacheLst != null) { int count = cacheLst.Count; //释放静态引用 if (count > 0) { for (int i = 0; i < deps.Count; i++) { AssetMgr.subRef(deps[i], count); } AssetMgr.subRef(resName, count); } //释放动态引用 for (int i = 0; i < cacheLst.Count; i++) { PoolObj po = cacheLst[i].GetComponent <PoolObj>(); if (po.getDepsNum() > 0) { List <string> dyDeps = po.getDeps(); for (int j = 0; j < dyDeps.Count; j++) { AssetMgr.subRef(dyDeps[i]); } } } //销毁gameobject for (int i = 0; i < cacheLst.Count; i++) { GameObject.Destroy(cacheLst[i]); } cacheLst.Clear(); cacheLst = null; } if (deps != null) { deps.Clear(); deps = null; } GameObject.Destroy(this.poolRoot.gameObject); }
private static void Init() { if (DicLocalization.Count == 0) { AssetMgr.GetInstance().LoadAsset(PathMgr.GetInstance().GetPath(Define.DataType.Localization), false, false, () => { string[] loc = AssetMgr.GetInstance().GetAsset().ToString().Split(new[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < loc.Length; i++) { loc[i] = loc[i].Replace("\r", ""); } LanguageList = loc[0].Split(','); for (int i = 1; i < loc.Length; i++) { string[] data = loc[i].Split(','); DicLocalization.Add(data[0], data); } }); } }
//www load IEnumerator wwwLoad() { //Debug.Log("加载资源" + url); status = E_LoadStatus.Loading; if (string.IsNullOrEmpty(url)) { status = E_LoadStatus.Fail; yield break; } //是否已经存在ab if (AssetMgr.isHave(url)) { for (int i = 0; i < handlerLst.Count; i++) { handlerLst[i].Invoke(url, true, AssetMgr.getBundle(url)); } status = E_LoadStatus.Finish; yield break; } //加载资源 AssetBundleCreateRequest abReq = AssetBundle.LoadFromFileAsync(Path.Combine(Application.dataPath, "Res/AssetBundle/" + url + ".assetbundle")); do { if (abReq.assetBundle == null) { status = E_LoadStatus.Fail; yield break; } yield return(new WaitForEndOfFrame()); } while (!abReq.isDone); AssetMgr.addBundle(url, abReq.assetBundle); for (int i = 0; i < handlerLst.Count; i++) { handlerLst[i].Invoke(url, true, AssetMgr.getBundle(url)); } status = E_LoadStatus.Finish; }
private void Awake() { if (Instance != null) { Destroy(Instance.gameObject); } Instance = this; DontDestroyOnLoad(gameObject); GameStats.Initialize(); GameStats.Debug = debug; AssetMgr.Loggable = debug; Updater.OnAssetsInitialized = (gameScene, onProgress) => { Assets.AddSearchPath("Assets/HotUpdateResources/Controller"); Assets.AddSearchPath("Assets/HotUpdateResources/Dll"); Assets.AddSearchPath("Assets/HotUpdateResources/Material"); Assets.AddSearchPath("Assets/HotUpdateResources/Other"); Assets.AddSearchPath("Assets/HotUpdateResources/Prefab"); Assets.AddSearchPath("Assets/HotUpdateResources/Scene"); Assets.AddSearchPath("Assets/HotUpdateResources/ScriptableObject"); Assets.AddSearchPath("Assets/HotUpdateResources/TextAsset"); Assets.AddSearchPath("Assets/HotUpdateResources/UI"); AssetMgr.LoadSceneAsync(gameScene, false, onProgress, (b) => { if (!b) { return; } Instance.Load(); ClassBindMgr.Instantiate(); Instance.OnHotFixLoaded(); }); }; }
public virtual void getObj(Action <GameObject> callBack, bool forceRemove = false, int count = 0) { if (cacheLst.Count > count) { //缓存池有 GameObject obj = cacheLst[0]; cacheLst.RemoveAt(0); obj.transform.SetParent(null); callBack(obj); } else { //bundle池有 if (AssetMgr.has(resName)) { PackAsset pab = AssetMgr.get(resName); pab.getObj(callBack); } else { if (forceRemove) { Debug.LogError("加载资源失败 path " + resName); } else { //都没有 先load ab if (handler == null) { handler = new List <Action <GameObject> >(); } handler.Add(callBack); LoadItemMgr.add(resName, resPath, loadFinish); } } } }
void doCheck(string name) { //1 ab池子是否已经有了 bool hasAB = AssetMgr.has(name); if (hasAB) { AssetMgr.addRef(name); taskFinish(""); } else { //如果加载任务里面有此任务 则加回调 if (LoadMgr.hasTask(name)) { LoadMgr.addHandler(name, taskFinish); } else { string resPath = Path.Combine(Define.abPre, name).ToLower(); LoadMgr.doLoad(name, resPath, taskFinish); } } }
/// <summary> /// 加载clip /// </summary> /// <param name="path"></param> /// <param name="callBack"></param> private void loadClip(string path, Action <AudioClip> callBack) { if (AssetMgr.isHave(path)) { TBundle tb = AssetMgr.getBundle(path); if (callBack != null) { callBack(tb.Ab.LoadAsset <AudioClip>(getAudioName(path))); } } else { //需要加载ab if (tasks.ContainsKey(path)) { tasks[path].addHandler(callBack); } else { AudioTask task = new AudioTask(path, callBack); tasks.Add(path, task); } } }
public void PrepareConfig(string config) { config = config.ToLower(); string[] settings = config.Split('|'); currentCharacter = settings[0]; Asset asset = AssetMgr.Load(currentCharacter); asset.OnAssetLoaded += delegate(Object obj) { root = (GameObject)GameObject.Instantiate(obj); }; currentConfiguration = new Dictionary <string, CharacterElement>(); for (int i = 1; i < settings.Length;) { string elementName = settings[i++]; asset = AssetMgr.Load(elementName); if (asset.LoadAssetAsync == null) { asset.LoadAssetAsync = delegate(Bundle bundle) { return(new CharacterRequest(elementName, bundle)); }; } asset.OnAssetLoaded += delegate(Object obj) { currentConfiguration.Add(elementName, obj as CharacterElement); if ((OnCharacterLoaded != null) && (currentConfiguration.Count == settings.Length - 1)) { OnCharacterLoaded(); } }; } }
public void LoadMesh(string respath, string name, Action <IProxy <Mesh> > finish) { var mesh = assetMgrIO.GetMesh(name); if (mesh != null) { var pmesh = new ProxyMesh(mesh, name); assetMgrIO.MeshAddRef(name); finish(pmesh); } else { ResmgrNative.Instance.LoadBytesFromCache(respath + "/mesh/" + name + ".mesh.bytes", name, (bytes, tagName) => { Mesh lmesh = AssetMgr.ReadMesh(bytes, tagName); assetMgrIO.AddMesh(tagName, lmesh); var pmesh = new ProxyMesh(lmesh, name); assetMgrIO.MeshAddRef(tagName); finish(pmesh); }); } }
private void OnGUI() { //释放所有ab if (GUILayout.Button("释放所有ab")) { AssetMgr.dispose(true); } //释放所有池子 if (GUILayout.Button("释放所有池子")) { PoolMgr.Instance.onDispose(); } //释放一个池子 if (GUILayout.Button("释放一个池子")) { if (roleObj != null) { string resName = roleObj.GetComponent <PoolObj>().resName; PoolMgr.Instance.disposePool(resName); UnityEngine.Debug.LogError("释放池子 " + resName); } } //创建一个模型 if (GUILayout.Button("创建一个模型")) { //watch.Start(); string role = "AssetBundle/Prefabs/model/role_ueman/model/role_ueman"; UnityEngine.Debug.LogError("加载role_ueman"); PoolMgr.Instance.getObj(role, onLoadUEManFinish); //UnityEngine.Debug.LogError("取消加载role_ueman"); //PoolMgr.Instance.unLoad(role, onLoadUEManFinish); } //回收一个模型 if (GUILayout.Button("回收一个模型")) { PoolMgr.Instance.recyleObj(roleObj); } //设置img的sprite if (GUILayout.Button("设置img的sprite")) { if (img != null) { string spName = "CZ_5".ToLower(); PoolMgr.Instance.getObj(spName, (sp, resName) => { img.sprite = sp; }); } else { UnityEngine.Debug.LogError("img == null "); } } //预加载模型 if (GUILayout.Button("预加载")) { watch.Start(); foreach (var item in preLoads) { E_PoolType pType = item.Key; int cacheCount = pType == E_PoolType.Model ? 3 : pType == E_PoolType.UICache ? 2 : 0; for (int i = 0; i < item.Value.Count; i++) { PoolMgr.Instance.preLoad(item.Value[i], preLoadCount, E_PoolMode.Overall, pType, cacheCount); } } } //打开技能UI if (GUILayout.Button("打开技能UI")) { string uiName = "assetbundle/prefabs/ui/BottomSkillUI"; PoolMgr.Instance.getObj(uiName, onLoadSkillUIFinish); } }
/// <summary> /// 卸载所有ab /// </summary> public static void unloadAllAssetBundle() { AssetMgr.clearAll(); }
//释放引用 public static void subRef(string resName, int count = 1) { AssetMgr.subRef(resName, count); }