1
This commit is contained in:
@@ -23,6 +23,7 @@ namespace BITKit.GameEditor
|
||||
|
||||
private void Rebuild()
|
||||
{
|
||||
rootVisualElement.Clear();
|
||||
var obj =AssetDatabase.LoadAssetAtPath<AssetCacheScriptableObject>("Assets/Artists/Configs/Asset Cache.asset");
|
||||
if (obj is null)
|
||||
{
|
||||
@@ -32,34 +33,41 @@ namespace BITKit.GameEditor
|
||||
//button.clicked += Rebuild;
|
||||
return;
|
||||
}
|
||||
|
||||
rootVisualElement.Bind(new SerializedObject(obj));
|
||||
//BITInspectorExtensions.FillDefaultInspector(rootVisualElement,new SerializedObject(obj),true);
|
||||
|
||||
var toggle = rootVisualElement.Create<Toggle>();
|
||||
toggle.bindingPath = "isEditable";
|
||||
toggle.label = "Edit";
|
||||
// toggle.RegisterValueChangedCallback(_ =>
|
||||
// {
|
||||
// Rebuild();
|
||||
// });
|
||||
var rebuildButton = rootVisualElement.Create<Button>();
|
||||
rebuildButton.text = "Rebuild";
|
||||
rebuildButton.clicked += Rebuild;
|
||||
|
||||
var scroll = rootVisualElement.Create<ScrollView>();
|
||||
scroll.style.flexGrow = 1;
|
||||
|
||||
if (obj.IsEditable)
|
||||
{
|
||||
BITInspectorExtensions.FillDefaultInspector(rootVisualElement,new SerializedObject(obj),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var defaultList = scroll.Create<Foldout>();
|
||||
defaultList.text = "Default";
|
||||
foreach (var x in obj.Assets)
|
||||
{
|
||||
var field = scroll.Create<ObjectField>();
|
||||
var field = defaultList.Create<ObjectField>();
|
||||
//field.label = x.name;
|
||||
field.style.opacity = 1;
|
||||
field.value = x;
|
||||
field.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var folder in obj.Folders)
|
||||
{
|
||||
var foldout = scroll.Create<Foldout>();
|
||||
foldout.text = folder.Key;
|
||||
foreach (var x in folder.Value)
|
||||
{
|
||||
var field = foldout.Create<ObjectField>();
|
||||
//field.label = x.name;
|
||||
field.style.opacity = 1;
|
||||
field.value = x;
|
||||
field.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
@@ -11,40 +12,9 @@ namespace BITKit.GameEditor
|
||||
{
|
||||
public class AssetCacheScriptableObject : ScriptableObject
|
||||
{
|
||||
[SerializeField] private bool isEditable;
|
||||
[SerializeField] private Object[] _assets;
|
||||
|
||||
public bool IsEditable => isEditable;
|
||||
[SerializeField] private SerializedDictionary<string, Object[]> folders;
|
||||
public Object[] Assets => _assets;
|
||||
public Dictionary<string, Object[]> Folders=>folders;
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(AssetCacheScriptableObject))]
|
||||
public class AssetCacheScriptableObjectEditor : BITInspector<AssetCacheScriptableObject>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
root.root.Clear();
|
||||
if (agent.IsEditable)
|
||||
{
|
||||
return base.CreateInspectorGUI();
|
||||
}
|
||||
|
||||
var toggle = root.Create<Toggle>();
|
||||
toggle.bindingPath = "isEditable";
|
||||
toggle.label = "Edit";
|
||||
|
||||
toggle.RegisterValueChangedCallback(x => CreateInspectorGUI());
|
||||
|
||||
foreach (var x in agent.Assets)
|
||||
{
|
||||
var field = root.Create<ObjectField>();
|
||||
//field.label = x.name;
|
||||
field.style.opacity = 1;
|
||||
field.value = x;
|
||||
field.SetEnabled(false);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"GUID:4988cf9794f41d64c884876ab6574b89",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:e6234d6c1f7bf4e4db20eddc411c00b8",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -70,7 +70,7 @@ namespace BITKit.GameEditor
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ namespace BITKit.Scene
|
||||
[SerializeField] private float size;
|
||||
|
||||
[SerializeField] private Optional<Vector3> bounds;
|
||||
private void OnDrawGizmos()
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (draw is false || AllowGizmos is false) return;
|
||||
var position = transform.position;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BITKit.UX;
|
||||
using UnityEditor;
|
||||
@@ -11,52 +12,86 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit.GameEditor
|
||||
{
|
||||
public class ScriptableObjectGroupEditor<T> : EditorWindow where T : Object
|
||||
public class ScriptableObjectGroupEditor<T> : EditorWindow where T : ScriptableObject
|
||||
{
|
||||
protected virtual string AssetsPath => $"Assets/Artists/";
|
||||
protected readonly List<T> List=new();
|
||||
|
||||
private ListView _listView;
|
||||
private VisualElement _container;
|
||||
protected VisualElement _container { get; private set; }
|
||||
private Button _createButton;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var paths = AssetDatabase.FindAssets($"t:{typeof(T).Name}");
|
||||
var allItem =
|
||||
(
|
||||
from path in paths.Select(AssetDatabase.GUIDToAssetPath)
|
||||
select AssetDatabase.LoadAssetAtPath<ScriptableObject>(path)
|
||||
).ToArray();
|
||||
List.AddRange(allItem.Cast<T>());
|
||||
|
||||
var container = rootVisualElement.Create<VisualElement>();
|
||||
RebuildList();
|
||||
|
||||
rootVisualElement.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
var css = AssetDatabase.LoadAssetAtPath<StyleSheet>(BITEditorUtils.InspectorPath);
|
||||
|
||||
rootVisualElement.styleSheets.Add(css);
|
||||
|
||||
rootVisualElement.styleSheets.Add(css);
|
||||
|
||||
var leftSlider = rootVisualElement.Create<VisualElement>();
|
||||
leftSlider.name = "LeftSlider";
|
||||
|
||||
container.style.flexDirection = FlexDirection.Row;
|
||||
var toolbarContainer = leftSlider.Create<VisualElement>();
|
||||
toolbarContainer.style.alignSelf = Align.Auto;
|
||||
toolbarContainer.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
var refreshButton = toolbarContainer.Create<Button>();
|
||||
refreshButton.text = "刷新";
|
||||
refreshButton.clicked += () =>
|
||||
{
|
||||
RebuildList();
|
||||
_listView.Rebuild();
|
||||
};
|
||||
var container = leftSlider.Create<VisualElement>();
|
||||
|
||||
var listViewContainer = container.Create<VisualElement>();
|
||||
|
||||
listViewContainer.style.flexDirection = FlexDirection.Column;
|
||||
var createContainer = listViewContainer.Create<VisualElement>();
|
||||
|
||||
listViewContainer.Create<Label>().text = $"{typeof(T).Name},数量:{List.Count}";
|
||||
createContainer.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
var nameField = createContainer.Create<TextField>();
|
||||
nameField.style.flexGrow = 1;
|
||||
|
||||
_createButton=createContainer.Create<Button>();
|
||||
_createButton.text = "创建";
|
||||
_createButton.clicked += () => CreateScriptableObject(nameField.value);
|
||||
|
||||
|
||||
container.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
listViewContainer.style.flexDirection = FlexDirection.Column;
|
||||
listViewContainer.style.flexGrow = 1;
|
||||
|
||||
listViewContainer.Create<Label>().text = $"获取到:{List.Count}个配置";
|
||||
listViewContainer.AddToClassList("pa-8");
|
||||
|
||||
_listView = listViewContainer.Create<ListView>();
|
||||
_listView = leftSlider.Create<ListView>();
|
||||
_listView.makeItem = MakeItem;
|
||||
_listView.bindItem = BindItem;
|
||||
_listView.itemsChosen += ItemsChosen;
|
||||
_listView.style.minWidth = 128;
|
||||
_listView.style.flexGrow = 1;
|
||||
|
||||
_listView.itemsSource = List;
|
||||
|
||||
var scroll = container.Create<ScrollView>();
|
||||
|
||||
var scroll = rootVisualElement.Create<ScrollView>();
|
||||
scroll.name = "Scroll";
|
||||
scroll.style.flexGrow = 1;
|
||||
|
||||
_container = scroll.Create<GroupBox>();
|
||||
|
||||
var pingButton = toolbarContainer.Create<Button>();
|
||||
pingButton.text = "Ping";
|
||||
pingButton.clicked += () =>
|
||||
{
|
||||
if (_listView.selectedIndex < 0) return;
|
||||
var item = List[_listView.selectedIndex];
|
||||
EditorGUIUtility.PingObject(item);
|
||||
};
|
||||
|
||||
//_container.style.flexGrow = 1;
|
||||
|
||||
@@ -64,7 +99,7 @@ namespace BITKit.GameEditor
|
||||
$"{GetType().Name} 已初始化,从{AssetsPath}获取到{List.Count}个{typeof(T).Name}");
|
||||
}
|
||||
|
||||
private void ItemsChosen(IEnumerable<object> obj)
|
||||
protected virtual void ItemsChosen(IEnumerable<object> obj)
|
||||
{
|
||||
var selected = obj.FirstOrDefault() as Object;
|
||||
var serializedObject = new SerializedObject(selected);
|
||||
@@ -73,12 +108,39 @@ namespace BITKit.GameEditor
|
||||
}
|
||||
protected virtual VisualElement MakeItem()
|
||||
{
|
||||
// var container = new VisualElement();
|
||||
// var label = container.Create<Label>(UXConstant.ContextLabel);
|
||||
// label.name = "ContextLabel";
|
||||
// label.text = typeof(T).Name;
|
||||
// return container;
|
||||
return new Label();
|
||||
var container = new VisualElement();
|
||||
var icon = container.Create<VisualElement>(UXConstant.Icon);
|
||||
var label = container.Create<Label>(UXConstant.ContextLabel);
|
||||
|
||||
container.style.flexDirection = FlexDirection.Row;
|
||||
container.style.alignContent = Align.Center;
|
||||
container.style.alignItems = Align.Center;
|
||||
|
||||
icon.style.width = 24;
|
||||
icon.style.height = 24;
|
||||
|
||||
container.AddManipulator(new ContextualMenuManipulator((evt) =>
|
||||
{
|
||||
evt.menu.AppendAction("复制", Copy, DropdownMenuAction.AlwaysEnabled);
|
||||
//evt.menu.AppendAction("Second menu item", (x) => Debug.Log("Second!!!!"), DropdownMenuAction.AlwaysEnabled);
|
||||
}));
|
||||
return container;
|
||||
|
||||
void Copy(DropdownMenuAction dropdownMenuAction)
|
||||
{
|
||||
if (container.userData is not ScriptableObject scriptableObject) return;
|
||||
var path = AssetDatabase.GetAssetPath(scriptableObject);
|
||||
var folder = Path.GetDirectoryName(path)!;
|
||||
path = Path.Combine(folder, $"{scriptableObject.name}Copy.asset");
|
||||
|
||||
var newObject = CreateInstance<T>();
|
||||
AssetDatabase.CreateAsset(newObject, path);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"复制成功:{path}");
|
||||
}
|
||||
}
|
||||
protected virtual void BindItem(VisualElement arg1, int arg2)
|
||||
{
|
||||
@@ -86,12 +148,50 @@ namespace BITKit.GameEditor
|
||||
{
|
||||
var item = List[arg2];
|
||||
arg1.Q<Label>().text = item.name;
|
||||
arg1.userData = item;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RebuildList()
|
||||
{
|
||||
List.Clear();
|
||||
var paths = AssetDatabase.FindAssets($"t:{typeof(T).Name}");
|
||||
var allItem =
|
||||
(
|
||||
from path in paths.Select(AssetDatabase.GUIDToAssetPath)
|
||||
select AssetDatabase.LoadAssetAtPath<ScriptableObject>(path)
|
||||
).ToArray();
|
||||
List.AddRange(allItem.Cast<T>());
|
||||
}
|
||||
|
||||
protected virtual void CreateScriptableObject(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
name = $"New {typeof(T).Name}";
|
||||
}
|
||||
|
||||
var path = $"{AssetsPath}{name}.asset";
|
||||
|
||||
if (EditorUtility.DisplayDialog("创建", $"是否创建{name}与{path}?", "是", "否") is false) return;
|
||||
|
||||
new DirectoryInfo(Path.GetDirectoryName(path)!).Create();
|
||||
|
||||
var item = CreateInstance<T>();
|
||||
item.name = name;
|
||||
AssetDatabase.CreateAsset(item, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
List.Add(item);
|
||||
|
||||
_listView.Rebuild();
|
||||
|
||||
ItemsChosen(new[] {item});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user