protected override ItemSlot DrawElement(Rect rect, ItemSlot value) { var id = DragAndDropUtilities.GetDragAndDropId(rect); DragAndDropUtilities.DrawDropZone(rect, value.item ? value.item.icon : null, null, id); // Draws the drop-zone using the items icon. if (value.item != null) { if (value.item.stackSize > 1) { // Item count var countRect = rect.Padding(2).AlignBottom(16); value.itemCount = EditorGUI.IntField(countRect, Mathf.Max(1, value.itemCount)); if (value.itemCount > value.item.stackSize) { value.itemCount = value.item.stackSize; } GUI.Label(countRect, "/ " + value.item.stackSize, SirenixGUIStyles.RightAlignedGreyMiniLabel); } } value = DragAndDropUtilities.DropZone(rect, value); // Drop zone for ItemSlot structs. value.item = DragAndDropUtilities.DropZone <Item>(rect, value.item); // Drop zone for Item types. value = DragAndDropUtilities.DragZone(rect, value, true, true); // Enables dragging of the ItemSlot return(value); }
protected override void DrawPropertyLayout(GUIContent label) { base.DrawPropertyLayout(label); // Draws a drop-zone where we can destroy items. var rect = GUILayoutUtility.GetRect(0, 40).Padding(2); var id = DragAndDropUtilities.GetDragAndDropId(rect); DragAndDropUtilities.DrawDropZone(rect, null as UnityEngine.Object, null, id); DragAndDropUtilities.DropZone <ItemSlot>(rect, new ItemSlot(), false, id); }
private void AddDragHandles(OdinMenuItem menuItem) { menuItem.OnDrawItem += x => DragAndDropUtilities.DragZone(menuItem.Rect, menuItem.Value, false, false); }
protected override void OnGUI() { _repaintSheduled = false; GUILayout.BeginHorizontal(); if (GUILayout.Button("Clear")) { _properties.Clear(); } Rect settingsRect = GUILayoutUtility.GetRect(24, 24, GUILayout.ExpandWidth(false)).AlignLeft(20).AlignCenterY(20); if (SirenixEditorGUI.IconButton(settingsRect, _showSettings ? EditorIcons.SettingsCog.Inactive : EditorIcons.SettingsCog.Active, "Settings")) { _showSettings = !_showSettings; } GUILayout.EndHorizontal(); if (_showSettings) { GUILayout.BeginHorizontal(); GUILayout.Space(40); GUI.changed = false; Rect rect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true)); _labelWidth = GUI.HorizontalSlider(rect, _labelWidth, rect.xMin, rect.xMax); if (GUI.changed) { EditorPrefs.SetFloat("OWW_labelWidth", _labelWidth); } EditorGUILayout.LabelField("Label Width", GUILayout.Width(70)); GUILayout.EndHorizontal(); } GUILayout.Space(5); bool first = true; if (_properties.Count == 0) { EditorGUILayout.LabelField("Right-click any property in an Inspector and select 'Watch' to make it show up here.", SirenixGUIStyles.MultiLineCenteredLabel); } GUIHelper.PushLabelWidth(_labelWidth - 30); for (int i = 0; i < _properties.Count; i++) { TreeValuesHolder holder = _properties[i]; holder.CheckRefresh(); if (!first) { GUILayout.Space(5); } first = false; Rect titleRect = SirenixEditorGUI.BeginBox(" " + holder.Tree.TargetType.Name); titleRect = titleRect.AlignTop(21); if (holder.ParentObject != null) { Rect alignRight = titleRect.AlignRight(200).AlignCenterY(16).AlignLeft(180); GUIHelper.PushGUIEnabled(false); SirenixEditorFields.UnityObjectField(alignRight, holder.ParentObject, typeof(GameObject), true); GUIHelper.PopGUIEnabled(); } if (SirenixEditorGUI.IconButton(titleRect.AlignRight(20).AlignCenterY(18), EditorIcons.X)) { _properties.RemoveAt(i--); } Rect titleDragDropRect = titleRect.AlignLeft(30).AlignCenter(20, 20); EditorIcons.List.Draw(titleDragDropRect); TreeValuesHolder treedragdrop = (TreeValuesHolder)DragAndDropUtilities.DragAndDropZone(titleDragDropRect, holder, typeof(TreeValuesHolder), false, false); if (treedragdrop != holder) { int treeDragDropIndex = _properties.IndexOf(treedragdrop); Swap(_properties, treeDragDropIndex, i); } if (holder.Tree.UnitySerializedObject?.targetObject == null) { EditorGUILayout.LabelField($"This component is no longer valid in the current context (loaded different scene?)", SirenixGUIStyles.MultiLineLabel); } else { InspectorUtilities.BeginDrawPropertyTree(holder.Tree, true); for (int index = 0; index < holder.ValuePaths.Count; index++) { string path = holder.ValuePaths[index]; GUILayout.BeginHorizontal(); Rect rect1 = GUILayoutUtility.GetRect(EditorGUIUtility.singleLineHeight + 5, EditorGUIUtility.singleLineHeight + 3, GUILayout.ExpandWidth(false)).AlignRight(EditorGUIUtility.singleLineHeight + 2); EditorIcons.List.Draw(rect1); ValueDragDropHolder dragdrop = (ValueDragDropHolder)DragAndDropUtilities.DragAndDropZone(rect1, new ValueDragDropHolder(holder, index), typeof(ValueDragDropHolder), false, false); if (dragdrop.TreeValuesHolder == holder && dragdrop.Index != index) { string ptemp = holder.ValuePaths[index]; holder.ValuePaths[index] = holder.ValuePaths[dragdrop.Index]; holder.ValuePaths[dragdrop.Index] = ptemp; } InspectorProperty propertyAtPath = holder.Tree.GetPropertyAtPath(path); if (propertyAtPath == null) { propertyAtPath = holder.Tree.GetPropertyAtUnityPath(path); } if (propertyAtPath != null) { propertyAtPath.Draw(); } else { EditorGUILayout.LabelField($"Could not find property ({path})"); } if (SirenixEditorGUI.IconButton(EditorIcons.X)) { holder.ValuePaths.RemoveAt(index--); if (holder.ValuePaths.Count == 0) { _properties.RemoveAt(i--); } } GUILayout.Space(3); GUILayout.EndHorizontal(); } InspectorUtilities.EndDrawPropertyTree(holder.Tree); } SirenixEditorGUI.EndBox(); } GUIHelper.PopLabelWidth(); }