RedDotController.cs 1.6 KB

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