protected virtual void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp) { Debug.LogWarning("!!! It should be implemented in the derived class !!!"); }
public override void OnInspectorGUI() { ExcelMachine machine = target as ExcelMachine; GUIStyle headerStyle = GUIHelper.MakeHeader(); GUILayout.Label("Excel Settings:", headerStyle); GUILayout.BeginHorizontal(); GUILayout.Label("File:", GUILayout.Width(50)); string path = ""; if (string.IsNullOrEmpty(machine.excelFilePath)) { path = Application.dataPath; } else { path = machine.excelFilePath; } machine.excelFilePath = GUILayout.TextField(path, GUILayout.Width(250)); if (GUILayout.Button("...", GUILayout.Width(20))) { string folder = Path.GetDirectoryName(path); #if UNITY_EDITOR_WIN path = EditorUtility.OpenFilePanel("Open Excel file", folder, "excel files;*.xls;*.xlsx"); #else path = EditorUtility.OpenFilePanel("Open Excel file", folder, "xls"); #endif if (path.Length != 0) { machine.SpreadSheetName = Path.GetFileName(path); // the path should be relative not absolute one. int index = path.IndexOf("Assets"); machine.excelFilePath = path.Substring(index); machine.SheetNames = new ExcelQuery(path).GetSheetNames(); } } GUILayout.EndHorizontal(); // Failed to get sheet name so we just return not to make editor on going. if (machine.SheetNames.Length == 0) { EditorGUILayout.Separator(); EditorGUILayout.LabelField("Error: Failed to retrieve the specified excel file."); EditorGUILayout.LabelField("If the excel file is opened, close it then reopen it again."); return; } machine.SpreadSheetName = EditorGUILayout.TextField("Spreadsheet File: ", machine.SpreadSheetName); machine.CurrentSheetIndex = EditorGUILayout.Popup(machine.CurrentSheetIndex, machine.SheetNames); if (machine.SheetNames != null) { machine.WorkSheetName = machine.SheetNames[machine.CurrentSheetIndex]; } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (machine.HasHeadColumn()) { if (GUILayout.Button("Update")) { Import(); } if (GUILayout.Button("Reimport")) { Import(true); } } else { if (GUILayout.Button("Import")) { Import(); } } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); DrawHeaderSetting(machine); EditorGUILayout.Separator(); GUILayout.Label("Path Settings:", headerStyle); machine.TemplatePath = EditorGUILayout.TextField("Template: ", machine.TemplatePath); machine.RuntimeClassPath = EditorGUILayout.TextField("Runtime: ", machine.RuntimeClassPath); machine.EditorClassPath = EditorGUILayout.TextField("Editor:", machine.EditorClassPath); //machine.DataFilePath = EditorGUILayout.TextField("Data:", machine.DataFilePath); machine.onlyCreateDataClass = EditorGUILayout.Toggle("Only DataClass", machine.onlyCreateDataClass); EditorGUILayout.Separator(); if (GUILayout.Button("Generate")) { ScriptPrescription sp = Generate(machine); if (sp != null) { Debug.Log("Successfully generated!"); } else { Debug.LogError("Failed to create a script from excel."); } } if (GUI.changed) { EditorUtility.SetDirty(machine); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }