protected override void Apply() { base.Apply(); if (VisualEditor is null) { return; } var scriptText = VisualEditor.GenerateText(); var scriptPath = AssetDatabase.GetAssetPath(ScriptAsset); File.WriteAllText(scriptPath, scriptText, Encoding.UTF8); ScriptView.ScriptModified = false; }
private void ApplyAndImportChecked() { if (!ScriptView.ScriptModified || !ObjectUtils.IsValid(ScriptAsset)) { return; } // Make sure the script actually changed before invoking `ApplyAndImport()`; // in case the generated script text will be the same as it was, Unity editor will // fail internally and loose reference to the edited asset target. var scriptPath = AssetDatabase.GetAssetPath(ScriptAsset); var modifiedScriptText = VisualEditor.GenerateText(); var savedScriptText = File.ReadAllText(scriptPath, Encoding.UTF8); if (modifiedScriptText == savedScriptText) { ScriptView.ScriptModified = false; return; } ApplyAndImport(); }