//////////////////////////////////////////////////////////////////////// #region Path /// <summary> /// Create interface for PathPoints /// </summary> /// <param name="_spawnPointIndex">Current SpawnPoint index</param> private void PathInterface(SpawnPoint _point) { GUIStyle _style = EditorStatics.GetBoxStyle(0, 0, 5, 0, 15, 15, 15, 15, 455); EditorGUILayout.BeginVertical(_style); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Paths", pointStyle, GUILayout.Width(35)); // Push to the right GUILayout.FlexibleSpace(); if (GUILayout.Button(EditorStatics.StringAddSign, EditorStatics.Width_30)) { // Add a path with a starting position same as the spawnpoint current position _point.Add(_point.Position); } int _count = _point.Paths.Count; // Remove a path if (GUILayout.Button(EditorStatics.StringRemoveSign, EditorStatics.Width_30)) { if (_count > 0) { _point.Paths.RemoveAt(_count - 1); _count--; } } EditorGUILayout.EndHorizontal(); // Dont show toggle if no paths added if (_count > 0) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); _point.FoldoutPaths = EditorGUILayout.Foldout( _point.FoldoutPaths, "Toggle" ); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } // Create a foldout for the paths if (_point.FoldoutPaths) { EditorGUILayout.Space(); PathsDraw(_point); } EditorGUILayout.EndVertical(); }
//////////////////////////////////////////////////////////////////////// #region Bar & Layout private void CreateTableNavigationBar() { // Contains navigation buttons and log EditorGUILayout.BeginHorizontal(); GUIStyle _style = EditorStatics.GetBoxStyle(10, 0, 10, 10, 15, 15, 15, 15); EditorGUILayout.BeginVertical(_style); // Contains navigation buttons EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Convert", EditorStatics.Width_100)) { LoadConvertInterface(); } if (GUILayout.Button("Browse", EditorStatics.Width_100)) { LoadTableBrowse(); } if (GUILayout.Button("Structure", EditorStatics.Width_100)) { LoadTableStructure(); } // Contains navigation buttons EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); DisplayLog(); // Contains navigation buttons and log EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (tableSO != null && tableSO && tableSO.Table != null) { if (currentView == CurrentView.TableBrowse) { //DrawTableBrowseCreateRowField(); } if (currentView == CurrentView.TableStructure) { //DrawTableStructureCreateField(); } } }
//////////////////////////////////////////////////////////////////////// #region Select SO /// <summary> /// Create a field for selecting a SpawnPointCollectionSO asset /// </summary> private void SelectSO() { GUIStyle _style = EditorStatics.GetBoxStyle(20, 0, 20, 10, 15, 15, 15, 15, 485); EditorGUILayout.BeginVertical(_style); so = (SpawnPointCollectionSO)EditorGUILayout.ObjectField( "Collection", so, typeof(SpawnPointCollectionSO), true ); EditorGUILayout.EndVertical(); }
/// <summary> /// Draw all Paths in the list to the inspector interface /// </summary> /// <param name="_spawnPointIndex">The index.</param> private void PathsDraw(SpawnPoint _point) { GUIStyle _style = EditorStatics.GetBoxStyle(0, 0, 5, 0, 15, 15, 15, 15, 425); int _pathCount = _point.Paths.Count; for (int _i = 0; _i < _pathCount; _i++) { Path _path = _point.Paths[_i]; EditorGUILayout.BeginVertical(_style); if (pointStyle == null) { pointStyle = new GUIStyle(EditorStyles.foldout); } EditorGUILayout.BeginHorizontal(); // Create a foldout for the path _so.Collection.Points _path.Foldout = EditorGUILayout.Foldout(_path.Foldout, _path.Name + " ID:" + _path.ID); if (EditPathHeader(_point, _path, _i)) { EditorGUILayout.EndVertical(); return; } EditorGUILayout.EndHorizontal(); EditPathInfo(_path); if (!_path.Foldout) { EditorGUILayout.EndVertical(); continue; } EditorGUILayout.Space(); /// DRAWN INSPECTOR INTERFACE PATH POINTS PathPointsList(_path); EditorGUILayout.EndVertical(); } }
//////////////////////////////////////////////////////////////////////// #region Select SO private void SelectTableSO() { if (currentView == CurrentView.Convert) { return; } EditorGUILayout.Space(); GUIStyle _style = EditorStatics.GetBoxStyle(10, 10, 0, 10, 15, 15, 15, 15, 390); EditorGUILayout.BeginVertical(_style); labelDistance = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 80; loadTableSO = (TableSO)EditorGUILayout.ObjectField( "Table SO", loadTableSO, typeof(TableSO), true, EditorStatics.Width_210 ); EditTableInfo(); EditorGUIUtility.labelWidth = labelDistance; EditorGUILayout.Space(); // Buttons EditorGUILayout.BeginHorizontal(); EditTableLoad(); InterfaceSave(); // Buttons EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); }
/// <summary> /// Edit color, name, position of a spawn point /// </summary> private void EditSpawnPointInfo(SpawnPoint _point) { GUIStyle _style = EditorStatics.GetBoxStyle(0, 0, 5, 0, 15, 15, 15, 15, 455); GUILayout.BeginVertical(_style); _point.Name = EditorStatics.CreateTextField( "Name", "Spawn point name - appears in header", ref _point.Name, EditorStatics.Width_300 ); _point.ColorGizmo = EditorGUILayout.ColorField( "Color", _point.ColorGizmo, EditorStatics.Width_300 ); EditorGUILayout.Space(); // Draw position field on the next line EditorGUILayout.BeginHorizontal(); // Spacing EditorGUILayout.LabelField("Position", EditorStatics.Width_150); _point.Position = EditorGUILayout.Vector3Field(string.Empty, _point.Position, EditorStatics.Width_210); EditorGUILayout.EndHorizontal(); // Draw rotation field on the next line EditorGUILayout.BeginHorizontal(); // Spacing EditorGUILayout.LabelField("Rotation", EditorStatics.Width_150); _point.Rotation = EditorGUILayout.Vector3Field(string.Empty, _point.Rotation, EditorStatics.Width_210); EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); }
private void DrawColumns() { GUIStyle _style = EditorStatics.GetBoxStyle(0, 0, 2, 2, 2, 2, 5, 5); EditorGUILayout.BeginVertical(_style); EditorGUILayout.BeginHorizontal(); // Edit row (Width_50), insert (Width_50), remove (Width_50) width in DrawRows() EditorStatics.CreateLabelField("", EditorStatics.Width_150); // Spacing fix EditorStatics.CreateLabelField("", EditorStatics.Width_5); // Shift row up and down (Width_20) width in DrawRows() EditorStatics.CreateLabelField("", EditorStatics.Width_20); EditorStatics.CreateLabelField("", EditorStatics.Width_20); EditorStatics.CreateLabelField("#", EditorStatics.Width_50); int _count = tableSO.Table.ColumnCount; for (int _i = 0; _i < _count; _i++) { EditorStatics.CreateLabelField( tableSO.Table.ColumnNames[_i].ShorterText(10, true), EditorStatics.Width_80, style ); // Push the next one EditorStatics.CreateLabelField("", EditorStatics.Width_5); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
//////////////////////////////////////////////////////////////////////// #region Log private void DisplayLog() { GUILayout.FlexibleSpace(); GUIStyle _style = EditorStatics.GetBoxStyle(20, 10, 10, 10, 15, 15, 15, 15, 600, 100); EditorGUILayout.BeginVertical(_style); scrollPositionLog = GUILayout.BeginScrollView(scrollPositionLog, false, false); logCount = logs.Count; for (int _i = logCount - 1; _i >= 0; _i--) { EditorStatics.CreateLabelField( logs[_i].LogMessage, EditorStatics.Width_500, logs[_i].ActionStatus ? colorLogSuccess : colorLogFail ); } GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); }
private void DrawTableLayout() { if (currentView == CurrentView.Convert) { DrawInterfaceConvert(); return; } if (tableSO == null || !tableSO || tableSO.Table == null) { return; } GUIStyle _style = EditorStatics.GetBoxStyle(10, 10, 0, 10, 15, 15, 15, 15); EditorGUILayout.BeginVertical(_style); if (currentView == CurrentView.TableBrowse) { DrawTableBrowseCreateRowField(); DrawColumns(); DrawRows(); } else if (currentView == CurrentView.TableStructure) { DrawTableStructure(); } else if (currentView == CurrentView.EditRow) { DrawTableRow(); } EditorGUILayout.EndVertical(); }
/// <summary> /// Create interface for a PathPoint which allows editing its position and rotation. /// You can also remove the point or focus scene camera on it. /// </summary> private void DrawPathPoints(Path _path) { EditorGUILayout.Space(); GUIStyle style = EditorStatics.GetBoxStyle(0, 0, 5, 0, 5, 5, 5, 5, 400); int _count = _path.Points.Count; for (int _i = 0; _i < _count; _i++) { PathPoint _point = _path.Points[_i]; EditorGUILayout.BeginVertical(style); DrawPathPointsTitle(_point, _i); DrawPathPointsPositionAndRemove(_point, _i, _path); DrawPathPointsRotationAndDisplay(_point); DrawPathPointName(_point); EditorGUILayout.EndVertical(); } }
private void DrawRows() { int _startIndex = currentPage * currentPerPageValue; List <TableRow> _rows = tableSO.Table.GetRows(_startIndex, _startIndex + currentPerPageValue, true); if (_rows == null) { return; } int _count = _rows.Count; for (int _i = 0; _i < _count; _i++) { TableRow _row = _rows[_i]; int _rowIndex = _startIndex + _i; GUIStyle _style = EditorStatics.GetBoxStyle(0, 0, 0, 0, 2, 2, 2, 2, 0, 30); EditorGUILayout.BeginVertical(_style); EditorGUILayout.BeginHorizontal(); // Insert a row before this one if (GUILayout.Button(new GUIContent("Insert", "Insert a row before this one"), EditorStatics.Width_50)) { tableSO.Table.InsertRow(_rowIndex); EditorGUILayout.EndHorizontal(); return; } // Insert a row before this one if (GUILayout.Button("Delete", EditorStatics.Width_50)) { tableSO.Table.RemoveRow(_rowIndex); EditorGUILayout.EndHorizontal(); return; } if (GUILayout.Button("Edit", EditorStatics.Width_50)) { EditTableRow(_rowIndex); } // Shift row to previous index if (GUILayout.Button(EditorStatics.StringArrowUp, EditorStatics.Width_20)) { int _nextIndex = _rowIndex - 1; if (tableSO.Table.ShiftRow(_rowIndex, _nextIndex)) { Debug.Log(string.Format("Shifted row up. From Index: {0}, To Index: {1}", _rowIndex, _nextIndex)); } } // Shift row to next index if (GUILayout.Button(EditorStatics.StringArrowDown, EditorStatics.Width_20)) { int _nextIndex = _rowIndex + 1; if (tableSO.Table.ShiftRow(_rowIndex, _nextIndex)) { Debug.Log(string.Format("Shifted row down. From Index: {0}, To Index: {1}", _rowIndex, _nextIndex)); } } // Display row index EditorStatics.CreateLabelField(_rowIndex.ToString(), EditorStatics.Width_50); GUIStyle _styleC = EditorStatics.GetBoxStyle(0, 0, 0, 0, 0, 0, 2, 2, 0, 26); _styleC.alignment = TextAnchor.MiddleCenter; style.wordWrap = true; int _columnCount = tableSO.Table.ColumnCount; for (int _j = 0; _j < _columnCount; _j++) { ITableRowValue _column = _row.RowColumns[_j]; EditorStatics.CreateLabelField( _column.Value.ShorterText(10, true), EditorStatics.Width_80, _styleC ); // Push the next one EditorStatics.CreateLabelField("", EditorStatics.Width_5); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } }
//////////////////////////////////////////////////////////////////////// #region Convert private void DrawInterfaceConvert() { GUIStyle _style = EditorStatics.GetBoxStyle(10, 00, 0, 10, 15, 15, 15, 15, 350); EditorGUILayout.BeginVertical(_style); textTable = (TextAsset)EditorGUILayout.ObjectField( "JSON Table", textTable, typeof(TextAsset), true, EditorStatics.Width_300 ); importTable = (TableSO)EditorGUILayout.ObjectField( "Import SO", importTable, typeof(TableSO), true, EditorStatics.Width_300 ); if (GUILayout.Button("Import", EditorStatics.Width_70)) { if (importTable == null || !importTable) { CreateLog("Import table reference not set!", false); return; } if (textTable != null && textTable) { if (!string.IsNullOrEmpty(textTable.text)) { try { Table table = JsonUtility.FromJson <Table>(textTable.text); if (table != null) { importTable.Table = table; EditorUtility.SetDirty(importTable); importTable = null; textTable = null; CreateLog("JSON successfully loaded into the export table SO!", true); } } catch (System.Exception _e) { CreateLog("Unable to parse JSON file as a Table!", false); } } else { CreateLog("JSON file contains no data!", false); } } else { CreateLog("JSON file reference not set!", false); } } EditorGUILayout.EndVertical(); }
/// <summary> /// Draws interface for every spawn point. /// </summary> private void SpawnPointsDraw() { int spawnPointCount = GetCount(); GUIStyle _style = EditorStatics.GetBoxStyle(20, 0, 0, 0, 15, 15, 15, 15, 485); for (int _i = 0; _i < spawnPointCount; _i++) { SpawnPoint _point = so.Collection.Points[_i]; GUILayout.BeginVertical(_style); if (pointStyle == null) { pointStyle = new GUIStyle(EditorStyles.boldLabel); } EditorGUILayout.BeginHorizontal(); EditorStatics.GUIPreColor = EditorStyles.label.normal.textColor; pointStyle.normal.textColor = Color.white; EditorGUILayout.LabelField(EditorStatics.StringMiddleMark, pointStyle, GUILayout.Width(20)); pointStyle.normal.textColor = EditorStatics.GUIPreColor; string _displayName = so.Collection.Points[_i].Name + " ID: " + _point.ID; _point.Foldout = EditorGUILayout.Foldout(_point.Foldout, _displayName); SpawnPointListOrder(GetCount(), _i); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); // Remove, focus, gizmos, keyboard if (EditSpawnPointHeaderButtons(_point, _i)) { EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); return; } EditorGUILayout.EndHorizontal(); // Do not show the spawn point if (!_point.Foldout) { GUILayout.EndVertical(); continue; } EditorGUILayout.Space(); EditSpawnPointInfo(_point); PathInterface(_point); GUILayout.EndVertical(); } }
private void Awake() { SceneView.onSceneGUIDelegate += OnSceneGUI; styleInterface = EditorStatics.GetBoxStyle(20, 0, 0, 10, 15, 15, 15, 15, 485); }