// Adds a new emitter at runtime public void AddEmitter(ProjectileEmitterBase emitter, int allocation) { // Default projectile if no projectile type set if (emitter.ProjectilePrefab == null) { emitter.ProjectilePrefab = GetProjectilePrefab(0); } // Increment group counter ProjectileTypeCounters[emitter.ProjectilePrefab.Index].TotalGroups++; // Should be a way to not allocate more than projectile type will allow - across all emitters emitter.Initialize(allocation); EmitterCount++; }
protected void Start() { // Get the components attached to your character. Animator commented out for still sprite testing rigidbody2d = GetComponentInChildren <Rigidbody2D>(); //collider = GetComponent<Collider2D>(); sprite = GetComponentInChildren <SpriteRenderer>(); shooter = GetComponentInChildren <BulletHell.ProjectileEmitterBase>(); instance = this; m_speed = GameplayParameters.instance.PlayerSpeed; CustomEvents.EventUtil.AddListener(CustomEventList.PARAMETER_CHANGE, OnParameterChange); CustomEvents.EventUtil.AddListener(CustomEventList.GAME_PAUSED, OnGamePause); CustomEvents.EventUtil.AddListener(CustomEventList.SLOW_TIME, OnSlowTime); }
// When adding emitter during play mode - you can register them with this function public void RegisterEmitter(ProjectileEmitterBase emitter) { // Should probably use Emittercount here int nextEmpty = -1; for (int n = 0; n < EmittersArray.Length; n++) { if (EmittersArray[n] == null) { nextEmpty = n; } } if (nextEmpty == -1) { Debug.Log("Max Emitters reached. Raise MaxEmitters if you need more. Max set to " + MaxEmitters + "."); } else { EmittersArray[nextEmpty] = emitter; ProjectileTypeCounters[emitter.ProjectileType.Index].TotalGroups++; int projectilesToAssign = emitter.ProjectilePoolSize; if (projectilesToAssign == -1) { emitter.ProjectilePoolSize = 1000; projectilesToAssign = 1000; } // Old code to auto assign pool sizes based on total Projectile Group -- would split allocation across all emitters. // This turns out to be problematic when adding/removing emitters on the fly. // New system will allocate per the emitter. // Total projectiles value not set on Emitter, Calculate max based on total groups even distribution //if (projectilesToAssign < 0) //{ // projectilesToAssign = emitter.ProjectileType.MaxProjectileCount / ProjectileTypeCounters[emitter.ProjectileType.Index].TotalGroups; //} // Initialize Emitter pool size emitter.Initialize(projectilesToAssign); ProjectileTypeCounters[emitter.ProjectileType.Index].TotalProjectilesAssigned += projectilesToAssign; EmitterCount++; } }
// Start is called before the first frame update protected void Start() { if (m_sprite == null) { m_sprite = this.GetComponentInChildren <SpriteRenderer>(); } if (m_emitter == null) { m_emitter = this.GetComponentInChildren <BulletHell.ProjectileEmitterBase>(); } SetActive(false); CustomEvents.EventUtil.AddListener(CustomEventList.PARAMETER_CHANGE, OnParameterChange); CustomEvents.EventUtil.AddListener(CustomEventList.GAME_PAUSED, OnGamePause); CustomEvents.EventUtil.AddListener(CustomEventList.SLOW_TIME, OnSlowTime); //OnParameterChange(); }
// When adding emitter during play mode - you can register them with this function public void RegisterEmitter(ProjectileEmitterBase emitter) { // Should probably use Emittercount here - find the next empty slot in the array int nextEmpty = -1; for (int n = 0; n < EmittersArray.Length; n++) { if (EmittersArray[n] == null) { nextEmpty = n; } } if (nextEmpty == -1) { Debug.Log("Max Emitters reached. Raise MaxEmitters if you need more. Max set to " + MaxEmitters + "."); } else { EmittersArray[nextEmpty] = emitter; ProjectileTypeCounters[emitter.ProjectilePrefab.Index].TotalGroups++; int projectilesToAssign = emitter.ProjectilePrefab.GetMaxProjectileCount(); if (projectilesToAssign == -1) { //emitter.ProjectilePoolSize = 1000; projectilesToAssign = 1000; } // Initialize Emitter pool size emitter.Initialize(projectilesToAssign); ProjectileTypeCounters[emitter.ProjectilePrefab.Index].TotalProjectilesAssigned += projectilesToAssign; EmitterCount++; } }