Beispiel #1
0
        public MyParticleEffect CreateInstance()
        {
            MyParticleEffect effect = MyParticlesManager.EffectsPool.Allocate(true);

            if (effect != null)
            {
                effect.Start(m_particleID);

                effect.Name          = Name;
                effect.Enabled       = Enabled;
                effect.Length        = Length;
                effect.m_globalScale = m_globalScale;
                effect.LowRes        = LowRes;
                effect.Loop          = m_loop;
                effect.DurationMin   = m_durationMin;
                effect.DurationMax   = m_durationMax;
                effect.SetRandomDuration();

                foreach (IMyParticleGeneration generation in m_generations)
                {
                    IMyParticleGeneration gen = generation.CreateInstance(effect);
                    if (gen != null)
                    {
                        effect.AddGeneration(gen);
                    }
                }

                foreach (MyParticleLight particleLight in m_particleLights)
                {
                    MyParticleLight pl = particleLight.CreateInstance(effect);
                    if (pl != null)
                    {
                        effect.AddParticleLight(pl);
                    }
                }

                foreach (MyParticleSound particleSound in m_particleSounds)
                {
                    MyParticleSound ps = particleSound.CreateInstance(effect);
                    if (ps != null)
                    {
                        effect.AddParticleSound(ps);
                    }
                }

                if (m_instances == null)
                {
                    m_instances = new List <MyParticleEffect>();
                }

                m_instances.Add(effect);
            }

            return(effect);
        }
Beispiel #2
0
        public void AddParticleLight(MyParticleLight particleLight)
        {
            m_particleLights.Add(particleLight);

            if (m_instances != null)
            {
                foreach (MyParticleEffect effect in m_instances)
                {
                    effect.AddParticleLight(particleLight.CreateInstance(effect));
                }
            }
        }
        public MyParticleEffect CreateInstance()
        {
            MyParticleEffect effect = MyParticlesManager.EffectsPool.Allocate(true);

            if (effect != null)
            {
                effect.Start(m_particleID);

                effect.Name    = Name;
                effect.Enabled = Enabled;
                effect.SetLength(GetLength());
                effect.SetPreload(GetPreload());
                effect.LowRes = LowRes;

                foreach (IMyParticleGeneration generation in m_generations)
                {
                    IMyParticleGeneration gen = generation.CreateInstance(effect);
                    if (gen != null)
                    {
                        effect.AddGeneration(gen);
                    }
                }

                foreach (MyParticleLight particleLight in m_particleLights)
                {
                    MyParticleLight pl = particleLight.CreateInstance(effect);
                    if (pl != null)
                    {
                        effect.AddParticleLight(pl);
                    }
                }

                foreach (MyParticleSound particleSound in m_particleSounds)
                {
                    MyParticleSound ps = particleSound.CreateInstance(effect);
                    if (ps != null)
                    {
                        effect.AddParticleSound(ps);
                    }
                }

                if (m_instances == null)
                {
                    m_instances = new List <MyParticleEffect>();
                }

                m_instances.Add(effect);
            }

            return(effect);
        }
        public MyParticleLight Duplicate(MyParticleEffect effect)
        {
            MyParticleLight particleLight = MyParticlesManager.LightsPool.Allocate();

            particleLight.Start(effect);

            particleLight.Name = Name;

            for (int i = 0; i < m_properties.Length; i++)
            {
                particleLight.m_properties[i] = m_properties[i].Duplicate();
            }

            return(particleLight);
        }
Beispiel #5
0
        public void RemoveParticleLight(int index)
        {
            MyParticleLight particleLight = m_particleLights[index];

            m_particleLights.Remove(particleLight);

            particleLight.Close();
            MyParticlesManager.LightsPool.Deallocate(particleLight);

            if (m_instances != null)
            {
                foreach (MyParticleEffect effect in m_instances)
                {
                    effect.RemoveParticleLight(index);
                }
            }
        }
        public MyParticleLight CreateInstance(MyParticleEffect effect)
        {
            MyParticleLight particleLight = MyParticlesManager.LightsPool.Allocate(true);

            if (particleLight == null)
            {
                return(null);
            }

            particleLight.Start(effect);

            particleLight.Name = Name;

            for (int i = 0; i < m_properties.Length; i++)
            {
                particleLight.m_properties[i] = m_properties[i];
            }

            return(particleLight);
        }
Beispiel #7
0
        public void RemoveParticleLight(MyParticleLight particleLight)
        {
            int index = m_particleLights.IndexOf(particleLight);

            RemoveParticleLight(index);
        }
        public void Deserialize(XmlReader reader)
        {
            m_name = reader.GetAttribute("name");
            int version = Convert.ToInt32(reader.GetAttribute("version"), CultureInfo.InvariantCulture);

            reader.ReadStartElement(); //ParticleEffect

            m_particleID = reader.ReadElementContentAsInt();

            m_length = reader.ReadElementContentAsFloat();

            m_preload = reader.ReadElementContentAsFloat();

            if (reader.Name == "LowRes")
            {
                LowRes = reader.ReadElementContentAsBoolean();
            }

            bool isEmpty = reader.IsEmptyElement;

            reader.ReadStartElement(); //Generations

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (isEmpty)
                {
                    break;
                }

                if (reader.Name == "ParticleGeneration")
                {
                    MyParticleGeneration generation = MyParticlesManager.GenerationsPool.Allocate();
                    generation.Start(this);
                    generation.Init();

                    generation.Deserialize(reader);

                    AddGeneration(generation);
                }
                else
                if (reader.Name == "ParticleGPUGeneration")
                {
                    MyParticleGPUGeneration generation = MyParticlesManager.GPUGenerationsPool.Allocate();
                    generation.Start(this);
                    generation.Init();

                    generation.Deserialize(reader);

                    AddGeneration(generation);
                }
            }

            if (!isEmpty)
            {
                reader.ReadEndElement(); //Generations
            }
            if (reader.NodeType != XmlNodeType.EndElement)
            {
                isEmpty = reader.IsEmptyElement;
                if (isEmpty)
                {
                    reader.Read();
                }
                else
                {
                    reader.ReadStartElement(); //Particle lights

                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        MyParticleLight particleLight = MyParticlesManager.LightsPool.Allocate();
                        particleLight.Start(this);
                        particleLight.Init();

                        particleLight.Deserialize(reader);

                        AddParticleLight(particleLight);
                    }

                    reader.ReadEndElement(); //Particle lights
                }
            }

            if (reader.NodeType != XmlNodeType.EndElement)
            {
                isEmpty = reader.IsEmptyElement;
                if (isEmpty)
                {
                    reader.Read();
                }
                else
                {
                    reader.ReadStartElement(); //Particle sounds

                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        MyParticleSound particleSound = MyParticlesManager.SoundsPool.Allocate();
                        particleSound.Start(this);
                        particleSound.Init();

                        particleSound.Deserialize(reader);

                        AddParticleSound(particleSound);
                    }

                    reader.ReadEndElement(); //Particle sounds
                }
            }

            reader.ReadEndElement(); //ParticleEffect
        }