47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using Quadtree;
|
|
using Quadtree.Items;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Industry
|
|
{
|
|
public class UnityTechServiceBase<T> : MonoBehaviour where T : IItem<T, Node<T>>
|
|
{
|
|
private static readonly CacheList<T> _devices = new();
|
|
public static void Register(T device)
|
|
{
|
|
_devices.Add(device);
|
|
_quadtreeRoot.Insert(device);
|
|
}
|
|
public static void UnRegister(T device)
|
|
{
|
|
_devices.Remove(device);
|
|
_quadtreeRoot.Remove(device);
|
|
}
|
|
|
|
public static T[] SearchDevice(Vector3 position, float radius)
|
|
{
|
|
return _quadtreeRoot.Find(new Bounds(position, Vector3.one * radius)).ToArray();
|
|
}
|
|
private static readonly QuadtreeRoot<T, Node<T>> _quadtreeRoot =
|
|
new(default, Vector3.one * 1024f);
|
|
|
|
[SerializeReference, SubclassSelector] private ITicker ticker;
|
|
|
|
protected void Start()
|
|
{
|
|
ticker.Add(OnTick);
|
|
destroyCancellationToken.Register(Dispose);
|
|
}
|
|
protected virtual void OnTick(float obj){}
|
|
protected virtual void Dispose()
|
|
{
|
|
ticker.Remove(OnTick);
|
|
}
|
|
}
|
|
}
|
|
|