Skip to content

Commit b6724da

Browse files
author
james7132
committed
Finalized testing of Particle Systems
Works even with non-symmetric bullets. I planned on moving the code for the rendering to a more generalized system in UnityUtilLib, but opted not to. "Don't break what's not broken".
1 parent 6390ccd commit b6724da

7 files changed

+25
-52
lines changed

Assets/External/DanmakU/Core/Danmaku.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,7 @@ public void MatchPrefab(DanmakuPrefab prefab) {
476476
layer = runtime.cachedLayer;
477477
colliderMask = collisionMask [layer];
478478

479-
IDanmakuController[] pcbs = runtime.ExtraControllers;
480-
if (pcbs.Length > 0) {
481-
for (int i = 0; i < pcbs.Length; i++) {
482-
controllerUpdate += pcbs[i].UpdateDanmaku;
483-
}
484-
}
479+
controllerUpdate += runtime.ExtraControllers;
485480
}
486481

487482
#region IPooledObject implementation

Assets/External/DanmakU/Core/DanmakuPool.cs

-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ internal class DanmakuPool : IPool<Danmaku> {
115115
//
116116
// #endregion
117117

118-
119-
120-
121-
122118
internal int[] queue;
123119
internal Danmaku[] all;
124120

Assets/External/DanmakU/Core/DanmakuPrefab.cs

+16-33
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,24 @@ static DanmakuPrefab() {
4343
hiddenParticle.axisOfRotation = Vector3.forward;
4444
}
4545

46+
47+
4648
[SerializeField]
4749
private IDanmakuController[] extraControllers;
48-
internal IDanmakuController[] ExtraControllers {
50+
51+
private DanmakuController controllerAggregate;
52+
53+
internal DanmakuController ExtraControllers {
4954
get {
50-
return extraControllers;
55+
return controllerAggregate;
5156
}
5257
}
5358

5459
public void Add(Danmaku danmaku) {
55-
// Debug.Log("Add");
56-
// if (currentDanmaku == null) {
57-
// currentDanmaku = new Danmaku[128];
58-
// }
59-
// danmakuCount++;
60-
// if (danmakuCount >= currentDanmaku.Length) {
61-
// Danmaku[] temp = new Danmaku[Mathf.NextPowerOfTwo(danmakuCount + 1)];
62-
// System.Array.Copy(currentDanmaku, temp, currentDanmaku.Length);
63-
// currentDanmaku = temp;
64-
// }
65-
// danmaku.renderIndex = danmakuCount;
66-
// currentDanmaku [danmakuCount] = danmaku;
6760
currentDanmaku.Add(danmaku);
6861
}
6962

7063
public void Remove(Danmaku danmaku) {
71-
// Debug.Log("remove");
72-
// int deadIndex = danmaku.poolIndex;;
73-
// Danmaku temp = currentDanmaku [danmakuCount];
74-
// currentDanmaku [danmakuCount] = danmaku;
75-
// currentDanmaku [deadIndex] = temp;
76-
// danmaku.renderIndex = danmakuCount;
77-
// danmaku.renderIndex = deadIndex;
78-
// danmakuCount--;
7964
currentDanmaku.Remove(danmaku);
8065
}
8166

@@ -94,9 +79,7 @@ void Update() {
9479
}
9580

9681
int count2 = runtimeSystem.GetParticles(particles);
97-
// if(count > count2) {
98-
// Debug.Log(count + ", " + count2);
99-
// }
82+
Debug.Log(count2);
10083
Vector3 forward = Vector3.forward;
10184
bool done;
10285
IEnumerator<Danmaku> enumerator = currentDanmaku.GetEnumerator();
@@ -165,18 +148,16 @@ void Update() {
165148
}
166149
}
167150
}
168-
169-
// for(; index < count; index++) {
170-
// particles[index].lifetime = 10000;
171-
// particles[index].position = Vector2.up * 20;
172-
// particles[index].size = 0f;
173-
// }
174151
runtimeSystem.SetParticles(particles, danmakuCount);
175152
}
176153

177154
public override void Awake() {
178155
base.Awake();
179156

157+
for (int i = 0; i < extraControllers.Length; i++) {
158+
controllerAggregate += extraControllers[i].UpdateDanmaku;
159+
}
160+
180161
GetComponent<SpriteRenderer>().enabled = false;
181162
GetComponent<CircleCollider2D>().enabled = false;
182163

@@ -203,14 +184,15 @@ public override void Awake() {
203184
runtimeSystem.gravityModifier = 0f;
204185
runtimeSystem.startSpeed = 0f;
205186
runtimeSystem.enableEmission = false;
206-
207-
runtimeSystem.Emit(runtimeSystem.maxParticles);
208187

209188
particles = new ParticleSystem.Particle[runtimeSystem.particleCount];
210189

211190
Material renderMaterial = new Material(Material);
212191
renderMaterial.mainTexture = Sprite.texture;
213192

193+
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
194+
propertyBlock.AddTexture("_MainTex", Sprite.texture);
195+
214196
if (useMesh) {
215197
spriteMesh = new Mesh();
216198

@@ -241,6 +223,7 @@ public override void Awake() {
241223
runtimeRenderer.renderMode = ParticleSystemRenderMode.Billboard;
242224
}
243225
runtimeRenderer.sharedMaterial = renderMaterial;
226+
runtimeRenderer.SetPropertyBlock(propertyBlock);
244227
runtimeRenderer.sortingLayerID = cachedSortingLayer;
245228
runtimeRenderer.sortingOrder = cachedSortingOrder;
246229
runtimeRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;

Assets/External/DanmakU/Core/DanmakuStatic.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ public static void DeactivateInCircle(Vector2 center, float radius, int layerMas
111111
public static void DirectDeactivateInCircle(Vector2 center, float radius, int layerMask = ~0) {
112112
Danmaku[] all = danmakuPool.all;
113113
Danmaku target;
114-
float sqrRadius = radius * radius, DRadius;
114+
float sqrRadius = radius * radius;
115115
for (int i = 0; i < all.Length; i++) {
116116
target = all[i];
117117
if((layerMask & (1 << target.layer)) != 0) {
118-
DRadius = target.colliderRadius;
119118
if(sqrRadius >= (target.Position - center).sqrMagnitude) {
120119
target.DeactivateImmediate();
121120
}

Assets/Testing/Danmaku Particle System.prefab

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ ParticleSystem:
203203
rgba: 4294967295
204204
maxColor:
205205
serializedVersion: 2
206-
rgba: 4278190335
206+
rgba: 4294967295
207207
minMaxState: 0
208208
startSize:
209209
scalar: 1
@@ -289,7 +289,7 @@ ParticleSystem:
289289
m_Mesh: {fileID: 0}
290290
randomDirection: 0
291291
EmissionModule:
292-
enabled: 1
292+
enabled: 0
293293
m_Type: 0
294294
rate:
295295
scalar: 10
@@ -1113,7 +1113,7 @@ ParticleSystemRenderer:
11131113
m_LengthScale: 2
11141114
m_SortingFudge: 0
11151115
m_NormalDirection: 1
1116-
m_SortMode: 3
1116+
m_SortMode: 2
11171117
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
11181118
m_Mesh1: {fileID: 0}
11191119
m_Mesh2: {fileID: 0}

Assets/Testing/Danmaku Prefab.prefab

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ MonoBehaviour:
7373
- '[]'
7474
- '{"$content":1}'
7575
- '{"$content":2}'
76-
- true
76+
- false
7777
_id: 0
7878
dbg: 0
7979
circleCollider: {fileID: 5818048}
8080
spriteRenderer: {fileID: 21290588}
81-
symmetric: 1
81+
symmetric: 0
8282
danmakuParticlePrefab: {fileID: 19897468, guid: f56f0572d67cbfa4f818e56887908592,
8383
type: 2}
8484
useMesh: 1

Assets/Testing/Test Scene 2.unity

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ MonoBehaviour:
205205
playerSpawnLocation: {x: .5, y: .25}
206206
camera2D: {fileID: 1407123246}
207207
camera3D: {fileID: 0}
208-
bottomLeft: {x: -26.638298, y: -20}
208+
bottomLeft: {x: -26.7073174, y: -20}
209209
viewportRect:
210210
serializedVersion: 2
211211
x: 0
@@ -284,7 +284,7 @@ MonoBehaviour:
284284
range: 0
285285
Count:
286286
type: 0
287-
centerValue: 500
287+
centerValue: 20
288288
range: 0
289289
DeltaVelocity:
290290
type: 0

0 commit comments

Comments
 (0)