2023-06-05 19:57:17 +08:00
|
|
|
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();
|
|
|
|
}
|
2023-08-11 23:57:37 +08:00
|
|
|
|
|
|
|
public interface IMarkSystem
|
|
|
|
{
|
|
|
|
event Action<IMarkObject> OnAdd;
|
|
|
|
event Action<IMarkObject> OnUpdate;
|
|
|
|
event Action<IMarkObject> OnRemove;
|
|
|
|
void Add(IMarkObject markObject);
|
|
|
|
void Remove(IMarkObject markObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class MarkSystemMonoProxy:IMarkSystem
|
|
|
|
{
|
|
|
|
[SerializeReference] private MonoBehaviour monoBehaviour;
|
|
|
|
private IMarkSystem _markSystemImplementation=>monoBehaviour as IMarkSystem;
|
|
|
|
public event Action<IMarkObject> OnAdd
|
|
|
|
{
|
|
|
|
add => _markSystemImplementation.OnAdd += value;
|
|
|
|
remove => _markSystemImplementation.OnAdd -= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action<IMarkObject> OnUpdate
|
|
|
|
{
|
|
|
|
add => _markSystemImplementation.OnUpdate += value;
|
|
|
|
remove => _markSystemImplementation.OnUpdate -= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action<IMarkObject> OnRemove
|
|
|
|
{
|
|
|
|
add => _markSystemImplementation.OnRemove += value;
|
|
|
|
remove => _markSystemImplementation.OnRemove -= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Add(IMarkObject markObject)
|
|
|
|
{
|
|
|
|
_markSystemImplementation.Add(markObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(IMarkObject markObject)
|
|
|
|
{
|
|
|
|
_markSystemImplementation.Remove(markObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class MarkSystemSingleton:IMarkSystem
|
2023-06-05 19:57:17 +08:00
|
|
|
{
|
2023-08-11 23:57:37 +08:00
|
|
|
private IMarkSystem _markSystemImplementation=>MarkSystem.Singleton;
|
|
|
|
public event Action<IMarkObject> OnAdd
|
|
|
|
{
|
|
|
|
add => _markSystemImplementation.OnAdd += value;
|
|
|
|
remove => _markSystemImplementation.OnAdd -= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action<IMarkObject> OnUpdate
|
|
|
|
{
|
|
|
|
add => _markSystemImplementation.OnUpdate += value;
|
|
|
|
remove => _markSystemImplementation.OnUpdate -= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action<IMarkObject> OnRemove
|
|
|
|
{
|
|
|
|
add => _markSystemImplementation.OnRemove += value;
|
|
|
|
remove => _markSystemImplementation.OnRemove -= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Add(IMarkObject markObject)
|
|
|
|
{
|
|
|
|
_markSystemImplementation.Add(markObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(IMarkObject markObject)
|
|
|
|
{
|
|
|
|
_markSystemImplementation.Remove(markObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class MarkSystem : MonoBehaviour,IMarkSystem
|
|
|
|
{
|
|
|
|
internal static IMarkSystem Singleton { get; private set; }
|
|
|
|
public event Action<IMarkObject> OnAdd;
|
|
|
|
public event Action<IMarkObject> OnUpdate;
|
|
|
|
public event Action<IMarkObject> OnRemove;
|
2023-06-05 19:57:17 +08:00
|
|
|
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);
|
|
|
|
}
|
2023-08-11 23:57:37 +08:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
Singleton = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
2023-06-05 19:57:17 +08:00
|
|
|
{
|
|
|
|
foreach (var markObject in markObjects.ToArray())
|
|
|
|
{
|
2023-08-11 23:57:37 +08:00
|
|
|
OnUpdate?.Invoke(markObject);
|
2023-06-05 19:57:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|