/// <summary>Create a ScriptableObject class and write it down on the specified folder.</summary> protected void CreateScriptableObjectClassScript(BaseMachine machine, ScriptPrescription sp) { sp.className = machine.WorkSheetName; sp.dataClassName = machine.WorkSheetName + "Data"; sp.template = GetTemplate("ScriptableObjectClass"); // check the directory path exists string fullPath = TargetPathForClassScript(machine.WorkSheetName); string folderPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(folderPath)) { EditorUtility.DisplayDialog( "Warning", "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.", "OK" ); return; } StreamWriter writer = null; try { // write a script to the given folder. writer = new StreamWriter(fullPath); writer.Write(new NewScriptGenerator(sp).ToString()); } catch (System.Exception e) { Debug.LogError(e); } finally { if (writer != null) { writer.Close(); writer.Dispose(); } } }
/// <summary> /// Create a data class which describes the spreadsheet and write it down on the specified folder. /// </summary> protected void CreateDataClassScript(BaseMachine machine, ScriptPrescription sp) { // check the directory path exists string fullPath = TargetPathForData(machine.WorkSheetName); string folderPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(folderPath)) { EditorUtility.DisplayDialog( "Warning", "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.", "OK" ); return; } List<MemberFieldData> fieldList = new List<MemberFieldData>(); //FIXME: replace ValueType to CellType and support Enum type. foreach (HeaderColumn header in machine.HeaderColumnList) { MemberFieldData member = new MemberFieldData(); member.Name = header.name; member.type = header.type; member.IsArrayType = header.isArray; fieldList.Add(member); } sp.className = machine.WorkSheetName + "Data"; sp.template = GetTemplate("DataClass"); sp.memberFields = fieldList.ToArray(); // write a script to the given folder. using (var writer = new StreamWriter(fullPath)) { writer.Write(new NewScriptGenerator(sp).ToString()); writer.Close(); } }
/// <summary> /// Generate script files with the given templates. /// Total four files are generated, two for runtime and others for editor. /// </summary> protected virtual ScriptPrescription Generate(BaseMachine m) { if (m == null) return null; ScriptPrescription sp = new ScriptPrescription(); if (m.onlyCreateDataClass) { CreateDataClassScript(m, sp); } else { CreateScriptableObjectClassScript(m, sp); CreateScriptableObjectEditorClassScript(m, sp); CreateDataClassScript(m, sp); CreateAssetCreationScript(m, sp); } AssetDatabase.Refresh(); return sp; }
/// <summary> /// Generate AssetPostprocessor editor script file. /// </summary> protected override void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp) { ExcelMachine machine = target as ExcelMachine; sp.className = machine.WorkSheetName; sp.dataClassName = machine.WorkSheetName + "Data"; sp.worksheetClassName = machine.WorkSheetName; // where the imported excel file is. sp.importedFilePath = machine.excelFilePath; // path where the .asset file will be created. string path = Path.GetDirectoryName(machine.excelFilePath); path += "/" + machine.WorkSheetName + ".asset"; sp.assetFilepath = path; sp.assetPostprocessorClass = machine.WorkSheetName + "AssetPostprocessor"; sp.template = GetTemplate("PostProcessor"); // write a script to the given folder. using (var writer = new StreamWriter(TargetPathForAssetPostProcessorFile(machine.WorkSheetName))) { writer.Write(new NewScriptGenerator(sp).ToString()); writer.Close(); } }
protected virtual void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp) { Debug.LogWarning("!!! It should be implemented in the derived class !!!"); }
private void CreateDataClassScriptFromSpreadSheet(ScriptPrescription sp) { List<MemberFieldData> fieldList = new List<MemberFieldData>(); Regex re = new Regex(@"\d+"); DoCellQuery((cell) => { // get numerical value from a cell's address in A1 notation only retrieves first column // of the worksheet which is used for member fields of the created data class. Match m = re.Match(cell.Title.Text); if (int.Parse(m.Value) > 1) return; // add cell's displayed value to the list. fieldList.Add(new MemberFieldData(cell.Value.Replace(" ", ""))); }); sp.className = machine.WorkSheetName + "Data"; sp.template = GetTemplate("DataClass"); sp.memberFields = fieldList.ToArray(); // write a script to the given folder. using (var writer = new StreamWriter(TargetPathForData(machine.WorkSheetName))) { writer.Write(new NewScriptGenerator(sp).ToString()); writer.Close(); } }
/// Create utility class which has menu item function to create an asset file. protected override void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp) { sp.className = machine.WorkSheetName; sp.worksheetClassName = machine.WorkSheetName; sp.assetFileCreateFuncName = "Create" + machine.WorkSheetName + "AssetFile"; sp.template = GetTemplate("AssetFileClass"); // write a script to the given folder. using (var writer = new StreamWriter(TargetPathForAssetFileCreateFunc(machine.WorkSheetName))) { writer.Write(new NewScriptGenerator(sp).ToString()); writer.Close(); } }
public NewScriptGenerator (ScriptPrescription scriptPrescription) { m_ScriptPrescription = scriptPrescription; }
public NewScriptGenerator(ScriptPrescription scriptPrescription) { m_ScriptPrescription = scriptPrescription; }