PromptController.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections.Generic;
  2. using UI.Common;
  3. using UnityEngine;
  4. using FairyGUI;
  5. using System;
  6. namespace GFGGame
  7. {
  8. public class PromptController : SingletonBase<PromptController>
  9. {
  10. private List<GComponent> _uis = new List<GComponent>();
  11. public PromptController()
  12. {
  13. Timers.inst.AddUpdate(Update);
  14. }
  15. private void Update(object param)
  16. {
  17. if (_uis.Count > 0)
  18. {
  19. GComponent ui = _uis[0];
  20. long endTime = (long)ui.data;
  21. if (endTime < ET.TimeHelper.ClientNow())
  22. {
  23. _uis.Remove(ui);
  24. GTweener gTweener = ui.TweenFade(0, 0.5f);
  25. gTweener.OnComplete(() => {
  26. ui.RemoveFromParent();
  27. ui.Dispose();
  28. });
  29. }
  30. }
  31. }
  32. public void ShowFloatTextPrompt(string message, MessageType messageType = MessageType.ERR)
  33. {
  34. GComponent ui;
  35. switch(messageType)
  36. {
  37. case MessageType.WARNING:
  38. ui = UI_FloatingTextPromptWarningUI.Proxy().target;
  39. break;
  40. case MessageType.NORMAL:
  41. ui = UI_FloatingTextPromptNarmalUI.Proxy().target;
  42. break;
  43. case MessageType.SUCCESS:
  44. ui = UI_FloatingTextPromptSuccessUI.Proxy().target;
  45. break;
  46. default:
  47. ui = UI_FloatingTextPromptErrUI.Proxy().target;
  48. break;
  49. }
  50. ViewManager.AddChildToTopLayer(ui);
  51. GTextField textField = ui.GetChild("txtMessage") as GTextField;
  52. textField.text = message;
  53. if (_uis.Count <= 0)
  54. {
  55. ui.Center();
  56. }
  57. else
  58. {
  59. MoveAllUp();
  60. GComponent preui = _uis[_uis.Count - 1];
  61. ui.x = preui.x;
  62. ui.y = preui.y + 50;
  63. }
  64. ui.data = ET.TimeHelper.ClientNow() + 3000;
  65. _uis.Add(ui);
  66. }
  67. private void MoveAllUp()
  68. {
  69. foreach (GComponent ui in _uis)
  70. {
  71. ui.y -= 50;
  72. }
  73. }
  74. }
  75. }