-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace DanmakU { | ||
|
||
public class DestroyDanmakuCollider : MonoBehaviour { | ||
|
||
public DanmakuCollider Collider; | ||
|
||
/// <summary> | ||
/// This function is called when the object becomes enabled and active. | ||
/// </summary> | ||
void OnEnable() { | ||
if (Collider != null) { | ||
Debug.Log("Subscribed"); | ||
Collider.OnDanmakuCollision += OnDanmakuCollision; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This function is called when the behaviour becomes disabled or inactive. | ||
/// </summary> | ||
void OnDisable() { | ||
if (Collider != null) { | ||
Collider.OnDanmakuCollision -= OnDanmakuCollision; | ||
} | ||
} | ||
|
||
void OnDanmakuCollision(DanmakuCollisionList collisions) { | ||
foreach (var collision in collisions) { | ||
collision.Danmaku.Destroy(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Reset is called when the user hits the Reset button in the Inspector's | ||
/// context menu or when adding the component the first time. | ||
/// </summary> | ||
void Reset() { | ||
Collider = GetComponent<DanmakuCollider>(); | ||
} | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace DanmakU { | ||
|
||
public struct DanmakuCollision { | ||
public Danmaku Danmaku; | ||
public RaycastHit2D RaycastHit; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Unity.Collections.LowLevel.Unsafe; | ||
|
||
namespace DanmakU { | ||
|
||
/// <summary> | ||
/// A read-only list of Danmaku. | ||
/// </summary> | ||
public struct DanmakuCollisionList : IReadOnlyList<DanmakuCollision> { | ||
|
||
readonly DanmakuCollision[] Array; | ||
public int Count { get; } | ||
|
||
internal DanmakuCollisionList(DanmakuCollision[] array, int count) { | ||
Array = array; | ||
Count = count; | ||
} | ||
|
||
public DanmakuCollision this[int index] { | ||
get { | ||
if (index < 0 && index >= Count) { | ||
throw new IndexOutOfRangeException(nameof(index)); | ||
} | ||
return Array[index]; | ||
} | ||
} | ||
|
||
public Enumerator GetEnumerator() => new Enumerator(this); | ||
IEnumerator<DanmakuCollision> IEnumerable<DanmakuCollision>.GetEnumerator() => GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
public struct Enumerator : IEnumerator<DanmakuCollision> { | ||
|
||
readonly DanmakuCollisionList list; | ||
int currentIndex; | ||
public DanmakuCollision Current => list[currentIndex]; | ||
object IEnumerator.Current => Current; | ||
|
||
internal Enumerator(DanmakuCollisionList list) { | ||
this.list = list; | ||
currentIndex = -1; | ||
} | ||
|
||
public bool MoveNext() { | ||
currentIndex++; | ||
return currentIndex < list.Count; | ||
} | ||
|
||
public void Reset() => currentIndex = -1; | ||
|
||
public void Dispose() {} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Unity.Collections.LowLevel.Unsafe; | ||
|
||
namespace DanmakU { | ||
|
||
internal class MutableDanmakuCollisionList { | ||
|
||
const int kDefaultCapacity = 16; | ||
const int kGrowthFactor = 2; | ||
|
||
DanmakuCollision[] Array; | ||
public int Capacity => Array?.Length ?? kDefaultCapacity; | ||
public int Count { get; private set; } | ||
|
||
public DanmakuCollisionList AsReadOnly() => new DanmakuCollisionList(Array, Count); | ||
|
||
public MutableDanmakuCollisionList() { | ||
Array = new DanmakuCollision[kDefaultCapacity]; | ||
} | ||
|
||
public void Add(DanmakuCollision obj) { | ||
if (Contains(obj)) return; | ||
CheckCapacity(1); | ||
Array[Count++] = obj; | ||
} | ||
|
||
public bool Contains(DanmakuCollision obj) { | ||
if (Count <= 1024) { | ||
bool contained = false; | ||
for (var i = 0; i < Count; i++) { | ||
contained |= Array[i].Danmaku == obj.Danmaku; | ||
} | ||
return contained; | ||
} else { | ||
for (var i = 0; i < Count; i++) { | ||
if (Array[i].Danmaku== obj.Danmaku) return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
public void Clear() => Count = 0; | ||
|
||
void CheckCapacity(int count) { | ||
if (Count + count <= Capacity) return; | ||
var newArray = new DanmakuCollision[Capacity * kGrowthFactor]; | ||
System.Array.Copy(Array, 0, newArray, 0, Count); | ||
Array = newArray; | ||
} | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.