Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using UnityEngine;
- using UnityEditor;
- using System.Text.RegularExpressions;
- class UCSSPostprocessor : AssetPostprocessor
- {
- static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
- {
- foreach (string str in importedAssets)
- {
- if (str.EndsWith(".uss"))
- {
- StreamReader reader = new StreamReader(Application.dataPath + "/../" + str);
- if (reader.ReadLine() == "/* Postprocess */")
- {
- // Debug.Log("Postprocessing " + str);
- Regex rx = new Regex(@"(?<=\n)\.(?=\S)",
- RegexOptions.Compiled);
- string data = reader.ReadToEnd();
- foreach(var prefix in Enum.GetNames(typeof(ScreenSizePrefix)))
- {
- // Replaces .classname with .prefix--classname
- string rdata = rx.Replace(data, "." + prefix + "--");
- string fname = Path.GetFileName(str);
- string path = str.Remove(str.Length - fname.Length);
- // Stores variants as prefix_origname.uss
- StreamWriter writer = new StreamWriter(Application.dataPath + "/../" + path + prefix + "_" + fname);
- writer.Write(rdata);
- writer.Close();
- }
- }
- reader.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement