/// <summary> /// Create a ScriptableObject editor class and write it down on the specified folder. /// </summary> protected void CreateScriptableObjectEditorClassScript(BaseMachine machine, ScriptPrescription sp) { sp.className = machine.WorkSheetName + "Editor"; sp.workSheetClassName = machine.GetComposedWorkSheetClassName(); sp.dataClassName = machine.GetComposedDataClassName(); sp.template = GetTemplate("ScriptableObjectEditorClass"); // check the directory path exists string fullPath = TargetPathForEditorScript(machine.WorkSheetName); string folderPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(folderPath)) { EditorUtility.DisplayDialog( "Warning", "The folder for editor 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 ScriptGenerator(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 (ColumnHeader header in machine.ColumnHeaderListDict.GetValue(machine.WorkSheetName).list) { MemberFieldData member = new MemberFieldData(); member.Name = header.name; member.type = header.type; member.IsArrayType = header.isArray; fieldList.Add(member); } sp.className = machine.GetComposedDataClassName(); sp.template = GetTemplate("DataClass"); sp.memberFields = fieldList.ToArray(); // write a script to the given folder. using (var writer = new StreamWriter(fullPath)) { writer.Write(new ScriptGenerator(sp).ToString()); writer.Close(); } }