Add assets

This commit is contained in:
2025-05-08 16:03:30 +09:00
parent cd4ebdb0a7
commit 57b037e0a9
977 changed files with 91747 additions and 28 deletions

View File

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Cainos.LucidEditor.Experimental
{
internal class SimpleTreeView : TreeView
{
private TreeMenuItem[] baseElements;
public Action<Rect, int> drawItemCallback;
public Func<int, float> itemHeightCallback;
public event Action<IList<int>> onSelectionChanged;
public SimpleTreeView(TreeViewState treeViewState) : base(treeViewState) { }
public void Setup(TreeMenuItem[] baseElements)
{
this.baseElements = baseElements;
Reload();
}
protected override TreeViewItem BuildRoot()
{
return new TreeViewItem { id = -1, depth = -1, displayName = "Root" };
}
protected override void RowGUI(RowGUIArgs args)
{
if (drawItemCallback != null)
{
Rect contentRect = args.rowRect;
contentRect.width -= GetContentIndent(args.item);
contentRect.x += GetContentIndent(args.item);
drawItemCallback.Invoke(contentRect, args.item.id);
}
else
{
base.RowGUI(args);
}
}
protected override float GetCustomRowHeight(int row, TreeViewItem item)
{
if (itemHeightCallback != null)
{
return itemHeightCallback.Invoke(item.id);
}
return base.GetCustomRowHeight(row, item);
}
protected override IList<TreeViewItem> BuildRows(TreeViewItem root)
{
var rows = GetRows() ?? new List<TreeViewItem>();
rows.Clear();
foreach (var baseElement in baseElements)
{
var baseItem = CreateTreeViewItem(baseElement);
root.AddChild(baseItem);
rows.Add(baseItem);
if (baseElement.childElements.Count > 0)
{
if (IsExpanded(baseItem.id))
{
AddChildrenRecursive(baseElement, baseItem, rows);
}
else
{
baseItem.children = CreateChildListForCollapsedParent();
}
}
}
SetupDepthsFromParentsAndChildren(root);
return rows;
}
protected override void SelectionChanged(IList<int> selectedIds)
{
onSelectionChanged?.Invoke(selectedIds);
}
private void AddChildrenRecursive(TreeMenuItem model, TreeViewItem item, IList<TreeViewItem> rows)
{
foreach (var childElement in model.childElements)
{
var childItem = CreateTreeViewItem(childElement);
item.AddChild(childItem);
rows.Add(childItem);
if (childElement.childElements.Count > 0)
{
if (IsExpanded(childElement.id))
{
AddChildrenRecursive(childElement, childItem, rows);
}
else
{
childItem.children = CreateChildListForCollapsedParent();
}
}
}
}
private TreeViewItem CreateTreeViewItem(TreeMenuItem model)
{
return new TreeViewItem { id = model.id, displayName = model.name };
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6808df22776e34bc9bdf425dc8012a27
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
using System;
using UnityEngine;
using UnityEditor;
namespace Cainos.LucidEditor.Experimental
{
public class TextFieldPopup : PopupWindowContent
{
public string text;
public Action<string> onValueChanged;
public Action onSubmit;
public Action onCancel;
private bool submit;
private bool initialized;
private bool didFocus = false;
private Rect size;
public void Show(Rect position)
{
size = position;
size.height = EditorGUIUtility.singleLineHeight;
PopupWindow.Show(position, this);
}
public override void OnGUI(Rect rect)
{
if (!initialized)
{
initialized = true;
onValueChanged?.Invoke(text);
}
if (LucidGUIEvent.GetKeyDown(KeyCode.Return))
{
submit = true;
editorWindow.Close();
}
string textFieldName = $"{GetType().Name}:{nameof(text)}";
using (var scope = new EditorGUI.ChangeCheckScope())
{
GUI.SetNextControlName(textFieldName);
Rect fieldRect = EditorGUILayout.GetControlRect();
fieldRect.xMin -= 2.7f;
fieldRect.xMax += 2.7f;
fieldRect.yMin -= 2.7f;
fieldRect.yMax += 2.7f;
text = EditorGUI.TextField(fieldRect, text);
if (scope.changed)
{
onValueChanged?.Invoke(text);
}
}
if (!didFocus)
{
GUI.FocusControl(textFieldName);
didFocus = true;
}
}
public override Vector2 GetWindowSize()
{
return new Vector2(size.width, EditorGUIUtility.singleLineHeight);
}
public override void OnClose()
{
base.OnClose();
if (submit) onSubmit?.Invoke();
else onCancel?.Invoke();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c25190bd6c58843cc9794694a38a740e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
using System.Collections.Generic;
using UnityEngine;
namespace Cainos.LucidEditor.Experimental
{
public sealed class Toolbar
{
private List<GUIContent> _items = new List<GUIContent>();
public IReadOnlyList<GUIContent> items => _items;
public int selected;
public GUIStyle style = null;
public GUI.ToolbarButtonSize size = GUI.ToolbarButtonSize.FitToContents;
public void AddItem(string item)
{
_items.Add(new GUIContent(item));
}
public void AddItem(GUIContent item)
{
_items.Add(item);
}
public bool RemoveItem(string item)
{
return _items.RemoveAll(x => x.text == item) > 0;
}
public bool RemoveItem(GUIContent item)
{
return _items.Remove(item);
}
public void Clear()
{
_items.Clear();
}
public int Show(Rect rect)
{
return Show(rect, selected);
}
private int Show(Rect rect, int selected)
{
this.selected = GUI.Toolbar(rect, selected, _items.ToArray(), style == null ? GUI.skin.button : style, size);
return this.selected;
}
public int ShowLayout(params GUILayoutOption[] options)
{
return ShowLayout(selected, options);
}
private int ShowLayout(int selected, params GUILayoutOption[] options)
{
this.selected = GUILayout.Toolbar(selected, _items.ToArray(), style == null ? GUI.skin.button : style, size, options);
return this.selected;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d113573c2d819423b815b8fbc1c07a21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,212 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
namespace Cainos.LucidEditor.Experimental
{
public class TreeMenu
{
private List<TreeMenuItem> baseElements = new List<TreeMenuItem>();
private SimpleTreeView simpleTreeView;
private TreeViewState state;
private int currentId = 0;
private List<TreeMenuItem> _selectedItems = new List<TreeMenuItem>();
public IReadOnlyList<TreeMenuItem> selectedItems => Array.AsReadOnly(_selectedItems.ToArray());
public event Action<IReadOnlyList<TreeMenuItem>> onSelectionChanged;
public Action<Rect, TreeMenuItem> drawItemCallback;
public Func<TreeMenuItem, float> itemHeightCallback;
public string searchString
{
get
{
return _searchString;
}
set
{
_searchString = value;
if (simpleTreeView != null) simpleTreeView.searchString = _searchString;
}
}
private string _searchString;
public void AddItem(string path)
{
string[] hierarchy = path.Split('/');
string currentPath = string.Empty;
TreeMenuItem parent = null;
for (int i = 0; i < hierarchy.Length; i++)
{
currentPath += hierarchy[i];
if (parent == null)
{
parent = baseElements.Find(x => x.name == hierarchy[i]);
if (parent == null)
{
parent = CreateItem(currentPath);
baseElements.Add(parent);
}
}
else
{
TreeMenuItem newParent = null;
foreach (TreeMenuItem child in parent.childElements)
{
if (child.name == hierarchy[i])
{
newParent = child;
parent = child;
break;
}
}
if (newParent == null)
{
newParent = CreateItem(currentPath);
parent.Add(newParent);
parent = newParent;
}
}
currentPath += '/';
}
}
private TreeMenuItem CreateItem(string path)
{
TreeMenuItem item = new TreeMenuItem(path);
item.id = currentId;
currentId++;
return item;
}
public void Show(Rect position)
{
if (simpleTreeView == null) Setup();
simpleTreeView.OnGUI(position);
}
public void ShowLayout(params GUILayoutOption[] options)
{
if (simpleTreeView == null) Setup();
simpleTreeView.OnGUI(EditorGUILayout.GetControlRect(false, simpleTreeView.totalHeight, options));
}
public void Setup()
{
state = new TreeViewState();
simpleTreeView = new SimpleTreeView(state);
simpleTreeView.searchString = _searchString;
simpleTreeView.Setup(baseElements.ToArray());
simpleTreeView.onSelectionChanged += (idList) =>
{
_selectedItems.Clear();
foreach (int id in idList)
{
TreeMenuItem item = FindItem(id);
if (item != null) _selectedItems.Add(item);
}
onSelectionChanged?.Invoke(_selectedItems);
};
if (drawItemCallback != null)
{
simpleTreeView.drawItemCallback = (rect, id) =>
{
drawItemCallback.Invoke(rect, FindItem(id));
};
}
if (itemHeightCallback != null)
{
simpleTreeView.itemHeightCallback = (id) =>
{
return itemHeightCallback.Invoke(FindItem(id));
};
}
}
private TreeMenuItem FindItem(int id)
{
TreeMenuItem item = null;
foreach(TreeMenuItem child in baseElements)
{
item = FindItem(child, id);
if (item != null) return item;
}
return null;
}
private TreeMenuItem FindItem(TreeMenuItem root, int id)
{
if (root.id == id) return root;
TreeMenuItem item = null;
foreach (TreeMenuItem child in root.childElements)
{
item = FindItem(child, id);
if (item != null) return item;
}
return null;
}
}
public class TreeMenuItem
{
public TreeMenuItem(string path)
{
this.path = path;
depth = path.Count(x => x == '/');
_name = path.Split('/').Last();
}
public readonly string path;
public readonly int depth;
internal int id;
public string name
{
get
{
return _name;
}
}
private string _name;
public TreeMenuItem parent { get; private set; }
private List<TreeMenuItem> _childElements = new List<TreeMenuItem>();
public IReadOnlyList<TreeMenuItem> childElements => _childElements;
public void Add(TreeMenuItem child)
{
if (child.parent != null)
{
child.parent.Remove(child);
}
_childElements.Add(child);
child.parent = this;
}
public bool Remove(TreeMenuItem child)
{
if (_childElements.Contains(child))
{
_childElements.Remove(child);
child.parent = null;
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8763dd98783e24b7d9684eec2742d817
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: