public static IEnumerable ExtractT4Templates(string extractionPath) { var checkRequirements = CharonCli.CheckRequirementsAsync(); yield return(checkRequirements); switch (checkRequirements.GetResult()) { case RequirementsCheckResult.MissingRuntime: yield return(UpdateRuntimeWindow.ShowAsync()); break; case RequirementsCheckResult.WrongVersion: case RequirementsCheckResult.MissingExecutable: yield return(CharonCli.DownloadCharon(ProgressUtils.ReportToLog(Resources.UI_UNITYPLUGIN_MENU_CHECK_UPDATES))); break; case RequirementsCheckResult.Ok: break; default: throw new InvalidOperationException("Unknown Tools check result."); } if (Settings.Current.Verbose) { Debug.Log(string.Format("Extracting T4 Templates to '{0}'...", extractionPath)); } var dumpProcess = CharonCli.DumpTemplatesAsync(extractionPath); yield return(dumpProcess); using (var dumpResult = dumpProcess.GetResult()) { if (string.IsNullOrEmpty(dumpResult.GetErrorData()) == false) { Debug.LogWarning(string.Format(Resources.UI_UNITYPLUGIN_T4_EXTRACTION_FAILED, dumpResult.GetErrorData())); } else { Debug.Log(Resources.UI_UNITYPLUGIN_T4_EXTRACTION_COMPLETE + "\r\n" + dumpResult.GetOutputData()); } } }
private static void Update() { if (Settings.Current == null) { return; } if (LastWatchedGameDataTrackerVersion != GameDataTracker.Version) { var gameDataPaths = new HashSet <string>(GameDataTracker.All); foreach (var gameDataPath in gameDataPaths) { if (Watchers.ContainsKey(gameDataPath) || File.Exists(gameDataPath) == false) { continue; } try { var fullPath = Path.GetFullPath(gameDataPath); var directoryName = Path.GetDirectoryName(fullPath); var watcher = new FileSystemWatcher(directoryName) { NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size }; watcher.Filter = Path.GetFileName(fullPath); watcher.Changed += GameDataChanged; Watchers.Add(gameDataPath, watcher); try { GameDataHashByPath[gameDataPath] = FileAndPathUtils.ComputeHash(gameDataPath); } catch { // ignored } watcher.EnableRaisingEvents = true; } catch (Exception e) { Debug.LogError("Failed to create FileSystemWatcher for GameData " + gameDataPath + ": " + e); } } foreach (var gameDataPath in Watchers.Keys.ToArray()) { if (gameDataPaths.Contains(gameDataPath)) { continue; } var watcher = Watchers[gameDataPath]; Watchers.Remove(gameDataPath); try { watcher.Dispose(); } catch (Exception e) { Debug.LogError("Failed to dispose FileSystemWatcher of GameData: " + e); } } LastWatchedGameDataTrackerVersion = GameDataTracker.Version; } var changedAssetsCopy = default(string[]); lock (ChangedAssetPaths) { if (ChangedAssetPaths.Count > 0) { changedAssetsCopy = ChangedAssetPaths.ToArray(); ChangedAssetPaths.Clear(); } } if (changedAssetsCopy != null) { foreach (var changedAsset in changedAssetsCopy) { if (Settings.Current.Verbose) { Debug.Log("Changed Asset: " + changedAsset); } if (!File.Exists(changedAsset) || GameDataTracker.IsTracked(changedAsset) == false) { continue; } var gameDataSettings = GameDataSettings.Load(changedAsset); if (!gameDataSettings.AutoGeneration) { continue; } var assetHash = default(string); try { assetHash = FileAndPathUtils.ComputeHash(changedAsset); } catch (Exception e) { Debug.LogWarning("Failed to compute hash of " + changedAsset + ": " + e); continue; } var oldAssetHash = default(string); if (GameDataHashByPath.TryGetValue(changedAsset, out oldAssetHash) && assetHash == oldAssetHash) { continue; // not changed } if (EditorApplication.isUpdating) { continue; } if (Settings.Current.Verbose) { Debug.Log("Asset's " + changedAsset + " hash has changed from " + (oldAssetHash ?? "<none>") + " to " + assetHash); } GameDataHashByPath[changedAsset] = assetHash; CoroutineScheduler.Schedule ( Menu.GenerateCodeAndAssetsAsync( path: changedAsset, progressCallback: ProgressUtils.ReportToLog("Generation(Auto): ")), "generation::" + changedAsset ); } } }
public override void OnInspectorGUI() { var gameDataAsset = (Object)this.target; var gameDataPath = FileAndPathUtils.MakeProjectRelative(AssetDatabase.GetAssetPath(gameDataAsset)); var assetPath = FileAndPathUtils.MakeProjectRelative(AssetDatabase.GetAssetPath(Selection.activeObject)); if (GameDataTracker.IsGameDataFile(assetPath) == false) { this.DrawDefaultInspector(); return; } if (this.lastAsset != gameDataAsset || this.gameDataSettings == null) { this.gameDataSettings = GameDataSettings.Load(gameDataPath); this.gameDataSettings.ScriptingAssemblies = this.gameDataSettings.ScriptingAssemblies ?? new string[0]; this.lastAsset = gameDataAsset; this.newScriptingAssembly = null; this.newScriptingAssemblyName = null; } GUI.enabled = true; GUILayout.Label(Path.GetFileName(gameDataPath), EditorStyles.boldLabel); this.gameDataSettings.Generator = (int)(GameDataSettings.CodeGenerator)EditorGUILayout.EnumPopup(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATOR, (GameDataSettings.CodeGenerator) this.gameDataSettings.Generator); if (this.gameDataSettings.Generator != (int)GameDataSettings.CodeGenerator.None) { this.codeGenerationFold = EditorGUILayout.Foldout(this.codeGenerationFold, Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATION_LABEL); if (this.codeGenerationFold) { this.gameDataSettings.AutoGeneration = EditorGUILayout.Toggle(Resources.UI_UNITYPLUGIN_INSPECTOR_AUTO_GENERATION, this.gameDataSettings.AutoGeneration); var codeAsset = !string.IsNullOrEmpty(this.gameDataSettings.CodeGenerationPath) && File.Exists(this.gameDataSettings.CodeGenerationPath) ? AssetDatabase.LoadAssetAtPath <TextAsset>(this.gameDataSettings.CodeGenerationPath) : null; var assetAsset = !string.IsNullOrEmpty(this.gameDataSettings.AssetGenerationPath) && File.Exists(this.gameDataSettings.AssetGenerationPath) ? AssetDatabase.LoadAssetAtPath <ScriptableObject>(this.gameDataSettings.AssetGenerationPath) : null; if (codeAsset != null) { this.gameDataSettings.CodeGenerationPath = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATION_PATH, codeAsset, typeof(TextAsset), false)); } else { this.gameDataSettings.CodeGenerationPath = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATION_PATH, this.gameDataSettings.CodeGenerationPath); } if (this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharpCodeAndAsset) { if (assetAsset != null) { this.gameDataSettings.AssetGenerationPath = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(Resources.UI_UNITYPLUGIN_INSPECTOR_ASSET_GENERATION_PATH, assetAsset, typeof(ScriptableObject), false)); } else { this.gameDataSettings.AssetGenerationPath = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_ASSET_GENERATION_PATH, this.gameDataSettings.AssetGenerationPath); } } if ((this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharp || this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharpCodeAndAsset) && Path.GetExtension(this.gameDataSettings.CodeGenerationPath) != ".cs") { this.gameDataSettings.CodeGenerationPath = Path.ChangeExtension(this.gameDataSettings.CodeGenerationPath, ".cs"); } if (this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharpCodeAndAsset && Path.GetExtension(this.gameDataSettings.AssetGenerationPath) != ".asset") { this.gameDataSettings.AssetGenerationPath = Path.ChangeExtension(this.gameDataSettings.AssetGenerationPath, ".asset"); } this.gameDataSettings.Namespace = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_NAMESPACE, this.gameDataSettings.Namespace); this.gameDataSettings.GameDataClassName = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_API_CLASS_NAME, this.gameDataSettings.GameDataClassName); this.gameDataSettings.DocumentClassName = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_DOCUMENT_CLASS_NAME, this.gameDataSettings.DocumentClassName); this.gameDataSettings.LineEnding = (int)(GameDataSettings.LineEndings)EditorGUILayout.EnumPopup( Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_LINE_ENDINGS, (GameDataSettings.LineEndings) this.gameDataSettings.LineEnding); this.gameDataSettings.Indentation = (int)(GameDataSettings.Indentations)EditorGUILayout.EnumPopup( Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_INDENTATION, (GameDataSettings.Indentations) this.gameDataSettings.Indentation); this.gameDataSettings.Options = (int)(CodeGenerationOptions)EditorGUILayout.EnumMaskField( Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_OPTIONS, (CodeGenerationOptions)this.gameDataSettings.Options); } } this.scriptingAssembliesFold = EditorGUILayout.Foldout(this.scriptingAssembliesFold, Resources.UI_UNITYPLUGIN_INSPECTOR_SCRIPTING_ASSEMBLIES_LABEL); if (this.scriptingAssembliesFold) { for (var i = 0; i < this.gameDataSettings.ScriptingAssemblies.Length; i++) { var watchedAssetPath = this.gameDataSettings.ScriptingAssemblies[i]; var assetExists = !string.IsNullOrEmpty(watchedAssetPath) && (File.Exists(watchedAssetPath) || Directory.Exists(watchedAssetPath)); var watchedAsset = assetExists ? AssetDatabase.LoadMainAssetAtPath(watchedAssetPath) : null; if (watchedAsset != null) { this.gameDataSettings.ScriptingAssemblies[i] = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(Resources.UI_UNITYPLUGIN_INSPECTOR_ASSET_LABEL, watchedAsset, typeof(Object), false)); } else { this.gameDataSettings.ScriptingAssemblies[i] = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_NAME_LABEL, watchedAssetPath); } } EditorGUILayout.Space(); this.newScriptingAssembly = EditorGUILayout.ObjectField("<" + Resources.UI_UNITYPLUGIN_INSPECTOR_ADD_ASSET_BUTTON + ">", this.newScriptingAssembly, typeof(Object), false); if (Event.current.type == EventType.repaint && this.newScriptingAssembly != null) { var assemblies = new HashSet <string>(this.gameDataSettings.ScriptingAssemblies); assemblies.Remove(""); assemblies.Add(AssetDatabase.GetAssetPath(this.newScriptingAssembly)); this.gameDataSettings.ScriptingAssemblies = assemblies.ToArray(); this.newScriptingAssembly = null; GUI.changed = true; } EditorGUILayout.BeginHorizontal(); this.newScriptingAssemblyName = EditorGUILayout.TextField("<" + Resources.UI_UNITYPLUGIN_INSPECTOR_ADD_NAME_BUTTON + ">", this.newScriptingAssemblyName); if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_ADD_BUTTON, EditorStyles.toolbarButton, GUILayout.Width(70), GUILayout.Height(18))) { var assemblies = new HashSet <string>(this.gameDataSettings.ScriptingAssemblies); assemblies.Remove(""); assemblies.Add(this.newScriptingAssemblyName); this.gameDataSettings.ScriptingAssemblies = assemblies.ToArray(); this.newScriptingAssemblyName = null; GUI.changed = true; this.Repaint(); } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); GUILayout.Label(Resources.UI_UNITYPLUGIN_INSPECTOR_ACTIONS_GROUP, EditorStyles.boldLabel); if (EditorApplication.isCompiling) { EditorGUILayout.HelpBox(Resources.UI_UNITYPLUGIN_COMPILING_WARNING, MessageType.Warning); } else if (CoroutineScheduler.IsRunning) { EditorGUILayout.HelpBox(Resources.UI_UNITYPLUGIN_COROUTINE_IS_RUNNIG_WARNING, MessageType.Warning); } EditorGUILayout.BeginHorizontal(); GUI.enabled = !CoroutineScheduler.IsRunning && !EditorApplication.isCompiling; if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_EDIT_BUTTON)) { AssetDatabase.OpenAsset(gameDataAsset); this.Repaint(); } if (this.gameDataSettings.Generator != (int)GameDataSettings.CodeGenerator.None && string.IsNullOrEmpty(this.gameDataSettings.CodeGenerationPath) == false) { if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_RUN_GENERATOR_BUTTON)) { CoroutineScheduler.Schedule(Menu.GenerateCodeAndAssetsAsync(gameDataPath, ProgressUtils.ReportToLog(Resources.UI_UNITYPLUGIN_INSPECTOR_GENERATION_PREFIX + " ")), "generation::" + gameDataPath) .ContinueWith(_ => this.Repaint()); } } GUI.enabled = !CoroutineScheduler.IsRunning && !EditorApplication.isCompiling; if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_VALIDATE_BUTTON)) { CoroutineScheduler.Schedule(Menu.ValidateAsync(gameDataPath, ProgressUtils.ReportToLog(Resources.UI_UNITYPLUGIN_INSPECTOR_VALIDATION_PREFIX + " ")), "validation::" + gameDataPath) .ContinueWith(_ => this.Repaint()); } if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_BACKUP_BUTTON)) { this.Backup(gameDataPath); } if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_RESTORE_BUTTON)) { this.Restore(gameDataPath); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; if (GUI.changed) { this.gameDataSettings.Save(gameDataPath); } }