From 0c657635f418a211c1487862b524aaaeff490cd8 Mon Sep 17 00:00:00 2001 From: gboulard Date: Mon, 11 Dec 2017 15:07:59 +0100 Subject: [PATCH] allow to specify compiled json destination folder --- .../Ink/Editor/Compiler/InkCompiler.cs | 2 +- .../Plugins/Ink/Editor/Ink Library/InkFile.cs | 32 +++++++++++++++++-- .../Ink/Editor/Ink Settings/InkSettings.cs | 4 ++- .../Editor/Ink Settings/InkSettingsEditor.cs | 4 ++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Assets/Plugins/Ink/Editor/Compiler/InkCompiler.cs b/Assets/Plugins/Ink/Editor/Compiler/InkCompiler.cs index e8de1645..31223378 100644 --- a/Assets/Plugins/Ink/Editor/Compiler/InkCompiler.cs +++ b/Assets/Plugins/Ink/Editor/Compiler/InkCompiler.cs @@ -143,7 +143,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.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath))) + ".json"; + string outputPath = InkEditorUtils.UnityRelativeToAbsolutePath(inkFile.jsonPath); string inkArguments = InkSettings.Instance.customInklecateOptions.additionalCompilerOptions + " -c -o " + "\"" + outputPath + "\" \"" + inputPath + "\""; CompilationStackItem pendingFile = new CompilationStackItem(); diff --git a/Assets/Plugins/Ink/Editor/Ink Library/InkFile.cs b/Assets/Plugins/Ink/Editor/Ink Library/InkFile.cs index 21b890b1..e47dfaf1 100644 --- a/Assets/Plugins/Ink/Editor/Ink Library/InkFile.cs +++ b/Assets/Plugins/Ink/Editor/Ink Library/InkFile.cs @@ -12,6 +12,9 @@ public sealed class InkFile { // A reference to the ink file public DefaultAsset inkAsset; + //specify json destination folder (if None, default to same folder as ink file) + public DefaultAsset jsonAssetPath; + // The compiled json file. Use this to start a story. public TextAsset jsonAsset; @@ -52,14 +55,39 @@ public sealed class InkFile { } } + public string jsonPath { + get { + DefaultAsset jsonFolder = jsonAssetPath; + if (jsonFolder == null) // no path specified for this specific file + { + if(InkSettings.Instance.defaultJsonAssetPath != null) + { + // use default path in InkSettings + jsonFolder = InkSettings.Instance.defaultJsonAssetPath; + } + + if (jsonFolder == null) + { + //fallback to same folder as .ink file + jsonFolder = AssetDatabase.LoadAssetAtPath(Path.GetDirectoryName(filePath)); + } + } + + string jsonPath = AssetDatabase.GetAssetPath(jsonFolder); + string strJsonAssetPath = InkEditorUtils.CombinePaths(jsonPath, Path.GetFileNameWithoutExtension(filePath)) + ".json"; + + return InkEditorUtils.SanitizePathString(strJsonAssetPath); + } + } + public InkFile (DefaultAsset inkAsset) { Debug.Assert(inkAsset != null); this.inkAsset = inkAsset; } public void FindCompiledJSONAsset () { - string jsonAssetPath = InkEditorUtils.CombinePaths(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)) + ".json"; - jsonAsset = AssetDatabase.LoadAssetAtPath(jsonAssetPath); + Debug.Assert(inkAsset != null); + jsonAsset = AssetDatabase.LoadAssetAtPath(jsonPath); } public override string ToString () { diff --git a/Assets/Plugins/Ink/Editor/Ink Settings/InkSettings.cs b/Assets/Plugins/Ink/Editor/Ink Settings/InkSettings.cs index a76b3362..d9e55331 100644 --- a/Assets/Plugins/Ink/Editor/Ink Settings/InkSettings.cs +++ b/Assets/Plugins/Ink/Editor/Ink Settings/InkSettings.cs @@ -32,7 +32,9 @@ public class InkSettings : ScriptableObject { } } - public bool compileAutomatically = true; + public DefaultAsset defaultJsonAssetPath; + + public bool compileAutomatically = true; public bool delayInPlayMode = true; public bool handleJSONFilesAutomatically = true; diff --git a/Assets/Plugins/Ink/Editor/Ink Settings/InkSettingsEditor.cs b/Assets/Plugins/Ink/Editor/Ink Settings/InkSettingsEditor.cs index 4f5a18dd..e8ae696a 100644 --- a/Assets/Plugins/Ink/Editor/Ink Settings/InkSettingsEditor.cs +++ b/Assets/Plugins/Ink/Editor/Ink Settings/InkSettingsEditor.cs @@ -21,7 +21,9 @@ public class InkSettingsEditor : Editor { } EditorGUILayout.PropertyField(serializedObject.FindProperty("templateFile")); - data.compileAutomatically = EditorGUILayout.Toggle(new GUIContent("Compile Ink Automatically", "When disabled, automatic compilation can be enabled on a per-story basis via the inspector for a master story file."), data.compileAutomatically); + EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultJsonAssetPath")); + + data.compileAutomatically = EditorGUILayout.Toggle(new GUIContent("Compile Ink Automatically", "When disabled, automatic compilation can be enabled on a per-story basis via the inspector for a master story file."), data.compileAutomatically); data.delayInPlayMode = EditorGUILayout.Toggle(new GUIContent("Delay compilation if in Play Mode", "When enabled, ink compilation is delayed if in play mode."), data.delayInPlayMode); data.handleJSONFilesAutomatically = EditorGUILayout.Toggle(new GUIContent("Handle JSON Automatically", "Whether JSON files are moved, renamed and deleted along with their ink files."), data.handleJSONFilesAutomatically);