private bool IsValidOutputFile(PlayMakerCodeGenerator compiler) { if (compiler.outputOptions.outputInPrefabDirectory) { if (PrefabUtility.GetPrefabType(compiler.gameObject) != PrefabType.Prefab) { return(false); } return(true); } try { var path = compiler.outputOptions.assetsRelativeOutputFile; if (string.IsNullOrEmpty(path)) { return(false); } // If an exception happens we'll return false var filename = Path.GetFileName(path); var dir = Path.Combine(Application.dataPath, Path.GetDirectoryName(path)); Path.Combine(dir, filename); return(true); } catch (Exception) { return(false); } }
private void WriteCode(PlayMakerCodeGenerator compiler) { var parser = new PlayMakerParser(compiler.parserOptions); try { var fsm = compiler.fsm as PlayMakerFSM; var model = parser.CreateModel(fsm); var generator = new CodeGenerator(compiler.generatorOptions); var output = generator.Generate(model, compiler.outputOptions.className); string outputFile; if (!GetOutputFilePath(compiler, out outputFile)) { return; } File.WriteAllText(outputFile, output.code); AssetDatabase.Refresh(); } catch (System.Exception e) { Debug.LogErrorFormat("PlayMakerCodeGenerator: error writing FSM: {0}", e.ToString()); return; } }
private bool GetOutputFilePath(PlayMakerCodeGenerator compiler, out string dstFile) { string filename = null; if (compiler.outputOptions.outputInPrefabDirectory) { var prefabPath = AssetDatabase.GetAssetPath(compiler.gameObject); var appPath = Application.dataPath.Substring(0, Application.dataPath.Length - "/Assets".Length); var fixedUpPrefabPath = (appPath + "/" + prefabPath).Replace("/", "\\"); filename = Path.GetFileNameWithoutExtension(fixedUpPrefabPath) + ".Generated.cs"; dstFile = Path.Combine(Path.GetDirectoryName(fixedUpPrefabPath), filename); return(true); } var path = compiler.outputOptions.assetsRelativeOutputFile; filename = Path.GetFileName(path); var dir = Path.Combine(Application.dataPath, Path.GetDirectoryName(path)); dstFile = Path.Combine(dir, filename); if (compiler.outputOptions.allowMakeDirs) { Directory.CreateDirectory(dir); } if (!Directory.Exists(dir)) { Debug.LogErrorFormat(compiler, "Cannot write FSM to '{0}', directories do not exist and allowMakeDirs is false", dstFile); return(false); } return(true); }
private void RegenerateDescription(PlayMakerCodeGenerator compiler) { var parser = new PlayMakerParser(compiler.parserOptions); try { var fsm = compiler.fsm as PlayMakerFSM; var model = parser.CreateModel(fsm); compiler.DebugDescription = Stringify.CreateDescription(model); } catch (System.Exception e) { Debug.LogErrorFormat("PlayMakerStringify, error parsing FSM: {0}", e.ToString()); return; } }