Ejemplo n.º 1
0
        void Start()
        {
            capacity = ShaderUtil.PowerOfTwo(capacity);

            Positions      = new PositionService(compute, capacity);
            Velocities     = new VelocityService(compute, capacity);
            Lifes          = new LifeService(compute, capacity);
            Constants      = new ConstantService(capacity, constants);
            VelSimulation  = new VelocitySimulation(compute, Velocities, Constants);
            PosSimulation  = new PositionSimulation(compute, Velocities, Positions);
            Collisions     = new HashGrid(compute, computeSort, Lifes, Positions, GenerateGrid());
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Collisions);
            BoundsChecker  = new BoundsChecker(compute, Lifes, Positions);
            Polygons       = new PolygonColliderService();
            PolygonSolver  = new PolygonCollisionSolver(compute, Velocities, Positions, Lifes, Polygons);

            var particles = new GameObject[capacity];

            foreach (var pfab in particlefabs)
            {
                pfab.transform.localScale = 2f * constants.radius * Vector3.one;
            }
            Profiler.BeginSample("Instantiate Particles");
            for (var i = 0; i < capacity; i++)
            {
                var pfab = particlefabs[Random.Range(0, particlefabs.Length)];
                particles[i] = (GameObject)Instantiate(pfab, Vector3.zero, Random.rotationUniform);
            }
            Profiler.EndSample();
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);
            for (var i = 0; i < capacity; i++)
            {
                Destroy(particles[i]);
            }

            UpdateConstantData();
            _initialized = true;
        }
Ejemplo n.º 2
0
        void Start()
        {
            capacity = ShaderUtil.PowerOfTwo(capacity);

            Positions = new PositionService(compute, capacity);
            Velocities = new VelocityService(compute, capacity);
            Lifes = new LifeService(compute, capacity);
            Constants = new ConstantService(capacity, constants);
            VelSimulation = new VelocitySimulation(compute, Velocities, Constants);
            PosSimulation = new PositionSimulation(compute, Velocities, Positions);
            Collisions = new HashGrid(compute, computeSort, Lifes, Positions, GenerateGrid());
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Collisions);
            BoundsChecker = new BoundsChecker(compute, Lifes, Positions);
            Polygons = new PolygonColliderService();
            PolygonSolver = new PolygonCollisionSolver(compute, Velocities, Positions, Lifes, Polygons);

            var particles = new GameObject[capacity];
            foreach (var pfab in particlefabs)
                pfab.transform.localScale = 2f * constants.radius * Vector3.one;
            Profiler.BeginSample("Instantiate Particles");
            for (var i = 0; i < capacity; i++) {
                var pfab = particlefabs[Random.Range(0, particlefabs.Length)];
                particles[i] = (GameObject)Instantiate(pfab, Vector3.zero, Random.rotationUniform);
            }
            Profiler.EndSample();
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);
            for (var i = 0; i < capacity; i++)
                Destroy(particles[i]);

            UpdateConstantData();
            _initialized = true;
        }