RedDotController.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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)
  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. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  46. }
  47. else
  48. {
  49. if (parentCom.GetChild("comResDot") != null)
  50. {
  51. comRedDot = parentCom.GetChild("comResDot").asCom;
  52. comRedDotPool.Add(comRedDot);
  53. parentCom.RemoveChild(comRedDot);
  54. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  55. }
  56. }
  57. }
  58. }
  59. }