PromptController.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. {
  27. ui.RemoveFromParent();
  28. ui.Dispose();
  29. });
  30. }
  31. }
  32. }
  33. public void ShowFloatTextPrompt(string message, MessageType messageType = MessageType.ERR)
  34. {
  35. GComponent ui;
  36. // switch(messageType)
  37. // {
  38. // case MessageType.WARNING:
  39. // ui = UI_FloatingTextPromptWarningUI.Proxy().target;
  40. // break;
  41. // case MessageType.NORMAL:
  42. // ui = UI_FloatingTextPromptNarmalUI.Proxy().target;
  43. // break;
  44. // case MessageType.SUCCESS:
  45. // ui = UI_FloatingTextPromptSuccessUI.Proxy().target;
  46. // break;
  47. // default:
  48. // ui = UI_FloatingTextPromptErrUI.Proxy().target;
  49. // break;
  50. // }
  51. ui = UI_FloatingTextPromptNarmalUI.Proxy().target;
  52. ViewManager.AddChildToFloatLayer(ui);
  53. GTextField textField = ui.GetChild("txtMessage") as GTextField;
  54. textField.text = message;
  55. if (_uis.Count <= 0)
  56. {
  57. ui.Center();
  58. }
  59. else
  60. {
  61. MoveAllUp();
  62. GComponent preui = _uis[_uis.Count - 1];
  63. ui.x = preui.x;
  64. ui.y = preui.y + 100;
  65. }
  66. ui.data = ET.TimeHelper.ClientNow() + 3000;
  67. _uis.Add(ui);
  68. }
  69. private void MoveAllUp()
  70. {
  71. foreach (GComponent ui in _uis)
  72. {
  73. ui.y -= 50;
  74. }
  75. }
  76. }
  77. }