Files
Studio/Assets/Editor/TriLibCore/Scripts/TriLibVersionNotes.cs

122 lines
4.8 KiB
C#
Raw Normal View History

2025-06-11 16:50:56 +09:00
using System;
using System.IO;
using System.Text.RegularExpressions;
2025-02-19 17:24:26 +09:00
using UnityEditor;
using UnityEngine;
2025-06-11 16:50:56 +09:00
using UnityEngine.Windows;
2025-02-19 17:24:26 +09:00
namespace TriLibCore.Editor
{
public class TriLibVersionNotes : EditorWindow
{
private class Styles
{
public static readonly GUIStyle HeaderStyle = new GUIStyle("label") { fontSize = 19, fontStyle = FontStyle.Bold, margin = new RectOffset(10, 10, 5, 5) };
public static readonly GUIStyle SubHeaderStyle = new GUIStyle("label") { margin = new RectOffset(10, 10, 5, 5), fontStyle = FontStyle.Bold };
public static readonly GUIStyle TextStyle = new GUIStyle("label") { margin = new RectOffset(20, 20, 5, 5) };
public static readonly GUIStyle TextAreaStyle = new GUIStyle(TextStyle) { wordWrap = true };
public static readonly GUIStyle ButtonStyle = new GUIStyle("button") { margin = new RectOffset(10, 10, 5, 5) };
}
private string _text;
private bool _loaded;
2025-06-11 16:50:56 +09:00
private Vector2 _scrollPosition;
private static readonly string ChangelogPattern = @"(?<=Changelog:)(.*?)(?=(Version Notes:|$))";
private static readonly string VersionNotesPattern = @"(?<=Version Notes:)(.*)";
private static readonly string Pattern = @"(https?://[^\s]+)";
private static readonly Regex URIRegex = new Regex(@"^https?://");
2025-02-19 17:24:26 +09:00
private static TriLibVersionNotes Instance
{
get
{
var window = GetWindow<TriLibVersionNotes>();
window.titleContent = new GUIContent("TriLib Version Notes");
return window;
}
}
public static void ShowWindow()
{
Instance.Show();
}
private void OnDestroy()
{
EditorPrefs.SetBool(TriLibVersionInfo.Instance.SkipVersionInfoKey, true);
}
private void OnGUI()
{
if (!_loaded)
{
var guids = AssetDatabase.FindAssets("TriLibReleaseNotes");
if (guids.Length > 0)
{
var guid = guids[0];
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
var textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
if (textAsset == null || textAsset.text == null)
{
AssetDatabase.Refresh();
textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
if (textAsset == null)
{
Close();
}
return;
}
_text = textAsset.text.Replace("\\n", "\n");
}
else
{
Close();
}
_loaded = true;
}
2025-06-11 16:50:56 +09:00
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
var changelogMatch = Regex.Match(_text, ChangelogPattern, RegexOptions.Singleline);
var changelogSection = changelogMatch.Success ? changelogMatch.Value.Trim() : "No changelog found";
var versionNotesMatch = Regex.Match(_text, VersionNotesPattern, RegexOptions.Singleline);
var versionNotesSection = versionNotesMatch.Success ? versionNotesMatch.Value.Trim() : "No version notes found";
GUILayout.Label("Version Notes", Styles.SubHeaderStyle);
var groups = Regex.Split(versionNotesSection, Pattern);
foreach (var group in groups)
2025-02-19 17:24:26 +09:00
{
2025-06-11 16:50:56 +09:00
if (!string.IsNullOrEmpty(group))
2025-02-19 17:24:26 +09:00
{
2025-06-11 16:50:56 +09:00
if (URIRegex.IsMatch(group))
2025-02-19 17:24:26 +09:00
{
2025-06-11 16:50:56 +09:00
GUILayout.BeginHorizontal();
GUILayout.Space(20);
if (EditorGUILayout.LinkButton(group))
2025-02-19 17:24:26 +09:00
{
2025-06-11 16:50:56 +09:00
Application.OpenURL(group);
2025-02-19 17:24:26 +09:00
}
2025-06-11 16:50:56 +09:00
GUILayout.EndHorizontal();
2025-02-19 17:24:26 +09:00
}
else
{
2025-06-11 16:50:56 +09:00
EditorGUILayout.TextArea(group, Styles.TextAreaStyle);
2025-02-19 17:24:26 +09:00
}
}
}
2025-06-11 16:50:56 +09:00
EditorGUILayout.Space();
GUILayout.Label("Changelog", Styles.SubHeaderStyle);
EditorGUILayout.TextArea(changelogSection, Styles.TextAreaStyle);
EditorGUILayout.EndScrollView();
EditorGUILayout.Space();
GUILayout.Label("You can show this window on the Project Settings/TriLib area", Styles.SubHeaderStyle);
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Close", Styles.ButtonStyle))
{
Close();
}
EditorGUILayout.EndHorizontal();
2025-02-19 17:24:26 +09:00
}
}
}