FlowSplashSpawnEmit.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using CW.Common;
  3. namespace FLOW
  4. {
  5. /// <summary>This component can be attached to any prefab spawned by the <b>FlowSplash</b> component, and it will emit an amount of particles relative to the splash strength.</summary>
  6. [RequireComponent(typeof(ParticleSystem))]
  7. [HelpURL(FlowCommon.HelpUrlPrefix + "FlowSplashSpawnEmit")]
  8. [AddComponentMenu(FlowCommon.ComponentMenuPrefix + "Splash Spawn Emit")]
  9. public class FlowSplashSpawnEmit : MonoBehaviour, ISplashSpawnHandler
  10. {
  11. /// <summary>The amount of particles that will be spawned when the splash strength is 0.</summary>
  12. public int CountMin { set { countMin = value; } get { return countMin; } } [SerializeField] private int countMin;
  13. /// <summary>The amount of particles that will be spawned when the splash strength is 1.</summary>
  14. public int CountMax { set { countMax = value; } get { return countMax; } } [SerializeField] private int countMax = 10;
  15. public void HandleSplashSpawn(float strength)
  16. {
  17. var count = Mathf.RoundToInt(Mathf.Lerp(countMin, countMax, strength));
  18. if (count > 0)
  19. {
  20. var particleSystem = GetComponent<ParticleSystem>();
  21. particleSystem.Emit(count);
  22. }
  23. }
  24. }
  25. }
  26. #if UNITY_EDITOR
  27. namespace FLOW
  28. {
  29. using UnityEditor;
  30. using TARGET = FlowSplashSpawnEmit;
  31. [CanEditMultipleObjects]
  32. [CustomEditor(typeof(TARGET))]
  33. public class FlowSplashSpawnEmit_Editor : CwEditor
  34. {
  35. protected override void OnInspector()
  36. {
  37. TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
  38. Draw("countMin", "The amount of particles that will be spawned when the splash strength is 0.");
  39. Draw("countMax", "The amount of particles that will be spawned when the splash strength is 1.");
  40. }
  41. }
  42. }
  43. #endif