1
This commit is contained in:
@@ -11,13 +11,14 @@ 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;
|
||||
private Button _createButton;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -29,6 +30,15 @@ namespace BITKit.GameEditor
|
||||
).ToArray();
|
||||
List.AddRange(allItem.Cast<T>());
|
||||
|
||||
var toolbarContainer = rootVisualElement.Create<VisualElement>();
|
||||
toolbarContainer.style.alignSelf = Align.Auto;
|
||||
toolbarContainer.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
|
||||
|
||||
var refreshButton = toolbarContainer.Create<Button>();
|
||||
refreshButton.text = "刷新";
|
||||
|
||||
var container = rootVisualElement.Create<VisualElement>();
|
||||
|
||||
var css = AssetDatabase.LoadAssetAtPath<StyleSheet>(BITEditorUtils.InspectorPath);
|
||||
@@ -37,11 +47,24 @@ namespace BITKit.GameEditor
|
||||
|
||||
container.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
|
||||
|
||||
var listViewContainer = container.Create<VisualElement>();
|
||||
|
||||
var createContainer = listViewContainer.Create<VisualElement>();
|
||||
|
||||
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);
|
||||
|
||||
listViewContainer.style.flexDirection = FlexDirection.Column;
|
||||
|
||||
listViewContainer.Create<Label>().text = $"{typeof(T).Name},数量:{List.Count}";
|
||||
listViewContainer.Create<Label>().text = $"获取到:{List.Count}个配置";
|
||||
listViewContainer.AddToClassList("pa-8");
|
||||
|
||||
_listView = listViewContainer.Create<ListView>();
|
||||
@@ -57,6 +80,15 @@ namespace BITKit.GameEditor
|
||||
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;
|
||||
|
||||
@@ -73,12 +105,18 @@ 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;
|
||||
|
||||
return container;
|
||||
}
|
||||
protected virtual void BindItem(VisualElement arg1, int arg2)
|
||||
{
|
||||
@@ -93,6 +131,27 @@ namespace BITKit.GameEditor
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
var item = CreateInstance<T>();
|
||||
item.name = name;
|
||||
AssetDatabase.CreateAsset(item, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
List.Add(item);
|
||||
|
||||
_listView.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user