更改文件架构

This commit is contained in:
CortexCore
2023-06-07 18:38:07 +08:00
parent 93292b1a59
commit ed84166723
720 changed files with 297 additions and 65 deletions

View File

@@ -0,0 +1,25 @@
{
"name": "BITKit.MarkSystem",
"rootNamespace": "",
"references": [
"GUID:a209c53514018594f9f482516f2a6781",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:66d2ae14764cc7d49aad4b16930747c0",
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:be17a8778dbfe454890ed8279279e153",
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"ODIN_INSPECTOR"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0b8afac07cb6a864385843f87eaa0e3f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using BITKit.SubSystems;
using UnityEngine;
namespace BITKit.Mark
{
public interface IMarkObject
{
string GetID();
string GetDisplay();
Vector3 GetPostion();
bool GetAcitve();
}
[SubSystemConfig(isMainThread = true)]
public class MarkSystem : SubBITSystem
{
public Action<IMarkObject> OnAdd;
public Action<IMarkObject> Update;
public Action<IMarkObject> OnRemove;
List<IMarkObject> markObjects = new();
public void Add(IMarkObject markObject)
{
markObjects.Add(markObject);
OnAdd?.Invoke(markObject);
}
public void Remove(IMarkObject markObject)
{
markObjects.TryRemove(markObject);
OnRemove?.Invoke(markObject);
}
public override void OnUpdate(float deltaTime)
{
foreach (var markObject in markObjects.ToArray())
{
Update?.Invoke(markObject);
}
}
}
}

View File

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

View File

@@ -0,0 +1,129 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit.UX;
using BITKit.SubSystems;
using UnityEngine.UIElements;
using Cysharp.Threading.Tasks;
using System.Threading.Tasks;
using System.Threading;
namespace BITKit.Mark
{
public class MarkSystemUIToolkit : MonoBehaviour
{
public UXElement element;
[SerializeReference, SubclassSelector] public References className;
Dictionary<string, Label> dictionary = new();
MarkSystem markSystem;
IPanel panel;
CancellationToken cancellationToken;
void Awake()
{
cancellationToken = gameObject.GetCancellationTokenOnDestroy();
}
void Start()
{
panel = element.GetVisualElement().panel;
markSystem = BITSystems.GetOrCreate<MarkSystem>();
if (markSystem is not null)
{
markSystem.OnAdd += OnAdd;
markSystem.Update += OnUpdate;
markSystem.OnRemove += OnRemove;
}
}
void OnDestroy()
{
if (markSystem is not null)
{
markSystem.OnAdd -= OnAdd;
markSystem.Update -= OnUpdate;
markSystem.OnRemove -= OnRemove;
}
}
void OnAdd(IMarkObject markObject)
{
GetOrCreate(markObject.GetID());
}
async void OnRemove(IMarkObject markObject)
{
try
{
await UniTask.SwitchToMainThread(cancellationToken);
if (dictionary.TryGetValue(markObject.GetID(), out var label))
{
element.GetVisualElement().Remove(label);
dictionary.Remove(markObject.GetID());
}
}
catch (System.Exception e)
{
if (e is not OperationCanceledException)
throw;
}
}
async void OnUpdate(IMarkObject markObject)
{
var cameraTrans = Camera.main.transform;
try
{
await UniTask.SwitchToMainThread();
var active = markObject.GetAcitve();
var label = GetOrCreate(markObject.GetID());
if (active)
{
var pos = RuntimePanelUtils
.CameraTransformWorldToPanel(panel, markObject.GetPostion(), Camera.main);
pos.x = (pos.x - label.layout.width / 2);
Rect elementRect = new()
{
position = pos,
size = label.layout.size,
};
label.text = markObject.GetDisplay();
label.transform.position = pos;
if (Vector3.Dot(cameraTrans.forward, markObject.GetPostion() - cameraTrans.position) > 0)
{
label.SetActive(true);
}
else
{
label.SetActive(false);
}
}
else
{
label.SetActive(false);
}
}
catch (OperationCanceledException)
{
}
catch (System.Exception)
{
throw;
}
}
Label GetOrCreate(string id)
{
if (dictionary.TryGetValue(id, out var label))
{
}
else
{
label = new();
label.AddToClassList(className);
label.style.position = Position.Absolute;
dictionary.Add(id, label);
element.GetVisualElement().Add(label);
}
return label;
}
}
}

View File

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