init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCoreCommon.Helpers.Editor.UIElements
|
||||
{
|
||||
[UxmlElement]
|
||||
public partial class FakeObjectField : VisualElement
|
||||
{
|
||||
private Image _objectImage;
|
||||
private Label _objectLabel;
|
||||
|
||||
public FakeObjectField() : this(null) { }
|
||||
|
||||
public FakeObjectField(string labelText = "")
|
||||
{
|
||||
var field = new VisualElement();
|
||||
field.AddToClassList("unity-object-field");
|
||||
field.AddToClassList("unity-base-field");
|
||||
field.AddToClassList("unity-base-field__aligned");
|
||||
field.style.marginLeft = field.style.marginRight = 3;
|
||||
|
||||
if (!string.IsNullOrEmpty(labelText))
|
||||
{
|
||||
var label = new Label(labelText);
|
||||
label.AddToClassList("unity-label");
|
||||
label.AddToClassList("unity-base-field__label");
|
||||
field.Add(label);
|
||||
}
|
||||
|
||||
var fieldInput = new VisualElement();
|
||||
fieldInput.AddToClassList("unity-base-field__input");
|
||||
fieldInput.AddToClassList("unity-object-field__input");
|
||||
field.Add(fieldInput);
|
||||
|
||||
var fieldObject = new VisualElement();
|
||||
fieldObject.AddToClassList("unity-object-field__object");
|
||||
fieldInput.Add(fieldObject);
|
||||
|
||||
_objectImage = new Image();
|
||||
_objectImage.AddToClassList("unity-object-field-display__icon");
|
||||
fieldObject.Add(_objectImage);
|
||||
|
||||
_objectLabel = new Label();
|
||||
_objectLabel.AddToClassList("unity-object-field-display__label");
|
||||
fieldObject.Add(_objectLabel);
|
||||
|
||||
var fieldSelector = new VisualElement();
|
||||
fieldSelector.AddToClassList("unity-object-field__selector");
|
||||
fieldInput.Add(fieldSelector);
|
||||
|
||||
Add(field);
|
||||
}
|
||||
|
||||
public void Set(string text, Texture image)
|
||||
{
|
||||
_objectLabel.text = text;
|
||||
_objectImage.image = image;
|
||||
}
|
||||
|
||||
public void Unset()
|
||||
{
|
||||
_objectLabel.text = null;
|
||||
_objectImage.image = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42c0552c878947b394d70f8745d0ec3b
|
||||
timeCreated: 1762538499
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCoreCommon.Helpers.Editor.UIElements
|
||||
{
|
||||
[UxmlElement]
|
||||
public partial class InspectorElement : UnityEditor.UIElements.InspectorElement
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a2d499847854192a17c936d66e234b7
|
||||
timeCreated: 1761410271
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCoreCommon.Helpers.Editor.UIElements
|
||||
{
|
||||
public class SearchFieldPopup : PopupWindowContent
|
||||
{
|
||||
// Elements
|
||||
private VisualElement _root;
|
||||
private ToolbarSearchField _searchField;
|
||||
private ScrollView _scrollView;
|
||||
|
||||
// Runtime
|
||||
private VisualElement _boundTo;
|
||||
private Dictionary<string, Action> _menuItems;
|
||||
|
||||
public SearchFieldPopup(VisualElement boundTo, Dictionary<string, Action> menuItems)
|
||||
{
|
||||
_boundTo = boundTo;
|
||||
_menuItems = menuItems;
|
||||
}
|
||||
|
||||
public override VisualElement CreateGUI()
|
||||
{
|
||||
_root = new VisualElement();
|
||||
_root.style.maxHeight = 500;
|
||||
_root.style.maxWidth = _boundTo.worldBound.width;
|
||||
|
||||
_searchField = new ToolbarSearchField();
|
||||
_searchField.style.left = _searchField.style.right = 0;
|
||||
_searchField.style.width = StyleKeyword.Auto;
|
||||
|
||||
_root.Add(_searchField);
|
||||
|
||||
_scrollView = new ScrollView();
|
||||
_root.Add(_scrollView);
|
||||
|
||||
// Show all options
|
||||
_menuItems.DictSelect((name, action) => new Button(() =>
|
||||
{
|
||||
action();
|
||||
Close();
|
||||
}) { text = name }).ForEach(_scrollView.Add);
|
||||
|
||||
// Do auto focus when appear
|
||||
_root.RegisterCallback<AttachToPanelEvent>(_ => _searchField.Focus());
|
||||
|
||||
// ESC - close
|
||||
// ENTER - select first visible
|
||||
_root.RegisterCallback<KeyDownEvent>(ev =>
|
||||
{
|
||||
if (ev.keyCode == KeyCode.Escape) Close();
|
||||
if (ev.keyCode == KeyCode.Return) _scrollView.Query<Button>().Visible().First().Click();
|
||||
}, TrickleDown.TrickleDown);
|
||||
|
||||
return _root;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
UnityEditor.PopupWindow.Show(_boundTo.worldBound, this);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
editorWindow.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: adea6e28eb7a41d691381ba9405fdb74
|
||||
timeCreated: 1762522548
|
||||
Reference in New Issue
Block a user