RedDotController.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 SetComRedDot(GComponent parentCom, bool isRed, string res = "", int left = 0, int top = 0)
  9. {
  10. GComponent comRedDot;
  11. if (isRed)
  12. {
  13. if (parentCom.GetChild("comResDot") != null)
  14. {
  15. comRedDot = parentCom.GetChild("comResDot").asCom;
  16. comRedDot.SetPosition(parentCom.width - comRedDot.width + left, top, 0);
  17. return;
  18. }
  19. if (comRedDotPool.Count > 0)
  20. {
  21. comRedDot = comRedDotPool[0];
  22. comRedDotPool.RemoveAt(0);
  23. }
  24. else
  25. {
  26. comRedDot = UIPackage.CreateObject("CommonGame", "ComRedDot").asCom;
  27. }
  28. parentCom.AddChild(comRedDot);
  29. comRedDot.name = "comResDot";
  30. comRedDot.SetPosition(parentCom.width - comRedDot.width + left, top, 0);
  31. // comRedDot.AddRelation(comRedDot, RelationType.TopExt_Top);
  32. // comRedDot.AddRelation(comRedDot, RelationType.RightExt_Right);
  33. string path = ResPathUtil.GetCommonGameResPath(res == "" ? "zx_hogndian" : res);
  34. GLoader loaIcon = comRedDot.GetChild("loaIcon").asLoader;
  35. loaIcon.url = path;
  36. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  37. }
  38. else
  39. {
  40. if (parentCom.GetChild("comResDot") != null)
  41. {
  42. comRedDot = parentCom.GetChild("comResDot").asCom;
  43. comRedDotPool.Add(comRedDot);
  44. parentCom.RemoveChild(comRedDot);
  45. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  46. }
  47. }
  48. }
  49. }
  50. }