public static bool GenerateScript(string folderPath, string filename, IScriptGenerator generator) { try { string path = folderPath + Path.AltDirectorySeparatorChar + filename; if (!File.Exists(path)) { using (var streamW = new StreamWriter(path)) { generator.Generate(streamW); } AssetDatabase.Refresh(); return(true); } else { Debug.LogError("Script with the same name already exists at path " + path); } } catch (Exception e) { Debug.LogException(e); } return(false); }
new public void FileInsertNewSingleFileScript(string filename, string file) { CSScriptFile csfile = new CSScriptFile(filename, file); SingleFileScriptPackage package = new SingleFileScriptPackage(csfile); IScriptGenerator generator = package.ExecuteCompiler(new SingleFileProjectCompiler()); ArrayList simulators = MetaverseController.Singleton.GetSimulators(); ISim sim = (ISim)simulators[0]; SimController.Singleton.InsertScript(sim, generator.Generate()); return; }