Example #1
0
        void IJobParallelFor.Execute(int i)
        {
            PheroStruct p = input[i];

            if (input[i].SpecialType == 1)             //repel
            {
                result[i] = new ParticleSystem.Particle
                {
                    position   = p.position,
                    startColor = new Color                     //rgb(91%,34%,98%)
                    {
                        r = .91f,
                        g = .34f,
                        b = .98f,
                        a = p.Strength * 3f,
                    },
                    startSize         = settings[0].particleSize * 2.2f,
                    remainingLifetime = 0,
                };
            }
            else if (input[i].SpecialType == 2)             //attract
            {
                float m = Mathf.Abs((settings[0].time + p.Strength * 150f) % 1f - 0.5f) * .5f + 0.75f;
                result[i] = new ParticleSystem.Particle
                {
                    position   = p.position,
                    startColor = new Color                     //rgb(34%,98%,52%)
                    {
                        r = .34f * m,
                        g = .98f * m,
                        b = .52f * m,
                        a = p.Strength * 4f,
                    },
                    startSize         = settings[0].particleSize * 1.4f,
                    remainingLifetime = 0,
                };
            }
            else
            {
                result[i] = new ParticleSystem.Particle
                {
                    position   = p.position,
                    startColor = new Color
                    {
                        r = (p.FoodDistance + p.HomeDistance) * .5f + p.Confusion,
                        g = p.FoodDistance * 0.1f,
                        b = (p.HomeDistance * 0.1f) + p.Confusion,
                        a = p.Strength * 0.6f,
                    },
                    startSize         = settings[0].particleSize,
                    remainingLifetime = 0,
                };
            }
        }
Example #2
0
    private static void UpdateParticles(NativeArray <PheroStruct> pheromones, NativeArray <ParticleSystem.Particle> target)
    {
        int count = pheromones.Length;

        for (int i = 0; i < count; i++)
        {
            PheroStruct p = pheromones[i];
            target[i] = new ParticleSystem.Particle
            {
                position   = p.position,
                startColor = new Color
                {
                    r = (p.FoodDistance + p.HomeDistance) * .5f + p.Confusion,
                    g = p.FoodDistance * 0.1f,
                    b = (p.HomeDistance * 0.1f) + p.Confusion,
                    a = p.Strength * 0.5f,
                },
                startSize         = 0.3f,
                remainingLifetime = 5,
            };
        }
    }
Example #3
0
 public void RenderThreaded(List <PheromoneModel> pheromones)
 {
     currentSettings.time = Time.time % 1f;
     if (CurrentState == RenderState.IDLE)
     {
         pheroCount = pheromones.Count;
         NativeArray <PheroStruct> input    = PheromoneInputBuffer;
         NativeArray <Settings>    settings = SettingsNativeArray;
         settings[0] = currentSettings;
         for (int i = 0; i < pheroCount; i++)
         {
             input[i] = PheroStruct.FromModel(pheromones[i]);
         }
         ParallelUpdate job = new ParallelUpdate
         {
             settings = SettingsNativeArray,
             input    = input,
             result   = JobResult,
         };
         jobHandle    = job.Schedule(pheroCount, 1024);          //maybe smaller batch size for mobile??
         CurrentState = RenderState.RENDERING;
     }
 }