This commit is contained in:
CortexCore
2023-06-05 16:25:06 +08:00
parent 9027120bb8
commit 4565ff2e35
2947 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.UIElements;
namespace BITKit
{
[System.Serializable]
public record UnityReference : IReference
{
[SerializeField] internal int index;
private AssetableReference asset;
public string Get()
{
asset ??= Addressables.LoadAssetAsync<AssetableReference>(nameof(AssetableReference)).WaitForCompletion();
return asset.Get(index);
}
internal void Set(int _index) => index = _index;
}
public class AssetableReference:ScriptableObject
{
[SerializeField]
private List<string> values;
internal string Get(int index) => values[index];
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(UnityReference))]
public class UnityReferenceInspector :PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var index = property.FindPropertyRelative(nameof(UnityReference.index)).intValue;
return new Label(index.ToString());
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var index = property.FindPropertyRelative(nameof(UnityReference.index)).intValue;
//var unityReference = property.serializedObject.targetObject.GetType().GetField(property.name).GetValue(property.serializedObject) as UnityReference;
EditorGUI.DrawRect(position,Color.gray);
//EditorGUI.LabelField(position,new GUIContent(unityReference.index.T
}
}
#endif
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
[System.Serializable]
public record DataReference : References
{
[SubclassSelector, SerializeReference] public References value;
public override string Get()
{
return Data.Get<string>(value) ?? value;
}
}
[System.Serializable]
public record DataReference<T> : References<T>
{
public DataReference(string key)
{
this.key = key;
}
public readonly string key;
public override T Get()
{
return Data.Get<T>(key);
}
}
}

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.UIElements;
#endif
namespace BITKit
{
[System.Serializable]
public class ReferenceSO : ScriptableObject
{
[TextArea]
public string value;
}
[System.Serializable]
public record ReferenceScriptableObject : References
{
public ReferenceSO so;
public override string Get() => so.value.IsNullOrEmpty() ? so.name : so.value;
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ReferenceScriptableObject))]
public class ReferenceScriptableObjectDrawer : BITProperty
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
VisualElement root = new();
root.Add(base.CreatePropertyGUI(property));
Button button = new();
root.Add(button);
return root;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
base.OnGUI(position, property, label);
EditorGUI.PropertyField(position, property);
EditorGUI.LinkButton(position, "New Button");
}
}
#endif
}

View File

@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class TestAssetableReference : MonoBehaviour
{
[SerializeReference, SubclassSelector] public IReference reference;
public UnityReference UnityReference;
}
}