/// 卸载场景; private IEnumerator <float> UnloadSceneFromAssetBundleAsync(string path, Action <UnityEngine.SceneManagement.Scene> onSceneUnloaded , Action <float> progress) { var name = Path.GetFileNameWithoutExtension(path); SceneManager.sceneUnloaded += (scene) => { AssetBundle assetBundle; if (_sceneAssetBundleDict.TryGetValue(path, out assetBundle)) { AssetBundleMgr.Instance.UnloadAsset(path, null); } if (onSceneUnloaded != null) { onSceneUnloaded(scene); } }; AsyncOperation operation = SceneManager.UnloadSceneAsync(name); while (operation.progress < 0.99f) { if (progress != null) { progress(operation.progress); } yield return(Timing.WaitForOneFrame); } while (!operation.isDone) { yield return(Timing.WaitForOneFrame); } LogHelper.Print(string.Format("[ResourceMgr]UnloadSceneFromAssetBundleAsync success:{0}.", path)); }
/// 构造函数; protected MonoSingleton() { if (null == _instance) { LogHelper.Print("[MonoSingleton]" + (typeof(T)).ToString() + " singleton instance created."); } }
public static void ExecuteCameraShot(Camera camera, Action <Texture2D> action) { CoroutineMgr.singleton.StartCoroutine(WaitForEndOfFrameItor(() => { var width = camera.pixelWidth; var height = camera.pixelHeight; var targetRt = camera.targetTexture; var activeRt = RenderTexture.active; var rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32); camera.targetTexture = rt; camera.Render(); RenderTexture.active = rt; var tex = new Texture2D(width, height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); camera.targetTexture = targetRt; RenderTexture.active = activeRt; RenderTexture.ReleaseTemporary(rt); var texByte = tex.EncodeToPNG(); LogHelper.Print($"[UIScreenShotHelper]Save Image to:{Application.dataPath.ToLower()}/../ScreenShot/"); FileHelper.Write2Bytes($"{Application.dataPath.ToLower()}/../ScreenShot/CameraShot.png", texByte); action?.Invoke(tex); })); }
/// 构造函数; protected MonoSingleton() { if (null == _singleton) { LogHelper.Print($"[MonoSingleton]{(typeof(T)).ToString()} singleton instance created."); } }
public static void BuildPb2Lua() { _paths.Clear(); _files.Clear(); Recursive(_pbluaDir); int index = 0; foreach (string f in _files) { index++; string name = Path.GetFileName(f); string ext = Path.GetExtension(f); string workPath = Path.GetDirectoryName(f); if (!ext.Equals(".proto")) { continue; } EditorUtility.DisplayProgressBar("Build PbLua File", "gen proto to lua:" + name, (float)index / (float)_files.Count); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = _protoc; info.Arguments = " --lua_out=./ --plugin=protoc-gen-lua=" + _protocGenDir + " " + name; info.WindowStyle = ProcessWindowStyle.Hidden; info.UseShellExecute = true; info.WorkingDirectory = workPath; info.ErrorDialog = true; LogHelper.Print("gen proto to lua:" + name); Process pro = Process.Start(info); pro.WaitForExit(); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public static void GenerateProtoToLua() { InitContext(); int index = 0; foreach (string tempFile in _files) { index++; string fileName = Path.GetFileName(tempFile); string fileExtension = Path.GetExtension(tempFile); string workPath = Path.GetDirectoryName(tempFile); if (!fileExtension.Equals(".proto")) { continue; } EditorUtility.DisplayProgressBar("Generate", "generate proto to lua:" + fileName, (float)index / (float)_files.Count); ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = Protoc; processStartInfo.Arguments = " --lua_out=./ --plugin=protoc-gen-lua=" + ProtocGenPath + " " + fileName; processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; processStartInfo.UseShellExecute = true; processStartInfo.WorkingDirectory = workPath; processStartInfo.ErrorDialog = true; LogHelper.Print("generate proto to lua:" + fileName); Process process = Process.Start(processStartInfo); process.WaitForExit(); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public override void Init() { base.Init(); float allMenory = GetAllMemory(); LogHelper.Print(string.Format("Used Heap Size: {0} MB", allMenory.ToString("F3"))); }
/// <summary> /// pbc/pblua函数回调; /// </summary> /// <param name="data"></param> /// <param name="func"></param> public static void OnCallLuaFunc(LuaByteBuffer data, LuaFunction func) { if (func != null) { func.Call(data); } LogHelper.Print("OnCallLuaFunc length:>>" + data.buffer.Length); }
/// <summary> /// AssetBundle异步加载LoadFromFileAsync,www异步加载消耗大于LoadFromFileAsync; /// </summary> /// <param name="path">资源路径</param> /// <param name="action">AssetBundle回调</param> /// <param name="progress">progress回调</param> /// <returns></returns> private IEnumerator <float> LoadAsync(string path, Action <AssetBundle> action, Action <float> progress) { if (string.IsNullOrEmpty(path)) { yield break; } AssetBundle assetBundle = null; while (IsAssetBundleLoading(path)) { yield return(Timing.WaitForOneFrame); } if (!assetBundleCache.ContainsKey(path)) { //开始加载; assetBundleLoading.Add(path); AssetBundleCreateRequest assetBundleReq = AssetBundle.LoadFromFileAsync(path); //加载进度; while (assetBundleReq.progress < 0.99) { if (null != progress) { progress(assetBundleReq.progress); } yield return(Timing.WaitForOneFrame); } while (!assetBundleReq.isDone) { yield return(Timing.WaitForOneFrame); } assetBundle = assetBundleReq.assetBundle; if (assetBundle == null) { LogHelper.Print(string.Format("[AssetBundleMgr]Load AssetBundle {0} failure!", path)); } else { assetBundleCache[path] = assetBundle; assetBundleReference[path] = 1; LogHelper.Print(string.Format("[AssetBundleMgr]Load AssetBundle {0} Success!", path)); } //加载完毕; assetBundleLoading.Remove(path); } else { assetBundle = assetBundleCache[path]; assetBundleReference[path]++; } if (action != null) { action(assetBundle); } }
private void OnConnected(Session session, SessionParam args) { LogHelper.Print(string.Format("[NetMgr]Session Connected!")); ProtoHelper.Register(); if (!GameMgr.Instance.CheckUpdateState) { GameMgr.Instance.CheckUpdateState = true; _checkUpdateState = true; } }
/// 加载场景; private IEnumerator <float> LoadSceneFromAssetBundleAsync(string path, Action <UnityEngine.SceneManagement.Scene> onSceneLoaded , Action <float> progress) { AssetBundle assetBundle = null; if (_sceneAssetBundleDict.TryGetValue(path, out assetBundle)) { if (assetBundle != null) { LogHelper.Print(string.Format("[ResourceMgr]LoadSceneFromAssetBundleAsync repeat:{0}.", path)); yield break; } } //此处加载占90%; IEnumerator itor = AssetBundleMgr.Instance.LoadFromFileAsync(path, bundle => { assetBundle = bundle; }, progress); while (itor.MoveNext()) { yield return(Timing.WaitForOneFrame); } _sceneAssetBundleDict[path] = assetBundle; var name = Path.GetFileNameWithoutExtension(path); //先等一帧; yield return(Timing.WaitForOneFrame); SceneManager.sceneLoaded += (scene, mode) => { if (onSceneLoaded != null) { onSceneLoaded(scene); } }; AsyncOperation operation = SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive); //此处加载占10%; while (operation.progress < 0.99f) { if (progress != null) { progress(0.9f + 0.1f * operation.progress); } yield return(Timing.WaitForOneFrame); } while (!operation.isDone) { yield return(Timing.WaitForOneFrame); } LogHelper.Print(string.Format("[ResourceMgr]LoadSceneFromAssetBundleAsync success:{0}.", path)); }
/// <summary> /// 构造函数; /// </summary> protected MonoSingleton() { if (null != _instance) { LogHelper.PrintWarning((typeof(T)).ToString() + " singleton Instance is not null."); } else { LogHelper.Print((typeof(T)).ToString() + " singleton Instance created."); } }
/// 加载场景; private IEnumerator <float> LoadScene(string path, Action <UnityEngine.SceneManagement.Scene> onSceneLoaded , Action <float> progress) { path = $"Assets/Bundles/{path}"; IEnumerator itor = SceneLoader.LoadSceneAsync(path, onSceneLoaded, progress); while (itor.MoveNext()) { yield return(Timing.WaitForOneFrame); } LogHelper.Print($"[ResourceMgr]LoadSceneAsync success:{path}."); }
private void MonitorMemorySize() { float allMenory = GetAllMemory(); if (allMenory > _maxMemoryUse) { LogHelper.PrintError(string.Format("Used Heap Size: {0} MB", allMenory.ToString("F3"))); FreeMemory(); } else { LogHelper.Print(string.Format("Used Heap Size: {0} MB", allMenory.ToString("F3"))); } }
private void MonitorMemorySize() { float allMenory = GetAllMemory(); if (allMenory > MaxMemoryUse) { LogHelper.PrintError($"Used Heap Size: {allMenory.ToString("F3")} MB"); FreeMemory(); } else { LogHelper.Print($"Used Heap Size: {allMenory.ToString("F3")} MB"); } }
public static void GenerateProtoToCsharp() { string[] allPath = Directory.GetFiles(protoFilePath, "*.*", SearchOption.AllDirectories); List <string> allAssetPath = new List <string>(); foreach (string tempPath in allPath) { string path = tempPath.Replace("\\", "/"); if (Path.GetExtension(path) == ".proto") { allAssetPath.Add(path); } ; } int index = 0; foreach (string f in allAssetPath) { index++; string fileName = Path.GetFileName(f); string fileExtension = Path.GetExtension(f); string workPath = Path.GetDirectoryName(f); string targetFileName = Path.GetFileNameWithoutExtension(f); if (!fileExtension.Equals(".proto")) { continue; } if (null == outPath) { continue; } if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } EditorUtility.DisplayProgressBar("Generate", "generate proto to c#:" + fileName, (float)index / (float)allAssetPath.Count); ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = protocPath; processStartInfo.Arguments = "--proto_path=" + workPath + " --csharp_out=" + outPath + " " + targetFileName + ".proto"; processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; processStartInfo.UseShellExecute = true; processStartInfo.WorkingDirectory = workPath; processStartInfo.ErrorDialog = true; LogHelper.Print("generate proto to c#:" + fileName); Process process = Process.Start(processStartInfo); process.WaitForExit(); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public void TestLoopScrollRect() { if (Application.isPlaying) { onLoopItemUpdate = (go, index) => { LogHelper.Print($"===>>>[curIndex]:{index}"); }; if (InitScrollRect()) { SetScrollRectCount(66); } } }
/// AssetBundle异步加载LoadFromFileAsync,www异步加载消耗大于LoadFromFileAsync; private IEnumerator <float> LoadAsync(string path, Action <AssetBundle> action, Action <float> progress) { if (string.IsNullOrEmpty(path)) { yield break; } AssetBundle assetBundle = null; while (IsAssetBundleLoading(path)) { yield return(Timing.WaitForOneFrame); } if (!assetBundleCache.ContainsKey(path)) { //开始加载; assetBundleLoading.Add(path); var assetBundleReq = AssetBundle.LoadFromFileAsync(path); //加载进度; while (assetBundleReq.progress < 0.99) { progress?.Invoke(assetBundleReq.progress); yield return(Timing.WaitForOneFrame); } while (!assetBundleReq.isDone) { yield return(Timing.WaitForOneFrame); } assetBundle = assetBundleReq.assetBundle; if (assetBundle == null) { LogHelper.Print($"[AssetBundleMgr]Load assetBundle:{path} failure."); } else { assetBundleCache[path] = assetBundle; assetBundleReference[path] = 1; LogHelper.Print($"[AssetBundleMgr]Load assetBundle:{path} success."); } //加载完毕; assetBundleLoading.Remove(path); } else { assetBundle = assetBundleCache[path]; assetBundleReference[path]++; } action?.Invoke(assetBundle); }
/// 初始化Lua; private void InitLua() { //Lua初始化; LuaAssetBundle = AssetBundleMgr.Instance.LoadLuaAssetBundle(); if (LuaAssetBundle != null) { var a = LuaAssetBundle.LoadAllAssets(); LogHelper.Print("[ResourceMgr]Load Lua Success!"); } else { LogHelper.PrintError("[ResourceMgr]Load Lua failure!"); } //AssetBundleMgr.Instance.UnloadMirroring(FilePathHelper.luaAssetBundleName); }
public void RegisterCallBack(Action <string> cb) { if (cb != null) { var cbName = cb.Method.Name; if (_sdkCallbackDict.ContainsKey(cbName)) { _sdkCallbackDict[cbName] = cb; } else { _sdkCallbackDict.Add(cbName, cb); } LogHelper.Print($"[SdkMgr]Register Callback Success:{cbName}"); } }
public void RegisterCallBack(Action <string> cb) { if (cb != null) { string cbName = cb.Method.Name; if (SdkCallBack.ContainsKey(cbName)) { SdkCallBack[cbName] = cb; } else { SdkCallBack.Add(cbName, cb); } LogHelper.Print("[SdkMgr]Register Callback Success:" + cbName); } }
/// <summary> /// 初始化Shader; /// </summary> private void InitShader() { //Shader初始化; AssetBundle shaderAssetBundle = AssetBundleMgr.Instance.LoadShaderAssetBundle(); if (shaderAssetBundle != null) { shaderAssetBundle.LoadAllAssets(); Shader.WarmupAllShaders(); LogHelper.Print("[ResourceMgr]Load Shader and WarmupAllShaders Success!"); } else { LogHelper.PrintError("[ResourceMgr]Load Shader and WarmupAllShaders failure!"); } AssetBundleMgr.Instance.UnloadMirroring(AssetType.Shader, "Shaders"); }
/// 初始化Shader; private void InitShader() { //Shader初始化; var shaderAssetBundle = AssetBundleMgr.singleton.LoadShaderAssetBundle(); if (shaderAssetBundle != null) { shaderAssetBundle.LoadAllAssets(); Shader.WarmupAllShaders(); LogHelper.Print("[ResourceMgr]Load Shader and WarmupAllShaders Success!"); } else { LogHelper.PrintError("[ResourceMgr]Load Shader and WarmupAllShaders failure!"); } //AssetBundleMgr.Instance.UnloadMirroring(FilePathHelper.shaderAssetBundleName); }
public static void ExecuteScreenShot(Action <Texture2D> action) { CoroutineMgr.singleton.StartCoroutine(WaitForEndOfFrameItor(() => { var width = Screen.width; var height = Screen.height; var tex = new Texture2D(width, height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); var texByte = tex.EncodeToPNG(); LogHelper.Print($"[UIScreenShotHelper]Save Image to:{Application.dataPath.ToLower()}/../ScreenShot/"); FileHelper.Write2Bytes($"{Application.dataPath.ToLower()}/../ScreenShot/ScreenShot.png", texByte); action?.Invoke(tex); })); }
/// 卸载场景; private IEnumerator <float> UnloadScene(string path, Action <UnityEngine.SceneManagement.Scene> onSceneUnloaded , Action <float> progress) { var name = Path.GetFileNameWithoutExtension(path); SceneLoader.UnloadSceneAsync(path, onSceneUnloaded, progress); AsyncOperation operation = SceneManager.UnloadSceneAsync(name); while (operation.progress < 0.99f) { progress?.Invoke(operation.progress); yield return(Timing.WaitForOneFrame); } while (!operation.isDone) { yield return(Timing.WaitForOneFrame); } LogHelper.Print($"[ResourceMgr]UnloadSceneAsync success:{path}."); }
public IEnumerator <float> LoadSceneAsync(string path, Action <UnityEngine.SceneManagement.Scene> onSceneLoaded, Action <float> progress) { if (singleton._sceneAssetBundleDict.TryGetValue(path, out var assetBundle)) { if (assetBundle != null) { LogHelper.Print($"[ResourceMgr]LoadSceneFromAssetBundleAsync repeat:{path}."); yield break; } } //此处加载占90%; var itor = AssetBundleMgr.singleton.LoadFromFileAsync(path, bundle => { assetBundle = bundle; }, progress); while (itor.MoveNext()) { yield return(Timing.WaitForOneFrame); } singleton._sceneAssetBundleDict[path] = assetBundle; var name = Path.GetFileNameWithoutExtension(path); //先等一帧; yield return(Timing.WaitForOneFrame); SceneManager.sceneLoaded += (scene, mode) => { onSceneLoaded?.Invoke(scene); }; var op = SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive); //此处加载占10%; while (op.progress < 0.99f) { progress?.Invoke(0.9f + 0.1f * op.progress); yield return(Timing.WaitForOneFrame); } while (!op.isDone) { yield return(Timing.WaitForOneFrame); } }
public static void BuildPb2Csharp() { _paths.Clear(); _files.Clear(); Recursive(_pbluaDir); int index = 0; foreach (string f in _files) { index++; string name = Path.GetFileName(f); string ext = Path.GetExtension(f); string workPath = Path.GetDirectoryName(f); string fileName = Path.GetFileNameWithoutExtension(f); if (!ext.Equals(".proto")) { continue; } //输出目录; string outPath = GetCsharpPath(f) + fileName; if (null == outPath) { continue; } if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } EditorUtility.DisplayProgressBar("Build PbLua File", "gen proto to c#:" + name, (float)index / (float)_files.Count); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = _protogen; info.Arguments = "-i:" + name + " -o:" + outPath + "/" + fileName + ".cs -p:detectMissing"; info.WindowStyle = ProcessWindowStyle.Hidden; info.UseShellExecute = true; info.WorkingDirectory = workPath; info.ErrorDialog = true; LogHelper.Print("gen proto to c#:" + name); Process pro = Process.Start(info); pro.WaitForExit(); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public static void Export() { /* * string path = EditorUtility.OpenFilePanel("选择Scene文件", Application.dataPath, "unity"); * if (string.IsNullOrEmpty(path)) * return; */ bool export = EditorUtility.DisplayDialog("提示", "确认导出当前场景的NavMesh数据!", "开始导出"); if (export) { NavMeshTriangulation triangNavMesh = NavMesh.CalculateTriangulation(); if (triangNavMesh.areas.Length == 0 && triangNavMesh.indices.Length == 0) { return; } Mesh mesh = new Mesh(); mesh.name = "_NavMesh"; mesh.vertices = triangNavMesh.vertices; mesh.triangles = triangNavMesh.indices; string sceneName = SceneManager.GetActiveScene().name; string parentName = _rootPath + sceneName; string fileName = parentName + "/" + sceneName + "_NavMesh.obj"; if (Directory.Exists(parentName)) { Directory.Delete(parentName, true); } Directory.CreateDirectory(parentName); AssetDatabase.Refresh(); using (StreamWriter sw = new StreamWriter(fileName)) { sw.Write(GenerateMesh(mesh)); } AssetDatabase.Refresh(); string assetName = fileName.Replace(Application.dataPath, "Assets"); GameObject navMesh = Object.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(assetName)); navMesh.name = "_NavMesh"; ExportNavData(navMesh); LogHelper.Print("导出NavMesh完成:" + sceneName + "_NavMesh.obj"); AssetDatabase.Refresh(); } }
public static void ExecuteScreenShot(Action <Texture2D> action) { CoroutineMgr.Instance.StartCoroutine(WaitForEndOfFrameItor(() => { var width = Screen.width; var height = Screen.height; Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); byte[] texByte = tex.EncodeToPNG(); LogHelper.Print("[UIScreenShotHelper]Save Image to:" + Application.dataPath.ToLower() + "/../ScreenShot/"); FileHelper.Write2Bytes(Application.dataPath.ToLower() + "/../ScreenShot/ScreenShot.png", texByte); if (action != null) { action(tex); } })); }
public static void GenerateProtoToCsharp() { InitContext(); int index = 0; foreach (string f in _files) { index++; string fileName = Path.GetFileName(f); string fileExtension = Path.GetExtension(f); string workPath = Path.GetDirectoryName(f); string targetFileName = Path.GetFileNameWithoutExtension(f); if (!fileExtension.Equals(".proto")) { continue; } //输出目录; string outPath = GetCsharpPath(f) + targetFileName; if (null == outPath) { continue; } if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } EditorUtility.DisplayProgressBar("Generate", "generate proto to c#:" + fileName, (float)index / (float)_files.Count); ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = ProtogenPath; processStartInfo.Arguments = "-i:" + fileName + " -o:" + outPath + "/" + targetFileName + ".cs -p:detectMissing"; processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; processStartInfo.UseShellExecute = true; processStartInfo.WorkingDirectory = workPath; processStartInfo.ErrorDialog = true; LogHelper.Print("generate proto to c#:" + fileName); Process process = Process.Start(processStartInfo); process.WaitForExit(); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }