···2121/// </remarks>
2222public struct Danmaku {
23232424- internal readonly int Index;
2424+ public readonly int Id;
2525 public readonly DanmakuPool Pool;
26262727 internal Danmaku(DanmakuPool pool, int index) {
2828 Pool = pool;
2929- Index = index;
2929+ Id = index;
3030 }
31313232 /// <summary>
3333 /// Gets the number of seconds since the Danmaku was created.
3434 /// </summary>
3535- public float Time => Pool.Times[Index];
3535+ public float Time => Pool.Times[Id];
36363737 /// <summary>
3838 /// Gets or sets the world position of the Danmaku.
3939 /// </summary>
4040 public Vector2 Position {
4141- get { return Pool.Positions[Index]; }
4242- set { Pool.Positions[Index] = value; }
4141+ get { return Pool.Positions[Id]; }
4242+ set { Pool.Positions[Id] = value; }
4343 }
44444545 /// <summary>
···5151 /// the Danmaku is moving in.
5252 /// </remarks>
5353 public float Rotation {
5454- get { return Pool.Rotations[Index]; }
5555- set { Pool.Rotations[Index] = value; }
5454+ get { return Pool.Rotations[Id]; }
5555+ set { Pool.Rotations[Id] = value; }
5656 }
57575858 /// <summary>
···6363 /// Can be negative.
6464 /// </remarks>
6565 public float Speed {
6666- get { return Pool.Speeds[Index]; }
6767- set { Pool.Speeds[Index] = value; }
6666+ get { return Pool.Speeds[Id]; }
6767+ set { Pool.Speeds[Id] = value; }
6868 }
69697070 /// <summary>
···7474 /// Units are in radians per second. Can be negative.
7575 /// </remarks>
7676 public float AngularSpeed {
7777- get { return Pool.AngularSpeeds[Index]; }
7878- set { Pool.AngularSpeeds[Index] = value; }
7777+ get { return Pool.AngularSpeeds[Id]; }
7878+ set { Pool.AngularSpeeds[Id] = value; }
7979 }
80808181 /// <summary>
8282 /// Gets or sets the Danmaku's rendering color.
8383 /// </summary>
8484 public Color Color {
8585- get { return Pool.Colors[Index]; }
8686- set { Pool.Colors[Index] = value; }
8585+ get { return Pool.Colors[Id]; }
8686+ set { Pool.Colors[Id] = value; }
8787 }
88888989 /// <summary>
+77
Assets/src/Core/DanmakuCollider.cs
···11+using System.Collections;
22+using System.Collections.Generic;
33+using UnityEngine;
44+using UnityEngine.Assertions;
55+66+namespace DanmakU {
77+88+public class DanmakuCollider : MonoBehaviour {
99+1010+ static readonly List<DanmakuCollider> Colliders;
1111+1212+ static DanmakuCollider() {
1313+ Colliders = new List<DanmakuCollider>();
1414+ }
1515+1616+ public static int ColliderCount => Colliders.Count;
1717+1818+ Collider2D[] colliders;
1919+ Bounds totalBounds;
2020+ int layerMask;
2121+2222+ /// <summary>
2323+ /// Awake is called when the script instance is being loaded.
2424+ /// </summary>
2525+ void Awake() {
2626+ colliders = GetComponentsInChildren<Collider2D>();
2727+ totalBounds = BuildBounds();
2828+ }
2929+3030+ /// <summary>
3131+ /// This function is called when the object becomes enabled and active.
3232+ /// </summary>
3333+ void OnEnable() => Colliders.Add(this);
3434+3535+ /// <summary>
3636+ /// This function is called when the behaviour becomes disabled or inactive.
3737+ /// </summary>
3838+ void OnDisable() => Colliders.Remove(this);
3939+4040+ /// <summary>
4141+ /// This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
4242+ /// </summary>
4343+ void FixedUpdate() {
4444+ totalBounds = BuildBounds();
4545+ layerMask = 1 << gameObject.layer;
4646+ }
4747+4848+ internal static int TestCollisions(Bounds bounds) {
4949+ int collisions = 0;
5050+ foreach (var collider in Colliders) {
5151+ if (!collider.totalBounds.Intersects(bounds)) continue;
5252+ collisions |= collider.layerMask;
5353+ }
5454+ return collisions;
5555+ }
5656+5757+ public Bounds BuildBounds() {
5858+ Bounds? bounds = null;
5959+ foreach (var collider in colliders) {
6060+ if (collider != null && collider.enabled && collider.gameObject.activeInHierarchy) {
6161+ if (bounds == null) {
6262+ bounds = collider.bounds;
6363+ } else {
6464+ bounds.Value.Encapsulate(collider.bounds);
6565+ }
6666+ }
6767+ }
6868+ var fullBounds = bounds ?? new Bounds(transform.position, Vector3.zero);
6969+ var extents = fullBounds.extents;
7070+ extents.z = float.PositiveInfinity;
7171+ fullBounds.extents = extents;
7272+ return fullBounds;
7373+ }
7474+7575+}
7676+7777+}