コード例 #1
0
        public ParticleSystem(ParticleSettings settings, Effect effect)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (effect == null) throw new ArgumentNullException("effect");
            if (settings.Texture == null) throw new ArgumentException("Texture is null.");

            Enabled = true;

            this.settings = settings;

            //----------------------------------------------------------------
            // システム名

            Name = settings.Name;

            //----------------------------------------------------------------
            // エフェクト

            particleEffect = new ParticleEffect(effect);
            particleEffect.Initialize(settings, settings.Texture);

            graphicsDevice = particleEffect.GraphicsDevice;

            //----------------------------------------------------------------
            // パーティクル

            particles = new ParticleVertex[settings.MaxParticles * 4];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            //----------------------------------------------------------------
            // 頂点バッファ

            vertexBuffer = new DynamicVertexBuffer(
                graphicsDevice, ParticleVertex.VertexDeclaration, settings.MaxParticles * 4, BufferUsage.WriteOnly);

            //----------------------------------------------------------------
            // インデックス バッファ

            var indices = new ushort[settings.MaxParticles * 6];
            for (int i = 0; i < settings.MaxParticles; i++)
            {
                indices[i * 6 + 0] = (ushort) (i * 4 + 0);
                indices[i * 6 + 1] = (ushort) (i * 4 + 1);
                indices[i * 6 + 2] = (ushort) (i * 4 + 2);

                indices[i * 6 + 3] = (ushort) (i * 4 + 0);
                indices[i * 6 + 4] = (ushort) (i * 4 + 2);
                indices[i * 6 + 5] = (ushort) (i * 4 + 3);
            }

            indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
        }
コード例 #2
0
    private void Init_ParticleEffect()
    {
        deactiveParticlePoolDic = new Dictionary <string, List <ParticleEffect> >();
        activeParticlePoolDic   = new Dictionary <string, List <ParticleEffect> >();

        for (int rootIdx = 0; rootIdx < transform.childCount; ++rootIdx)
        {
            Transform poolTrans = transform.GetChild(rootIdx);

            List <ParticleEffect> deActivePool = new List <ParticleEffect>();
            for (int particleIdx = 0; particleIdx < poolTrans.childCount; ++particleIdx)
            {
                ParticleEffect newEffect = poolTrans.GetChild(particleIdx).GetComponent <ParticleEffect>();
                newEffect.Initialize(poolTrans.name, OverParticleReturnToPool);
                deActivePool.Add(newEffect);
            }
            deactiveParticlePoolDic.Add(poolTrans.name, deActivePool);

            List <ParticleEffect> activePool = new List <ParticleEffect>();
            activeParticlePoolDic.Add(poolTrans.name, activePool);
        }
    }
コード例 #3
0
        public ParticleSystem(ParticleSettings settings, Effect effect)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }
            if (settings.Texture == null)
            {
                throw new ArgumentException("Texture is null.");
            }

            Enabled = true;

            this.settings = settings;

            //----------------------------------------------------------------
            // システム名

            Name = settings.Name;

            //----------------------------------------------------------------
            // エフェクト

            particleEffect = new ParticleEffect(effect);
            particleEffect.Initialize(settings, settings.Texture);

            graphicsDevice = particleEffect.GraphicsDevice;

            //----------------------------------------------------------------
            // パーティクル

            particles = new ParticleVertex[settings.MaxParticles * 4];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            //----------------------------------------------------------------
            // 頂点バッファ

            vertexBuffer = new DynamicVertexBuffer(
                graphicsDevice, ParticleVertex.VertexDeclaration, settings.MaxParticles * 4, BufferUsage.WriteOnly);

            //----------------------------------------------------------------
            // インデックス バッファ

            var indices = new ushort[settings.MaxParticles * 6];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                indices[i * 6 + 0] = (ushort)(i * 4 + 0);
                indices[i * 6 + 1] = (ushort)(i * 4 + 1);
                indices[i * 6 + 2] = (ushort)(i * 4 + 2);

                indices[i * 6 + 3] = (ushort)(i * 4 + 0);
                indices[i * 6 + 4] = (ushort)(i * 4 + 2);
                indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
        }