void Convert(bool forceConversion) { converter = new CSharpToUnityScriptConverter(m_scriptRelativePath); string sourceScriptPath = Application.dataPath + m_scriptRelativePath + m_scriptName + m_sourceScriptExtension; string targetScriptPath = sourceScriptPath.Replace(m_sourceScriptExtension, m_targetScriptExtension); if (!File.Exists(sourceScriptPath)) { Debug.LogError("CustomScriptDev.Convert() : source script does not exists at path [" + sourceScriptPath + "]"); return; } // convert if forcer, or target does not exist, or source newer than target if (forceConversion || !File.Exists(targetScriptPath) || File.GetLastWriteTime(sourceScriptPath) > File.GetLastWriteTime(targetScriptPath)) { CSharpToUnityScriptConverter.importedAssemblies.Clear(); StreamReader reader = new StreamReader(sourceScriptPath); string inputCode = reader.ReadToEnd(); reader.Close(); string outputCode; converter.Convert(inputCode); //CSharpToUnityScriptConverter convertor = new CSharpToUnityScriptConverter (inputCode); outputCode = converter.convertedCode; StreamWriter writer = new StreamWriter(targetScriptPath); writer.Write(outputCode); writer.Flush(); writer.Close(); Debug.Log("Convert " + m_scriptName + " at " + DateTime.Now.ToLocalTime()); AssetDatabase.Refresh(); } }
// ---------------------------------------------------------------------------------- /// <summaray> /// Called 100 times per second /// Perform the conversion, one file per frame /// </summary> void Update() { if (scriptsToConvertList.Count > 0) { Script scriptInConversion = scriptsToConvertList[0]; // makes sure the target directory exists string targetScriptPath = Application.dataPath + targetDirectory + scriptInConversion.relativePath; Directory.CreateDirectory(targetScriptPath); // make sure the directory exist, or create it // write the converted code into the file if (converter == null) { converter = new CSharpToUnityScriptConverter(sourceDirectory); } // converter.Convert(scriptInConversion.text); //CSharpToUnityScriptConverter converter = new CSharpToUnityScriptConverter(scriptInConversion.text); StreamWriter writer = new StreamWriter(targetScriptPath + scriptInConversion.name + ".js"); writer.Write(converter.Convert(scriptInConversion.text)); writer.Flush(); writer.Close(); Debug.Log("Converted " + scriptInConversion.relativePath + scriptInConversion.name); scriptsToConvertList.RemoveAt(0); Repaint(); // update the GUI // auto refresh the project once all files have been converted if (scriptsToConvertList.Count <= 0) { Debug.LogWarning("Conversion done ! Refreshing project."); AssetDatabase.Refresh(); } } }