RedDotController.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections.Generic;
  2. using FairyGUI;
  3. namespace GFGGame
  4. {
  5. public class RedDotController : SingletonBase<RedDotController>
  6. {
  7. private List<GComponent> comRedDotPool = new List<GComponent>();
  8. public void Clear()
  9. {
  10. for (int i = 0; i < comRedDotPool.Count; i++)
  11. {
  12. comRedDotPool[i].Dispose();
  13. }
  14. comRedDotPool.Clear();
  15. }
  16. public void SetComRedDot(GComponent parentCom, bool isRed, string res = "", int left = 0, int top = 0, bool dispatchEvent = true)
  17. {
  18. GComponent comRedDot;
  19. if (isRed)
  20. {
  21. if (parentCom.GetChild("comResDot") != null)
  22. {
  23. comRedDot = parentCom.GetChild("comResDot").asCom;
  24. comRedDot.visible = true;
  25. comRedDot.SetPosition(parentCom.width - comRedDot.width + left, top, 0);
  26. return;
  27. }
  28. if (comRedDotPool.Count > 0)
  29. {
  30. comRedDot = comRedDotPool[0];
  31. comRedDotPool.RemoveAt(0);
  32. }
  33. else
  34. {
  35. comRedDot = UIPackage.CreateObject("CommonGame", "ComRedDot").asCom;
  36. }
  37. parentCom.AddChild(comRedDot);
  38. comRedDot.name = "comResDot";
  39. comRedDot.SetPosition(parentCom.width - comRedDot.width + left, top, 0);
  40. // comRedDot.AddRelation(comRedDot, RelationType.TopExt_Top);
  41. // comRedDot.AddRelation(comRedDot, RelationType.RightExt_Right);
  42. string path = ResPathUtil.GetCommonGameResPath(res == "" ? "zx_hogndian" : res);
  43. GLoader loaIcon = comRedDot.GetChild("loaIcon").asLoader;
  44. loaIcon.url = path;
  45. if (dispatchEvent)
  46. {
  47. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  48. }
  49. }
  50. else
  51. {
  52. if (parentCom.GetChild("comResDot") != null)
  53. {
  54. comRedDot = parentCom.GetChild("comResDot").asCom;
  55. comRedDotPool.Add(comRedDot);
  56. parentCom.RemoveChild(comRedDot);
  57. if (dispatchEvent)
  58. {
  59. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }