private void EndPerf(bool showLog = false) { if (_perfingList.Count == 0) { return; } var nowTime = Time.realtimeSinceStartup * 1000; var perfing = _perfingList.Pop(); if (!_allPerfStatList.ContainsKey(perfing.realKey)) { return; } var perfStat = _allPerfStatList[perfing.realKey]; perfStat.lastCostTime = Math.Round(nowTime - perfing.beginTime, 1); perfStat.recordList.Add(perfStat.lastCostTime); perfStat.totalTimes++; perfStat.totalCostTime += perfStat.lastCostTime; if (showLog) { FTDebug.LogWarning(string.Format("Key[{0}] RealKey[{1}] CostTime[{2}] TotalCostTime[{3}] TotalTimes[{4}] AverageTime[{5}] BeginTime[{6}] EndTime[{7}]", perfing.key, perfing.realKey, perfStat.lastCostTime, perfStat.totalCostTime, perfStat.totalTimes, Math.Round(perfStat.totalCostTime / perfStat.totalTimes, 1), perfing.beginTime, nowTime), "PERF"); } if (this._onStatRefresh != null) { this._onStatRefresh(); } }
private void OnDownloadState(GameAsyncResInfo resInfo, GameResDownloadState state, float progress, int downloadSize) { if (resInfo != null) { FTDebug.LogWarning($"SingleAsnycRes Download State [{resInfo.bundleName}] [{state}] [{progress}] [{downloadSize}]"); } if (state == GameResDownloadState.SUCCESS && resInfo != null) { GameAsyncRes.OnAsyncResDownloadSuccess(resInfo.bundleName); } var iState = (int)state; if (_onDownloadState != null) { _onDownloadState(iState, progress, downloadSize); } if (_downloadEvent != null) { if (_isDetailEvent || iState >= (int)GameResDownloadState.SUCCESS || iState != _lastEventState) { _downloadEvent(iState, progress, downloadSize); _lastEventState = iState; } } if (state == GameResDownloadState.SUCCESS || state == GameResDownloadState.FAILED) { _onDownloadState = null; } }
public static void Print() { foreach (var key in AllCachedObjects.Keys) { FTDebug.LogWarning($"CacheObject ID[{key}] Object[{AllCachedObjects[key].name}-{AllCachedObjects[key].GetInstanceID()}]"); } FTDebug.LogWarning($"ObjectCache Count[{AllCachedObjects.Count}]"); }
public override void OnInspectorGUI() { serializedObject.Update(); SerializedProperty objectNameList = serializedObject.FindProperty("_objectNameList"); SerializedProperty objectName; //---- [1]开始垂直布局 ---- EditorGUILayout.BeginVertical(); for (int index = 0; index < objectNameList.arraySize; index++) { objectName = objectNameList.GetArrayElementAtIndex(index); //---- [2]开始水平布局 ---- EditorGUILayout.BeginHorizontal(); //索引 EditorGUILayout.LabelField((index + 1).ToString(), GUILayout.Width(30)); //监听是否更改 GUI.changed = false; //自定义命名 objectName.stringValue = EditorGUILayout.TextField(objectName.stringValue); if (GUILayout.Button("X")) { FTDebug.LogWarning($"Delete {index} {objectNameList.GetArrayElementAtIndex(index).stringValue}"); objectNameList.DeleteArrayElementAtIndex(index); serializedObject.ApplyModifiedProperties(); AssetDatabase.SaveAssets(); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); //---- [2]结束水平布局 ---- } //新增按钮 if (GUILayout.Button("新增", GUILayout.MaxHeight(30))) { objectNameList.InsertArrayElementAtIndex(objectNameList.arraySize); objectName = objectNameList.GetArrayElementAtIndex(objectNameList.arraySize - 1); objectName.stringValue = ""; serializedObject.ApplyModifiedProperties(); AssetDatabase.SaveAssets(); } //新增按钮 if (GUILayout.Button("导出", GUILayout.MaxHeight(40))) { // 去重 CheckSameName(serializedObject, objectNameList); GenerateLuaFile(objectNameList); } //---- [2]开始水平布局 ---- EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.EndHorizontal(); //---- [2]结束水平布局 ---- EditorGUILayout.HelpBox("每次新增组件名字后,需要重新生成Lua枚举文件", MessageType.Info); EditorGUILayout.EndVertical(); //---- [1]结束垂直布局 ---- serializedObject.ApplyModifiedProperties(); }
public void SetExtraFollowerBoneName(string boneName) { try { _extraFollower.target = _endUnit.GetBoneTransform(boneName); } catch (Exception ex) { FTDebug.LogError($"SetExtraFollowerBoneName Error {this.gameObject.name} {ex.Message} {ex.StackTrace}", true); } }
public void SetExtraPositionBone(string boneName) { try { _extraTransform.position = _endUnit.GetBonePosition(boneName); } catch (Exception ex) { FTDebug.LogError($"SetExtraPositionBone Error {this.gameObject.name} {ex.Message} {ex.StackTrace}", true); } }
private void BeginPerf(string key, bool ignoreParent = false) { if (!PERF_OPEN) { return; } if (string.IsNullOrEmpty(key)) { FTDebug.LogError("[GamePerf] Perf Lose Key"); return; } var parentKey = ""; if (_perfingList.Count != 0 && !ignoreParent) { parentKey = _perfingList.First().realKey; } var perfing = new GamePerfingData() { key = key, parentKey = parentKey, beginTime = 0, }; if (!_allPerfStatList.ContainsKey(perfing.realKey)) { var perfStat = new GamePerfStat() { key = key, parentKey = parentKey, totalTimes = 0, totalCostTime = 0, lastCostTime = 0, recordList = new List <double>(), childList = new List <string>(), statLevel = 0, }; _allPerfStatList.Add(perfing.realKey, perfStat); if (_allPerfStatList.Keys.Contains(parentKey)) { var parentPerf = _allPerfStatList[parentKey]; parentPerf.childList.Add(perfing.realKey); perfStat.statLevel = parentPerf.statLevel + 1; } } _perfingList.Push(perfing); perfing.beginTime = Time.realtimeSinceStartup * 1000; }
public void UnLoadAssetBundleGroup(string manifestName) { if (!_allAssetBundleMap.ContainsKey(manifestName)) { return; } var bundleGroupMap = _allAssetBundleMap[manifestName]; foreach (var bundleName in bundleGroupMap.Keys) { bundleGroupMap[bundleName].assetBundle.Unload(true); FTDebug.LogWarning(string.Format("UnLoadAssetBundleGroup ManifestName[{0}] BundleName[{1}]", manifestName, bundleName)); } bundleGroupMap.Clear(); }
public void UnLoadAssetBundle(string bundleName, string manifestName, bool unloadAll = true) { if (!_allAssetBundleMap.ContainsKey(manifestName)) { return; } var bundleGroupMap = _allAssetBundleMap[manifestName]; if (!bundleGroupMap.ContainsKey(bundleName)) { return; } bundleGroupMap[bundleName].assetBundle.Unload(unloadAll); bundleGroupMap.Remove(bundleName); FTDebug.LogWarning(string.Format("UnLoadAssetBundle Name[{0}] UnLoadAll[{1}]", bundleName, unloadAll)); }
public static void CreateObjectNameCache() { var selectObjects = Selection.GetFiltered(typeof(Object), SelectionMode.TopLevel | SelectionMode.Assets); if (selectObjects == null || selectObjects.Length == 0) { FTDebug.LogWarning($"CreateObjectNameCache - Cannot find select objects"); return; } var objFolder = selectObjects.FirstOrDefault(obj => Directory.Exists(AssetDatabase.GetAssetPath(obj))); if (objFolder == null) { FTDebug.LogWarning($"CreateObjectNameCache - Cannot find select folder object"); return; } AssetDatabase.CreateAsset(new ObjectNameCache(), AssetDatabase.GetAssetPath(objFolder) + "/NewObjectNameCache.asset"); }
private IEnumerator LoadAssetBundleFromFile(Dictionary <string, GameResAssetBundle> bundleGroupMap, string bundleName, string manifestName, string hash, string fullPath, System.Action <bool> onLoadDone) { var realHash = Hash128.Parse(hash); var req = AssetBundle.LoadFromFileAsync(fullPath); while (!req.isDone) { yield return(null); } if (req.assetBundle == null) { onLoadDone(false); yield break; } if (bundleGroupMap.ContainsKey(bundleName) && bundleGroupMap[bundleName].hash != hash) { UnLoadAssetBundle(bundleName, manifestName); } if (!bundleGroupMap.ContainsKey(bundleName)) { bundleGroupMap.Add(bundleName, new GameResAssetBundle() { hash = hash, assetBundle = req.assetBundle, }); } // 清除缓存中除当前使用的 Caching.ClearOtherCachedVersions(bundleName, realHash); onLoadDone(true); FTDebug.LogWarning(string.Format("LoadAssetBundleFromFile Name[{0}] Path[{1}]", bundleName, fullPath)); }
private IEnumerator LoadAssetBundleFromCache(Dictionary <string, GameResAssetBundle> bundleGroupMap, string bundleName, string manifestName, string hash, string[] urls, System.Action <bool> onLoadDone) { var realHash = Hash128.Parse(hash); bool success = false; foreach (string url in urls) { float checkTimeOutTime = Time.time; float progress = 0; var webRequest = GameWebRequest.SendAssetBundleWebRequest(url, realHash, true); while (!webRequest.request.isDone) { if (!string.IsNullOrEmpty(webRequest.request.error)) { break; } if (progress != webRequest.request.downloadProgress) { checkTimeOutTime = Time.time; } else if (Time.time - checkTimeOutTime >= 5) { break; } yield return(null); } if (!string.IsNullOrEmpty(webRequest.request.error) || !webRequest.request.isDone) { FTDebug.LogWarning(string.Format("Failed To LoadAssetBundleFromCache Name[{0}] From[{1}] Error[{2}]", bundleName, url, webRequest.request.error)); GameWebRequest.DestroyAssetBundleWebRequest(webRequest); Caching.ClearCachedVersion(bundleName, realHash); continue; } AssetBundle assetBundle = null; try { assetBundle = DownloadHandlerAssetBundle.GetContent(webRequest.request); if (assetBundle == null) { FTDebug.LogWarning(string.Format("Failed To LoadAssetBundleFromCache Name[{0}] From[{1}] Error[AssetBundle is Null]", bundleName, url)); GameWebRequest.DestroyAssetBundleWebRequest(webRequest); Caching.ClearCachedVersion(bundleName, realHash); continue; } } catch (System.Exception e) { FTDebug.LogWarning(string.Format("Failed To LoadAssetBundleFromCache Name[{0}] From[{1}] Error[{2}]", bundleName, url, e.Message)); GameWebRequest.DestroyAssetBundleWebRequest(webRequest); Caching.ClearCachedVersion(bundleName, realHash); continue; } if (bundleGroupMap.ContainsKey(bundleName) && bundleGroupMap[bundleName].hash != hash) { UnLoadAssetBundle(bundleName, manifestName); } if (!bundleGroupMap.ContainsKey(bundleName)) { bundleGroupMap.Add(bundleName, new GameResAssetBundle() { hash = hash, assetBundle = assetBundle, }); } GameWebRequest.DestroyAssetBundleWebRequest(webRequest); success = true; FTDebug.Log(string.Format("LoadAssetBundleFromCache Name[{0}] From[{1}]", bundleName, url)); // 清除除当前使用的 Caching.ClearOtherCachedVersions(bundleName, realHash); break; } onLoadDone(success); }
private IEnumerator _DownloadAsync(GameResDownloadTask task) { _curTask = task; var realHash = Hash128.Parse(task.hash); task.state = GameResDownloadState.DOWNLOADING; #if UNITY_ANDROID && !UNITY_EDITOR Caching.compressionEnabled = !task.bundleName.Contains("video"); #endif bool success = false; foreach (string url in task.urls) { float checkTimeOutTime = Time.time; float progress = 0; FTDebug.Log(string.Format("Download {0} From {1} Size[{2}]", task.bundleName, url, task.totalSize)); _curWebRequest = GameWebRequest.SendAssetBundleWebRequest(url, realHash, true); if (task.onDownloadState != null) { task.onDownloadState((int)GameResDownloadState.DOWNLOADING, 0, 0, _taskList.Count); } while (_curWebRequest != null && !_curWebRequest.request.isDone) { if (!string.IsNullOrEmpty(_curWebRequest.request.error)) { break; } var _progress = _curWebRequest.request.downloadProgress; if (task.timeOut != 0) { if (progress != _progress) { checkTimeOutTime = Time.time; } else if (Time.time - checkTimeOutTime >= task.timeOut) { break; } } if (progress != _progress && task.onDownloadState != null) { task.onDownloadState((int)GameResDownloadState.DOWNLOADING, _progress, (int)(_progress * task.totalSize), _taskList.Count); } progress = _progress; yield return(null); } FTDebug.LogWarning(string.Format("Download Result {0} From {1} Error[{2}] {3}", task.bundleName, url, _curWebRequest.request.error, _curWebRequest.request.isDone)); if (!string.IsNullOrEmpty(_curWebRequest.request.error) || !_curWebRequest.request.isDone) { FTDebug.LogWarning(string.Format("Failed To Download {0} From {1} Error[{2}]", task.bundleName, url, _curWebRequest.request.error)); GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; continue; } FTDebug.Log(string.Format("Download Success {0} From {1} Size[{2}]", task.bundleName, url, task.totalSize)); GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; success = true; break; } #if UNITY_ANDROID && !UNITY_EDITOR if (!Caching.compressionEnabled) { Caching.compressionEnabled = true; } #endif task.state = success ? GameResDownloadState.SUCCESS : GameResDownloadState.FAILED; OnDownloadFinish(task); }