public override void OnInspectorGUI()
        {
            var asset     = (Object)this.target;
            var assetPath = FileUtils.MakeProjectRelative(AssetDatabase.GetAssetPath(asset));

            if (assetPath == null || assetPath.EndsWith(".tt") == false)
            {
                this.DrawDefaultInspector();
                return;
            }

            if (this.lastAsset != asset || this.templateSettings == null)
            {
                this.templateSettings = TemplateSettings.Load(assetPath);
                this.lastAsset        = asset;
            }
            GUI.enabled = true;
            GUILayout.Label(Path.GetFileName(assetPath), EditorStyles.boldLabel);
            this.templateSettings.OutputType = (int)(TemplateSettings.OutputTypes)EditorGUILayout.EnumPopup("Output Type", (TemplateSettings.OutputTypes) this.templateSettings.OutputType);
            var codeAsset = !string.IsNullOrEmpty(this.templateSettings.OutputPath) && File.Exists(this.templateSettings.OutputPath) ? AssetDatabase.LoadAssetAtPath(this.templateSettings.OutputPath, typeof(Object)) : null;

            if (codeAsset != null)
            {
                this.templateSettings.OutputPath = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField("Output Path", codeAsset, typeof(Object), false));
            }
            else
            {
                this.templateSettings.OutputPath = EditorGUILayout.TextField("Output Path", this.templateSettings.OutputPath);
            }
            this.templateSettings.Trigger      = (int)(TemplateSettings.Triggers)EditorGUILayout.EnumMaskField("Auto-Gen Triggers", (TemplateSettings.Triggers)templateSettings.Trigger);
            this.templateSettings.TriggerDelay = (int)EditorGUILayout.IntField("Auto-Gen Delay (Ms)", templateSettings.TriggerDelay);

            if ((this.templateSettings.Trigger & (int)TemplateSettings.Triggers.AssetChanges) != 0)
            {
                EditorGUILayout.Space();
                GUILayout.Label("Assets to Watch", EditorStyles.boldLabel);
                for (var i = 0; i < this.templateSettings.WatchedAssets.Length; i++)
                {
                    var watchedAssetPath = this.templateSettings.WatchedAssets[i];
                    var assetExists      = !string.IsNullOrEmpty(watchedAssetPath) && (File.Exists(watchedAssetPath) || Directory.Exists(watchedAssetPath));
                    var watchedAsset     = assetExists ? AssetDatabase.LoadMainAssetAtPath(watchedAssetPath) : null;
                    if (watchedAsset != null)
                    {
                        this.templateSettings.WatchedAssets[i] = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(watchedAsset.GetType().Name, watchedAsset, typeof(Object), false));
                    }
                    else
                    {
                        this.templateSettings.WatchedAssets[i] = EditorGUILayout.TextField("Path", watchedAssetPath);
                    }
                }
                EditorGUILayout.Space();
                this.newAssetToWatch = EditorGUILayout.ObjectField("<New>", this.newAssetToWatch, typeof(Object), false);
                if (Event.current.type == EventType.repaint && newAssetToWatch != null)
                {
                    var watchedAssets = new HashSet <string>(this.templateSettings.WatchedAssets);
                    watchedAssets.Remove("");
                    watchedAssets.Add(AssetDatabase.GetAssetPath(this.newAssetToWatch));
                    this.templateSettings.WatchedAssets = watchedAssets.ToArray();
                    this.newAssetToWatch = null;
                    GUI.changed          = true;
                }
            }

            EditorGUILayout.Space();
            GUILayout.Label("Actions", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Generate " + this.lastGenerationResult))
            {
                if (UnityTemplateGenerator.RunForTemplate(assetPath) == false)
                {
                    this.lastGenerationResult = "(Failure)";
                }
                else
                {
                    this.lastGenerationResult = "(Success)";
                }
            }
            EditorGUILayout.EndHorizontal();

            if (GUI.changed)
            {
                this.templateSettings.Save(assetPath);
                if ((this.templateSettings.Trigger & (int)TemplateSettings.Triggers.AssetChanges) != 0)
                {
                    AssetChangesTrigger.ReloadWatchList();
                }
            }
        }
        public override void OnInspectorGUI()
        {
            var asset     = (Object)this.target;
            var assetPath = PathUtils.MakeProjectRelative(AssetDatabase.GetAssetPath(asset));

            if (assetPath == null || assetPath.EndsWith(".tt") == false)
            {
                this.DrawDefaultInspector();
                return;
            }

            if (this.lastAsset != asset || this.templateSettings == null)
            {
                this.templateSettings = TemplateSettings.Load(assetPath);
                this.lastAsset        = asset;
            }
            GUI.enabled = true;
            GUILayout.Label(Path.GetFileName(assetPath), EditorStyles.boldLabel);
            this.templateSettings.OutputType = (int)(TemplateSettings.OutputTypes)EditorGUILayout.EnumPopup("Output Type", (TemplateSettings.OutputTypes) this.templateSettings.OutputType);
            var codeAsset = !string.IsNullOrEmpty(this.templateSettings.OutputPath) && File.Exists(this.templateSettings.OutputPath) ? AssetDatabase.LoadAssetAtPath(this.templateSettings.OutputPath, typeof(Object)) : null;

            if (codeAsset != null)
            {
                this.templateSettings.OutputPath = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField("Output Path", codeAsset, typeof(Object), false));
            }
            else
            {
                this.templateSettings.OutputPath = EditorGUILayout.TextField("Output Path", this.templateSettings.OutputPath);
            }
            this.templateSettings.Trigger      = (int)(TemplateSettings.Triggers)EditorGUILayout.EnumMaskField("Auto-Gen Triggers", (TemplateSettings.Triggers) this.templateSettings.Trigger);
            this.templateSettings.TriggerDelay = (int)EditorGUILayout.IntField("Auto-Gen Delay (Ms)", this.templateSettings.TriggerDelay);

            if ((this.templateSettings.Trigger & (int)TemplateSettings.Triggers.AssetChanges) != 0)
            {
                EditorGUILayout.Space();
                GUILayout.Label("Assets to Watch", EditorStyles.boldLabel);
                for (var i = 0; i < this.templateSettings.WatchedAssets.Length; i++)
                {
                    var watchedAssetPath = this.templateSettings.WatchedAssets[i];
                    var assetExists      = !string.IsNullOrEmpty(watchedAssetPath) && (File.Exists(watchedAssetPath) || Directory.Exists(watchedAssetPath));
                    var watchedAsset     = assetExists ? AssetDatabase.LoadMainAssetAtPath(watchedAssetPath) : null;
                    if (watchedAsset != null)
                    {
                        this.templateSettings.WatchedAssets[i] = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(watchedAsset.GetType().Name, watchedAsset, typeof(Object), false));
                    }
                    else
                    {
                        this.templateSettings.WatchedAssets[i] = EditorGUILayout.TextField("Path", watchedAssetPath);
                    }
                }
                EditorGUILayout.Space();
                this.newAssetToWatch = EditorGUILayout.ObjectField("<New>", this.newAssetToWatch, typeof(Object), false);
                if (Event.current.type == (EventType)7 && this.newAssetToWatch != null)
                {
                    var watchedAssets = new HashSet <string>(this.templateSettings.WatchedAssets);
                    watchedAssets.Remove("");
                    watchedAssets.Add(AssetDatabase.GetAssetPath(this.newAssetToWatch));
                    this.templateSettings.WatchedAssets = watchedAssets.ToArray();
                    this.newAssetToWatch = null;
                    GUI.changed          = true;
                }
            }

            EditorGUILayout.Space();
            GUILayout.Label("Actions", EditorStyles.boldLabel);

            if (EditorApplication.isCompiling)
            {
                EditorGUILayout.HelpBox("No action could be made while Unity Editor is compiling scripts.", MessageType.Warning);
            }

            GUI.enabled = !EditorApplication.isCompiling;
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Generate " + this.lastGenerationResult))
            {
                switch (UnityTemplateGenerator.RunForTemplate(assetPath))
                {
                case GenerationResult.Success:
                case GenerationResult.NoChanges:
                    this.lastGenerationResult = "(Success)";
                    AssetChangesTrigger.DoDelayedAssetRefresh();
                    break;

                case GenerationResult.UnknownOutputType:
                    this.lastGenerationResult = "(Unknown output type)";
                    break;

                case GenerationResult.TemplateProcessingError:
                    this.lastGenerationResult = "(Template processing error)";
                    break;

                case GenerationResult.TemplateCompilationError:
                    this.lastGenerationResult = "(Template compilation error)";
                    break;

                default:
                    this.lastGenerationResult = "(Failure)";
                    break;
                }
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;

            if (GUI.changed)
            {
                this.templateSettings.Save(assetPath);
                if ((this.templateSettings.Trigger & (int)TemplateSettings.Triggers.AssetChanges) != 0)
                {
                    AssetChangesTrigger.ReloadWatchList();
                }
            }
        }