PromptController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. private int showCount = 3; //ÏÔʾ¶àÉÙÌõ
  12. public PromptController()
  13. {
  14. Timers.inst.AddUpdate(Update);
  15. }
  16. private void Update(object param)
  17. {
  18. if (_uis.Count > 0)
  19. {
  20. GComponent ui = _uis[0];
  21. long endTime = (long)ui.data;
  22. if (endTime < ET.TimeHelper.ClientNow())
  23. {
  24. _uis.Remove(ui);
  25. GTweener gTweener = ui.TweenFade(0, 0.5f);
  26. gTweener.OnComplete(() =>
  27. {
  28. ui.RemoveFromParent();
  29. ui.Dispose();
  30. });
  31. }
  32. }
  33. }
  34. public void ShowFloatTextPrompt(string message, MessageType messageType = MessageType.ERR)
  35. {
  36. GComponent ui;
  37. // switch(messageType)
  38. // {
  39. // case MessageType.WARNING:
  40. // ui = UI_FloatingTextPromptWarningUI.Proxy().target;
  41. // break;
  42. // case MessageType.NORMAL:
  43. // ui = UI_FloatingTextPromptNarmalUI.Proxy().target;
  44. // break;
  45. // case MessageType.SUCCESS:
  46. // ui = UI_FloatingTextPromptSuccessUI.Proxy().target;
  47. // break;
  48. // default:
  49. // ui = UI_FloatingTextPromptErrUI.Proxy().target;
  50. // break;
  51. // }
  52. ui = UI_FloatingTextPromptNarmalUI.Proxy().target;
  53. ViewManager.AddChildToFloatLayer(ui);
  54. GTextField textField = ui.GetChild("txtMessage") as GTextField;
  55. textField.text = message;
  56. if (_uis.Count <= 0)
  57. {
  58. ui.Center();
  59. }
  60. else
  61. {
  62. MoveAllUp();
  63. GComponent preui = _uis[_uis.Count - 1];
  64. ui.x = preui.x;
  65. ui.y = preui.y + 100;
  66. if (_uis.Count >= showCount) {
  67. GComponent uiFirst = _uis[0];
  68. _uis.Remove(uiFirst);
  69. uiFirst.RemoveFromParent();
  70. uiFirst.Dispose();
  71. }
  72. }
  73. ui.data = ET.TimeHelper.ClientNow() + 3000;
  74. _uis.Add(ui);
  75. }
  76. private void MoveAllUp()
  77. {
  78. foreach (GComponent ui in _uis)
  79. {
  80. ui.y -= 100;
  81. }
  82. }
  83. }
  84. }