public void AddOrUpdate(
            Entity unit,
            string name,
            string file,
            ParticleAttachment attachment,
            params object[] controlPoints)
        {
            if (unit == null)
            {
                throw new ArgumentNullException(nameof(unit));
            }

            if (!unit.IsValid)
            {
                throw new ArgumentException("Value should be valid.", nameof(unit));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var particle = _particles.FirstOrDefault(p => p.Name == name);

            if (particle == null)
            {
                _particles.Add(new ParticleEffectContainer(name, file, unit, attachment, controlPoints));
            }
            else
            {
                // parts changed
                if (!ReferenceEquals(particle.Unit, unit) || particle.File != file || particle.Attachment != attachment)
                {
                    particle.Dispose();

                    _particles.Remove(particle);
                    _particles.Add(new ParticleEffectContainer(name, file, unit, attachment, controlPoints));
                    return;
                }

                // control points changed
                try
                {
                    var hash = controlPoints.Sum(p => p.GetHashCode());
                    if (particle.GetControlPointsHashCode() != hash)
                    {
                        particle.SetControlPoints(controlPoints);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Beispiel #2
0
        public ParticleEffectContainer(string name, string file, Entity unit, ParticleAttachment attachment, params object[] controlPoints)
        {
            this.Name          = name;
            this.File          = file;
            this.Unit          = unit;
            this.Attachment    = attachment;
            this.ControlPoints = controlPoints;

            this.Effect = new ParticleEffect(file, unit, attachment);
            this.SetControlPoints();
        }
Beispiel #3
0
        public void AddOrUpdate(Entity unit, string name, string file, ParticleAttachment attachment, RestartType restart = RestartType.FullRestart, params object[] controlPoints)
        {
            if (unit == null)
            {
                throw new ArgumentNullException(nameof(unit));
            }

            if (!unit.IsValid)
            {
                throw new ArgumentException("Value should be valid.", nameof(unit));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var particle = Particles.FirstOrDefault(p => p.Name == name);

            if (particle == null)
            {
                Particles.Add(new ParticleEffectContainer(name, file, unit, attachment, controlPoints));
            }
            else
            {
                // parts changed
                if (particle.Unit != unit || particle.File != file || particle.Attachment != attachment)
                {
                    particle.Dispose();

                    Particles.Remove(particle);
                    Particles.Add(new ParticleEffectContainer(name, file, unit, attachment, controlPoints));
                    return;
                }

                // control points changed
                // var hash = controlPoints.Sum(p => p.GetHashCode());
                var hash = controlPoints.Aggregate(0, (sum, p) => unchecked (sum + p.GetHashCode()));
                if (particle.GetControlPointsHashCode() != hash)
                {
                    particle.SetControlPoints(restart, controlPoints);
                }
            }
        }
Beispiel #4
0
        public Model GetWornMesh(int gender)
        {
            int i1 = maleModel1;
            int i2 = maleModel2;
            int i3 = maleModel3;

            if (gender == 1)
            {
                i1 = femaleModel1;
                i2 = femaleModel2;
                i3 = femaleModel3;
            }

            if (i1 == -1)
            {
                return(null);
            }

            Model mesh = new Model(i1);

            if (i2 != -1)
            {
                if (i3 != -1)
                {
                    mesh = new Model(3, new Model[] { mesh, new Model(i2), new Model(i3) });
                }
                else
                {
                    mesh = new Model(2, new Model[] { mesh, new Model(i2) });
                }
            }

            if (gender == 0 && maleOffY != 0)
            {
                mesh.Translate(0, maleOffY, 0);
            }

            if (gender == 1 && femaleOffY != 0)
            {
                mesh.Translate(0, femaleOffY, 0);
            }

            if (oldColor != null)
            {
                mesh.SetColors(oldColor, newColor);
            }

            if (particleConfigs != null)
            {
                foreach (var config in particleConfigs)
                {
                    var attachment = new ParticleAttachment(config.vertexIndex);
                    attachment.EmissionRate    = (float)config.emissionRate;
                    attachment.GravityModifier = (float)config.gravityModifier;
                    attachment.StartColor      = new Color((float)config.r, (float)config.g, (float)config.b, (float)config.a);
                    attachment.StartLifetime   = (float)config.startLifetime;
                    attachment.StartSize       = (float)config.startSize;
                    attachment.StartSpeed      = (float)config.startSpeed;
                    mesh.Attachments.Add(attachment);
                }
            }

            if (index == 7053)
            {
                var attachment = new LightAttachment(13);
                mesh.Attachments.Add(attachment);
            }
            return(mesh);
        }