public static UnityEngine.Rect New(UnityEngine.Rect area, float widthOffset = 0) { var indentedArea = EditorGUI.IndentedRect(area); EditorGuiIndentManager.New(0); GuiLabelWidthManager.New(EditorGUIUtility.labelWidth + widthOffset - ((indentedArea.x - area.x))); return(indentedArea); }
public static void Layout(string label, string tooltip, float labelWidth, SerializedProperty prop, params GUILayoutOption[] options) { var val = prop.intValue; GuiLabelWidthManager.New(labelWidth); var newVal = EditorGUILayout.IntField(new GUIContent(label, tooltip), val, options); GuiLabelWidthManager.Revert(); if (val != newVal) { prop.intValue = newVal; } }
public override void OnGUI(Rect area, SerializedProperty property, GUIContent label) { var groupProp = property.FindPropertyRelative("_group"); var volumeProp = property.FindPropertyRelative("_volume"); var minPitchProp = property.FindPropertyRelative("_minPitch"); var maxPitchProp = property.FindPropertyRelative("_maxPitch"); var panProp = property.FindPropertyRelative("_pan"); var spatialBlendProp = property.FindPropertyRelative("_spatialBlend"); var dopplerLevelProp = property.FindPropertyRelative("_dopplerLevel"); var spreadProp = property.FindPropertyRelative("_spread"); var rolloffProp = property.FindPropertyRelative("_rolloff"); var minDistanceProp = property.FindPropertyRelative("_minDistance"); var maxDistanceProp = property.FindPropertyRelative("_maxDistance"); EditorGuiIndentManager.New(0); var fold = Fold(property); var open = !fold.Get; GUI.Box(area, default(Texture2D)); var lh = EditorGUIUtility.singleLineHeight; var lhs = lh + SPACING; var line = area.CutBottom(area.height - lh); var labelSize = label.text.Length * 6; fold.Set = !EditorGUI.Foldout(line.CutRight(area.width - labelSize), open, open ? "" : label.text); if (!open) { var icon = IconCache.Get("Gear").Texture; if (icon != null && GUI.Button(line.RequestHeight(icon.height).CutLeft(line.width - icon.width).MoveLeft(2).MoveDown(1), icon, K10GuiStyles.basicStyle)) { fold.Set = false; } EditorGuiIndentManager.Revert(); return; } area = area.CutTop(2 * SPACING); area = area.CutLeft(SPACING * 4); area = area.CutRight(SPACING * 4); //line = line.CutLeft( labelSize ); line = area.CutBottom(area.height - lh); //line = SeparationLine.Vertical( line ); //GUI.Box( line, default( Texture2D ) ); //EditorGUI.PropertyField( area.CutBottom( area.height - lh ), groupProp ); area = area.CutTop( lhs ); GuiLabelWidthManager.New(42); EditorGUI.PropertyField(line, groupProp); area = area.CutTop(lhs); GuiLabelWidthManager.Revert(); GuiLabelWidthManager.New(50); EditorGUI.PropertyField(area.CutBottom(area.height - lh), volumeProp); area = area.CutTop(lhs); GuiLabelWidthManager.Revert(); // GuiLabelWidthManager.New( 33 ); var minPitch = minPitchProp.floatValue; var maxPitch = maxPitchProp.floatValue; GUI.Label(area.CutBottom(area.height - lh).CutRight(area.width - 33), "Pitch"); minPitch = EditorGUI.FloatField(area.CutBottom(area.height - lh).CutLeft(33).CutRight(area.width - 83), minPitch); minPitch = Mathf.Clamp(minPitch, .011f, 3f); EditorGUI.MinMaxSlider(area.CutBottom(area.height - lh).CutLeft(88).CutRight(55), ref minPitch, ref maxPitch, 0.01f, 3f); maxPitch = EditorGUI.FloatField(area.CutBottom(area.height - lh).CutLeft(area.width - 50), maxPitch); maxPitch = Mathf.Clamp(maxPitch, .011f, 3f); area = area.CutTop(lhs); minPitchProp.floatValue = minPitch; maxPitchProp.floatValue = maxPitch; // GuiLabelWidthManager.Revert(); GuiLabelWidthManager.New(27); EditorGUI.PropertyField(area.CutBottom(area.height - lh), panProp); area = area.CutTop(lhs); GuiLabelWidthManager.Revert(); GuiLabelWidthManager.New(85); EditorGUI.PropertyField(area.CutBottom(area.height - lh), spatialBlendProp); area = area.CutTop(lhs); EditorGUI.PropertyField(area.CutBottom(area.height - lh), dopplerLevelProp); area = area.CutTop(lhs); GuiLabelWidthManager.Revert(); GuiLabelWidthManager.New(47); EditorGUI.PropertyField(area.CutBottom(area.height - lh), spreadProp); area = area.CutTop(lhs); EditorGUI.PropertyField(area.CutBottom(area.height - lh), rolloffProp); area = area.CutTop(lhs); GuiLabelWidthManager.Revert(); line = area.CutBottom(area.height - lh); GuiLabelWidthManager.New(28); var distSize = 55; GUI.Label(line.CutRight(line.width - distSize), "Distance"); line = line.CutLeft(distSize); var iconSize = 16; if (IconButton.Draw(line.CutLeft(line.width - iconSize).RequestHeight(iconSize), "RefreshButton", 'R', "Reset configuration to default value", Color.white)) { volumeProp.floatValue = 1; minPitchProp.floatValue = 1; maxPitchProp.floatValue = 1; panProp.floatValue = 0; spatialBlendProp.floatValue = 0; dopplerLevelProp.floatValue = 1; spreadProp.floatValue = 1; rolloffProp.enumValueIndex = (int)AudioRolloffMode.Custom; minDistanceProp.floatValue = 1; maxDistanceProp.floatValue = 25; } line = line.CutRight(iconSize); maxDistanceProp.floatValue = EditorGUI.FloatField(line.CutLeft(line.width / 2), "Max", maxDistanceProp.floatValue); minDistanceProp.floatValue = EditorGUI.FloatField(line.CutRight(line.width / 2), "Min", minDistanceProp.floatValue); EditorGuiIndentManager.Revert(); GuiLabelWidthManager.Revert(); area = area.CutTop(lhs); EditorGuiIndentManager.Revert(); }
public override void OnInspectorGUI() { serializedObject.Update(); exporting = false; for (int i = 0; i < _exportation.Count && !exporting; i++) { var ex = _exportation[i]; exporting |= ex.Exporting; } GUILayout.BeginVertical(GUI.skin.box); bool allSelected = true; // bool allSelectedAreOpen = true; // bool allUnselectedAreClosed = true; for (int i = 0; i < _exportFields.arraySize; i++) { var element = _exportFields.GetArrayElementAtIndex(i); var selected = element.isExpanded; allSelected &= selected; // var editMode = element.isExpanded; // if( selected ) allSelectedAreOpen &= editMode; // else allUnselectedAreClosed &= !editMode; } GUILayout.BeginHorizontal(GUI.skin.box); EditorGUI.BeginDisabledGroup(exporting); if (GUILayout.Button($"{( allSelected ? "Unselect" : "Select" )} All")) { for (int i = 0; i < _exportFields.arraySize; i++) { var element = _exportFields.GetArrayElementAtIndex(i); element.isExpanded = !allSelected; } } if (GUILayout.Button($"Invert Selection")) { for (int i = 0; i < _exportFields.arraySize; i++) { var element = _exportFields.GetArrayElementAtIndex(i); var selected = element.FindPropertyRelative("_selected"); selected.boolValue = !selected.boolValue; } } EditorGUI.EndDisabledGroup(); // if( GUILayout.Button( $"{( allSelectedAreOpen ? "Close" : "Open" )} all selected(s)" ) ) ToggleElements( _exportFields, !allSelectedAreOpen, true ); // if( GUILayout.Button( $"{( allUnselectedAreClosed ? "Open" : "Close" )} all unselected(s)" ) ) ToggleElements( _exportFields, allUnselectedAreClosed, false ); GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(exporting); _exportList.DoLayoutList(); EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginVertical(GUI.skin.box); GuiLabelWidthManager.New(25); EditorGUI.BeginDisabledGroup(exporting); var authorName = _author.Get; bool authorIsValid = IsValidAuthorName(authorName); if (!authorIsValid) { GuiColorManager.New(K10GuiStyles.RED_TINT_COLOR); } GUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Author", GUILayout.MaxWidth(40)); authorName = EditorGUILayout.TextArea(authorName); EditorGUILayout.EndHorizontal(); _author.Set = authorName; bool canSend = !exporting && IsValidAuthorName(authorName); EditorGUILayout.PropertyField(_urlField); EditorGUI.BeginDisabledGroup(!canSend); var send = GUILayout.Button("Export", K10GuiStyles.bigbuttonStyle) && canSend; EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); if (!authorIsValid) { GuiColorManager.Revert(); } EditorGUI.EndDisabledGroup(); GuiLabelWidthManager.Revert(); GUILayout.BeginVertical(GUI.skin.box); if (_exportation.Count > 0) { for (int i = 0; i < _exportation.Count; i++) { var color = _exportation[i].GetColor(); if (color.HasValue) { GuiColorManager.New(color.Value); } GUILayout.BeginHorizontal(GUI.skin.box); if (color.HasValue) { GuiColorManager.Revert(); } GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label("\"" + _exportation[i].Name + "\""); GUILayout.EndHorizontal(); if (color.HasValue) { GuiColorManager.New(color.Value); } GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label(_exportation[i].Message); GUILayout.EndHorizontal(); if (color.HasValue) { GuiColorManager.Revert(); } GUILayout.EndHorizontal(); } } else { GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label("No export data"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); if (!exporting) { var exporter = target as JsonExporterData; int count = exporter.FieldsCount; while (_exportation.Count < count) { _exportation.Add(new ExportationElement()); } while (_exportation.Count > count) { _exportation.RemoveAt(_exportation.Count - 1); } for (int i = 0; i < count; i++) { var field = exporter.GetField(i); _exportation[i].Set(field); } if (send) { if (_exportation.Count > 0) { JsonExporterData.OnPreExport?.Invoke(); var url = _urlField.stringValue; IEventTrigger sendNext = new CallOnce(SetDataDirty); for (int i = _exportation.Count - 1; i >= 0; i--) { var exp = _exportation[i]; if (exp.Ignored) { continue; } var f = exporter.GetField(i); var field = f.Reference.Definition; var batchSize = f.BatchSize; var nextTrigger = sendNext; var datas = new List <string>(); if (batchSize == 0) { datas.Add($"{{ \"tableName\": \"{field.FieldName}\", \"data\": {field.GetMemberValueSerialized()} }}"); } else { var elementsCount = field.GetCount(); for (int e = 0; e < elementsCount; e += batchSize) { datas.Add($"{{ \"tableName\": \"{field.FieldName}\"," + $" \"ignoreClear\": {( ( e != 0 ) ? "true" : "false" )}," + $"\"data\": {field.GetMemberValueSerialized( e, batchSize )} }}"); } } exp.SetState(EExportStep.Queue); sendNext = new CallOnce(() => { exp.Trigger(url, datas, nextTrigger, authorName); SetDataDirty(); }); } sendNext.Trigger(); } } } }