Skip to content

Commit 77669fe

Browse files
committed
Adds ability to get the location of the package, handy for finding files within it. Use that to get the changelog
1 parent dbaeae9 commit 77669fe

File tree

3 files changed

+102
-21
lines changed

3 files changed

+102
-21
lines changed

Assets/Publishing/Editor/Tools/PublishingTools.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using System;
12
using UnityEngine;
23
using UnityEditor;
34
using System.Collections.Generic;
45
using System.IO;
6+
using System.Text;
57
using System.Text.RegularExpressions;
68
using Ink.UnityIntegration;
9+
using UnityEngine.Networking;
710

811
// Should be run to update files in the package folder from the root of the repo, and to create demo and release packages.
912
public static class PublishingTools {
@@ -16,6 +19,7 @@ public static void PreparePublish() {
1619
CreateDemoPackages();
1720
SyncReadme();
1821
CreatePackage();
22+
DescribeNextSteps();
1923
}
2024

2125
[MenuItem("Publishing/Tasks/Create .unitypackage for demos")]
@@ -135,4 +139,58 @@ public static void CreatePackage () {
135139

136140
Debug.Log("PublishingTools.CreatePackage: Created .unitypackage at "+Path.GetFullPath(Path.Combine(Application.dataPath, packageExportPath)));
137141
}
142+
143+
144+
145+
[MenuItem("Publishing/Show Helper Window")]
146+
static void DescribeNextSteps() {
147+
PublishingToolsHelperWindow.ShowWindow();
148+
}
149+
150+
public class PublishingToolsHelperWindow : EditorWindow {
151+
// Vector2 scrollPosition;
152+
153+
public static void ShowWindow () {
154+
PublishingToolsHelperWindow window = GetWindow(typeof(PublishingToolsHelperWindow), true, "Ink Publishing Tools", true) as PublishingToolsHelperWindow;
155+
}
156+
157+
void OnGUI () {
158+
EditorGUILayout.BeginVertical();
159+
EditorGUILayout.LabelField("Version "+InkLibrary.unityIntegrationVersionCurrent, EditorStyles.centeredGreyMiniLabel);
160+
161+
// Editor
162+
//
163+
if (GUILayout.Button("Prepare for publishing (run all tasks)")) {
164+
PreparePublish();
165+
}
166+
if (GUILayout.Button("Show Package")) {
167+
EditorUtility.RevealInFinder(Path.GetFullPath(Path.Combine(Application.dataPath, "../..")));
168+
}
169+
if (GUILayout.Button("Draft GitHub Release")) {
170+
// 1.1.7
171+
var version = UnityWebRequest.EscapeURL($"v{InkLibrary.unityIntegrationVersionCurrent}");
172+
173+
var title = UnityWebRequest.EscapeURL($"{InkLibrary.unityIntegrationVersionCurrent} is out!");
174+
175+
var packageDirectory = InkEditorUtils.FindAbsolutePluginDirectory();
176+
var changelogText = File.ReadAllText(Path.Combine(packageDirectory, "CHANGELOG.md"));
177+
var versionSections = Regex.Split(changelogText, "## "); // Split markdown text into version sections
178+
179+
StringBuilder sb = new StringBuilder();
180+
if (versionSections.Length > 1) {
181+
var section = versionSections[1];
182+
var lines = section.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // Split each section into lines
183+
for (int i = 1; i < lines.Length; i++) {
184+
var bulletPoint = lines[i].TrimStart('-').TrimStart(' ');
185+
sb.AppendLine($"• {bulletPoint}");
186+
}
187+
}
188+
var body = UnityWebRequest.EscapeURL($"{sb.ToString()}");
189+
190+
191+
Application.OpenURL($"https://github.com/inkle/ink-unity-integration/releases/new?tag={version}&title={title}&body={body}");
192+
}
193+
EditorGUILayout.EndVertical();
194+
}
195+
}
138196
}

Packages/Ink/Editor/Core/InkEditorUtils.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using UnityEngine;
22
using UnityEditor;
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
65
using System.Text;
76
using System.Linq;
@@ -343,5 +342,31 @@ from ch in json
343342

344343
return String.Concat(result);
345344
}
345+
346+
347+
// If this plugin is installed as a package, returns info about it.
348+
public static UnityEditor.PackageManager.PackageInfo GetPackageInfo() {
349+
var packageAssetPath = "Packages/com.inkle.ink-unity-integration";
350+
if (AssetDatabase.IsValidFolder(packageAssetPath)) return UnityEditor.PackageManager.PackageInfo.FindForAssetPath(packageAssetPath);
351+
else return null;
352+
}
353+
354+
// Gets the root directory of this plugin, enabling us to find assets within it.
355+
// Less efficent if not installed as a package because the location/folder name is not known.
356+
public static string FindAbsolutePluginDirectory() {
357+
var packageInfo = GetPackageInfo();
358+
if (packageInfo != null) {
359+
return packageInfo.resolvedPath;
360+
} else {
361+
// Find the InkLibs folder. We assume that it exists in the top level of the plugin folder. We use this folder because it has a fairly unique name and is essential for the plugin to function.
362+
string[] guids = AssetDatabase.FindAssets("t:DefaultAsset", new[] {"Assets"}).Where(g => AssetDatabase.GUIDToAssetPath(g).EndsWith("/InkLibs")).ToArray();
363+
if (guids.Length > 0) {
364+
var assetPathOfInkLibsFolder = AssetDatabase.GUIDToAssetPath(guids[0]);
365+
var rootPluginFolder = assetPathOfInkLibsFolder.Substring(0, assetPathOfInkLibsFolder.Length - "/InkLibs".Length);
366+
return Path.GetFullPath(Path.Combine(Application.dataPath, rootPluginFolder));
367+
}
368+
}
369+
return null; // If no folder is found
370+
}
346371
}
347372
}

Packages/Ink/Editor/Tools/Startup Window/InkUnityIntegrationStartupWindow.cs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Text.RegularExpressions;
34
using UnityEditor;
45
using UnityEngine;
@@ -11,7 +12,7 @@ public class InkUnityIntegrationStartupWindow : EditorWindow {
1112

1213
Vector2 scrollPosition;
1314
static int announcementVersionPreviouslySeen;
14-
static TextAsset changelogTextAsset;
15+
static string changelogText;
1516

1617
static InkUnityIntegrationStartupWindow () {
1718
EditorApplication.delayCall += TryCreateWindow;
@@ -34,9 +35,9 @@ public static void ShowWindow () {
3435
}
3536

3637
void OnEnable() {
37-
changelogTextAsset = (TextAsset) AssetDatabase.LoadAssetAtPath("Packages/com.inkle.ink-unity-integration/CHANGELOG.md", typeof(TextAsset));
38+
var packageDirectory = InkEditorUtils.FindAbsolutePluginDirectory();
39+
changelogText = File.ReadAllText(Path.Combine(packageDirectory, "CHANGELOG.md"));
3840
}
39-
4041

4142
void OnGUI ()
4243
{
@@ -80,27 +81,24 @@ void OnGUI ()
8081

8182
EditorGUILayout.Space();
8283

83-
if(changelogTextAsset != null) {
84+
if(changelogText != null) {
8485
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
85-
{
86-
var versionSections = Regex.Split(changelogTextAsset.text, "## "); // Split markdown text into version sections
87-
88-
foreach (var section in versionSections)
89-
{
90-
if (string.IsNullOrWhiteSpace(section)) continue;
91-
92-
var lines = section.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // Split each section into lines
93-
var version = lines[0]; // First line is version
86+
87+
var versionSections = Regex.Split(changelogText, "## "); // Split markdown text into version sections
88+
foreach (var section in versionSections) {
89+
if (string.IsNullOrWhiteSpace(section)) continue;
9490

95-
EditorGUILayout.BeginVertical(GUI.skin.box);
96-
EditorGUILayout.LabelField($"{version}", EditorStyles.boldLabel);
97-
for (int i = 1; i < lines.Length; i++) {
98-
var bulletPoint = lines[i].TrimStart('-').TrimStart(' ');
99-
EditorGUILayout.LabelField($"• {bulletPoint}", EditorStyles.wordWrappedLabel);
100-
}
91+
var lines = section.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // Split each section into lines
92+
var version = lines[0]; // First line is version
10193

102-
EditorGUILayout.EndVertical();
94+
EditorGUILayout.BeginVertical(GUI.skin.box);
95+
EditorGUILayout.LabelField($"{version}", EditorStyles.boldLabel);
96+
for (int i = 1; i < lines.Length; i++) {
97+
var bulletPoint = lines[i].TrimStart('-').TrimStart(' ');
98+
EditorGUILayout.LabelField($"• {bulletPoint}", EditorStyles.wordWrappedLabel);
10399
}
100+
101+
EditorGUILayout.EndVertical();
104102
}
105103

106104
EditorGUILayout.EndScrollView();

0 commit comments

Comments
 (0)