private static void CheckChangedAssets() { var changedAssetsCopy = default(string[]); lock (changedAssets) { if (changedAssets.Count > 0) { changedAssetsCopy = changedAssets.ToArray(); changedAssets.Clear(); } } if (changedAssetsCopy == null) { return; } var triggeredTemplatePaths = new HashSet <string>(); foreach (var changedAsset in changedAssetsCopy) { //if (Menu.VerboseLogs) // Debug.Log("Changed Asset: " + changedAsset); if (!File.Exists(changedAsset)) { continue; } foreach (var watchedPath in templatePathByWatchedPaths.Keys) { if (changedAsset.StartsWith(watchedPath, StringComparison.Ordinal)) { foreach (var templatePath in templatePathByWatchedPaths[watchedPath]) { triggeredTemplatePaths.Add(templatePath); } } } } foreach (var templatePath in triggeredTemplatePaths) { if (Menu.VerboseLogs) { Debug.Log(string.Format("Asset modification is triggered T4 template's generator at '{0}'.", templatePath)); } var settings = TemplateSettings.Load(templatePath); UnityTemplateGenerator.RunForTemplateWithDelay(templatePath, TimeSpan.FromMilliseconds(settings.TriggerDelay)); } }
private static void Initialize() { EditorApplication.update -= InitializeCallback; System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(TemplateInspector).TypeHandle); foreach (var templatePath in TemplateSettings.ListTemplatesInProject()) { var settings = TemplateSettings.Load(templatePath); if ((settings.Trigger & (int)TemplateSettings.Triggers.CodeCompilation) == 0) { continue; } if (Menu.VerboseLogs) { Debug.Log(string.Format("Code compilation in project is triggered T4 template's generator at '{0}'.", templatePath)); } UnityTemplateGenerator.RunForTemplateWithDelay(templatePath, TimeSpan.FromMilliseconds(settings.TriggerDelay)); } }