コード例 #1
0
        /// <summary>
        /// 指定した頂点位置にパーティクルを生成する
        /// </summary>
        /// <param name="vertices">頂点郡</param>
        /// <param name="particleCount">頂点ごとのパーティクル数</param>
        public void EmitWithVertices(Vector3[] vertices, int particleCount, float delay = 0)
        {
            ParticleParam[] paramList = new ParticleParam[vertices.Length];

            for (int i = 0; i < vertices.Length; i++)
            {
                ParticleParam p = DefaultParam;
                p.Position   = vertices[i];
                p.Delay      = delay;
                paramList[i] = p;
            }

            Burst(paramList, particleCount);
        }
コード例 #2
0
        /// <summary>
        /// パーティクルをエミットする
        /// </summary>
        /// <param name="p">パーティクル設定</param>
        /// <param name="count">パーティクル数</param>
        public void Emit(ParticleParam p, int count)
        {
            if (!_isInitialized)
            {
                Initialize();
            }

            _computeShader.SetBuffer(_emitKernel, _particlesId, _particlesBuffer);
            _computeShader.SetBuffer(_emitKernel, _particlePoolId, _particlePoolBuffer);
            _computeShader.SetVector(_positionId, CurlParticleUtility.GetRandomVector(p.Position, _randomRange));
            _computeShader.SetVector(_colorId, p.Color);
            _computeShader.SetFloat(_minLifeTimeId, _minLifeTime);
            _computeShader.SetFloat(_maxLifeTimeId, _maxLifeTime);
            _computeShader.SetFloat(_delayId, p.Delay);
            _computeShader.SetFloat(_scaleId, 1.0f);
            _computeShader.SetFloat(_baseScaleId, _baseScale);

            int poolSize = GetParticlePoolSize() / 8;

            if (poolSize <= 0)
            {
                return;
            }

            int countSize = count / 8;
            int size      = Mathf.Min(countSize, poolSize);

            _computeShader.Dispatch(_emitKernel, size, 1, 1);

            float lifeTime = _maxLifeTime + p.Delay;

            if (lifeTime > _lifeTime)
            {
                _lifeTime = lifeTime;
            }

            Activate();
        }