void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Excel路径 : ", GUILayout.Width(80)); _excelPath = EditorGUILayout.TextField(_excelPath, GUILayout.Width(400)); bool selectPath = GUILayout.Button("选择"); if (selectPath) { _excelPath = EditorWindowUtil.SelectFileWithFilters("选择Excel路径", _excelPath, new string[] { "xls,xlsx", "xls,xlsx" }); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); bool load = GUILayout.Button("Load"); bool save = GUILayout.Button("Save"); EditorGUILayout.EndHorizontal(); if (load) { LoadFile(); } if (save) { SaveFile(); } if (_excel == null || _excel.excelData == null) { return; } _position = EditorGUILayout.BeginScrollView(_position); for (int i = 0; i < _excel.excelData.count; i++) { EditorGUILayout.BeginHorizontal(); _tmpRow = _excel.excelData.GetRow(i); if (_tmpRow.rowType == ExcelRowType.Content || _tmpRow.rowType == ExcelRowType.Comment) { DrawRow(_tmpRow, DrawCell); } else if (_tmpRow.rowType == ExcelRowType.Type) { DrawRow(_tmpRow, DrawTypeCell); } else if (_tmpRow.rowType == ExcelRowType.Name) { DrawRow(_tmpRow, DrawNameCell); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
void LoadFile() { if (string.IsNullOrEmpty(_excelPath)) { _excelPath = EditorWindowUtil.SelectFileWithFilters("选择Excel路径", _excelPath, new string[] { "xls,xlsx", "xls,xlsx" }); } if (string.IsNullOrEmpty(_excelPath) || (!_excelPath.EndsWith(".xls") && !_excelPath.EndsWith(".xlsx"))) { Debug.LogError("请选择正确的excel文件"); return; } _excel = new Excel(_excelPath); _excel.Load(); }