Skip to content

Commit

Permalink
Unity 2017 fixes
Browse files Browse the repository at this point in the history
Resolves empty character compilation bug and removes legacy warnings
  • Loading branch information
tomkail committed Jan 25, 2018
1 parent e7115ca commit 4c9af71
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
33 changes: 26 additions & 7 deletions Assets/Plugins/Ink/Editor/Compiler/InkCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public enum State {
}

static InkCompiler () {
#if UNITY_2017_2_OR_NEWER
EditorApplication.playModeStateChanged += (state) => OnPlayModeChange();
#if UNITY_2017
EditorApplication.playModeStateChanged += OnPlayModeChange;
#else
EditorApplication.playmodeStateChanged += OnPlayModeChange;
// EditorApplication.playmodeStateChanged += LegacyOnPlayModeChange;
#endif
EditorApplication.update += Update;
}
Expand Down Expand Up @@ -102,7 +102,22 @@ public enum State {
}
}

private static void OnPlayModeChange () {
#if UNITY_2017
static void OnPlayModeChange (PlayModeStateChange mode) {
if(mode == PlayModeStateChange.EnteredEditMode && InkLibrary.Instance.pendingCompilationStack.Count > 0) {
InkLibrary.CreateOrReadUpdatedInkFiles (InkLibrary.Instance.pendingCompilationStack);
foreach (var pendingFile in GetUniqueMasterInkFilesToCompile(InkLibrary.Instance.pendingCompilationStack))
InkCompiler.CompileInk(pendingFile);
InkLibrary.Instance.pendingCompilationStack.Clear();
}

if(mode == PlayModeStateChange.EnteredPlayMode && compiling)
Debug.LogWarning("Entered Play Mode while Ink was still compiling. Recommend exiting and re-entering play mode.");
}

#else

static void LegacyOnPlayModeChange () {
if(!EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying && InkLibrary.Instance.pendingCompilationStack.Count > 0) {
InkLibrary.CreateOrReadUpdatedInkFiles (InkLibrary.Instance.pendingCompilationStack);
foreach (var pendingFile in GetUniqueMasterInkFilesToCompile(InkLibrary.Instance.pendingCompilationStack))
Expand All @@ -113,7 +128,7 @@ public enum State {
if(EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying && compiling)
Debug.LogWarning("Entered Play Mode while Ink was still compiling. Recommend exiting and re-entering play mode.");
}

#endif
/// <summary>
/// Starts a System.Process that compiles a master ink file, creating a playable JSON file that can be parsed by the Ink.Story class
/// </summary>
Expand Down Expand Up @@ -147,7 +162,7 @@ public enum State {
Debug.LogWarning("Inklecate path should not contain a space. This might lead to compilation failing. Path is '"+inklecatePath+"'. If you don't see any compilation errors, you can ignore this warning.");
}*/
string inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath));
string outputPath = InkEditorUtils.UnityRelativeToAbsolutePath(inkFile.jsonPath);
string outputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath))) + ".json";
string inkArguments = InkSettings.Instance.customInklecateOptions.additionalCompilerOptions + " -c -o " + "\"" + outputPath + "\" \"" + inputPath + "\"";

CompilationStackItem pendingFile = new CompilationStackItem();
Expand Down Expand Up @@ -219,8 +234,12 @@ public enum State {
}

private static void ProcessError (Process process, string message) {
if (message == null || message.Length == 0 || message == "???")
message = message.Trim();
if (InkEditorUtils.IsNullOrWhiteSpace(message) || message == "???")
return;
Debug.Log(message[0]);
Debug.Log(char.IsWhiteSpace(message[0]));
Debug.Log((int)(message[0]));
CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(process);
compilingFile.errorOutput.Add(message);
}
Expand Down
13 changes: 13 additions & 0 deletions Assets/Plugins/Ink/Editor/Tools/InkEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,18 @@ public static class InkEditorUtils {
Debug.LogWarning("More than one "+typeName+" was found. Deleted newer excess asset instances.");
return GUIDs[oldestIndex];
}

//Replacement until Unity upgrades .Net
public static bool IsNullOrWhiteSpace(string s){
return (string.IsNullOrEmpty(s) || IsWhiteSpace(s));
}

//Returns true if string is only white space
public static bool IsWhiteSpace(string s){
foreach(char c in s){
if(c != ' ' && c != '\t') return false;
}
return true;
}
}
}

2 comments on commit 4c9af71

@gboulard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure the UNITY_2017 is still defined in unity 2018.y ?
i think the UNITY_2017_2_OR_NEWER is safer here
(2018.1 beta already available)

@tomkail
Copy link
Collaborator Author

@tomkail tomkail commented on 4c9af71 Jan 25, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.