ParticleSettings.cs 5.1 KB

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