Exemple #1
0
        static void AddMarco(string assetPath, System.Func <string, string> fun)
        {
            HelpEditor.ForEach(assetPath, (AssetImporter importer) =>
            {
                var marco = fun(importer.assetPath);
                if (string.IsNullOrEmpty(marco))
                {
                    return;
                }

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append($"#if {marco}");
                {
                    string start = sb.ToString();

                    string file_text = ReadText(System.IO.File.ReadAllBytes(importer.assetPath));
                    if (file_text.StartsWith(start))
                    {
                        return;
                    }

                    sb.AppendLine();
                    sb.Append(file_text);
                    sb.AppendLine();
                }
                sb.Append($"#endif");
                WriteBytes(importer.assetPath, System.Text.Encoding.UTF8.GetBytes(sb.ToString()));
            },
                               (string file, string root) =>
            {
                return(file.EndsWith(".cs", true, null));
            });
        }
Exemple #2
0
        static void AddMarco(string assetPath, System.Func <string, string> fun)
        {
            HelpEditor.ForEach(assetPath, (AssetImporter importer) =>
            {
                var marco = fun(importer.assetPath);
                if (string.IsNullOrEmpty(marco))
                {
                    return;
                }

                string start     = string.Format("#if {0}\r", marco);
                string file_text = File.ReadAllText(importer.assetPath);
                if (file_text.StartsWith(start))
                {
                    return;
                }

                string text = string.Format("{0}{1}\r#endif", start, file_text);
                File.WriteAllText(importer.assetPath, text);
            },
                               (string file, string root) =>
            {
                return(file.EndsWith(".cs", true, null));
            });
        }