This commit is contained in:
CortexCore
2024-03-29 00:58:24 +08:00
parent 967ad8eacf
commit 05315ef4a8
232 changed files with 53368 additions and 8539 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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
}

View File

@@ -6,7 +6,7 @@
"GUID:4988cf9794f41d64c884876ab6574b89",
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
"GUID:e6234d6c1f7bf4e4db20eddc411c00b8",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
"GUID:d525ad6bd40672747bde77962f1c401e"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BITKit.UX;
using UnityEditor;
@@ -22,13 +23,7 @@ namespace BITKit.GameEditor
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>());
RebuildList();
var toolbarContainer = rootVisualElement.Create<VisualElement>();
toolbarContainer.style.alignSelf = Align.Auto;
@@ -38,6 +33,11 @@ namespace BITKit.GameEditor
var refreshButton = toolbarContainer.Create<Button>();
refreshButton.text = "刷新";
refreshButton.clicked += () =>
{
RebuildList();
_listView.Rebuild();
};
var container = rootVisualElement.Create<VisualElement>();
@@ -116,7 +116,28 @@ namespace BITKit.GameEditor
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)
{
@@ -124,12 +145,24 @@ 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)
{