public static bool ReleaseResNode(IResNodeHandle _handle, ResNode _resNode, bool _bImmediate) { bool result = false; if (_handle != null && _resNode != null && _resNode.IsValid()) { if (m_dicResNodeHandle.ContainsKey(_handle)) { List <ResNode> listValue = m_dicResNodeHandle[_handle]; ResNode FindedResNode = null; foreach (ResNode tmpResNode in listValue) { if (tmpResNode.instanceID == _resNode.instanceID) { FindedResNode = tmpResNode; break; } } if (FindedResNode != null) { listValue.Remove(FindedResNode); DeleteAssets(ref FindedResNode, _bImmediate); result = true; } } } return(result); }
private static void PrefabResourceCallBack(ResConfigData cof, ResNode nod, System.Object userDataObj) { List <AsyncLoadingObject> list = null; ////预制体依赖加载完了,预制体本身也加载完了,这时候发现,已经不需要这个预制体了 //if (m_NeedToDeletePrefab.Contains(nod.instanceID)) //{ // m_NeedToDeletePrefab.Remove(nod.instanceID); // DeletePrefabResourceAsync(ref nod, PrefabResourceCallBack, true); // return; //} //预制体加载失败的 if (nod != null && !nod.IsValid()) { UnLoadDependenicesAsync(nod.instanceID); } else { ReleaseDependenicesAssetBundleIfNeed(nod); } ReleaseAssetBundleIfNeed(nod); PushLoadedAssetInfo(nod, GetPrefabDependenciesResNode(nod.instanceID)); if (m_PrefabRequestTable.TryGetValue(nod.instanceID, out list)) { m_PrefabRequestTable.Remove(nod.instanceID); foreach (AsyncLoadingObject obj in list) { obj.callBack(cof, nod, obj.UserDataObj); } } }
private static void AsyncLoadDependenicesCallBack(ResConfigData config, ResNode res, System.Object userData) { if (null != res && !res.IsValid()) { Debug.LogWarning(config.AssetName + "-预制体依赖资源加载失败,类型:" + res.assetType.ToString() + ",资源路径:" + config.AssetBundleName + "--" + config.AssetName); } }
/// <summary> /// 判断是否为null /// </summary> /// <param name="res"></param> /// <returns></returns> public static bool isNullOrEmpty(ResNode res) { if (null == res) { return(true); } if (res.isAsync) { if (res.isLoadFinish) { return(!res.IsValid()); } return(false); } return(!res.IsValid()); }
/// <summary> /// 初始化 /// </summary> /// <param name="host">挂载物体</param> /// <param name="config">音效配置</param> /// <returns></returns> public bool Init(GameObject host, SoundConfigData config, int enityID = -1, bool _AsyncLoad = true) { Clear(); m_entityID = enityID; m_Config = config; m_host = host; m_AudioInstance = GetComponent <AudioSource>(); orginalVolume = m_AudioInstance.volume; //m_AudioInstance.hideFlags = HideFlags.HideAndDontSave; m_Valid = true; if (_AsyncLoad) { m_ResNode = AssetBundleManager.GetAssetsAsync(AssetType.Asset_Audio, config, this, this); } else { m_ResNode = AssetBundleManager.GetAssets(AssetType.Asset_Audio, config); } if (null == m_ResNode) { m_Valid = false; return(false); } bAsyncLoad = _AsyncLoad; if (!_AsyncLoad && m_ResNode.IsValid()) { if (ApplyConfig()) { isFinish = false; if (config.bPlayOnAwake || bPlay) { Play(); } } } return(true); }
private ResNode GetResNode(string _strPath, SceneEffectParamBase _param) { ResNodeHandleParamBase param = new ResNodeHandleParam_Path(AssetType.Asset_Prefab, _strPath); ResNode resultResNode = AssetBundleManager.GetResNode(this, param); if (resultResNode != null) { if (resultResNode.IsValid()) { return(resultResNode); } } return(null); }
private static void ReleaseDependenicesAssetBundleIfNeed(ResNode prefabResNdode) { if (null == prefabResNdode) { return; } if (!prefabResNdode.IsValid()) { return; } PrefabDependenciesResNode dependenciesRes = null; if (m_PrefabDependenciesResNodeTable.TryGetValue(prefabResNdode.instanceID, out dependenciesRes)) { foreach (ResNode resGUID in dependenciesRes.TextureResNode) { ReleaseAssetBundleIfNeed(resGUID); } foreach (ResNode resGUID in dependenciesRes.MaterialResNode) { ReleaseAssetBundleIfNeed(resGUID); } foreach (ResNode resGUID in dependenciesRes.FBXResNode) { ReleaseAssetBundleIfNeed(resGUID); } foreach (ResNode resGUID in dependenciesRes.AnimatonClipResNode) { ReleaseAssetBundleIfNeed(resGUID); } foreach (ResNode resGUID in dependenciesRes.AnimatorControllerResNode) { ReleaseAssetBundleIfNeed(resGUID); } } }
private void LoadWebBrowser() { if (m_browserInstance != null) { return; } if (WebBrowserProgressBar != null) { WebBrowserProgressBar.gameObject.SetActive(true); } m_webBrowserResNode = UISystem.Instance.GetResNode("UI/Widgets/WebBrowser/WebBrowser"); if (m_webBrowserResNode == null || !m_webBrowserResNode.IsValid()) { return; } m_browserInstance = m_webBrowserResNode.InstanceMainRes <UBrowser>(); if (m_browserInstance == null) { return; } if (m_browserInstance.WebBrowserToolbar != null) { m_browserInstance.WebBrowserToolbar.gameObject.SetActive(false); } m_browserInstance.Width = (int)WebBrowserSize.x; m_browserInstance.Height = (int)WebBrowserSize.y; m_browserInstance.InitialURL = m_curUrl == "" ? WebBrowserUrl : m_curUrl; m_browserInstance.GetRectTransform.SetParent(WebBrowserContainer, false); m_reqUrlList.AddLast(m_browserInstance.InitialURL); m_browserInstance.OnPageLoadedEvent.RemoveListener(OnPageLoadedEvent); m_browserInstance.OnPageLoadedEvent.AddListener(OnPageLoadedEvent); }
public void OnAdvanceLoginClick(int nLoginType) { if (nLoginType < 0 || nLoginType > (int)EAdvanceLoginType.EALT_WeChat) { return; } AdvanceLoginType = (EAdvanceLoginType)nLoginType; if (null != m_BrowserInstance) { m_BrowserInstance.OnToolbarUrlFieldEndEdit(GetWebLoginURL(AdvanceLoginType)); return; } UIMsgCmdData msg = new UIMsgCmdData((int)WndMsgID.WND_MSG_CREATEHERO_WEBBROWSER_STATE, 1, "", IntPtr.Zero, 0); UISystem.Instance.SendTargetWndMessage(WndID.WND_ID_LOGIN, WndMsgID.WND_MSG_CREATEHERO_WEBBROWSER_STATE, msg); m_WebBrowserResNode = UISystem.Instance.GetResNode("UI/Widgets/WebBrowser/WebBrowser"); if (m_WebBrowserResNode.IsValid()) { m_BrowserInstance = m_WebBrowserResNode.InstanceMainRes <UBrowser>(); m_BrowserInstance.Width = (int)WebBrowserSize.x; m_BrowserInstance.Height = (int)WebBrowserSize.y; m_BrowserInstance.InitialURL = GetWebLoginURL(AdvanceLoginType); m_BrowserInstance.SetToolbarType(UWebBrowserToolbarWidget.EToolbar.ETB_Close); m_BrowserInstance.GetRectTransform.SetParent(GetAttachParent(), false); m_BrowserInstance.GetRectTransform.anchoredPosition = WebBrowserPosOffset; m_BrowserInstance.OnJsQueryEvent.RemoveListener(OnJSQueryEvent); m_BrowserInstance.OnJsQueryEvent.AddListener(OnJSQueryEvent); m_BrowserInstance.OnDisConnectedEvent.RemoveListener(OnDisConnectedEvent); m_BrowserInstance.OnDisConnectedEvent.AddListener(OnDisConnectedEvent); } }
protected void InitEffectParam(ResNode resNodeInfo, SceneEffectParamBase _effectParam) { if (resNodeInfo != null && resNodeInfo.IsValid()) { if (_effectParam.GetSceneEffectDelaySpawnTime() > 0) { DelaySceneEffect(_effectParam); } else { _CreateSceneEffect(_effectParam); } _effectParam.Init(); if (_effectParam is SceneEffectParamAsync) { if ((_effectParam as SceneEffectParamAsync).onResLoadFinished != null) { (_effectParam as SceneEffectParamAsync).onResLoadFinished.Invoke((_effectParam as SceneEffectParamAsync).ResLoadUserObject); } } } }
/// <summary> /// 只加载预制体的资源依赖 /// </summary> /// <param name="pefabConfig"></param> /// <returns></returns> private static bool LoadDependenicesResource(ResConfigData pefabConfig, out PrefabDependenciesResNode dependenciesRes) { int guid = GUIDToInstanceID(pefabConfig.AssetGUID); dependenciesRes = null; //取得依赖配置表 PrefabDependenicesResConfigData dependenciesConfig = null; if (!m_PrefabDependenciesConfigTable.TryGetValue(pefabConfig.AssetGUID, out dependenciesConfig)) { Debug.LogWarning("预制体找不到对应的依赖配置:" + pefabConfig.AssetBundleName + "[" + pefabConfig.AssetName + "]"); return(false); } if (m_PrefabDependenciesResNodeTable.TryGetValue(guid, out dependenciesRes)) { Debug.LogWarning("!!!!!!!!!!!!!!天哪撸,出超级大bug了。资源系统出大问题了。这个问题,赶紧找程序解决!!!!!!!!:" + pefabConfig.AssetBundleName + "[" + pefabConfig.AssetName + "]"); return(false); } dependenciesRes = new PrefabDependenciesResNode(); /*加载顺序是不能乱的,要是乱的话。你可以试试,只要有一个加载失败就退出*/ //先加载贴图,贴图要区分是Sprite还是普通的Texture foreach (string resGUID in dependenciesConfig.TextureResConfigDatas) { ResNode currRes = null; ResConfigData tex = GetDependenicesConfig(resGUID); if (null == tex) { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,依赖表中找不到资源,类型:[贴图]"); return(false); } if (IsUIAssetBundle(tex.AssetBundleName)) { currRes = GetSpriteResource(tex); } else { currRes = GetTextureResource(tex); } if (null != currRes && currRes.IsValid()) { dependenciesRes.TextureResNode.Add(currRes); } else { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,类型:[贴图],资源路径:" + tex.AssetBundleName + "--" + tex.AssetName); return(false); } } //再加载材质 foreach (string resGUID in dependenciesConfig.MaterialResConfigDatas) { ResConfigData tex = GetDependenicesConfig(resGUID); if (null == tex) { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,依赖表中找不到资源,类型:[Material]"); return(false); } ResNode currRes = GetMaterialResource(tex); if (null != currRes && currRes.IsValid()) { dependenciesRes.MaterialResNode.Add(currRes); } else { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,类型:[Material],资源路径:" + tex.AssetBundleName + "--" + tex.AssetName); return(false); } } //再加载AnimatorClip foreach (string resGUID in dependenciesConfig.AnimatonClipResConfigDatas) { ResConfigData tex = GetDependenicesConfig(resGUID); if (null == tex) { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,依赖表中找不到资源,类型:[AnimatorClip]"); return(false); } ResNode currRes = GetAnimationClipResource(tex); if (null != currRes && currRes.IsValid()) { dependenciesRes.AnimatonClipResNode.Add(currRes); } else { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,类型:[AnimatorClip],资源路径:" + tex.AssetBundleName + "--" + tex.AssetName); return(false); } } //再加载FBX foreach (string resGUID in dependenciesConfig.FBXResConfigDatas) { ResConfigData tex = GetDependenicesConfig(resGUID); if (null == tex) { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,依赖表中找不到资源,类型:[FBX]"); return(false); } ResNode currRes = GetFBXResource(tex); if (null != currRes && currRes.IsValid()) { dependenciesRes.FBXResNode.Add(currRes); } else { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,类型:[FBX],资源路径:" + tex.AssetBundleName + "--" + tex.AssetName); return(false); } } //再加载AnimatorController foreach (string resGUID in dependenciesConfig.AnimatorControllerResConfigDatas) { ResConfigData tex = GetDependenicesConfig(resGUID); if (null == tex) { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,依赖表中找不到资源,类型:[AnimatorController]"); return(false); } ResNode currRes = GetAnimatorControllerResource(tex); if (null != currRes && currRes.IsValid()) { dependenciesRes.AnimatorControllerResNode.Add(currRes); } else { Debug.LogWarning(pefabConfig.AssetName + "-预制体依赖资源加载失败,类型:[AnimatorController],资源路径:" + tex.AssetBundleName + "--" + tex.AssetName); return(false); } } return(true); }
private static void BuildPrefabWhenInAsyncLoading(ref ResNode res, UnionResConfigData config) { //先检查 if (null == res) { return; } if (!isOnRunTimeMode) { return; } if (!res.isAsync) { return; } if (res.isLoadFinish) { return; } res.StartLoadedTime(); //先从回调列表里移除 if (m_AsyncLoadingDependicensPrefabResNode.ContainsKey(res.instanceID)) { m_AsyncLoadingDependicensPrefabResNode.Remove(res.instanceID); } //卸载依赖 UnLoadDependenicesAsync(res.instanceID); //开始加载依赖 if (LoadDependenices(config)) { ResourcePackage pkg = null; pkg = GetResourcePackge(config); if (null != pkg) { LoadAssetFromAssetBundle <GameObject>(ref res, config, pkg.AssetBundleInstance); } else { AssetBudleLog("加载AssetBundle失败:" + config.AssetBundleName); } if (!res.IsValid()) { UnLoadDependenices(res.instanceID); } } else { UnLoadDependenices(res.instanceID); } res.status = ResNodeStatus.LoadFinish; m_PrefabResTable.Add(res.instanceID, res); //取出回调列表 List <AsyncLoadingObject> list = null; if (m_PrefabRequestTable.TryGetValue(res.instanceID, out list)) { ReleaseDependenicesAssetBundleIfNeed(res); ReleaseAssetBundleIfNeed(res); m_PrefabRequestTable.Remove(res.instanceID); foreach (AsyncLoadingObject obj in list) { PushToResDelayCallBackList(res, config, obj.callBack, obj.UserDataObj); } } return; }