Esempio n. 1
0
        public override void OnEnable()
        {
            base.OnEnable();

            if (config is null)
            {
                config = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>();
            }
            ScriptAsset = assetTarget as Script;
            scriptText  = File.ReadAllText(AssetDatabase.GetAssetPath(ScriptAsset));

            if (config.EnableVisualEditor)
            {
                VisualEditor = new ScriptView(config, ApplyRevertHackGUI, ApplyAndImportChecked);
                VisualEditor.GenerateForScript(scriptText, ScriptAsset);

                ScriptAssetPostprocessor.OnModified += HandleScriptModified;
                return;
            }

            previewContent = scriptText;
            if (previewContent.Length > previewLengthLimit)
            {
                previewContent  = previewContent.Substring(0, previewLengthLimit);
                previewContent += $"{System.Environment.NewLine}<...>";
            }

            labelTags = ScriptAsset.Lines.OfType <LabelScriptLine>().Select(l => new GUIContent($"# {l.LabelText}")).ToArray();
            gotoTags  = ScriptAsset.ExtractCommands().OfType <Commands.Goto>()
                        .Where(c => !string.IsNullOrEmpty(c.Path.Name))
                        .Select(c => new GUIContent($"@goto {c.Path.ToString().Replace(".null", "")}")).ToArray();
        }
Esempio n. 2
0
        public override void OnEnable()
        {
            base.OnEnable();

            if (config is null)
            {
                config = Configuration.LoadOrDefault <ScriptsConfiguration>();
            }
            scriptAsset = assetTarget as ScriptAsset;

            if (config.EnableVisualEditor)
            {
                visualEditor = new ScriptView(config, ApplyRevertHackGUI, ApplyAndImport);
                visualEditor.GenerateForScript(scriptAsset);

                ScriptImporter.OnModified += visualEditor.GenerateForScript;
                return;
            }

            previewContent = scriptAsset.ScriptText;
            if (previewContent.Length > previewLengthLimit)
            {
                previewContent  = previewContent.Substring(0, previewLengthLimit);
                previewContent += $"{System.Environment.NewLine}<...>";
            }

            var script = new Script(scriptAsset.name, scriptAsset.ScriptText, ignoreErrors: true);

            labelTags = script.LabelLines.Select(l => new GUIContent($"# {l.LabelText}")).ToArray();
            gotoTags  = script.CommandLines
                        .Where(c => c.CommandName.EqualsFastIgnoreCase("goto") && c.CommandParameters.TryGetValue(string.Empty, out var path) && !path.StartsWithFast("."))
                        .Select(c => new GUIContent($"@goto {c.CommandParameters[string.Empty]}")).ToArray();
        }