打包尽量别输出Log,别拼接字符串

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();
        }   
    }
}

猜你喜欢

转载自blog.csdn.net/SendSI/article/details/83957767