void Loaded(CSResource res) { if (!mLoadedDic.ContainsKey(res.Key)) { return; } ModelLoadData data = mLoadedDic[res.Key]; GameObject go = res.MirrorObj as GameObject; if (go == null) { LoadedOne(res); return; } data.atlas = go.GetComponent <SFAtlas>(); if (data.atlas != null) { data.atlas.ResPath = res.Path; } AtlasPoolItemDeal(data.atlas); if (FlagFinish(res.Key) && IsAllFinish())//如果FlagFinish成功,表示是最新的,如果由于动作切换太快,后面的动作比前面动作加载快,那么Loaded都会调用,但是onFinishAll之后后面的动作到了之后才会调用 { CallOnFinishAll(); //else //{ // Debug.Log("onFinishAll is Null = "); //} } else { LoadedOne(res); } }
/// <summary> /// 查找当前资源优先级的最大下标 /// </summary> /// <param name="newRes"></param> /// <returns></returns> private int FindProriIndex(CSResource newRes) { int index = -1; bool isFind = false; for (int i = 0; i < waitingWWWQueue.Count; i++) { CSResource res = waitingWWWQueue[i]; if ((int)newRes.AssistType > (int)res.AssistType) { index = i; isFind = true; break; } } if (!isFind) { return(waitingWWWQueue.Count); } if (index == -1) { return(0); } return(index); }
private void LoadedOneCallback(CSResource obj) { int MaxCount = WaitLoadComponentKey.Count; //例如左手武器/右手武器,可能不同架构使用同种资源,这需要去判定 for (int i = 0; i < MaxCount; i++) { ModelComponentLoadData data = WaitLoadComponentKey[i]; if (obj.FileName == data.FileName) { data.ResPath = obj.Path; ModelComponentLoadedCacheDic[data.Key] = data; AddWaitModelComponent(data); SingleComponentLoaded(); WaitLoadComponentKey.RemoveAt(i); MaxCount--; i--; } } if (WaitLoadComponentKey.Count == 0) { AllComponentLoaded(); } }
private void RemoveWaitingQueueDic(CSResource res) { if (waitingQueueDic.ContainsKey(res.Path)) { waitingQueueDic.Remove(res.Path); } }
/// <summary> /// 读取本地的场景文件 /// </summary> /// <param name="sceneName"></param> /// <returns></returns> protected virtual IEnumerator DynaLoadScene(string sceneName) { string fliePath = URL.FilePrePath; fliePath = fliePath + "/" + CSResource.GetTypeRelativePath(EResourceType.SceneRes) + sceneName; if (!System.IO.File.Exists(fliePath)) { //if (CSDebug.developerConsoleVisible) //{ // CSDebug.Log("path is not exsit=" + fliePath); //} yield break; } if (CSDebug.developerConsoleVisible) { CSDebug.Log("Loading Assetbundle Scene =" + fliePath); } CSResource res = CSResourceManager.Instance.AddQueue(sceneName, EResourceType.SceneRes, null, EResourceAssistType.ForceLoad); while (!res.IsDone) { yield return(null); } }
private void AddWaitingQueueDic(CSResource res) { if (!waitingQueueDic.ContainsKey(res.Path)) { waitingQueueDic.Add(res.Path, res); } }
protected virtual void BeginLoadRes() { for (int i = 0; i < mObjectList.Count; i++) { long key = mObjectList[i]; ModelLoadData data = mLoadedDic[key]; string path = SFOut.IResourceManager.GetKeyPath(key); if (!string.IsNullOrEmpty(path)) { AddHasUseModelResList(path); CSResource res = SFOut.IResourceManager.AddQueue(path, data.type, Loaded, data.assistType, true, key); BeginLoadModelResCallBack(res); } else { int modelID = 0, motion = 0, direction = 0; SplitKey(key, ref modelID, ref motion, ref direction); string Model = GetCombineModel((uint)modelID, (uint)motion, (uint)direction); path = CSResource.GetPath(Model, data.type, false); AddHasUseModelResList(path); SFOut.IResourceManager.AddKeyPath(key, path); //Debug.Log(Model + " " + type+" TimeCount = "+Time.frameCount); CSResource res = SFOut.IResourceManager.AddQueue(path, data.type, Loaded, data.assistType, true, key); BeginLoadModelResCallBack(res); } } }
private void AddLoadedQueue(CSResource res) { if (loadedQueue.ContainsKey(res.Path)) { return; } loadedQueue.Add(res.Path, res); }
private void RemoveLoadingQueue(CSResource res) { if (loadingQueue.ContainsKey(res.Path)) { loadingQueue.Remove(res.Path); } loadingQueueList.Remove(res); }
private void AddLoadingQueue(CSResource res) { if (!loadingQueue.ContainsKey(res.Path)) { loadingQueue.Add(res.Path, res); } if (!loadingQueueList.Contains(res)) { loadingQueueList.Add(res); } }
private CSObjectPoolItem AddPool(string resPath) { CSResource resource = CSResourceManager.Instance.GetLoadedRes(resPath); if (resource == null) { return(null); } CSObjectPoolItem item = resource.GetPoolItem(EPoolType.Normal); return(item); }
/// <summary> /// 调整资源优先级 /// </summary> /// <param name="res"></param> private void AdjustProri(CSResource res) { if (waitingQueueDic.ContainsKey(res.Path)) { waitingWWWQueue.Remove(res); int index = FindProriIndex(res); waitingWWWQueue.Insert(index, res); } else { int index = FindProriIndex(res); waitingWWWQueue.Insert(index, res); } }
void ClearWaitModelRes() { for (int i = 0; i < mHasUseModelResList.Count; i++) { if (SFOut.IResourceManager == null) { continue; } CSResource res = SFOut.IResourceManager.GetRes(mHasUseModelResList[i]); if (res != null) { res.onLoaded -= Loaded; SFOut.IResourceManager.RemoveWaitingQueueDic(res.Path); } } mHasUseModelResList.Clear(); }
public void Init(long avatarID1, Vector3 delta1, long avatarID2, Vector3 delta2, int showDist = 6) { mIsShow = true; this.avatarID1 = avatarID1; this.avatarID2 = avatarID2; this.delta1 = delta1; this.delta2 = delta2; this.showDist = showDist; if (mLine == null) { CSResource res = SFOut.IResourceManager.AddQueue("Line", ResourceType.Effect, OnLoaded, ResourceAssistType.Terrain); } else { Show(true); UpdateLinePos(); } }
public void __Gen_Delegate_Imp4(CSResource p0) { #if THREAD_SAFE || HOTFIX_ENABLE lock (luaEnv.luaEnvLock) { #endif RealStatePtr L = luaEnv.rawL; int errFunc = LuaAPI.pcall_prepare(L, errorFuncRef, luaReference); ObjectTranslator translator = luaEnv.translator; translator.Push(L, p0); PCall(L, 1, 0, errFunc); LuaAPI.lua_settop(L, errFunc - 1); #if THREAD_SAFE || HOTFIX_ENABLE } #endif }
/// <summary> /// 在Update中检测资源的更新 /// </summary> private void LoadWWWLine() { ///正在等待加载的资源列表 if (waitingWWWQueue.Count == 0) { return; } for (int i = 0; i < waitingWWWQueue.Count; i++) { CSResource res = waitingWWWQueue[i]; if (res != null) { if (res.AssistType == EResourceAssistType.ForceLoad) { waitingWWWQueue.RemoveAt(i); RemoveWaitingQueueDic(res); AddLoadingQueue(res); res.Load(); break; } else { if (loadingQueue.Count > maxSyncLoadingNum) { return; } waitingWWWQueue.RemoveAt(i); RemoveWaitingQueueDic(res); res.Load(); break; } } else { waitingWWWQueue.RemoveAt(i); break; } } }
public void Load(uint modelID, uint motion, uint direction, uint structure, ResourceType type, ResourceAssistType assistType) { //Debug.Log(modelID + " " + motion + " " + direction); if (SFOut.IResourceManager == null) { return; } long key = GetKey((int)modelID, (int)motion, (int)direction); //if (avater != null && avater.getAvatarType() == EAvatarType.MainPlayer) //{ // Debug.Log("motion = " + (CSMotion)motion); //} if (mLoadedDic.ContainsKey(key)) { ModelLoadData data = mLoadedDic[key]; if (data != null && data.atlas != null && !data.atlas.HasBeenDestroy) { mStructures[structure] = key; string path = SFOut.IResourceManager.GetKeyPath(key); CSResource res = SFOut.IResourceManager.GetRes(path); if (res != null) { BeginLoadModelResCallBack(res); } return; } } else { ModelLoadData data = new ModelLoadData(); mLoadedDic.Add(key, data); data.type = type; data.assistType = assistType; } mStructures[structure] = key; mObjectList.Add(key); mObjectFinishStateList.Add(false); }
void OnLoaded(CSResource res) { if (!mIsShow) { return; } if (SFOut.IScene == null) { return; } if (mLine == null) { ISFAvater avatar = SFOut.IScene.getAvatarByISFAvatar(avatarID1); if (avatar == null) { return; } GameObject go = res.GetObjInst() as GameObject; if (go == null) { return; } SFMisc.SetLayer(go, 0); Transform trans = go.transform; trans.parent = avatar.CacheTransform; trans.localPosition = Vector3.zero; trans.localScale = Vector3.one; mLine = go.GetComponent <LineRenderer>(); } if (mLine == null) { Destroy(); return; } UpdateLinePos(); }
public void GetWaitModelRes() { for (int i = 0; i < mObjectList.Count; i++) { long key = mObjectList[i]; if (!mLoadedDic.ContainsKey(key)) { continue; } int modelID = 0, motion = 0, direction = 0; SplitKey(key, ref modelID, ref motion, ref direction); ModelLoadData data = mLoadedDic[key]; string path = SFOut.IResourceManager.GetKeyPath(key); if (SFOut.IResourceManager == null) { return; } if (!string.IsNullOrEmpty(path)) { CSResource res = SFOut.IResourceManager.GetRes(path); if (res != null && res.IsCanBeDelete) { SFOut.IResourceManager.RemoveWaitingQueueDic(res.Path); } } else { string Model = GetCombineModel((uint)modelID, (uint)motion, (uint)direction); path = CSResource.GetPath(Model, data.type, false); CSResource res = SFOut.IResourceManager.GetRes(path); if (res != null && res.IsCanBeDelete) { SFOut.IResourceManager.RemoveWaitingQueueDic(res.Path); } } } }
/// <summary> /// 加载资源到队列中 /// </summary> /// <param name="name">资源名字</param> /// <param name="type">资源类型</param> /// <param name="onLoadCallBack">加载完成后回调</param> /// <param name="assistType">资源加载优先级</param> /// <param name="isPath">是否为全路径</param> /// <returns></returns> public CSResource AddQueue(string name, EResourceType type, CSEventDelegate <CSResource> .OnLoaded onLoadCallBack, EResourceAssistType assistType, bool isFullPath = false, object param = null) { string path = isFullPath ? name : CSResource.GetPath(name, type, false); //从已经加载完成的字典中查询 CSResource res = GetLoadedRes(path); //如果没有下载完成,从正在下载队列中查找 if (res == null) { res = GetLoadingRes(path); } //如果没有下载,也没有正在下载,那么去等待下载队列中查找 if (res == null) { res = GetWaitingQueueRes(path); } //如果在等待队列中找到了,那么去看看是否需要调整优先级 if (res != null) { if ((int)assistType > (int)res.AssistType) { res.AssistType = assistType;//优先级 只曾不减,防止主角正在等待下载时,来了一个其他玩家优先级较低的下载 } AdjustProri(res); } else { //如果3个队列都没有找到,说明之前没有下载过对应资源,那么,新增资源下载数据 res = new CSResourceWWW(name, path, type); if ((int)assistType > (int)res.AssistType) { res.AssistType = assistType;//优先级 只曾不减,防止主角正在等待下载时,来了一个其他玩家优先级较低的下载 } AddWaitingQueueDic(res); AdjustProri(res); } if (onLoadCallBack != null) { if (res.IsDone) { if (onLoadCallBack != null) { onLoadCallBack(res); } } else { res.onLoaded -= onLoadCallBack; res.onLoaded += onLoadCallBack; } } res.Param = param; return(res); }
/// <summary> /// WWW资源下载完成后调用 /// </summary> /// <param name="res"></param> public void WWWLoaded(CSResource res) { RemoveLoadingQueue(res); AddLoadedQueue(res); }
protected virtual void LoadedOne(CSResource res) { }
public virtual void BeginLoadModelResCallBack(CSResource res) { }