LightningGizmoScript.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Procedural Lightning for Unity
  3. // (c) 2015 Digital Ruby, LLC
  4. // Source code may be used for personal or commercial projects.
  5. // Source code may NOT be redistributed or sold.
  6. //
  7. using UnityEngine;
  8. using System.Collections;
  9. namespace DigitalRuby.ThunderAndLightning
  10. {
  11. /// <summary>
  12. /// Draws lightning bolt script gizmos
  13. /// </summary>
  14. public class LightningGizmoScript : MonoBehaviour
  15. {
  16. #if UNITY_EDITOR
  17. /// <summary>
  18. /// Label
  19. /// </summary>
  20. public string Label { get; set; }
  21. /// <summary>
  22. /// Lightning bolt script
  23. /// </summary>
  24. public LightningBoltScript LightningBoltScript { get; set; }
  25. private static readonly Vector3 labelOffset = Vector3.up * 1.5f;
  26. private static GUIStyle style;
  27. private void OnDrawGizmos()
  28. {
  29. if (Label == null || (LightningBoltScript != null && LightningBoltScript.HideGizmos))
  30. {
  31. return;
  32. }
  33. else if (style == null)
  34. {
  35. style = new GUIStyle();
  36. style.fontSize = 14;
  37. style.fontStyle = FontStyle.Normal;
  38. style.normal.textColor = Color.white;
  39. }
  40. Vector3 v = gameObject.transform.position;
  41. if ((Label == "0" || Label.StartsWith("0,")))
  42. {
  43. Gizmos.DrawIcon(v, "LightningPathStart.png");
  44. }
  45. else
  46. {
  47. Gizmos.DrawIcon(v, "LightningPathNext.png");
  48. }
  49. UnityEditor.Handles.Label(v + labelOffset, Label, style);
  50. }
  51. #endif
  52. }
  53. }