Esempio n. 1
0
        // 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++;
        }
        // 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++;
            }
        }
Esempio n. 3
0
        // 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++;
            }
        }