AttractionParticleAffector.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. 
  2. // =================================
  3. // Namespaces.
  4. // =================================
  5. using UnityEngine;
  6. // =================================
  7. // Define namespace.
  8. // =================================
  9. namespace MirzaBeig
  10. {
  11. namespace Scripting
  12. {
  13. namespace Effects
  14. {
  15. // =================================
  16. // Classes.
  17. // =================================
  18. public class AttractionParticleAffector : ParticleAffector
  19. {
  20. // =================================
  21. // Nested classes and structures.
  22. // =================================
  23. // ...
  24. // =================================
  25. // Variables.
  26. // =================================
  27. // ...
  28. [Header("Affector Controls")]
  29. public float arrivalRadius = 1.0f;
  30. public float arrivedRadius = 0.5f;
  31. float arrivalRadiusSqr;
  32. float arrivedRadiusSqr;
  33. // =================================
  34. // Functions.
  35. // =================================
  36. // ...
  37. protected override void Awake()
  38. {
  39. base.Awake();
  40. }
  41. // ...
  42. protected override void Start()
  43. {
  44. base.Start();
  45. }
  46. // ...
  47. protected override void Update()
  48. {
  49. base.Update();
  50. }
  51. // ...
  52. protected override void LateUpdate()
  53. {
  54. float uniformTransformScale = transform.lossyScale.x;
  55. arrivalRadiusSqr = (arrivalRadius * arrivalRadius) * uniformTransformScale;
  56. arrivedRadiusSqr = (arrivedRadius * arrivedRadius) * uniformTransformScale;
  57. // ...
  58. base.LateUpdate();
  59. }
  60. // ...
  61. protected override Vector3 GetForce()
  62. {
  63. Vector3 force;
  64. if (parameters.distanceToAffectorCenterSqr < arrivedRadiusSqr)
  65. {
  66. force.x = 0.0f;
  67. force.y = 0.0f;
  68. force.z = 0.0f;
  69. }
  70. else if (parameters.distanceToAffectorCenterSqr < arrivalRadiusSqr)
  71. {
  72. float inverseArrivalScaleNormalized = 1.0f - (parameters.distanceToAffectorCenterSqr / arrivalRadiusSqr);
  73. force = Vector3.Normalize(parameters.scaledDirectionToAffectorCenter) * inverseArrivalScaleNormalized;
  74. }
  75. else
  76. {
  77. force = Vector3.Normalize(parameters.scaledDirectionToAffectorCenter);
  78. }
  79. return force;
  80. }
  81. // ...
  82. protected override void OnDrawGizmosSelected()
  83. {
  84. if (enabled)
  85. {
  86. base.OnDrawGizmosSelected();
  87. // ...
  88. float uniformTransformScale = transform.lossyScale.x;
  89. float arrivalRadius = this.arrivalRadius * uniformTransformScale;
  90. float arrivedRadius = this.arrivedRadius * uniformTransformScale;
  91. Vector3 center = transform.position + offset;
  92. Gizmos.color = Color.yellow;
  93. Gizmos.DrawWireSphere(center, arrivalRadius);
  94. Gizmos.color = Color.red;
  95. Gizmos.DrawWireSphere(center, arrivedRadius);
  96. //Gizmos.color = Color.white;
  97. //Gizmos.DrawLine(currentParticleSystem.transform.position, center);
  98. }
  99. }
  100. // =================================
  101. // End functions.
  102. // =================================
  103. }
  104. // =================================
  105. // End namespace.
  106. // =================================
  107. }
  108. }
  109. }
  110. // =================================
  111. // --END-- //
  112. // =================================