UICanvasManager.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. namespace ETFXPEL
  5. {
  6. public class UICanvasManager : MonoBehaviour {
  7. public static UICanvasManager GlobalAccess;
  8. void Awake () {
  9. GlobalAccess = this;
  10. }
  11. public bool MouseOverButton = false;
  12. public Text PENameText;
  13. public Text ToolTipText;
  14. // Use this for initialization
  15. void Start () {
  16. if (PENameText != null)
  17. PENameText.text = ParticleEffectsLibrary.GlobalAccess.GetCurrentPENameString();
  18. }
  19. // Update is called once per frame
  20. void Update () {
  21. // Mouse Click - Check if mouse over button to prevent spawning particle effects while hovering or using UI buttons.
  22. if (!MouseOverButton) {
  23. // Left Button Click
  24. if (Input.GetMouseButtonUp (0)) {
  25. // Spawn Currently Selected Particle System
  26. SpawnCurrentParticleEffect();
  27. }
  28. }
  29. if (Input.GetKeyUp (KeyCode.A)) {
  30. SelectPreviousPE ();
  31. }
  32. if (Input.GetKeyUp (KeyCode.D)) {
  33. SelectNextPE ();
  34. }
  35. }
  36. public void UpdateToolTip(ButtonTypes toolTipType) {
  37. if (ToolTipText != null) {
  38. if (toolTipType == ButtonTypes.Previous) {
  39. ToolTipText.text = "Select Previous Particle Effect";
  40. }
  41. else if (toolTipType == ButtonTypes.Next) {
  42. ToolTipText.text = "Select Next Particle Effect";
  43. }
  44. }
  45. }
  46. public void ClearToolTip() {
  47. if (ToolTipText != null) {
  48. ToolTipText.text = "";
  49. }
  50. }
  51. private void SelectPreviousPE() {
  52. // Previous
  53. ParticleEffectsLibrary.GlobalAccess.PreviousParticleEffect();
  54. if (PENameText != null)
  55. PENameText.text = ParticleEffectsLibrary.GlobalAccess.GetCurrentPENameString();
  56. }
  57. private void SelectNextPE() {
  58. // Next
  59. ParticleEffectsLibrary.GlobalAccess.NextParticleEffect();
  60. if (PENameText != null)
  61. PENameText.text = ParticleEffectsLibrary.GlobalAccess.GetCurrentPENameString();
  62. }
  63. private RaycastHit rayHit;
  64. private void SpawnCurrentParticleEffect() {
  65. // Spawn Particle Effect
  66. Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
  67. if (Physics.Raycast (mouseRay, out rayHit)) {
  68. ParticleEffectsLibrary.GlobalAccess.SpawnParticleEffect (rayHit.point);
  69. }
  70. }
  71. /// <summary>
  72. /// User interfaces the button click.
  73. /// </summary>
  74. /// <param name="buttonTypeClicked">Button type clicked.</param>
  75. public void UIButtonClick(ButtonTypes buttonTypeClicked) {
  76. switch (buttonTypeClicked) {
  77. case ButtonTypes.Previous:
  78. // Select Previous Prefab
  79. SelectPreviousPE();
  80. break;
  81. case ButtonTypes.Next:
  82. // Select Next Prefab
  83. SelectNextPE();
  84. break;
  85. default:
  86. // Nothing
  87. break;
  88. }
  89. }
  90. }
  91. }