打包儘量別輸出Log,別拼接字串
阿新 • • 發佈:2018-11-11
Unity EDITOR_LOG.輸出會產生GC.拼接字串也會產生.開發時用巨集log.打包時去掉巨集
using System; using System.IO; using UnityEditor; using UnityEngine; using System.Collections.Generic; using System.Text; public class ModifyScriptEditor : EditorWindow { [MenuItem("Tools/簡單生成")] public static void ModifyGenerate() { var tGuids = AssetDatabase.FindAssets("t:Script", new string[] { "Assets/Scripts" }); var tProject = Application.dataPath.Replace("/Assets", ""); var tTxts = new Dictionary<string,string>(); foreach (var tGuid in tGuids) { var tPath = tProject +"/"+ AssetDatabase.GUIDToAssetPath(tGuid); var tOld = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(tGuid)) as TextAsset; tTxts[tPath] = tOld.text; } foreach (var item in tTxts) { var tTA = item.Value; var tPath = item.Key; var tLines = tTA.Split(new string[] { "\r\n" }, StringSplitOptions.None); var sb = new StringBuilder(); for (int i = 0; i < tLines.Length; i++) { var tLine = tLines[i]; if (tLine.Contains("Debug")) { sb.AppendLine("#if EDITOR_LOG"); sb.AppendLine(tLine); sb.AppendLine("#endif"); } else { sb.AppendLine(tLine); } } StreamWriter tReader = new StreamWriter(tPath, false); tReader.Write(sb.ToString()); tReader.Close(); } } }