/// <summary> /// Adds a varying particle parameter. /// </summary> /// <typeparam name="T">The type of the parameter value.</typeparam> /// <param name="name">The name of the parameter (e.g. "Color", "Position", etc.).</param> /// <returns>The existing or newly created particle parameter.</returns> /// <remarks> /// If the collection does not contain a particle parameter with the given /// <paramref name="name"/>, a new varying particle parameter is added. If the collection /// contains a varying particle parameter with the given <paramref name="name"/>, then only the /// existing particle parameter is returned. If the collection contains a uniform particle /// parameter with the given <paramref name="name"/>, then the existing particle parameter is /// removed and replaced by a new varying particle parameter. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="name"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="name"/> is empty. /// </exception> /// <exception cref="ParticleSystemException"> /// A particle parameter with the given name was found but the parameter type cannot be cast to /// type <typeparamref name="T"/>. /// </exception> public IParticleParameter <T> AddVarying <T>(string name) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("The particle parameter name must not be empty.", "name"); } IParticleParameter <T> parameter = Get <T>(name, true); T defaultValue = default(T); if (parameter is UniformParticleParameter <T> ) { // Remove uniform parameter, but keep default value. defaultValue = parameter.DefaultValue; _collection.Remove(name); } else if (parameter != null) { return(parameter); } parameter = new VaryingParticleParameter <T>(name, ParticleSystem.MaxNumberOfParticles); parameter.DefaultValue = defaultValue; _collection.Add(parameter); OnChanged(EventArgs.Empty); return(parameter); }