This commit is contained in:
parent
637bbef7d2
commit
37e7fcea51
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IWorldItemObject
|
||||
{
|
||||
public IBasicItem Item { get; set; }
|
||||
public event Action<IBasicItem> OnSetItem;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e0adbb35ce4784342a0ed37ac4a56200
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -36,8 +37,8 @@ namespace BITKit.Modification
|
|||
/// </summary>
|
||||
public interface IModifyElement
|
||||
{
|
||||
IModifyElement[] Require { get; }
|
||||
IModifyElement[] Incompatible { get; }
|
||||
IModifyElement[] Require => Array.Empty<IModifyElement>();
|
||||
IModifyElement[] Incompatible => Array.Empty<IModifyElement>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 改装管理器
|
||||
|
|
|
@ -119,11 +119,16 @@ namespace BITKit
|
|||
}
|
||||
public bool TryRemoveProperty<T>()
|
||||
{
|
||||
if(properties.TryGetValue(typeof(T).FullName, out var x))
|
||||
foreach (var pair in properties.Where(x=>x.Value is T))
|
||||
{
|
||||
properties.Remove(typeof(T).Name);
|
||||
properties.Remove(pair.Key);
|
||||
return true;
|
||||
}
|
||||
// if(properties.TryGetValue(typeof(T).FullName, out var x))
|
||||
// {
|
||||
// properties.Remove(typeof(T).Name);
|
||||
// return true;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
public bool TrySetProperty<T>(T value)
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
"id": "07dfe885-d709-4482-9686-57f671b1aed6",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"interactions": "Press",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3dd71e8003b3af4da8de14f81d9fcd2
|
||||
guid: 7dd870423004cd94fbeafd33a46884b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "BITKit.Pool",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 381f7acf3ae78534b99dbc017cb8e0d5
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class PoolService : MonoBehaviour
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, Transform> _Prefabs = new();
|
||||
private static readonly ConcurrentDictionary<string,UnityPool<Transform>> _Pools = new();
|
||||
public static Transform Get(Transform prefab)
|
||||
{
|
||||
_Prefabs.TryAdd(prefab.name, prefab);
|
||||
var pool = _Pools.GetOrAdd(prefab.name, CreatePool);
|
||||
return pool.Get();
|
||||
}
|
||||
public static bool TryGet(Transform prefab, out Transform instance)
|
||||
{
|
||||
_Prefabs.TryAdd(prefab.name, prefab);
|
||||
var pool = _Pools.GetOrAdd(prefab.name, CreatePool);
|
||||
instance = null;
|
||||
if (pool.InstanceCount>=pool.DefaultCapacity) return false;
|
||||
instance = pool.Get();
|
||||
return true;
|
||||
}
|
||||
public static void Release(string name,Transform instance)
|
||||
{
|
||||
var pool = _Pools.GetOrAdd(name, CreatePool);
|
||||
pool.Return(instance);
|
||||
}
|
||||
private static UnityPool<Transform> CreatePool(string name)
|
||||
{
|
||||
var pool = new UnityPool<Transform>
|
||||
{
|
||||
Prefab = _Prefabs[name],
|
||||
OnReturn = null,
|
||||
};
|
||||
return pool;
|
||||
}
|
||||
[SerializeField] private SerializedDictionary<Transform,int> initialCapacity;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (var (key, value) in initialCapacity)
|
||||
{
|
||||
var pool = new UnityPool<Transform>
|
||||
{
|
||||
Prefab = key,
|
||||
DefaultCapacity = value,
|
||||
Root = transform,
|
||||
OnReturn = null,
|
||||
};
|
||||
_Prefabs.TryAdd(key.name, key);
|
||||
_Pools.TryAdd(key.name, pool);
|
||||
var list = new List<Transform>();
|
||||
for (var i = 0; i < pool.DefaultCapacity; i++)
|
||||
{
|
||||
list.Add(pool.Get());
|
||||
}
|
||||
foreach (var x in list)
|
||||
{
|
||||
x.gameObject.SetActive(false);
|
||||
pool.Return(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_Prefabs.Clear();
|
||||
_Pools.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 74a03a9938f67ec498c7972cb0338ea6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,117 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Object = UnityEngine.Object;
|
||||
using Random = UnityEngine.Random;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class AddressableHelper:MonoBehaviour
|
||||
{
|
||||
private static IDictionary<ulong,string> PathsById { get; } = new Dictionary<ulong, string>();
|
||||
public static T Get<T>(ulong id) where T : Object
|
||||
{
|
||||
var task = YooAssets.LoadAssetAsync<T>(PathsById[id]);
|
||||
task.WaitForAsyncComplete();
|
||||
return task.AssetObject.As<T>();
|
||||
}
|
||||
[SerializeField] private SerializedDictionary<ulong,string> pathsById;
|
||||
private void Start()
|
||||
{
|
||||
PathsById.Clear();
|
||||
foreach (var x in pathsById)
|
||||
{
|
||||
PathsById.Add(x.Key,x.Value);
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[BIT]
|
||||
private void BuildCache()
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets($"t:Object",new[] {"Assets"});
|
||||
var paths = guids.Select(AssetDatabase.GUIDToAssetPath);
|
||||
|
||||
var objects = new List<IAddressable>();
|
||||
var stringBuilder = new System.Text.StringBuilder();
|
||||
|
||||
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var asset = AssetDatabase.LoadAssetAtPath<Object>(path);
|
||||
switch (asset)
|
||||
{
|
||||
case GameObject go when go.TryGetComponent(out IAddressable addressable):
|
||||
objects.Add(addressable);
|
||||
break;
|
||||
case IAddressable addressable:
|
||||
objects.Add(addressable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stringBuilder.AppendLine($"所有资源数量:{guids.Length},其中包含{objects.Count}个Addressable资源");
|
||||
|
||||
pathsById.Clear();
|
||||
foreach (var x in objects)
|
||||
{
|
||||
if (x is not Object unityObject) continue;
|
||||
|
||||
//if (x.AddressableId is ulong.MinValue or ulong.MaxValue)
|
||||
{
|
||||
x.AddressableId = RandomUlong.NextUlong;
|
||||
EditorUtility.SetDirty(unityObject);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (x.AddressableId is not ulong.MinValue && !string.IsNullOrEmpty(x.AddressablePath))
|
||||
{
|
||||
if (pathsById.TryAdd(x.AddressableId, x.AddressablePath))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.AppendLine($"资源{unityObject.name}的AddressableId:{x.AddressableId}已经存在");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.AppendLine($"{unityObject.name}的AddressableId或AddressablePath为空");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
stringBuilder.AppendLine($"{unityObject.name}遇到了错误:{e.Message}");
|
||||
}
|
||||
}
|
||||
EditorUtility.SetDirty(this);
|
||||
Debug.Log(stringBuilder);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static class RandomUlong
|
||||
{
|
||||
private static readonly System.Random _random = new();
|
||||
|
||||
public static ulong NextUlong
|
||||
{
|
||||
get
|
||||
{
|
||||
var buf = new byte[8];
|
||||
_random.NextBytes(buf);
|
||||
return BitConverter.ToUInt64(buf, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using BITKit.IO;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Object = UnityEngine.Object;
|
||||
using Random = UnityEngine.Random;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class AddressableHelper:MonoBehaviour
|
||||
{
|
||||
private static IDictionary<ulong,string> PathsById { get; } = new Dictionary<ulong, string>();
|
||||
public static T Get<T>(ulong id) where T : Object
|
||||
{
|
||||
var task = YooAssets.LoadAssetAsync<T>(PathsById[id]);
|
||||
task.WaitForAsyncComplete();
|
||||
return task.AssetObject.As<T>();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
PathsById.Clear();
|
||||
|
||||
YooAssetUtils.OnPackageRegistered += OnRegister;
|
||||
|
||||
foreach (var registeredResource in YooAssetUtils.RegisteredResourcePackages)
|
||||
{
|
||||
OnRegister(registeredResource.PackageName);
|
||||
}
|
||||
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
YooAssetUtils.OnPackageRegistered -= OnRegister;
|
||||
});
|
||||
}
|
||||
|
||||
private static async void OnRegister(string obj)
|
||||
{
|
||||
Stopwatch stopWatcher = new();
|
||||
stopWatcher.Start();
|
||||
|
||||
BIT4Log.Log<AddressableHelper>($"开始注册:{obj}的资源");
|
||||
var package = YooAssets.GetPackage(obj);
|
||||
var assetInfos = package.GetAssetInfos(nameof(IAddressable));
|
||||
|
||||
var reportBuilder = new StringBuilder();
|
||||
foreach (var x in assetInfos)
|
||||
{
|
||||
var asyncHandle = YooAssets.LoadAssetAsync(x.AssetPath);
|
||||
await asyncHandle;
|
||||
if (asyncHandle.AssetObject is IAddressable addressable)
|
||||
{
|
||||
if (PathsById.TryAdd(addressable.AddressableId, addressable.AddressablePath) is false)
|
||||
{
|
||||
var existing = PathsById[addressable.AddressableId];
|
||||
BIT4Log.Warning<AddressableHelper>($"{addressable.AddressablePath}的Id:{addressable.AddressableId}已被注册为{existing}");
|
||||
}
|
||||
reportBuilder.AppendLine($"{addressable.AddressablePath}的Id:{addressable.AddressableId}");
|
||||
}
|
||||
}
|
||||
BIT4Log.Log<AddressableHelper>($"注册:{obj}的资源完成,耗时:{stopWatcher.ElapsedMilliseconds}ms");
|
||||
BIT4Log.Log<AddressableHelper>(reportBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class RandomUlong
|
||||
{
|
||||
private static readonly System.Random _random = new();
|
||||
|
||||
public static ulong NextUlong
|
||||
{
|
||||
get
|
||||
{
|
||||
var buf = new byte[8];
|
||||
_random.NextBytes(buf);
|
||||
return BitConverter.ToUInt64(buf, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.IData
|
||||
{
|
||||
public interface IBindableData
|
||||
{
|
||||
object Data { get; }
|
||||
}
|
||||
public interface IBindableData<T>:IBindableData
|
||||
{
|
||||
new T Data { get; }
|
||||
}
|
||||
public readonly struct BindableData:IBindableData
|
||||
{
|
||||
public BindableData(object data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
public object Data { get; }
|
||||
}
|
||||
public readonly struct BindableData<T>:IBindableData<T>
|
||||
{
|
||||
public T Data { get; }
|
||||
object IBindableData.Data => Data;
|
||||
public BindableData(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e4704dff2c65b154fa34acdb40b4230e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -110,6 +110,7 @@ namespace BITKit.Entities
|
|||
}
|
||||
public interface IDamagable
|
||||
{
|
||||
string Tag { get; }
|
||||
IHealth Health { get; }
|
||||
IUnityEntity UnityEntity { get; }
|
||||
Rigidbody Rigidbody { get; }
|
||||
|
|
|
@ -6,6 +6,8 @@ namespace BITKit.Entities
|
|||
{
|
||||
public class EntityHitbox : MonoBehaviour,IDamagable
|
||||
{
|
||||
public string Tag => tag is null ? base.tag : tag.Value;
|
||||
|
||||
public IHealth Health
|
||||
{
|
||||
get
|
||||
|
@ -36,6 +38,7 @@ namespace BITKit.Entities
|
|||
}
|
||||
|
||||
[SerializeField]private Rigidbody m_rigidbody;
|
||||
[SerializeReference, SubclassSelector] private new IReference tag;
|
||||
|
||||
[Inject(true)]
|
||||
private IHealth _health;
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:9354affc93e0f3e4a904785e7d4c0f59",
|
||||
"GUID:c56f2ae4d67b9b947a600c84225206a2"
|
||||
"GUID:c56f2ae4d67b9b947a600c84225206a2",
|
||||
"GUID:296866320aab85a42a0403bf684bac59"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace BITKit
|
|||
{
|
||||
public interface IClosePoint
|
||||
{
|
||||
Collider Collider { get; }
|
||||
bool TryGetClosePoint(out Vector3 vector3);
|
||||
}
|
||||
[System.Serializable]
|
||||
|
@ -16,6 +17,8 @@ namespace BITKit
|
|||
public Transform root;
|
||||
public LayerMask layerMask;
|
||||
public float distance;
|
||||
public Collider Collider { get; set; }
|
||||
|
||||
public bool TryGetClosePoint(out Vector3 vector3)
|
||||
{
|
||||
vector3 = default;
|
||||
|
@ -44,6 +47,8 @@ namespace BITKit
|
|||
if(hit!= collider)
|
||||
return false;
|
||||
}
|
||||
|
||||
Collider = collider;
|
||||
return true;
|
||||
//return vector3.y >= collider.bounds.center.y + collider.bounds.extents.y;
|
||||
//return true;
|
||||
|
@ -67,9 +72,25 @@ namespace BITKit
|
|||
|
||||
public Vector3 StartPosition;
|
||||
public Vector3 EndPosition;
|
||||
|
||||
public Collider Collider { get; set; }
|
||||
private Rigidbody rigidbody;
|
||||
|
||||
private bool isInitialized;
|
||||
|
||||
public bool TryGetClosePoint(out Vector3 vector3)
|
||||
{
|
||||
if (isInitialized is false)
|
||||
{
|
||||
rigidbody = groundReference.GetComponent<Rigidbody>();
|
||||
isInitialized = true;
|
||||
}
|
||||
if (rigidbody)
|
||||
{
|
||||
vector3 = default;
|
||||
if (rigidbody.velocity.GetLength() < 0.1f) return false;
|
||||
}
|
||||
|
||||
var reportBuilder = new System.Text.StringBuilder();
|
||||
|
||||
var forward = root.forward;
|
||||
|
|
|
@ -71,6 +71,10 @@ namespace BITKit.IData
|
|||
Name = attribute.Name;
|
||||
VisualElement.GetType().GetProperty("label",ReflectionHelper.Flags)!.SetValue(VisualElement, Name);
|
||||
}
|
||||
if (fieldInfo.GetCustomAttribute<ReadOnlyAttribute>() is not null)
|
||||
{
|
||||
VisualElement.SetEnabled(false);
|
||||
}
|
||||
if(VisualElement is INotifyValueChanged<TDataType> notifyValueChanged)
|
||||
{
|
||||
notifyValueChanged.SetValueWithoutNotify(currentValue);
|
||||
|
@ -80,6 +84,8 @@ namespace BITKit.IData
|
|||
currentValue = x.newValue;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return VisualElement;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -25,6 +26,53 @@ namespace BITKit.IData
|
|||
}
|
||||
private static readonly Dictionary<Type,IUXDataBinder> _Binders = new();
|
||||
private static readonly CacheList<IUXDataBinder> _Instances = new();
|
||||
|
||||
public static VisualElement Create(object target)
|
||||
{
|
||||
var visualElement = new VisualElement();
|
||||
var fields = target.GetType().GetFields(ReflectionHelper.Flags);
|
||||
foreach (var fieldInfo in fields.Where(x=>x.GetCustomAttribute<ExportAttribute>() is not null))
|
||||
{
|
||||
var handler = UXDataBindingService.Create(target,fieldInfo);
|
||||
var ui = handler.CreateUI(target, fieldInfo);
|
||||
visualElement.Add(ui);
|
||||
}
|
||||
|
||||
foreach (var methodInfo in target.GetType().GetMethods(ReflectionHelper.Flags))
|
||||
{
|
||||
if (Attribute.IsDefined(methodInfo, typeof(ExportAttribute)) is false) continue;
|
||||
var exportAttribute = methodInfo.GetCustomAttribute<ExportAttribute>();
|
||||
|
||||
var button = visualElement.Create<Button>();
|
||||
button.text =string.IsNullOrEmpty(exportAttribute.Name) ? methodInfo.Name:exportAttribute.Name;
|
||||
|
||||
button.clicked += OnClicked;
|
||||
|
||||
continue;
|
||||
void OnClicked()
|
||||
{
|
||||
try
|
||||
{
|
||||
methodInfo.Invoke(target, null);
|
||||
}
|
||||
catch (TargetInvocationException targetInvocationException)
|
||||
{
|
||||
if (targetInvocationException.InnerException is InGameException e is false) return;
|
||||
switch (e)
|
||||
{
|
||||
case {InnerException:not null}:
|
||||
Alert.Print(e.Message,e.InnerException.Message);
|
||||
break;
|
||||
default:
|
||||
Alert.Print(e.Message,e.Source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return visualElement;
|
||||
}
|
||||
|
||||
public static IUXDataBinder Create(object target,FieldInfo fieldInfo)
|
||||
{
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace BITKit.UX
|
|||
{
|
||||
Clear();
|
||||
style.flexDirection = FlexDirection.Row;
|
||||
style.justifyContent = Justify.SpaceAround;
|
||||
style.justifyContent = Justify.FlexStart;
|
||||
instanceColumns.Clear();
|
||||
|
||||
if (string.IsNullOrEmpty(Json)) return;
|
||||
|
@ -64,7 +64,9 @@ namespace BITKit.UX
|
|||
var rowLength = jArray.Count;
|
||||
for (var i = 0; i < colLength; i++)
|
||||
{
|
||||
instanceColumns.Add(this.Create<VisualElement>());
|
||||
var newContainer = this.Create<VisualElement>();
|
||||
newContainer.name = $"{nameof(VisualElement)}-{i}";
|
||||
instanceColumns.Add(newContainer);
|
||||
}
|
||||
for (var y = 0; y < rowLength; y++)
|
||||
{
|
||||
|
|
|
@ -75,13 +75,23 @@ namespace BITKit.UX
|
|||
BITKit.UX.UXUtils.Inject(this);
|
||||
if(IsValid && autoEntry)
|
||||
UXService.Entry(this);
|
||||
|
||||
var returnButton= document.rootVisualElement.Q("return-button");
|
||||
returnButton?.RegisterCallback<MouseDownEvent>(x =>
|
||||
{
|
||||
if (x.button is 0)
|
||||
OnReturn();
|
||||
});
|
||||
}
|
||||
public bool IsEntered { get; set; }
|
||||
public void Entry()
|
||||
{
|
||||
UXService.Entry(this);
|
||||
}
|
||||
|
||||
protected virtual void OnReturn()
|
||||
{
|
||||
UXService.Return();
|
||||
}
|
||||
protected virtual void OnEnable()=>UXService.Register(this);
|
||||
protected virtual void OnDisable()=>UXService.UnRegister(this);
|
||||
protected virtual void OnPanelEntry(){}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
@ -12,6 +13,14 @@ namespace BITKit
|
|||
public abstract class VisualBehaviour:MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
public abstract class MonoBehaviourSingleton<T> : MonoBehaviour
|
||||
{
|
||||
public static T Singleton { get; private set; }
|
||||
protected void Awake()
|
||||
{
|
||||
if (this is T t) Singleton = t;
|
||||
}
|
||||
}
|
||||
public abstract class BITBehavior : MonoBehaviour, ICustomInspector
|
||||
{
|
||||
|
|
|
@ -69,8 +69,8 @@ namespace BITKit
|
|||
}
|
||||
|
||||
var type = serializedObject.targetObject.GetType();
|
||||
var fieldInfo = serializedObject.targetObject.GetType().GetField(property.propertyPath, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
if (fieldInfo is not null && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute)))
|
||||
var fieldInfo = serializedObject.targetObject.GetType().GetField(property.propertyPath, ReflectionHelper.Flags);
|
||||
if (fieldInfo is not null && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute),true))
|
||||
{
|
||||
var attribute = fieldInfo.GetCustomAttribute<ReadOnlyAttribute>();
|
||||
var _container = container.Create<VisualElement>();
|
||||
|
|
|
@ -12,10 +12,6 @@ namespace BITKit
|
|||
[System.Serializable]
|
||||
public class UnityPool<T> where T : Component
|
||||
{
|
||||
public UnityPool()
|
||||
{
|
||||
pool = new ObjectPool<T>(Spawn, OnGet, OnReturn, OnDestroy, maxSize: 16);
|
||||
}
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private int defaultCapacity = 16;
|
||||
[Header(Constant.Header.Prefabs)]
|
||||
|
@ -23,17 +19,32 @@ namespace BITKit
|
|||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform root;
|
||||
|
||||
private ObjectPool<T> pool;
|
||||
|
||||
public Action<T> OnGet { get; set; } = x=>x.gameObject.SetActive(true);
|
||||
public Action<T> OnReturn { get; set; } = x=>x.gameObject.SetActive(false);
|
||||
public Action<T> OnDestroy { get; set; } = x=>Object.Destroy(x.gameObject);
|
||||
private ObjectPool<T> pool=> _pool ??=
|
||||
new ObjectPool<T>
|
||||
(Spawn, OnGet, OnReturn, OnDestroy,defaultCapacity:DefaultCapacity, maxSize:DefaultCapacity);
|
||||
private ObjectPool<T> _pool;
|
||||
private readonly List<T> _list=new();
|
||||
|
||||
public T Prefab
|
||||
{
|
||||
get => prefab;
|
||||
set => prefab = value;
|
||||
}
|
||||
public Transform Root
|
||||
{
|
||||
get => root;
|
||||
set => root = value;
|
||||
}
|
||||
|
||||
public int DefaultCapacity
|
||||
{
|
||||
get => defaultCapacity;
|
||||
set => defaultCapacity = value;
|
||||
}
|
||||
|
||||
public int InstanceCount => _list.Count;
|
||||
public T Get(T element = null, Transform _root = null)
|
||||
{
|
||||
if (_list.Count == defaultCapacity)
|
||||
|
@ -64,10 +75,6 @@ namespace BITKit
|
|||
_list.Remove(element);
|
||||
}
|
||||
private T Spawn() => Object.Instantiate(prefab, root);
|
||||
private void OnGet(T element) => element.gameObject.SetActive(true);
|
||||
private void OnReturn(T element) => element.gameObject.SetActive(false);
|
||||
private void OnDestroy(T element) => Object.Destroy(element.gameObject);
|
||||
|
||||
#region 拓展
|
||||
|
||||
private readonly ConcurrentDictionary<string, T> _dictionary=new();
|
||||
|
|
|
@ -25,12 +25,17 @@ namespace BITKit.OpenWorld
|
|||
var bounds1 = _collider.bounds;
|
||||
size = bounds1.size;
|
||||
offset = bounds1.center - transform.position;
|
||||
|
||||
return;
|
||||
}
|
||||
Bounds bounds = new();
|
||||
foreach (var x in GetComponentsInChildren<Collider>())
|
||||
{
|
||||
bounds.Encapsulate(x.bounds);
|
||||
if (x.bounds.size.sqrMagnitude > 64)
|
||||
{
|
||||
Debug.LogWarning($"{x.gameObject.name}:Size is too large, please check the size of the collider");
|
||||
}
|
||||
}
|
||||
size = bounds.size;
|
||||
offset = bounds.center - transform.position;
|
||||
|
|
|
@ -26,7 +26,16 @@ namespace BITKit.OpenWorld
|
|||
var enabledCollider = arg2 is 0;
|
||||
foreach (var x in colliders)
|
||||
{
|
||||
x.enabled = enabledCollider;
|
||||
try
|
||||
{
|
||||
x.enabled = enabledCollider;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Warning<ColliderChunkObject>(gameObject.name);
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
|
|
|
@ -48,6 +48,7 @@ namespace BITKit.OpenWorld
|
|||
}
|
||||
protected virtual void OnTick(float deltaTime)
|
||||
{
|
||||
if (!enabled) return;
|
||||
while (_unregisterQueue.TryDequeue(out var obj))
|
||||
{
|
||||
_quadtree.Remove(obj);
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
"GUID:508392158bd966c4d9c21e19661a441d",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:1193c2664d97cc049a6e4c486c6bce71"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
@ -3,6 +3,8 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Quadtree;
|
||||
using Quadtree.Items;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.WorldNodes
|
||||
|
@ -32,9 +34,19 @@ namespace BITKit.WorldNodes
|
|||
[ExecuteInEditMode]
|
||||
public class WorldNodeService : MonoBehaviour,IWorldNodeService
|
||||
{
|
||||
private class WorldNodeProxy : IItem<WorldNodeProxy, Node<WorldNodeProxy>>
|
||||
{
|
||||
public Bounds Bounds;
|
||||
public Bounds GetBounds()=>Bounds;
|
||||
public Node<WorldNodeProxy> ParentNode { get; set; }
|
||||
public void QuadTree_Root_Initialized(IQuadtreeRoot<WorldNodeProxy, Node<WorldNodeProxy>> root)
|
||||
{
|
||||
}
|
||||
}
|
||||
public static event Action OnDrawGizmo;
|
||||
public static readonly CacheList<IWorldNode> WorldNodeList = new();
|
||||
public static IWorldNode[] WorldNodes => WorldNodeList.ValueArray;
|
||||
private static QuadtreeRoot<WorldNodeProxy, Node<WorldNodeProxy>> _QuadtreeRoot;
|
||||
public static IWorldNode[] GetNodes(Vector3 position, float radius)
|
||||
{
|
||||
return WorldNodes.Where(node => InRange(position, node, radius))
|
||||
|
@ -77,6 +89,13 @@ namespace BITKit.WorldNodes
|
|||
{
|
||||
WorldNodeList.Clear();
|
||||
}
|
||||
|
||||
[SerializeField] private Vector3 size;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_QuadtreeRoot = new QuadtreeRoot<WorldNodeProxy, Node<WorldNodeProxy>>(transform.position,size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ namespace BITKit.OpenWorld
|
|||
|
||||
private void AddCullingSource(MeshCombiner meshcombiner)
|
||||
{
|
||||
AddCullingSource();
|
||||
if (enabled)
|
||||
AddCullingSource();
|
||||
}
|
||||
|
||||
[BIT]
|
||||
|
|
|
@ -22,11 +22,10 @@ namespace BITKit
|
|||
protected override void OnStop(bool interrupted)
|
||||
{
|
||||
base.OnStop(interrupted);
|
||||
if (interrupted)
|
||||
{
|
||||
if(output.isDefined)
|
||||
QuestSystem.Cancel(output.value);
|
||||
}
|
||||
if (!interrupted) return;
|
||||
if (QuestSystem.quests.TryGetValue(output.value, out var info) &&
|
||||
info.State == QuestSystem.State.InProcess)
|
||||
QuestSystem.Cancel(output.value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1705803e58f488146b0c364b69f275ff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "BITKit.Extensions.TranslucentImage",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:ff218ee40fe2b8648ab3234d56415557"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"LeTai_TranslucentImage"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4dea7f9c2d5c3d4abb7467736ee56df
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using LeTai.Asset.TranslucentImage;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class TranslucentService : MonoBehaviour
|
||||
{
|
||||
public static RenderTexture BlurredScreen;
|
||||
[SerializeField] private TranslucentImageSource source;
|
||||
[SerializeField] private RenderTexture blurredScreen;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 14ba5b1e81092234d944bec5c7063bc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,23 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
|
||||
public class TranslucentVisualElement : VisualElement
|
||||
{
|
||||
public new class UxmlFactory : UxmlFactory<TranslucentVisualElement, UxmlTraits> { }
|
||||
public TranslucentVisualElement()
|
||||
{
|
||||
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
}
|
||||
private void OnGeometryChanged(GeometryChangedEvent evt)
|
||||
{
|
||||
if (style.display.value is not DisplayStyle.Flex) return;
|
||||
style.backgroundImage = new StyleBackground(Background.FromRenderTexture(TranslucentService.BlurredScreen));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 45ff73d2202441b44a5453c22ebf0dab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.iOS;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXTranslucentService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
private float alpha;
|
||||
private void Start()
|
||||
{
|
||||
BITAppForUnity.AllowCursor.AddListener(OnCursor);
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
}
|
||||
private void Dispose()
|
||||
{
|
||||
BITAppForUnity.AllowCursor.RemoveListener(OnCursor);
|
||||
}
|
||||
private void OnCursor(bool obj)
|
||||
{
|
||||
image.enabled = obj;
|
||||
if (obj) alpha = 0;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (BITAppForUnity.AllowCursor.Allow && alpha is not 1)
|
||||
{
|
||||
alpha = Mathf.Clamp01(alpha + Time.deltaTime*5);
|
||||
image.color = new Color(0, 0, 0, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c99210a06ff163b4ab4bfce7ebbccbe9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue