internal static unsafe void TestPoolCollisions(DanmakuPool pool) { var layersPtr = (int * )(pool.CollisionMasks.GetUnsafePtr()); var count = pool.ActiveCount; for (var i = 0; i < count; i++) { if (*layersPtr++ == 0) { continue; } var layerMask = pool.CollisionMasks[i]; var oldPosition = pool.OldPositions[i]; var direction = pool.Positions[i] - oldPosition; var distance = direction.magnitude; var hits = Physics2D.CircleCastNonAlloc(oldPosition, pool.ColliderRadius, direction, raycastCache, distance, layerMask); if (hits <= 0) { continue; } var danmaku = new Danmaku(pool, i); for (var j = 0; j < hits; j++) { var collider = raycastCache[j].collider; List <DanmakuCollider> danmakuColliders; if (!ColliderMap.TryGetValue(collider, out danmakuColliders)) { continue; } var collision = new DanmakuCollision { Danmaku = danmaku, RaycastHit = raycastCache[j] }; foreach (var dCollider in danmakuColliders) { if (dCollider != null && dCollider.isActiveAndEnabled) { dCollider.AddDanmaku(collision); } } } } }
/// <summary> /// Instantaneously translates all of the Danmaku in the collections by a specified change in position. /// All contained null objects will be ignored. /// </summary> /// <param name="danmakus">The enumerable collection of Danmaku. Does nothing if it is null.</param> /// <param name="deltaPos">The change in position.</param> public static T Translate <T> (this T danmakus, Vector2 deltaPos) where T : class, IEnumerable <Danmaku> { if (danmakus == null) { return(null); } //if movement is nonexistent, don't waste time and return immediately if (deltaPos == new Vector2(0f, 0f)) { return(danmakus); } var arrayTest = danmakus as Danmaku[]; if (arrayTest != null) { for (int i = 0; i < arrayTest.Length; i++) { Danmaku danmaku = arrayTest[i]; if (danmaku != null) { danmaku.Position += deltaPos; } } } else { foreach (var danmaku in danmakus) { if (danmaku != null) { danmaku.Position += deltaPos; } } } return(danmakus); }
public static void GetInactive(FireData data, Danmaku[] prealloc) { if (danmakuPool == null) { new GameObject("Danmaku Game Controller").AddComponent <DanmakuGameController>(); } if (data == null) { throw new System.ArgumentNullException(); } danmakuPool.Get(prealloc); for (int i = 0; i < prealloc.Length; i++) { Danmaku danmaku = prealloc[i]; danmaku.MatchPrefab(data.Prefab); danmaku.position.x = data.Position.x; danmaku.position.y = data.Position.y; danmaku.Rotation = data.Rotation.Value; danmaku.Speed = data.Speed.Value; danmaku.AngularSpeed = data.AngularSpeed.Value; danmaku.AddController(data.Controller); danmaku.Damage = data.Damage.Value; } }
public static T Color <T> (this T danmakus, IList <Color> colors) where T : class, IEnumerable <Danmaku> { if (danmakus == null) { return(null); } if (colors == null) { throw new System.ArgumentNullException(); } int max = colors.Count; var arrayTest = danmakus as Danmaku[]; if (arrayTest != null) { for (int i = 0; i < arrayTest.Length; i++) { Danmaku danmaku = arrayTest[i]; if (danmaku != null) { danmaku.Color = colors[Random.Range(0, max)]; } } } else { foreach (var danmaku in danmakus) { if (danmaku != null) { danmaku.Color = colors[Random.Range(0, max)]; } } } return(danmakus); }
public static T Damage <T> (this T danmakus, IList <DynamicInt> damages) where T : class, IEnumerable <Danmaku> { if (danmakus == null) { return(null); } if (damages == null) { throw new System.ArgumentNullException(); } int max = damages.Count; var arrayTest = danmakus as Danmaku[]; if (arrayTest != null) { for (int i = 0; i < arrayTest.Length; i++) { Danmaku danmaku = arrayTest[i]; if (danmaku != null) { danmaku.Damage = damages[Random.Range(0, max)].Value; } } } else { foreach (var danmaku in danmakus) { if (danmaku != null) { danmaku.Damage = damages[Random.Range(0, max)].Value; } } } return(danmakus); }
public static T AngularSpeed <T> (this T danmakus, IList <DynamicFloat> angularSpeeds) where T : class, IEnumerable <Danmaku> { if (danmakus == null) { return(null); } if (angularSpeeds == null) { throw new System.ArgumentNullException(); } int max = angularSpeeds.Count; var arrayTest = danmakus as Danmaku[]; if (arrayTest != null) { for (int i = 0; i < arrayTest.Length; i++) { Danmaku danmaku = arrayTest[i]; if (danmaku != null) { danmaku.AngularSpeed = angularSpeeds[Random.Range(0, max)]; } } } else { foreach (var danmaku in danmakus) { if (danmaku != null) { danmaku.AngularSpeed = angularSpeeds[Random.Range(0, max)]; } } } return(danmakus); }
void Update() { danmakuCount = currentDanmaku.Count; int count = runtimeSystem.particleCount; if (danmakuCount > count) { runtimeSystem.maxParticles = Mathf.NextPowerOfTwo(danmakuCount); runtimeSystem.Emit(danmakuCount - count); count = danmakuCount; } if (danmakuCount > particles.Length) { particles = new ParticleSystem.Particle[Mathf.NextPowerOfTwo(danmakuCount + 1)]; } runtimeSystem.GetParticles(particles); //Debug.Log(count2); bool done; IEnumerator <Danmaku> enumerator = currentDanmaku.GetEnumerator(); if (fixedAngle) { for (int i = 0; i < danmakuCount; i++) { done = enumerator.MoveNext(); if (done) { Danmaku danmaku = enumerator.Current; particles[i].position = danmaku.position; particles[i].startSize = danmaku.Scale; particles[i].lifetime = 1000; particles[i].startColor = danmaku.Color; } else { particles[i].startSize = 0f; particles[i].lifetime = -1; } } } else { Vector3 forward = Vector3.forward; for (int i = 0; i < danmakuCount; i++) { done = enumerator.MoveNext(); if (done) { Danmaku danmaku = enumerator.Current; particles[i].position = danmaku.position; particles[i].rotation = danmaku.rotation; particles[i].startSize = danmaku.Scale; particles[i].axisOfRotation = forward; particles[i].startColor = danmaku.Color; if (particles[i].lifetime <= 1) { particles[i].lifetime = 1000; } } else { particles[i].startSize = 0f; particles[i].lifetime = -1; } } } runtimeSystem.SetParticles(particles, danmakuCount); }
internal void Remove(Danmaku danmaku) { currentDanmaku.Remove(danmaku); }
internal void Add(Danmaku danmaku) { currentDanmaku.Add(danmaku); }
public void Return(Danmaku obj) { queue [endIndex] = obj.poolIndex; endIndex = (endIndex + 1) % size; inactiveCount++; }
void Update() { //runtimeRenderer.GetPropertyBlock(mpb); //mpb.SetTexture("_MainTexture", cachedSprite.texture); //runtimeRenderer.SetPropertyBlock(mpb); danmakuCount = currentDanmaku.Count; int count = runtimeSystem.particleCount; if (danmakuCount > count) { //Debug.Log("hello"); runtimeSystem.maxParticles = Mathf.NextPowerOfTwo(danmakuCount); runtimeSystem.Emit(danmakuCount - count); //Debug.Log(runtimeSystem.particleCount); count = danmakuCount; } if (danmakuCount > particles.Length) { particles = new ParticleSystem.Particle[Mathf.NextPowerOfTwo(danmakuCount + 1)]; } runtimeSystem.GetParticles(particles); //Debug.Log(count2); bool done; IEnumerator <Danmaku> enumerator = currentDanmaku.GetEnumerator(); if (fixedAngle) { for (int i = 0; i < danmakuCount; i++) { done = enumerator.MoveNext(); if (done) { Danmaku danmaku = enumerator.Current; particles[i].position = danmaku.position; particles[i].size = danmaku.Scale; //particles[i].axisOfRotation = forward; particles[i].lifetime = 1000; particles[i].color = danmaku.Color; } else { particles[i].size = 0f; particles[i].lifetime = -1; } } } else { Vector3 forward = Vector3.forward; for (int i = 0; i < danmakuCount; i++) { done = enumerator.MoveNext(); if (done) { Danmaku danmaku = enumerator.Current; particles[i].position = danmaku.position; particles[i].rotation = danmaku.rotation; particles[i].size = danmaku.Scale; particles[i].axisOfRotation = forward; particles[i].color = danmaku.Color; if (particles[i].lifetime <= 1) { particles[i].lifetime = 1000; } } else { particles[i].size = 0f; particles[i].lifetime = -1; } } } runtimeSystem.SetParticles(particles, danmakuCount); }
/// <summary> /// Sets the firing origin to the current position of a bullet. /// </summary> /// /// <remarks> /// To move the origin of firing after calling this requries additional calls to this method. /// This will also 'un-link' the instance from any GameObjects. /// </remarks> /// <param name="danmaku">Danmaku.</param> public FireBuilder From(Danmaku danmaku) { Position = danmaku.Position; positionSource = null; return(this); }
/// <summary> /// Handles a Danmaku collision. Only ever called with Danmaku that pass the filter. /// </summary> /// <param name="danmaku">the danmaku that hit the collider.</param> /// <param name="info"> additional information about the collision</param> protected abstract void DanmakuCollision(Danmaku danmaku, RaycastHit2D info);
protected virtual void OnLevelWasLoaded(int level) { Danmaku.DeactivateAll(); }
public override void Awake() { base.Awake(); Danmaku.Setup(danmakuInitialCount, danmakuSpawnOnEmpty, angleResolution); }
public virtual void Update() { Danmaku.UpdateAll(); }