更改了文件结构
This commit is contained in:
125
Src/Unity/Scripts/MarkSystem/MarkSystem.cs
Normal file
125
Src/Unity/Scripts/MarkSystem/MarkSystem.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
foreach (var markObject in markObjects.ToArray())
|
||||
{
|
||||
OnUpdate?.Invoke(markObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user