Advertisement
ilih

Untitled

Dec 16th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. #if UNITY_EDITOR && (UNITY_2018_1 || UNITY_2018_2)
  2. namespace UIWidgets
  3. {
  4.     using System;
  5.     using System.IO;
  6.     using System.Linq;
  7.     using UnityEditor;
  8.  
  9.     public static class TextMeshProSupportFix
  10.     {
  11.         [MenuItem("Edit/Project Settings/New UI Widgets/Fix TextMesh Pro support files", false, 1100)]
  12.         public static void RemoveForceRecompile()
  13.         {
  14.             RemoveForceRecompileByLabel("TMProFolder");
  15.         }
  16.  
  17.         public static bool RemoveForceRecompileByLabel(string label)
  18.         {
  19.             var path = Utilites.GetAssetPath(label);
  20.             if (path == null)
  21.             {
  22.                 return false;
  23.             }
  24.  
  25.             if (Directory.Exists(path))
  26.             {
  27.                 RemoveForceRecompileFolder(path);
  28.             }
  29.             else
  30.             {
  31.                 RemoveForceRecompileFile(path);
  32.             }
  33.  
  34.             return true;
  35.         }
  36.  
  37.         static void RemoveForceRecompileFolder(string path)
  38.         {
  39.             var dir = new DirectoryInfo(path);
  40.             var files = dir.GetFiles("*.cs", SearchOption.AllDirectories);
  41.             foreach (var file in files)
  42.             {
  43.                 RemoveForceRecompileFile(file.FullName);
  44.             }
  45.  
  46.             AssetDatabase.Refresh();
  47.         }
  48.  
  49.         static void RemoveForceRecompileFile(string filepath)
  50.         {
  51.             var lines = File.ReadAllLines(filepath).ToList();
  52.             var prefix = "// Force script reload at ";
  53.  
  54.             if (lines[lines.Count - 1].StartsWith(prefix))
  55.             {
  56.                 lines.RemoveAt(lines.Count - 1);
  57.  
  58.                 File.WriteAllText(filepath, string.Join("\r\n", lines.ToArray()));
  59.                 File.SetLastWriteTimeUtc(filepath, DateTime.UtcNow);
  60.             }
  61.         }
  62.     }
  63. }
  64. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement