static private void UnLoadResource(SEUResources resource) { if (resource != null) { resource.UnUsed(); } }
private void UnUsed() { if (m_RefCount == 0) { Debug.LogError("多次调用的 UnLoadUsedResource " + StackTraceUtility.ExtractStackTrace()); } else { m_RefCount--; #if SEU_DEBUG Debug_StackInfo.Add("[UnUse]" + StackTraceUtility.ExtractStackTrace()); #endif if (m_RefCount == 0) { if (m_Pool != null) { m_Pool.PopResource(this); for (int i = 0; i < m_DependenceResources.Count; i++) { SEUResources.UnLoadResource(m_DependenceResources[i]); } } else { Debug.LogError(GetType() + " pool is NULL"); } } } }
protected override IEnumerator LoadAssetAsync() { AsyncRequest request = m_Pool.LoadBundleAsyn(m_LoadPath, true); yield return(request); SEUResources bundleRes = request.resource; if (bundleRes != null) { AddDependenceResources(bundleRes); AssetBundle bundle = bundleRes.asset as AssetBundle; if (bundle != null) { AssetBundleRequest bdRequest = bundle.LoadAssetAsync(System.IO.Path.GetFileName(m_LoadPath), m_Type); yield return(bdRequest); if (m_Asset == null) { m_Asset = bdRequest.asset; } } } LogResult(); }
internal void AttachAssetToInstance(Object asset, Object instObj) { int assetCode = asset.GetInstanceID(); int instanceCode = instObj.GetInstanceID(); SEUResources refResource = null; if (m_AssetRefSEUResources.ContainsKey(assetCode)) { refResource = m_AssetRefSEUResources[assetCode]; } if (refResource == null) { m_InstanceRefSEUResources.TryGetValue(assetCode, out refResource); } if (refResource != null) { if (!m_InstanceRefSEUResources.ContainsKey(instanceCode)) { m_InstanceRefSEUResources.Add(instanceCode, refResource); refResource.Use(); } else { Debug.LogError("SEUResources Instantiate Objec ,But this is a ref System Error"); } } else { Debug.LogError("SEUResources Instantiate Object ,But the Object is not in ref system " + StackTraceUtility.ExtractStackTrace()); } }
private void DeBug_AddInstanceObject(Object instance, SEUResources res) { GameObject debugObj = new GameObject(res.m_LoadPath); Debeg_InstantiateObjects.Add(instance.GetInstanceID(), debugObj); debugObj.transform.SetParent(Debug_SEUObjectPoolObject.transform); }
internal void DesotoryObject(Object asset) { int assetCode = asset.GetInstanceID(); SEUResources refRes = null; if (m_AssetRefSEUResources.ContainsKey(assetCode)) { refRes = m_AssetRefSEUResources[assetCode]; } else if (m_InstanceRefSEUResources.ContainsKey(assetCode)) { Object.Destroy(asset); refRes = m_InstanceRefSEUResources[assetCode]; m_InstanceRefSEUResources.Remove(assetCode); } if (refRes != null) { UnLoadResource(refRes); if (refRes.refCount == 0) { m_AssetRefSEUResources.Remove(refRes.asset.GetInstanceID()); } } else { Debug.LogError("[SEUResources] Try Destory Object ,But it not in Ref System " + StackTraceUtility.ExtractStackTrace()); } }
internal SEUResources LoadManifest(string path) { if (m_ManifestPath != null) { string manifestPath = m_ManifestPath; System.Type type = typeof(AssetBundleManifest); int resGUID = ToResGUID(manifestPath, type); SEUResources resource = null; if (m_AssetBundles.ContainsKey(resGUID)) { resource = m_AssetBundles[resGUID]; if (resource.asset == null) { resource.LoadAsset(); } } else { resource = new SEUResourceMenifest(manifestPath, type); PushResource(resource); resource.LoadAsset(); } return(resource); } return(null); }
private AsyncRequest LoadAsynInternal(string path, System.Type type, System.Action <SEUResources> callback) { SEUResources resource = null; int resGUID = ToResGUID(path, type); if (m_Resources.ContainsKey(resGUID)) { resource = m_Resources[resGUID]; } else { switch (m_LoaderType) { case SEULoaderType.RESOURCE: resource = new SEUResourceNormal(path, type); break; case SEULoaderType.AB: resource = new SEUResourcesFromBundle(path, type); break; } PushResource(resource); } resource.Use(); return(resource.SendLoadAsyncRequest(callback)); }
internal SEUResources LoadBundle(string path, bool isNeedConvertBundlePath = false) { string bundlePath = path; if (isNeedConvertBundlePath) { bundlePath = m_ResourceToBundlePathConverter.HandlePath(path); } System.Type type = typeof(AssetBundle); int resGUID = ToResGUID(bundlePath, type); SEUResources resource = null; if (m_AssetBundles.ContainsKey(resGUID)) { resource = m_AssetBundles[resGUID]; /// 这样处理 为了同步和异步并存 if (resource.asset == null) { resource.LoadAsset(); } } else { resource = new SEUResourcesBundle(bundlePath, type); PushResource(resource); resource.LoadAsset(); } return(resource); }
private SEUResources LoadInternal(string path, System.Type type) { SEUResources resource = null; int resGUID = ToResGUID(path, type); if (m_Resources.ContainsKey(resGUID)) { resource = m_Resources[resGUID]; } else { switch (m_LoaderType) { case SEULoaderType.RESOURCE: resource = new SEUResourceNormal(path, type); break; case SEULoaderType.AB: resource = new SEUResourcesFromBundle(path, type); break; } PushResource(resource); } /// 这样处理 为了同步和异步并存 if (resource.asset == null) { resource.LoadAsset(); } resource.Use(); return(resource); }
internal void PopResource(SEUResources resource) { int resGUI = resource.GUID(); Dictionary <int, SEUResources> container = null; if (resource is SEUResourcesBundle || resource is SEUResourceMenifest) { container = m_AssetBundles; } else { container = m_Resources; } if (container.ContainsKey(resGUI)) { if (m_UnloadType == SEUUnLoadType.REFCOUNT_ZERO) { container.Remove(resGUI); resource.ReleaseResource(); #if SEU_DEBUG GameObject.Destroy(resource.DebugObject); #endif } } else { Debug.LogError("PopResource resource ,But can not find it in ResourcePool"); } }
private void PushResource(SEUResources resource) { int resGUID = resource.GUID(); Dictionary <int, SEUResources> container = null; if (resource is SEUResourcesBundle || resource is SEUResourceMenifest) { container = m_AssetBundles; } else { container = m_Resources; } if (!container.ContainsKey(resGUID)) { container.Add(resGUID, resource); resource.AttachPool(this); #if SEU_DEBUG resource.DebugCreateObject(); if (resource is SEUResourcesBundle || resource is SEUResourceMenifest) { resource.DebugObject.transform.SetParent(Debug_AssetBundlesObject.transform); } else { resource.DebugObject.transform.SetParent(Debug_GroupPoolObject.transform); } #endif } else { Debug.Log(resGUID); Debug.LogError("Error"); } }
static private SEUResources _Load(string path, System.Type type) { path = path.ToLower(); SEUResources result = m_ResourcePool.Load(path, type); return(result); }
internal Object GetObject(SEUResources resource) { Object asset = null; if (resource != null) { Dictionary <int, SEUResources> record = null; record = m_AssetRefSEUResources; if (resource.asset != null) { int code = resource.asset.GetInstanceID(); if (!record.ContainsKey(code)) { record.Add(code, resource); } asset = resource.asset; } else { //没有加载到资源,内部就把SEUResource 对象释放 UnLoadResource(resource); } } return(asset); }
protected void AddDependenceResources(SEUResources resource) { if (m_DependenceResources.Contains(resource) == false && resource != null) { m_DependenceResources.Add(resource); resource.Use(); } }
internal SEUBundleLoader GetBundleLoader(string bundleName) { SEUBundleLoader bundleLoader = SEUResources.GetBundleLoader(m_BundleLoaderType); if (bundleLoader != null) { bundleLoader.SetBundleName(bundleName); } return(bundleLoader); }
static public bool PreLoadBundle(string path) { SEUResources res = m_ResourcePool.LoadBundle(path); if (res.asset != null) { return(true); } return(false); }
internal AsyncRequest(SEUResources resource, System.Action <SEUResources> callback = null) { m_Resource = resource; if (resource.asset == null) { AsyncOperator.SendReqest(MainLoop(callback)); } else { if (callback != null) { callback(resource); } m_KepWaiting = false; } }
protected override IEnumerator LoadAssetAsync() { SEUBundleLoader bundleLoader = m_Pool.GetBundleLoader(m_LoadPath); if (bundleLoader != null) { yield return(bundleLoader.LoadAsync()); if (m_Asset == null) { m_Asset = bundleLoader.assetBundle; } else { Debug.LogWarning("[同步冲突] 已经处理"); } } SEUResources manifestRes = m_Pool.LoadManifest(m_LoadPath); AddDependenceResources(manifestRes); if (manifestRes != null && manifestRes.asset != null) { AssetBundleManifest manifest = manifestRes.asset as AssetBundleManifest; if (manifest != null) { string[] dependenciesPaths = manifest.GetAllDependencies(m_LoadPath); if (dependenciesPaths != null) { for (int i = 0; i < dependenciesPaths.Length; i++) { AsyncRequest request = m_Pool.LoadBundleAsyn(dependenciesPaths[i]); yield return(request); SEUResources depRes = request.resource; AddDependenceResources(depRes); } } } } //LogResult(); }
internal AsyncRequest LoadManifestAsync(string path) { if (m_ManifestPath != null) { string manifestPath = m_ManifestPath; System.Type type = typeof(UnityEngine.Object); int resGUID = ToResGUID(manifestPath, type); SEUResources resource = null; if (m_AssetBundles.ContainsKey(resGUID)) { resource = m_AssetBundles[resGUID]; } else { resource = new SEUResourceMenifest(manifestPath, type); PushResource(resource); } return(resource.SendLoadAsyncRequest()); } return(null); }
protected override void LoadAsset() { SEUResources bundleRes = m_Pool.LoadBundle(m_LoadPath, true); if (bundleRes != null) { AddDependenceResources(bundleRes); AssetBundle bundle = bundleRes.asset as AssetBundle; if (bundle != null) { string assetName = System.IO.Path.GetFileName(m_LoadPath); Object asset = bundle.LoadAsset(assetName + ".prefab", m_Type); if (m_Asset == null) { m_Asset = asset; } } } LogResult(); }
void DrawSEUResources(SEUResources res, bool showDeps = false) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField(res.loadPath); if (showDeps) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.ObjectField(res.DebugObject, typeof(GameObject), true); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField("RefCount: " + res.refCount.ToString()); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Use /UnUse Stack Info", EditorStyles.boldLabel); var loadList = res.Debug_StackInfo.FindAll((p) => p.StartsWith("[Use]")); EditorGUILayout.LabelField(string.Format("Use [{0}] UnUse[{1}]", loadList.Count, res.Debug_StackInfo.Count - loadList.Count)); Color old = GUI.color; for (int i = 0; i < res.Debug_StackInfo.Count; i++) { string info = res.Debug_StackInfo[i]; if (info.StartsWith("[Use]")) { GUI.color = Color.green; } else { GUI.color = Color.magenta; } EditorGUILayout.LabelField(res.Debug_StackInfo[i], EditorStyles.textArea); } GUI.color = old; EditorGUILayout.EndVertical(); } EditorGUILayout.EndVertical(); }
internal AsyncRequest LoadBundleAsyn(string path, bool isNeedConvertBundlePath = false) { string bundlePath = path; if (isNeedConvertBundlePath) { bundlePath = m_ResourceToBundlePathConverter.HandlePath(path); } System.Type type = typeof(AssetBundle); int resGUID = ToResGUID(bundlePath, type); SEUResources resource = null; if (m_AssetBundles.ContainsKey(resGUID)) { resource = m_AssetBundles[resGUID]; } else { resource = new SEUResourcesBundle(bundlePath, type); PushResource(resource); } return(resource.SendLoadAsyncRequest()); }
protected override void LoadAsset() { SEUBundleLoader bundleLoader = m_Pool.GetBundleLoader(m_LoadPath); if (bundleLoader != null) { bundleLoader.Load(); if (m_Asset == null) { m_Asset = bundleLoader.assetBundle; } else { Debug.LogWarning("[异步冲突]"); } } SEUResources manifestRes = m_Pool.LoadManifest(m_LoadPath); AddDependenceResources(manifestRes); if (manifestRes != null && manifestRes.asset != null) { AssetBundleManifest manifest = manifestRes.asset as AssetBundleManifest; if (manifest != null) { string[] dependenciesPaths = manifest.GetAllDependencies(m_LoadPath); if (dependenciesPaths != null) { for (int i = 0; i < dependenciesPaths.Length; i++) { SEUResources depRes = m_Pool.LoadBundle(dependenciesPaths[i]); AddDependenceResources(depRes); } } } } //LogResult(); }
static public Object Load(string path, System.Type type) { SEUResources resource = _Load(path, type); return(m_ObjectPool.GetObject(resource)); }