Advertisement
_Cery

UCSSPostprocessor

Jun 4th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.Text.RegularExpressions;
  6.  
  7. class UCSSPostprocessor : AssetPostprocessor
  8. {
  9.     static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  10.     {
  11.         foreach (string str in importedAssets)
  12.         {
  13.             if (str.EndsWith(".uss"))
  14.             {
  15.                 StreamReader reader = new StreamReader(Application.dataPath + "/../" + str);
  16.                 if (reader.ReadLine() == "/* Postprocess */")
  17.                 {
  18.                     // Debug.Log("Postprocessing " + str);
  19.                     Regex rx = new Regex(@"(?<=\n)\.(?=\S)",
  20.                         RegexOptions.Compiled);
  21.                     string data = reader.ReadToEnd();
  22.                     foreach(var prefix in Enum.GetNames(typeof(ScreenSizePrefix)))
  23.                     {
  24.                         // Replaces .classname with .prefix--classname
  25.                         string rdata = rx.Replace(data, "." + prefix + "--");
  26.                         string fname = Path.GetFileName(str);
  27.                         string path = str.Remove(str.Length - fname.Length);
  28.                         // Stores variants as prefix_origname.uss
  29.                         StreamWriter writer = new StreamWriter(Application.dataPath + "/../" + path + prefix + "_" + fname);
  30.                         writer.Write(rdata);
  31.                         writer.Close();
  32.                     }
  33.                 }
  34.                 reader.Close();
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement