/// <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 void DrawHeaderSetting(BaseMachine m) { if (m.HasHeadColumn()) { //EditorGUILayout.LabelField("type settings"); GUIStyle headerStyle = GUIHelper.MakeHeader(); GUILayout.Label("Type Settings:", headerStyle); //curretScroll = EditorGUILayout.BeginScrollView(curretScroll, false, false); EditorGUILayout.BeginVertical("box"); //string lastCellName = string.Empty; foreach (HeaderColumn header in m.HeaderColumnList) { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(header.name, GUILayout.MaxWidth(250)); header.type = (CellType)EditorGUILayout.EnumPopup(header.type, GUILayout.MaxWidth(150)); GUILayout.Space(20); EditorGUILayout.LabelField("array:", GUILayout.MaxWidth(40)); header.isArray = EditorGUILayout.Toggle(header.isArray, GUILayout.MaxWidth(50)); GUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); //EditorGUILayout.EndScrollView(); } }
protected virtual void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp) { Debug.LogWarning("!!! It should be implemented in the derived class !!!"); }