BITFALL/Assets/BITKit/UnityEditor/AssetCacheScriptableObject.cs

51 lines
1.1 KiB
C#
Raw Normal View History

2023-10-24 23:37:59 +08:00
using System.Collections;
using System.Collections.Generic;
2023-11-15 23:54:54 +08:00
#if UNITY_EDITOR
2023-10-24 23:37:59 +08:00
using UnityEditor;
using UnityEditor.UIElements;
2023-11-15 23:54:54 +08:00
#endif
2023-10-24 23:37:59 +08:00
using UnityEngine;
using UnityEngine.UIElements;
namespace BITKit
{
public class AssetCacheScriptableObject : ScriptableObject
{
[SerializeField] private bool isEditable;
[SerializeField] private Object[] _assets;
public bool IsEditable => isEditable;
public Object[] Assets => _assets;
}
#if UNITY_EDITOR
[CustomEditor(typeof(AssetCacheScriptableObject))]
public class AssetCacheScriptableObjectEditor : BITInspector<AssetCacheScriptableObject>
{
public override VisualElement CreateInspectorGUI()
{
2023-11-30 00:23:23 +08:00
root.root.Clear();
2023-10-24 23:37:59 +08:00
if (agent.IsEditable)
{
return base.CreateInspectorGUI();
}
2023-11-30 00:23:23 +08:00
var toggle = root.Create<Toggle>();
toggle.bindingPath = "isEditable";
toggle.label = "Edit";
toggle.RegisterValueChangedCallback(x => CreateInspectorGUI());
2023-10-24 23:37:59 +08:00
foreach (var x in agent.Assets)
{
2023-11-30 00:23:23 +08:00
var field = root.Create<ObjectField>();
//field.label = x.name;
field.style.opacity = 1;
field.value = x;
field.SetEnabled(false);
2023-10-24 23:37:59 +08:00
}
return root;
}
}
#endif
}