breakpoint

This commit is contained in:
CortexCore
2023-06-17 16:30:53 +08:00
parent cd02761be7
commit 877ba6e548
88 changed files with 8715 additions and 988 deletions

View File

@@ -15,14 +15,6 @@ namespace BITKit
}
}
public class CreateOnStart:System.Attribute
{
public readonly string path;
public CreateOnStart(params string[] path)
{
this.path = string.Join("/", path);
}
}
public class BITAppForUnity : MonoBehaviour, IDiagnostics
{
public struct Path
@@ -55,43 +47,25 @@ namespace BITKit
#endif
}
[RuntimeInitializeOnLoadMethod]
private static async void Reload()
private static void Reload()
{
IsPlaying = true;
BIT4Log.OnLog += Debug.Log;
BIT4Log.OnWarning += Debug.LogWarning;
BIT4Log.OnException += Debug.LogException;
BIT4Log.Log<BITApp>($"正在初始化");
BIT4Log.Log<BITApp>($"正在注册Log");
BIT4Log.Log<BITApp>($"正在加载配置文件");
var settings = Addressables.LoadAssetAsync<ScriptableObject>(nameof(BITApp.AppSettings)).WaitForCompletion() as BITSettingsSO;
BIT4Log.Log<BITApp>($"正在启动{Application.productName}");
//启动BITApp
BITApp.Start(Application.productName, settings!.appSettings);
AllowCursor = new();
AllowTouchSupport = new();
BIT4Log.Log<BITApp>($"正在创建{nameof(BITApp)}");
GameObject = new(nameof(BITApp));
GameObject.AddComponent<BITAppForUnity>();
DontDestroyOnLoad(GameObject);
AllowCursor.AddListener(ToggleCursor);
AllowTouchSupport.AddListener(ToggleTouchSupport);
foreach (var x in await ReflectionHelper.GetAttributes<CreateOnStart>())
{
var prefab = Addressables.LoadAssetAsync<GameObject>(x.path).WaitForCompletion();
var instance = Instantiate(prefab);
DontDestroyOnLoad(instance);
}
BIT4Log.Log<BITApp>($"已创建{nameof(BITApp)}");
}
static void ToggleCursor(bool active)
{

View File

@@ -1,13 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace BITKit
{
[CreateOnStart(BITAppForUnity.Path.Services,"Framework")]
public class BITFramework : MonoBehaviour
{
[RuntimeInitializeOnLoadMethod]
private static void Reload()
{
Instantiate(Addressables.LoadAssetAsync<GameObject>("Services/Framework").WaitForCompletion());
}
}
}

View File

@@ -2,10 +2,10 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using System.IO;
using Cysharp.Threading.Tasks;
using BITKit.IO;
using System.IO.Compression;
namespace BITKit
{
public class SaveToFile : Provider, IAction
@@ -63,7 +63,7 @@ namespace BITKit
string GetPath()
{
string path;
var fileName = nameProvider.GetName(null, extensions);
var fileName = nameProvider.GetName(null, extensions.Get());
if (isPersistentData)
{
path = PathHelper.GetFilePath(Utility.Path.persistentDataPath, this.path.Get(), fileName);

View File

@@ -57,7 +57,7 @@ namespace BITKit
private CinemachineBrain _brain;
public void Reset()
{
lookInput = startLocation.position.TransientRotationAxis();
lookInput = MathV.TransientRotationAxis(startLocation.position);
cameraRoot.position = startLocation;
tpv.CameraDistance = startDistance;
}
@@ -79,14 +79,14 @@ namespace BITKit
{
cameraRoot.position = x.cameraRoot.position;
//lookInput = x.lookInput;
lookInput = x.cameraRoot.rotation.eulerAngles.TransientRotationAxis();
lookInput = MathV.TransientRotationAxis(x.cameraRoot.rotation.eulerAngles);
if (x.tpv)
tpv.CameraDistance = x.tpv.CameraDistance;
}
else if (target.TryGetComponent<CinemachineVirtualCamera>(out var vCam))
{
cameraRoot.position = vCam.Follow.position;
lookInput = vCam.LookAt.rotation.eulerAngles.TransientRotationAxis();
lookInput = MathV.TransientRotationAxis(vCam.LookAt.rotation.eulerAngles);
var e = vCam.GetCinemachineComponent<Cinemachine3rdPersonFollow>();
if (e)
{
@@ -97,7 +97,7 @@ namespace BITKit
else
{
cameraRoot.position = target.position;
lookInput = target.eulerAngles.TransientRotationAxis();
lookInput = MathV.TransientRotationAxis(target.eulerAngles);
}
}
public void SaveLocation()
@@ -115,7 +115,7 @@ namespace BITKit
}
public void LoadLocation()
{
lookInput = savedLocation.rotation.eulerAngles.TransientRotationAxis();
lookInput = MathV.TransientRotationAxis(savedLocation.rotation.eulerAngles);
cameraRoot.position = savedLocation;
tpv.CameraDistance = savedDistance;
}
@@ -151,7 +151,7 @@ namespace BITKit
private void OnEnable()
{
SetEnabled(true);
lookInput = cameraRoot.eulerAngles.TransientRotationAxis();
lookInput = MathV.TransientRotationAxis(cameraRoot.eulerAngles);
freeLooking.RemoveDisableElements(this);

View File

@@ -32,8 +32,8 @@ namespace BITKit.Entities
if (id != value)
{
id = value;
EntitiesManager.Dictionary.TryRemove(id, out var _);
EntitiesManager.GetOrAdd(id, x => this);
UnityEntitiesManager.Dictionary.TryRemove(id, out var _);
UnityEntitiesManager.GetOrAdd(id, x => this);
}
}
}
@@ -48,12 +48,12 @@ namespace BITKit.Entities
{
entityComponents.ForEach(x => x.OnAwake());
entityComponents.ForEach(x => x.OnStart());
EntitiesManager.Dictionary.AddOrUpdate(id, (x) => this, (x1, x2) => this);
UnityEntitiesManager.Dictionary.AddOrUpdate(id, (x) => this, (x1, x2) => this);
}
protected virtual void OnDestroy()
{
entityComponents.ForEach(x => x.OnDestroyComponent());
EntitiesManager.Dictionary.TryRemove(id, out var _);
UnityEntitiesManager.Dictionary.TryRemove(id, out var _);
}
protected virtual void Update()
{

View File

@@ -21,7 +21,7 @@ namespace BITKit.Entities
{
var id = reader.ReadInt32();
var path = reader.ReadString();
var entity = EntitiesManager.GetOrAdd(id, _id => Create(id, path));
var entity = UnityEntitiesManager.GetOrAdd(id, _id => Create(id, path));
return entity;
}
public override void WriteBinary(BinaryWriter writer, IEntity value)

View File

@@ -5,17 +5,21 @@ using UnityEngine;
using UnityEngine.AddressableAssets;
using BITKit;
using System.Collections.Concurrent;
namespace BITKit.Entities
{
public class EntitiesManager
public interface IEntitesManager
{
}
public class UnityEntitiesManager:MonoBehaviour
{
[RuntimeInitializeOnLoadMethod]
static void Reload()
{
Dictionary.Clear();
}
public static ConcurrentDictionary<int, IEntity> Dictionary = new();
public static Func<int, IEntity> CreateFactory;
public static readonly ConcurrentDictionary<int, IEntity> Dictionary = new();
public static IEntity Get(int id)
{
if (Dictionary.TryGetValue(id, out var entity))
@@ -29,8 +33,16 @@ namespace BITKit.Entities
}
public static IEntity GetOrAdd(int id)
{
return GetOrAdd(id, CreateFactory);
var instance = Instantiate(Singleton.prefab);
instance.Id = id;
return GetOrAdd(id,x=>instance);
}
public static IEntity GetOrAdd(int id, Func<int, IEntity> createFacotry) => Dictionary.GetOrAdd(id, createFacotry);
private static UnityEntitiesManager Singleton;
public Entity prefab;
private void Awake()
{
Singleton = this;
}
}
}

View File

@@ -34,7 +34,7 @@ namespace BITKit.UX
{
try
{
await UniTask.SwitchToMainThread(gameObject.GetCancellationTokenOnDestroy());
await UniTask.SwitchToMainThread(cancellationToken);
switch (visualElement)
{
case INotifyValueChanged<float> iNotify:
@@ -45,20 +45,23 @@ namespace BITKit.UX
fillElement.style.width = new StyleLength(Length.Percent(value));
break;
}
if (labelElement is not null)
labelElement.text = value.ToString();
}
catch (System.Exception e)
catch (OperationCanceledException)
{
if (e is not OperationCanceledException)
throw;
}
}
public async void SetDirect(float progess,string label)
{
await UniTask.SwitchToMainThread(gameObject.GetCancellationTokenOnDestroy());
await UniTask.SwitchToMainThread(cancellationToken);
Set(progess);
labelElement.text = label;
if (labelElement is not null)
{
labelElement.text = label;
}
}
float IProvider<float>.Get()
{

View File

@@ -74,7 +74,7 @@ namespace BITKit
return direction.sqrMagnitude < factor; */
return Vector3.Angle(vectorX, vectorY) < 8;
}
public static Vector3 TransientRotationAxis(this Vector3 transientAxis)
public static Vector3 TransientRotationAxis(Vector3 transientAxis)
{
transientAxis.x = TransientRotationAxis(transientAxis.x);
transientAxis.y = TransientRotationAxis(transientAxis.y);
@@ -90,10 +90,10 @@ namespace BITKit
z = GetAlign(self.z),
};
return result * snapSize;
int GetAlign(float self)
int GetAlign(float _self)
{
var size = (int)self / snapSize;
var remainder = self % snapSize;
var size = (int)_self / snapSize;
var remainder = _self % snapSize;
return remainder > snapSize / 2 ? size + 1 : size;
}
}
@@ -105,7 +105,7 @@ namespace BITKit
{
var addValue = self.x + self.y + self.z;
var subtractValue = self.x - self.y - self.z;
if (MathF.Abs(addValue) == Mathf.Abs(subtractValue))
if (Math.Abs(MathF.Abs(addValue) - Mathf.Abs(subtractValue)) < 0.01f)
{
return addValue;
}

View File

@@ -12,7 +12,6 @@ namespace BITKit
public string path;
public Location location;
}
//[CreateOnStart(BITAppForUnity.Path.Services,nameof(VFXService))]
public class VFXService : MonoBehaviour, IObjectMatcher<string, Transform>
{
static VFXService sinleton;