private void DisplaySceneForkflowButtons(float width) { using (VerticalScope vertical = new VerticalScope()) { GUILayout.Label("Scenes Context", ExtGUIStyles.MiniTextCentered, GUILayout.Height(HEIGHT_TEXT)); using (HorizontalScope horizontal = new HorizontalScope()) { EditorGUI.BeginChangeCheck(); _refGameAsset = EditorGUILayout.ObjectField(_refGameAsset, typeof(ContextListerAsset), false, GUILayout.Width(50), GUILayout.Height(HEIGHT_BUTTON)) as ContextListerAsset; if (EditorGUI.EndChangeCheck()) { ExtSaveAssetGUID.ResetKey(KEY_USED_FOR_CONTEXT_ASSET); ExtSaveAssetGUID.SaveAssetReference(_refGameAsset, KEY_USED_FOR_CONTEXT_ASSET, ""); } #if UNITY_2018_3_OR_NEWER if (IsRightClickContext()) { CreateGenericMenu(); } #endif if (_refGameAsset != null) { DisplayContextButtonsName(); } } } }
public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow) { using (var h = new HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); return(DelayedTextField(value)); } }
public static void ShortCut2Modifier1Keys(string description, string toolTip, string modifierKey1, ModifierKey defaultModifierKey1, string modifierKey2, ModifierKey defaultModifierKey2, string key, KeyCode defaultKey) { using (HorizontalScope horizontalScope = new HorizontalScope()) { GUIStyle centeredStyle = new GUIStyle(GUI.skin.GetStyle("Label")); centeredStyle.alignment = TextAnchor.MiddleLeft; GUILayout.Label(new GUIContent(description, toolTip), centeredStyle); if (!string.IsNullOrEmpty(modifierKey1)) { if (!EditorPrefs.HasKey(modifierKey1)) { EditorPrefs.SetInt(modifierKey1, (int)defaultModifierKey1); } ModifierKey currentModifier = (ModifierKey)EditorPrefs.GetInt(modifierKey1); EditorGUI.BeginChangeCheck(); ModifierKey enumModifierSelected = (ModifierKey)EditorGUILayout.EnumPopup(currentModifier, GUILayout.Width(60)); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt(modifierKey1, (int)enumModifierSelected); } } if (!string.IsNullOrEmpty(modifierKey2)) { if (!EditorPrefs.HasKey(modifierKey2)) { EditorPrefs.SetInt(modifierKey2, (int)defaultModifierKey2); } ModifierKey currentModifier = (ModifierKey)EditorPrefs.GetInt(modifierKey2); EditorGUI.BeginChangeCheck(); ModifierKey enumModifierSelected = (ModifierKey)EditorGUILayout.EnumPopup(currentModifier, GUILayout.Width(60)); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt(modifierKey2, (int)enumModifierSelected); } } if (!EditorPrefs.HasKey(key)) { EditorPrefs.SetInt(key, (int)defaultKey); } KeyCode currentKey = (KeyCode)EditorPrefs.GetInt(key); EditorGUI.BeginChangeCheck(); KeyCode enumSelected = (KeyCode)EditorGUILayout.EnumPopup(currentKey, GUILayout.Width(100)); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt(key, (int)enumSelected); } } }
private static void DisplayClearListButton() { using (HorizontalScope horizontalScope = new HorizontalScope()) { GUILayout.Label("Reset bookmarks & previously selected list: ", GUILayout.ExpandWidth(false)); if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false))) { PeekSerializeObject.Reset(); } } }
public override AnimationCurve Inspect(string label, AnimationCurve value, object parent, DatabaseInspector inspectorWindow) { using (var h = new HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); if (value == null) { value = new AnimationCurve(); } value = CurveField(value, Color.yellow, new Rect(0, 0, 1, 1)); } return(value); }
private static void ManageSlider(string key, string description, string toolTip, float defaultValue, float from, float to) { using (HorizontalScope horiz = new HorizontalScope()) { EditorGUILayout.LabelField(new GUIContent(description, toolTip), GUILayout.ExpandWidth(false)); EditorGUI.BeginChangeCheck(); float sliderPosition = EditorGUILayout.Slider(EditorPrefs.GetFloat(key, defaultValue), from, to, GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetFloat(key, sliderPosition); } } }
protected override void OnCustomInspectorGUI() { this.UpdateEditor(); using (HorizontalScope scope = new HorizontalScope()) { SerializedProperty plane3d = this.GetPropertie(ExtPlaneProperty.PROPERTY_PLANE_3D); bool allowDown = ExtPlaneProperty.GetAllowDown(plane3d); bool allowDownChange = GUILayout.Toggle(allowDown, "Allow Down", EditorStyles.miniButton); if (allowDownChange != allowDown) { ExtPlaneProperty.SetAllowDown(plane3d, allowDownChange); this.ApplyModification(); } } }
protected override void OnCustomInspectorGUI() { this.UpdateEditor(); using (HorizontalScope scope = new HorizontalScope()) { SerializedProperty disc = this.GetPropertie(nameof(MovableDisc.Disc)); bool allowDown = ExtDiscProperty.GetAllowDown(disc); bool allowDownChange = GUILayout.Toggle(allowDown, "Allow Down", EditorStyles.miniButton); if (allowDownChange != allowDown) { ExtDiscProperty.SetAllowDown(disc, allowDownChange); this.ApplyModification(); } } }
public override float Inspect(string label, float value, object parent, DatabaseInspector inspectorWindow, InspectableTemperatureAttribute attribute) { using (var h = new HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); GUILayout.Label("°K", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); value = DelayedFloatField(value); GUILayout.Label("°C", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); value = DelayedFloatField(value - 273.15f) + 273.15f; GUILayout.Label("°F", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); value = (DelayedFloatField((value - 273.15f) * 1.8f + 32) - 32) / 1.8f + 273.15f; return(value); } }
public static void ManageEnumKey(string key, KeyCode type, string description, string toolTip, int defaultKey) { if (!EditorPrefs.HasKey(key)) { EditorPrefs.SetInt(key, defaultKey); } KeyCode current = (KeyCode)EditorPrefs.GetInt(key); using (HorizontalScope horizontal = new HorizontalScope()) { EditorGUILayout.LabelField(new GUIContent(description, toolTip), GUILayout.Width(100)); EditorGUI.BeginChangeCheck(); KeyCode enumSelected = (KeyCode)EditorGUILayout.EnumPopup(current, GUILayout.Width(100)); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt(key, (int)enumSelected); } } }
public override Guid Inspect(string label, Guid value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute link) { using (new HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); var valueEntry = DatabaseInspector.CultCache.Get(value); using (var h = new HorizontalScope(GUI.skin.box)) { GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Drag and drop: {DatabaseListView.FormatTypeName(link.EntryType.Name)}"); if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) { var guid = (Guid)DragAndDrop.GetGenericData("Item"); var dragEntry = DatabaseInspector.CultCache.Get(guid); var dragValid = dragEntry != null && link.EntryType.IsInstanceOfType(dragEntry) && dragEntry != valueEntry; if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; } else if (Event.current.type == EventType.DragPerform) { if (dragValid) { DragAndDrop.AcceptDrag(); GUI.changed = true; return(guid); } } } if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3))) { return(Guid.Empty); } } } return(value); }
public override Dictionary <Guid, int> Inspect(string label, Dictionary <Guid, int> value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute attribute) { Space(); LabelField(label, EditorStyles.boldLabel); using (var v = new VerticalScope(GUI.skin.box)) { if (value.Count == 0) { using (var h = new HorizontalScope(DatabaseInspector.ListItemStyle)) { GUILayout.Label("Drag from list to add item"); } } foreach (var ingredient in value.ToArray()) { using (var h = new HorizontalScope(DatabaseInspector.ListItemStyle)) { var entry = DatabaseInspector.CultCache.Get(ingredient.Key); if (entry == null) { value.Remove(ingredient.Key); GUI.changed = true; return(value); } if (entry is INamedEntry named) { GUILayout.Label(named.EntryName); } else { GUILayout.Label(entry.ID.ToString()); } value[ingredient.Key] = DelayedIntField(value[ingredient.Key], GUILayout.Width(50)); // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3)) || value[ingredient.Key] == 0) { value.Remove(ingredient.Key); } } } if (v.rect.Contains(Event.current.mousePosition)) { var dragData = DragAndDrop.GetGenericData("Item"); var isId = dragData is Guid guid; var dragEntry = isId ? DatabaseInspector.CultCache.Get(guid) : null; var correctType = attribute.EntryType.IsInstanceOfType(dragEntry); if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; } else if (Event.current.type == EventType.DragPerform) { if (isId && correctType) { DragAndDrop.AcceptDrag(); value[guid] = 1; GUI.changed = true; } } } } return(value); }
/// <summary> /// display the content of the peek toolBar /// </summary> public bool DisplayPeekToolBar() { if (PeekSaveDatas.Instance == null) { return(false); } if (PeekSerializeObject.CurrentIndex >= PeekSerializeObject.SelectedObjectsCount) { PeekSerializeObject.SetCurrentIndex(PeekSerializeObject.SelectedObjectsCount - 1); PeekSerializeObject.Save(30); } using (VerticalScope vertical = new VerticalScope()) { GUILayout.Label("Browse selections", ExtGUIStyles.MiniTextCentered, GUILayout.Height(_heightText)); using (HorizontalScope horizontal = new HorizontalScope()) { if (GUILayout.Button(EditorGUIUtility.IconContent(OPEN_EDITOR_WINDOW_ICON), ExtGUIStyles.MicroButton, GUILayout.Width(28), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) { PeekLogic.ManageOpenPeekEditorWindow(); } #if UNITY_2018_3_OR_NEWER if (IsRightClickContext()) { return(true); } #endif EditorGUI.BeginDisabledGroup(PeekSerializeObject.SelectedObjectsCount == 0); { float delta = 0; bool isScrollingDown = ExtMouse.IsScrollingDown(Event.current, ref delta); StringBuilder previousTip = new StringBuilder(); previousTip.Append("Go to previous selection ("); previousTip.Append(ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY)); previousTip.Append("+"); previousTip.Append(ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_PREVIOUS_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_PREVIOUS_KEY)); previousTip.Append(")"); if ((GUILayout.Button(new GUIContent(PREVIOUS_ICON, previousTip.ToString()), ExtGUIStyles.MicroButton, GUILayout.Width(23), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) || isScrollingDown) { if (Selection.objects.Length != 0) { PeekLogic.AddToIndex(-1); } PeekLogic.ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex)); } #if UNITY_2018_3_OR_NEWER if (IsRightClickContext()) { return(true); } #endif bool isScrollingUp = ExtMouse.IsScrollingUp(Event.current, ref delta); StringBuilder nextTip = new StringBuilder(); nextTip.Append("Go to next selection ("); nextTip.Append(ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY)); nextTip.Append("+"); nextTip.Append(ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_NEXT_KEY)); nextTip.Append(")"); if ((GUILayout.Button(new GUIContent(NEXT_ICON, nextTip.ToString()), ExtGUIStyles.MicroButton, GUILayout.Width(23), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) || isScrollingUp) { PeekLogic.AddToIndex(1); PeekLogic.ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex)); } #if UNITY_2018_3_OR_NEWER if (IsRightClickContext()) { return(true); } #endif if (PeekSerializeObject.SelectedObjectsCount == 0) { GUIContent gUIContent = new GUIContent("-/-", "there is no previously selected objects"); GUILayout.Label(gUIContent); } else { string showCount = (PeekSerializeObject.CurrentIndex + 1).ToString() + "/" + (PeekSerializeObject.SelectedObjectsCount); GUIContent gUIContent = new GUIContent(showCount, "Scroll Up/Down to browse previous/next"); GUILayout.Label(gUIContent); } } EditorGUI.EndDisabledGroup(); } } GUILayout.FlexibleSpace(); return(false); }
/// <summary> /// draw a float field with a slider to move /// must be called in OnSceneGUI /// </summary> /// <param name="valueToModify"></param> /// <param name="min"></param> /// <param name="max"></param> /// <returns></returns> public static float FloatField(float valueToModify, UnityEngine.Object objToRecord, out bool valueHasChanged, string label = "", string toolTipText = "", float min = -9999, float max = 9999, bool createHorizontalScope = true, bool delayedFloatField = false, float defaultWidth = 40, params GUILayoutOption[] options) { float oldValue = valueToModify; if (objToRecord != null) { Undo.RecordObject(objToRecord, "record " + objToRecord.name + " editor GUI change"); } float newValue = valueToModify; if (createHorizontalScope) { using (HorizontalScope horizontalScopeSlider = new HorizontalScope(GUILayout.MaxWidth(50))) { newValue = FloatFieldWithSlider(valueToModify, label, toolTipText, min, max, delayedFloatField, defaultWidth, options); } } else { newValue = FloatFieldWithSlider(valueToModify, label, toolTipText, min, max, delayedFloatField, defaultWidth, options); } valueHasChanged = oldValue != newValue; if (valueHasChanged && Event.current.control /* && Event.current.button == 0 && Event.current.GetTypeForControl(GUIUtility.GetControlID(FocusType.Passive)) == EventType.MouseDown*/) { newValue = Round(newValue, 1); } /* * else if (valueHasChanged && Event.current.shift) * { * Debug.Log(Event.current); * * Debug.Log("shift"); * float diff = (oldValue - newValue) / 100; * newValue = oldValue - diff; * } */ else if (valueHasChanged && Event.current.alt) { float diff = (oldValue - newValue) * 100; newValue = oldValue - diff; } if (valueHasChanged && objToRecord != null) { EditorUtility.SetDirty(objToRecord); } return(newValue); }
public void OnGUI() { Event currentEvent = Event.current; EventType currentEventType = currentEvent.type; _view = BeginScrollView( _view, false, false, GUIStyle.none, GUI.skin.verticalScrollbar, GUI.skin.scrollView, GUILayout.Width(EditorGUIUtility.currentViewWidth), GUILayout.ExpandHeight(true)); if (currentEventType == EventType.DragUpdated) { // Indicate that we don't accept drags ourselves DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } using (var h = new HorizontalScope()) { _connectionString = TextField(_connectionString); if (GUILayout.Button("Connect")) { EditorPrefs.SetString("RethinkDB.URL", _connectionString); _queryStatus = RethinkConnection.RethinkConnect(_databaseCache, _connectionString); } } using (var h = new HorizontalScope()) { if (GUILayout.Button("Connect All")) { EditorPrefs.SetString("RethinkDB.URL", _connectionString); _queryStatus = RethinkConnection.RethinkConnect(_databaseCache, _connectionString, true, false); } if (GUILayout.Button("Save")) { _databaseCache.Save(new DirectoryInfo(Application.dataPath).Parent.FullName); } } using (new HorizontalScope()) { if (GUILayout.Button("Delete Orphaned Blueprints")) { int count = 0; foreach (var blueprintData in _databaseCache.GetAll <BlueprintData>().ToArray()) { if (_databaseCache.Get(blueprintData.Item) == null) { _databaseCache.Delete(blueprintData); count++; } } Debug.Log($"Deleted {count} orphaned blueprints!"); } } if (_queryStatus != null && _queryStatus.RetrievedItems < _queryStatus.GalaxyEntries + _queryStatus.ItemsEntries) { var progressRect = GetControlRect(false, 20); EditorGUI.ProgressBar(progressRect, (float)_queryStatus.RetrievedItems / (_queryStatus.GalaxyEntries + _queryStatus.ItemsEntries), "Sync Progress"); } // else // { // if(_itemBlueprints == null) // _itemBlueprints = _databaseCache.GetAll<ItemData>() // .Select(itemData => new {itemData, blueprints = _databaseCache.GetAll<BlueprintData>() // .Where(blueprintData => blueprintData.Item == itemData.ID) // .Select(bp => bp.ID) // .ToList()}) // .ToDictionary(x => x.itemData.ID, x => x.blueprints); // } GUILayout.Space(5); // if(GUILayout.Button("Log Cache Count")) // Debug.Log($"Cache contains {_databaseCache.AllEntries.Count()} elements"); using (var h = new HorizontalScope(ListItemStyle)) { _itemsFoldout = Foldout(_itemsFoldout, "Items", true); } if (_itemsFoldout) { var items = _databaseCache.AllEntries.Where(item => item is ItemData).Cast <ItemData>().ToArray(); for (var i = 0; i < _itemTypes.Length; i++) { using (var h = new HorizontalScope(ListItemStyle)) { GUILayout.Space(10); _itemTypeFoldouts[i] = Foldout(_itemTypeFoldouts[i], ((NameAttribute)_itemTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_itemTypes[i].Name), true); } if (_itemTypeFoldouts[i]) { var typedItems = items.Where(e => e.GetType() == _itemTypes[i]).OrderBy(item => item.Name); IEnumerable <IGrouping <string, ItemData> > itemGroups = new List <IGrouping <string, ItemData> >(); if (_itemTypes[i] == typeof(SimpleCommodityData)) { itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(SimpleCommodityCategory), (item as SimpleCommodityData).Category)); } else if (_itemTypes[i] == typeof(CompoundCommodityData)) { itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(CompoundCommodityCategory), (item as CompoundCommodityData).Category)); } else if (_itemTypes[i] == typeof(GearData)) { itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HardpointType), (item as GearData).Hardpoint)); } else if (_itemTypes[i] == typeof(HullData)) { itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HullType), (item as HullData).HullType)); } foreach (var itemGroup in itemGroups) { using (var h = new HorizontalScope(ListItemStyle)) { GUILayout.Space(20); if (Foldout(_itemGroupFoldouts.Contains(itemGroup.Key), FormatTypeName(itemGroup.Key), true)) { _itemGroupFoldouts.Add(itemGroup.Key); } else { _itemGroupFoldouts.Remove(itemGroup.Key); } } if (_itemGroupFoldouts.Contains(itemGroup.Key)) { foreach (var item in itemGroup) { var style = ListItemStyle; var selected = SelectedItem == item.ID; using (new HorizontalScope(selected?SelectedStyle:style)) { using (var h = new HorizontalScope()) { if (h.rect.Contains(currentEvent.mousePosition)) { if (currentEventType == EventType.MouseDrag) { DragAndDrop.PrepareStartDrag(); DragAndDrop.SetGenericData("Item", item.ID); DragAndDrop.StartDrag("Database Item"); } else if (currentEventType == EventType.MouseUp) { Select(item); } } GUILayout.Space(30); GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); } using (var h = new HorizontalScope(GUILayout.Width(15))) { if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) { if (_itemBlueprintFoldouts.Contains(item.ID)) { _itemBlueprintFoldouts.Remove(item.ID); } else { _itemBlueprintFoldouts.Add(item.ID); } } GUILayout.Label(_itemBlueprints[item.ID].Count.ToString()); var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); if (Event.current.type == EventType.Repaint) { var controlId = GUIUtility.GetControlID(1337, FocusType.Keyboard, position); EditorStyles.foldout.Draw(rect, GUIContent.none, controlId, _itemBlueprintFoldouts.Contains(item.ID)); } } } if (_itemBlueprintFoldouts.Contains(item.ID)) { foreach (var blueprintData in _itemBlueprints[item.ID] .Select(id => _databaseCache.Get <BlueprintData>(id)) .OrderBy(bp => bp.Quality)) { var blueprintStyle = ListItemStyle; var blueprintSelected = SelectedItem == blueprintData.ID; using (var h = new HorizontalScope(blueprintSelected ? SelectedStyle : blueprintStyle)) { if (h.rect.Contains(currentEvent.mousePosition)) { if (currentEventType == EventType.MouseDrag) { DragAndDrop.PrepareStartDrag(); DragAndDrop.SetGenericData("Item", blueprintData.ID); DragAndDrop.StartDrag("Database Item"); } else if (currentEventType == EventType.MouseUp) { Select(blueprintData); } } GUILayout.Space(40); GUILayout.Label(blueprintData.Name, blueprintSelected ? EditorStyles.whiteLabel : GUI.skin.label); } } using (var h = new HorizontalScope(ListItemStyle)) { if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) { var blueprint = new BlueprintData { Item = item.ID, Name = item.Name }; _databaseCache.Add(blueprint); Select(blueprint); } GUILayout.Space(40); GUILayout.Label("New Blueprint"); var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); } } } using (var h = new HorizontalScope(ListItemStyle)) { if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) { CreateItem(_itemTypes[i], newItem => { if (newItem is SimpleCommodityData simpleCommodityData) { simpleCommodityData.Category = (SimpleCommodityCategory)Enum.Parse(typeof(SimpleCommodityCategory), itemGroup.Key); simpleCommodityData.Name = $"New {itemGroup.Key}"; } else if (newItem is CompoundCommodityData compoundCommodityData) { compoundCommodityData.Category = (CompoundCommodityCategory)Enum.Parse( typeof(CompoundCommodityCategory), itemGroup.Key); compoundCommodityData.Name = $"New {itemGroup.Key}"; } else if (newItem is GearData gearData) { gearData.Hardpoint = (HardpointType)Enum.Parse(typeof(HardpointType), itemGroup.Key); gearData.Name = $"New {itemGroup.Key}"; } else if (newItem is HullData hullData) { hullData.HullType = (HullType)Enum.Parse(typeof(HullType), itemGroup.Key); hullData.Name = $"New {itemGroup.Key}"; } }); } GUILayout.Space(30); GUILayout.Label("New " + itemGroup.Key); var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); } } } if (!itemGroups.Any()) { using (var h = new HorizontalScope(ListItemStyle)) { if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) { CreateItem(_itemTypes[i]); } GUILayout.Space(20); GUILayout.Label("New " + _itemTypes[i].Name); var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); } } } } } var entries = _databaseCache.AllEntries.Where(item => !(item is ItemData)).ToArray(); for (var i = 0; i < _entryTypes.Length; i++) { using (var h = new HorizontalScope(ListItemStyle)) { _entryFoldouts[i] = Foldout(_entryFoldouts[i], ((NameAttribute)_entryTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_entryTypes[i].Name), true); } if (_entryFoldouts[i]) { int index = 0; foreach (var entry in entries.Where(e => e.GetType() == _entryTypes[i]).OrderBy(entry => entry is INamedEntry namedEntry ? namedEntry.EntryName : entry.ID.ToString())) { index++; var style = ListItemStyle; var selected = SelectedItem == entry.ID; using (var h = new HorizontalScope(selected?SelectedStyle:style)) { if (h.rect.Contains(currentEvent.mousePosition)) { if (currentEventType == EventType.MouseDrag) { DragAndDrop.PrepareStartDrag(); DragAndDrop.SetGenericData("Item", entry.ID); DragAndDrop.StartDrag("Database Item"); } else if (currentEventType == EventType.MouseUp) { Select(entry); } } GUILayout.Space(10); GUILayout.Label((entry as INamedEntry)?.EntryName ?? index.ToString(), selected ? EditorStyles.whiteLabel : GUI.skin.label); } } using (var h = new HorizontalScope(ListItemStyle)) { if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) { CreateItem(_entryTypes[i]); } GUILayout.Space(10); GUILayout.Label("New " + _entryTypes[i].Name); var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); } } } EndScrollView(); }
private void DisplayOneItem(Object toDisplay, string nameInListPath, int index, float width, bool disable) { if (toDisplay == null && string.IsNullOrEmpty(nameInListPath)) { return; } if (toDisplay == null && !UnityEssentialsPreferences.GetBool(UnityEssentialsPreferences.SHOW_GAMEOBJECTS_FROM_OTHER_SCENE, true)) { return; } GUI.color = (PeekSerializeObject.LastSelectedObject == toDisplay && toDisplay != null) ? Color.green : Color.white; EditorGUI.BeginDisabledGroup(disable); { using (HorizontalScope horizontalScope = new HorizontalScope(GUILayout.Width(width), GUILayout.Height(_heightLine))) { float widthExtent = CalculateWidthExtentOptions.CalculateWidthExtent(width, index, ListToDisplay.arraySize); float widthButtonWithoutExtent = CalculateWidthExtentOptions.CalculateButtonWidthWithoutExtent(widthExtent, _heightLine, _margin); if (_calculateExtent) { GUILayout.Label("", GUILayout.Width(widthExtent), GUILayout.Height(_heightLine)); } //display bookmark button bool clicOnBookMark = BookMarkButtonOptions.ButtonImageWithHover(WIDTH_BUTTON_HOVER, toDisplay != null, _heightLine); if (clicOnBookMark) { OnBookMarkClic?.Invoke(index); return; } //display main logo DisplayLogoByTypeOfObject(toDisplay, _heightLine); if (!disable && !_dragSettings.IsDragging) { Rect logoContent = GUILayoutUtility.GetLastRect(); if (logoContent.Contains(Event.current.mousePosition)) { EditorGUIUtility.AddCursorRect(logoContent, MouseCursor.MoveArrow); if (Event.current.type == EventType.MouseDown) { _listToDisplayCopy = ListToDisplay.ToObjectList(); _dragSettings.StartDragging(index, logoContent); Event.current.Use(); } } } //display main button EditorGUI.BeginDisabledGroup(toDisplay == null); { string nameObjectToSelect; if (toDisplay == null) { nameObjectToSelect = !string.IsNullOrEmpty(nameInListPath) ? ObjectNames.NicifyVariableName(nameInListPath) : " --- not found --- "; } else { nameObjectToSelect = ObjectNames.NicifyVariableName(toDisplay.name); } GUIContent buttonSelectContent = ShortenNameIfNeeded(nameObjectToSelect, width, widthButtonWithoutExtent); buttonSelectContent.tooltip = "Clic to select, Right clic to Pin only"; if (GUILayout.Button(buttonSelectContent, BookMarkButtonOptions.GuiStyle, GUILayout.ExpandWidth(true), GUILayout.Height(_heightLine))) { if (Event.current.button == 0) { OnSelectItem?.Invoke(index); } else { OnPinItem?.Invoke(index); } return; } } EditorGUI.EndDisabledGroup(); //display special scene buttons if (toDisplay == null && OnInfoItem != null) { bool selectScene = false; bool goToScene = false; DisplaySpecialSceneSettings(ref selectScene, ref goToScene); if (goToScene) { OnInfoForceItem?.Invoke(index); return; } else if (selectScene) { OnInfoItem?.Invoke(index); return; } } //display delete button GUIContent buttonDeletContent = EditorGUIUtility.IconContent(DELETE_ICON); buttonDeletContent.tooltip = "Remove from list"; if (GUILayout.Button(buttonDeletContent, BookMarkButtonOptions.GuiStyle, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(WIDTH_BUTTON_HOVER), GUILayout.Height(_heightLine)) && Event.current.button == 0) { OnRemoveItem?.Invoke(index); return; } if (_calculateExtent) { GUILayout.Label("", GUILayout.Width(widthExtent), GUILayout.Height(_heightLine)); } } } EditorGUI.EndDisabledGroup(); }