ParticleSettings.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //-----------------------------------------------------------------------------
  2. // ParticleSettings.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using Microsoft.Xna.Framework;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using Microsoft.Xna.Framework.Content;
  11. namespace Particle3DSample
  12. {
  13. /// <summary>
  14. /// Settings class describes all the tweakable options used
  15. /// to control the appearance of a particle system.
  16. /// </summary>
  17. public class ParticleSettings
  18. {
  19. // Name of the texture used by this particle system.
  20. public string? TextureName = null;
  21. // Maximum number of particles that can be displayed at one time.
  22. public int MaxParticles = 100;
  23. // How long these particles will last.
  24. public TimeSpan Duration = TimeSpan.FromSeconds(1);
  25. // If greater than zero, some particles will last a shorter time than others.
  26. public float DurationRandomness = 0;
  27. // Controls how much particles are influenced by the velocity of the object
  28. // which created them. You can see this in action with the explosion effect,
  29. // where the flames continue to move in the same direction as the source
  30. // projectile. The projectile trail particles, on the other hand, set this
  31. // value very low so they are less affected by the velocity of the projectile.
  32. public float EmitterVelocitySensitivity = 1;
  33. // Range of values controlling how much X and Z axis velocity to give each
  34. // particle. Values for individual particles are randomly chosen from somewhere
  35. // between these limits.
  36. public float MinHorizontalVelocity = 0;
  37. public float MaxHorizontalVelocity = 0;
  38. // Range of values controlling how much Y axis velocity to give each particle.
  39. // Values for individual particles are randomly chosen from somewhere between
  40. // these limits.
  41. public float MinVerticalVelocity = 0;
  42. public float MaxVerticalVelocity = 0;
  43. // Direction and strength of the gravity effect. Note that this can point in any
  44. // direction, not just down! The fire effect points it upward to make the flames
  45. // rise, and the smoke plume points it sideways to simulate wind.
  46. public Vector3 Gravity = Vector3.Zero;
  47. // Controls how the particle velocity will change over their lifetime. If set
  48. // to 1, particles will keep going at the same speed as when they were created.
  49. // If set to 0, particles will come to a complete stop right before they die.
  50. // Values greater than 1 make the particles speed up over time.
  51. public float EndVelocity = 1;
  52. // Range of values controlling the particle color and alpha. Values for
  53. // individual particles are randomly chosen from somewhere between these limits.
  54. public Color MinColor = Color.White;
  55. public Color MaxColor = Color.White;
  56. // Range of values controlling how fast the particles rotate. Values for
  57. // individual particles are randomly chosen from somewhere between these
  58. // limits. If both these values are set to 0, the particle system will
  59. // automatically switch to an alternative shader technique that does not
  60. // support rotation, and thus requires significantly less GPU power. This
  61. // means if you don't need the rotation effect, you may get a performance
  62. // boost from leaving these values at 0.
  63. public float MinRotateSpeed = 0;
  64. public float MaxRotateSpeed = 0;
  65. // Range of values controlling how big the particles are when first created.
  66. // Values for individual particles are randomly chosen from somewhere between
  67. // these limits.
  68. public float MinStartSize = 100;
  69. public float MaxStartSize = 100;
  70. // Range of values controlling how big particles become at the end of their
  71. // life. Values for individual particles are randomly chosen from somewhere
  72. // between these limits.
  73. public float MinEndSize = 100;
  74. public float MaxEndSize = 100;
  75. // Alpha blending settings.
  76. [ContentSerializerIgnore]
  77. public BlendState BlendState = BlendState.NonPremultiplied;
  78. [ContentSerializer(ElementName = "BlendState")]
  79. private string BlendStateSerializationHelper
  80. {
  81. get { return BlendState.Name.Replace("BlendState.", string.Empty); }
  82. set
  83. {
  84. switch (value)
  85. {
  86. case "AlphaBlend": BlendState = BlendState.AlphaBlend; break;
  87. case "Additive": BlendState = BlendState.Additive; break;
  88. case "NonPremultiplied": BlendState = BlendState.NonPremultiplied; break;
  89. default:
  90. throw new ArgumentException("Unknown blend state " + value);
  91. }
  92. }
  93. }
  94. }
  95. }