Beispiel #1
0
 void DisplayHeader()
 {
     if (attached)
     {
         EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
         GUILayout.Label(new GUIContent("Attached", "This story reference has been attached from elsewhere"));
         if (GUILayout.Button(new GUIContent("Detach", "Detach from the loaded external story"), EditorStyles.toolbarButton))
         {
             Detach();
         }
         EditorGUILayout.EndHorizontal();
     }
     else
     {
         EditorGUILayout.BeginVertical();
         EditorGUI.BeginChangeCheck();
         storyJSONTextAsset = EditorGUILayout.ObjectField("Story JSON", storyJSONTextAsset, typeof(TextAsset), false) as TextAsset;
         if (EditorGUI.EndChangeCheck())
         {
             if (storyJSONTextAsset == null)
             {
                 story  = null;
                 errors = null;
             }
             else
             {
                 Stop();
                 Play(storyJSONTextAsset);
             }
         }
         if (storyJSONTextAsset != null && storyJSON != null)
         {
             string fullJSONFilePath = InkEditorUtils.UnityRelativeToAbsolutePath(AssetDatabase.GetAssetPath(storyJSONTextAsset));
             var    updatedStoryJSONLastEditDateTime = File.GetLastWriteTime(fullJSONFilePath);
             if (currentStoryJSONLastEditDateTime != updatedStoryJSONLastEditDateTime)
             {
                 EditorGUILayout.HelpBox("Story JSON file has changed. Restart to play updated story.", MessageType.Warning);
             }
         }
         EditorGUILayout.EndVertical();
     }
 }
Beispiel #2
0
        /// <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>
        /// <param name="inkFile">Ink file.</param>
        public static void CompileInk(InkFile inkFile)
        {
            if (inkFile == null)
            {
                Debug.LogError("Tried to compile ink file " + inkFile.filePath + ", but input was null.");
                return;
            }
            if (!inkFile.metaInfo.isMaster)
            {
                Debug.LogWarning("Compiling InkFile which is an include. Any file created is likely to be invalid. Did you mean to call CompileInk on inkFile.master?");
            }
            if (InkLibrary.GetCompilationStackItem(inkFile) != null)
            {
                UnityEngine.Debug.LogWarning("Tried compiling ink file, but file is already compiling. " + inkFile.filePath);
                return;
            }

            string inklecatePath = InkEditorUtils.GetInklecateFilePath();

            if (inklecatePath == null)
            {
                UnityEngine.Debug.LogWarning("Inklecate (the ink compiler) not found in assets. This will prevent automatic building of JSON TextAsset files from ink story files.");
                return;
            }
            if (Application.platform == RuntimePlatform.OSXEditor)
            {
                SetInklecateFilePermissions(inklecatePath);
            }
            if (inklecatePath.Contains("'"))
            {
                Debug.LogError("Due to a Unity bug, Inklecate path cannot contain an apostrophe. Ink will not compile until this is resolved. Path is '" + inklecatePath + "'");
                return;
            }
            // This hasn't been affecting us lately. Left it in so we can easily restore it in case of future bugs.

            /* else if(inklecatePath.Contains(" ")){
             *      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 inkArguments = InkSettings.Instance.customInklecateOptions.additionalCompilerOptions + " -c -o " + "\"" + outputPath + "\" \"" + inputPath + "\"";

            CompilationStackItem pendingFile = new CompilationStackItem();

            pendingFile.inkFile              = InkLibrary.GetInkFileWithAbsolutePath(inputPath);
            pendingFile.inkAbsoluteFilePath  = inputPath;
            pendingFile.jsonAbsoluteFilePath = outputPath;
            pendingFile.state = CompilationStackItem.State.Compiling;
            InkLibrary.Instance.compilationStack.Add(pendingFile);
            InkLibrary.Save();

            Process process = new Process();

            if (InkSettings.Instance.customInklecateOptions.runInklecateWithMono && Application.platform != RuntimePlatform.WindowsEditor)
            {
                if (File.Exists(_libraryMono))
                {
                    process.StartInfo.FileName = _libraryMono;
                }
                else if (File.Exists(_usrMono))
                {
                    process.StartInfo.FileName = _usrMono;
                }
                else
                {
                    Debug.LogError("Mono was not found on machine");
                    return;
                }
                process.StartInfo.Arguments = inklecatePath + " " + inkArguments;
            }
            else
            {
                process.StartInfo.FileName  = inklecatePath;
                process.StartInfo.Arguments = inkArguments;
            }

            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.EnableRaisingEvents = true;
            process.OutputDataReceived += OnProcessOutput;
            // For some reason having this line enabled spams the output and error streams with null and "???" (only on OSX?)
            // Rather than removing unhandled error detection I thought it'd be best to just catch those messages and ignore them instead.
            process.ErrorDataReceived += OnProcessError;
            process.Exited            += OnCompileProcessComplete;
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            pendingFile.process = process;
            // If you'd like to run this command outside of unity, you could instead run process.StartInfo.Arguments in the command line.
        }