Skip to content

Commit afa7f99

Browse files
author
Tom Kail
committed
Fixes compilation
1 parent 77cafec commit afa7f99

File tree

7 files changed

+206
-10
lines changed

7 files changed

+206
-10
lines changed

Assets/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/InkLibraryEditor.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace Ink.UnityIntegration {
7+
8+
[CustomEditor(typeof(InkLibrary))]
9+
public class InkLibraryEditor : Editor {
10+
11+
#pragma warning disable
12+
protected InkLibrary data;
13+
14+
public void OnEnable() {
15+
data = (InkLibrary) target;
16+
}
17+
18+
protected override void OnHeaderGUI () {
19+
GUILayout.BeginHorizontal();
20+
GUILayout.Space(38f);
21+
GUILayout.BeginVertical();
22+
GUILayout.Space(19f);
23+
GUILayout.BeginHorizontal();
24+
25+
GUILayoutUtility.GetRect(10f, 10f, 16f, 16f, EditorStyles.layerMaskField);
26+
GUILayout.FlexibleSpace();
27+
28+
29+
EditorGUI.BeginDisabledGroup(InkCompiler.compiling);
30+
if (GUILayout.Button(new GUIContent("Rebuild Library", "Rebuilds the ink library. Do this if you're getting unusual errors"), EditorStyles.miniButton)) {
31+
InkLibrary.Rebuild();
32+
}
33+
EditorGUI.EndDisabledGroup();
34+
35+
GUILayout.EndHorizontal();
36+
GUILayout.EndVertical();
37+
GUILayout.EndHorizontal();
38+
39+
Rect lastRect = GUILayoutUtility.GetLastRect();
40+
Rect rect = new Rect(lastRect.x, lastRect.y, lastRect.width, lastRect.height);
41+
Rect iconRect = new Rect(rect.x + 6f, rect.y + 6f, 32f, 32f);
42+
GUI.DrawTexture(iconRect, InkBrowserIcons.inkFileIconLarge);
43+
44+
Rect titleRect = new Rect(rect.x + 44f, rect.y + 6f, rect.width - 44f - 38f - 4f, 16f);
45+
titleRect.yMin -= 2f;
46+
titleRect.yMax += 2f;
47+
GUI.Label(titleRect, "Ink Library", EditorStyles.largeLabel);
48+
49+
Rect infoRect = titleRect;
50+
infoRect.y += titleRect.height;
51+
GUI.Label(infoRect, "Caches information about ink files in your project", EditorStyles.miniLabel);
52+
}
53+
54+
public override void OnInspectorGUI() {
55+
serializedObject.Update();
56+
57+
58+
EditorGUILayout.Toggle("HasLockedUnityCompilation", InkCompiler.hasLockedUnityCompilation);
59+
if(GUILayout.Button("Unlock")) {
60+
EditorApplication.UnlockReloadAssemblies();
61+
}
62+
#if UNITY_2019_4_OR_NEWER
63+
if(GUILayout.Button("AllowAutoRefresh")) {
64+
AssetDatabase.AllowAutoRefresh();
65+
}
66+
#endif
67+
68+
if(InkCompiler.compiling) {
69+
Rect r = EditorGUILayout.BeginVertical();
70+
EditorGUI.ProgressBar(r, InkCompiler.GetEstimatedCompilationProgress(), "Compiling...");
71+
GUILayout.Space(EditorGUIUtility.singleLineHeight);
72+
EditorGUILayout.EndVertical();
73+
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
74+
} else {
75+
var filesRequiringRecompile = InkLibrary.GetFilesRequiringRecompile();
76+
if(filesRequiringRecompile.Any()) {
77+
var files = string.Join("\n", filesRequiringRecompile.Select(x => x.filePath).ToArray());
78+
if(EditorApplication.isPlaying && InkSettings.Instance.delayInPlayMode) {
79+
EditorGUILayout.HelpBox("Some Ink files marked to compile on exiting play mode.\n"+files, MessageType.Info);
80+
} else {
81+
EditorGUILayout.HelpBox("Some Ink files marked to compile automatically are not compiled! Check they don't have compile errors, or else try compiling now.\n"+files, MessageType.Warning);
82+
}
83+
} else {
84+
EditorGUILayout.HelpBox("All Ink files marked to compile automatically are compiled", MessageType.Info);
85+
}
86+
}
87+
EditorGUI.BeginDisabledGroup(InkCompiler.compiling);
88+
if (GUILayout.Button(new GUIContent("Recompile All", "Recompiles all files marked to compile automatically."))) {
89+
InkEditorUtils.RecompileAll();
90+
}
91+
92+
if(EditorApplication.isPlaying && InkSettings.Instance.delayInPlayMode) {
93+
var filesRequiringRecompile = InkLibrary.GetFilesRequiringRecompile();
94+
if(filesRequiringRecompile.Any()) {
95+
var files = string.Join("\n", filesRequiringRecompile.Select(x => x.filePath).ToArray());
96+
if (GUILayout.Button(new GUIContent("Recompile Pending", "Recompiles all files marked to compile on exiting play mode."))) {
97+
InkEditorUtils.RecompileAll();
98+
}
99+
}
100+
}
101+
102+
EditorGUI.EndDisabledGroup();
103+
104+
EditorGUI.BeginDisabledGroup(true);
105+
EditorGUILayout.PropertyField(serializedObject.FindProperty("inkLibrary"), true);
106+
EditorGUILayout.PropertyField(serializedObject.FindProperty("pendingCompilationStack"), true);
107+
EditorGUILayout.PropertyField(serializedObject.FindProperty("compilationStack"), true);
108+
EditorGUI.EndDisabledGroup();
109+
110+
if (GUILayout.Button(new GUIContent("Clear Compilation Stacks"))) {
111+
InkLibrary.ClearCompilationStacks();
112+
}
113+
if(GUI.changed && target != null)
114+
EditorUtility.SetDirty(target);
115+
serializedObject.ApplyModifiedProperties();
116+
}
117+
}
118+
}

Assets/Editor/InkLibraryEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace Ink.UnityIntegration {
7+
public class InkLibraryEditorWindow : EditorWindow {
8+
9+
#pragma warning disable
10+
Editor inkLibraryEditor;
11+
12+
[MenuItem("Window/Ink Library Editor Window")]
13+
static void Init() {
14+
var window = (InkLibraryEditorWindow)EditorWindow.GetWindow(typeof(InkLibraryEditorWindow));
15+
window.titleContent = new GUIContent("Ink Library Window");
16+
window.Show();
17+
}
18+
19+
public void OnEnable() {
20+
inkLibraryEditor = Editor.CreateEditor(InkLibrary.Instance);
21+
}
22+
23+
void OnInspectorUpdate() {
24+
Repaint();
25+
}
26+
27+
public void OnGUI() {
28+
inkLibraryEditor.OnInspectorGUI();
29+
}
30+
}
31+
}

Assets/Editor/InkLibraryEditorWindow.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Ink/Editor/Core/Compiler/InkCompiler.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ private static void Update () {
115115
if(InkLibrary.NumFilesInCompilingStackInState(CompilationStackItem.State.Queued) == 0) {
116116
DelayedComplete();
117117
} else {
118-
// Debug.LogWarning("Ignorable InkCompiler warning!\nThe ink compiler has hit a fallback state where TryCompileNextFileInStack had to be called in Update. We'd like to fix this properly but don't have enough information on the bug.");
119-
// TryCompileNextFileInStack();
118+
// We used to avoid calling this here in favour of calling it CompileInkThreaded but it seems that it doesn't run when called there, for some reason.
119+
// If someone can make this work please let me know!
120+
TryCompileNextFileInStack();
120121
}
121122
}
122123
}
@@ -267,8 +268,7 @@ private static void CompileInkInternal (InkFile inkFile, bool immediate) {
267268
immediate = immediate
268269
};
269270

270-
InkLibrary.Instance.compilationStack.Add(pendingFile);
271-
InkLibrary.SaveToFile();
271+
InkLibrary.AddToCompilationStack(pendingFile);
272272

273273
TryCompileNextFileInStack();
274274
}
@@ -294,7 +294,6 @@ private static void TryCompileNextFileInStack () {
294294
ThreadPool.QueueUserWorkItem(CompileInkThreaded, fileToCompile);
295295
}
296296
} else {
297-
// Debug.Log("TryCompileNextFileInStack COMPILING ALREADY "+fileToCompile);
298297
}
299298
}
300299

@@ -349,7 +348,11 @@ private static void CompileInkThreaded(object itemObj) {
349348
}
350349

351350
CompleteCompilingFile(item);
352-
TryCompileNextFileInStack();
351+
352+
// This doesn't seem to execute when called in a thread, and I apparently don't have a bloody clue how threads work.
353+
// If someone can make this work, I'd rather that TryCompileNextFileInStack ran directly after CompileInkThreaded finishes.
354+
// I couldn't make it work, so I've put TryCompileNextFileInStack in Update instead. Bleh!
355+
// TryCompileNextFileInStack();
353356
}
354357

355358
// When all files in stack have been compiled. This is called via update because Process events run in another thread.
@@ -434,8 +437,7 @@ private static void DelayedComplete () {
434437
Debug.Log(outputLog);
435438
}
436439

437-
InkLibrary.Instance.compilationStack.Clear();
438-
InkLibrary.SaveToFile();
440+
InkLibrary.ClearCompilationStack();
439441

440442
#if !UNITY_EDITOR_LINUX
441443
EditorUtility.ClearProgressBar();

Packages/Ink/Editor/Core/Ink Library/InkLibrary.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static InkLibrary Instance {
5555
// If InkSettings' delayInPlayMode option is true, dirty files are added here when they're changed in play mode
5656
// This ensures they're remembered when you exit play mode and can be compiled
5757
public List<string> pendingCompilationStack = new List<string>();
58-
// The state of files currently being compiled. You can ignore this!
58+
// The state of files currently being compiled.
5959
public List<InkCompiler.CompilationStackItem> compilationStack = new List<InkCompiler.CompilationStackItem>();
6060

6161
public int Count {
@@ -121,7 +121,6 @@ static void BuildLookupDictionary () {
121121
foreach(var inkFile in Instance.inkLibrary) {
122122
Instance.inkLibraryDictionary.Add(inkFile.inkAsset, inkFile);
123123
}
124-
Debug.Log("Dictionary Created with "+Instance.inkLibrary.Count+" values");
125124
}
126125

127126
/// <summary>
@@ -434,12 +433,28 @@ public static void RebuildInkFileConnections () {
434433

435434

436435

436+
public static void AddToCompilationStack (InkCompiler.CompilationStackItem compilationStackItem) {
437+
if(!InkLibrary.Instance.compilationStack.Contains(compilationStackItem)) {
438+
InkLibrary.Instance.compilationStack.Add(compilationStackItem);
439+
SaveToFile();
440+
}
441+
}
442+
443+
public static void ClearCompilationStack () {
444+
if(InkLibrary.Instance.compilationStack.Count != 0) {
445+
InkLibrary.Instance.compilationStack.Clear();
446+
SaveToFile();
447+
}
448+
}
449+
450+
437451
public static void AddToPendingCompilationStack (string filePath) {
438452
if(!InkLibrary.Instance.pendingCompilationStack.Contains(filePath)) {
439453
InkLibrary.Instance.pendingCompilationStack.Add(filePath);
440454
SaveToFile();
441455
}
442456
}
457+
443458
public static void RemoveFromPendingCompilationStack (InkFile inkFile) {
444459
bool anyChange = false;
445460
anyChange = InkLibrary.Instance.pendingCompilationStack.Remove(inkFile.filePath) || anyChange;

0 commit comments

Comments
 (0)