This commit is contained in:
CortexCore 2024-06-11 17:16:34 +08:00
parent 0e1bf20595
commit 01b19130a9
8 changed files with 161 additions and 3 deletions

View File

@ -10,8 +10,22 @@ using UnityEngine.Pool;
using UnityEngine.UIElements;
namespace BITKit
{
[Serializable]
public sealed class UXWaitingSingleton : IUXWaiting
{
private IUXWaiting Implementation => UXWaiting.Singleton;
public IUXWaitingHandle Get()
{
return Implementation.Get();
}
public void Release(IUXWaitingHandle handle)
{
Implementation.Release(handle);
}
}
[CustomType(typeof(IUXWaiting))]
public class UXWaiting : MonoBehaviour,IUXWaiting
public class UXWaiting : MonoBehaviourSingleton<UXWaiting>,IUXWaiting
{
public sealed class WaitingHandle : IUXWaitingHandle
{
@ -69,8 +83,9 @@ namespace BITKit
_handles.Remove(handle);
Check();
}
private void Awake()
protected override void Awake()
{
base.Awake();
UXUtils.Inject(this);
_container.Clear();
_pool = new Pool<IUXWaitingHandle>(Create,OnReset,10);

View File

@ -17,7 +17,7 @@ namespace BITKit
public abstract class MonoBehaviourSingleton<T> : MonoBehaviour
{
public static T Singleton { get; private set; }
protected void Awake()
protected virtual void Awake()
{
if (this is T t) Singleton = t;
}

View File

@ -0,0 +1,53 @@
using System;
using UnityEngine;
namespace BITKit.GameEditor
{
/// <summary>
/// Serializable wrapper for System.Guid.
/// Can be implicitly converted to/from System.Guid.
///
/// Author: Searous
/// </summary>
[Serializable]
public struct SerializableGuid : ISerializationCallbackReceiver {
private Guid guid;
[SerializeField] private string serializedGuid;
public SerializableGuid(Guid guid) {
this.guid = guid;
serializedGuid = null;
}
public override bool Equals(object obj) {
return obj is SerializableGuid guid &&
this.guid.Equals(guid.guid);
}
public override int GetHashCode() {
return -1324198676 + guid.GetHashCode();
}
public void OnAfterDeserialize() {
try {
guid = Guid.Parse(serializedGuid);
} catch {
guid = Guid.Empty;
Debug.LogWarning($"Attempted to parse invalid GUID string '{serializedGuid}'. GUID will set to System.Guid.Empty");
}
}
public void OnBeforeSerialize() {
serializedGuid = guid.ToString();
}
public override string ToString() => guid.ToString();
public static bool operator ==(SerializableGuid a, SerializableGuid b) => a.guid == b.guid;
public static bool operator !=(SerializableGuid a, SerializableGuid b) => a.guid != b.guid;
public static implicit operator SerializableGuid(Guid guid) => new SerializableGuid(guid);
public static implicit operator Guid(SerializableGuid serializable) => serializable.guid;
public static implicit operator SerializableGuid(string serializedGuid) => new SerializableGuid(Guid.Parse(serializedGuid));
public static implicit operator string(SerializableGuid serializedGuid) => serializedGuid.ToString();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3f2176099811c34d858b911d7b4f6aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,59 @@
#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEngine;
namespace BITKit.GameEditor
{
/// <summary>
/// Property drawer for SerializableGuid
///
/// Author: Searous
/// </summary>
[CustomPropertyDrawer(typeof(SerializableGuid))]
public class SerializableGuidPropertyDrawer : PropertyDrawer {
private float ySep = 20;
private float buttonSize;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
// Start property draw
EditorGUI.BeginProperty(position, label, property);
// Get property
SerializedProperty serializedGuid = property.FindPropertyRelative("serializedGuid");
// Draw label
position = EditorGUI.PrefixLabel(new Rect(position.x, position.y + ySep / 2, position.width, position.height), GUIUtility.GetControlID(FocusType.Passive), label);
position.y -= ySep / 2; // Offsets position so we can draw the label for the field centered
buttonSize = position.width / 3; // Update size of buttons to always fit perfeftly above the string representation field
// Buttons
if(GUI.Button(new Rect(position.xMin, position.yMin, buttonSize, ySep - 2), "New")) {
serializedGuid.stringValue = Guid.NewGuid().ToString();
}
if(GUI.Button(new Rect(position.xMin + buttonSize, position.yMin, buttonSize, ySep - 2), "Copy")) {
EditorGUIUtility.systemCopyBuffer = serializedGuid.stringValue;
}
if(GUI.Button(new Rect(position.xMin + buttonSize * 2, position.yMin, buttonSize, ySep - 2), "Empty"))
{
serializedGuid.stringValue = Guid.Empty.ToString();
}
// Draw fields - passs GUIContent.none to each so they are drawn without labels
Rect pos = new Rect(position.xMin, position.yMin + ySep, position.width, ySep - 2);
EditorGUI.PropertyField(pos, serializedGuid, GUIContent.none);
// End property
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
// Field height never changes, so ySep * 2 will always return the proper hight of the field
return ySep * 2;
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5401aab2c353e7849b99fc7a79189283
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4fcafdc7f8d41b147b350ebc3a7f7091
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -122,6 +122,7 @@ namespace BITKit.GameEditor
ExportData(exportPath);
BIT4Log.Log<ScriptableObjectGroupEditor<T>>($"导出成功:{exportPath}");
}
protected virtual void ExportData(string path)
{