RedDotController.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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)
  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, 0, 0);
  26. comRedDot.AddRelation(comRedDot, RelationType.TopExt_Top);
  27. comRedDot.AddRelation(comRedDot, RelationType.RightExt_Right);
  28. }
  29. else
  30. {
  31. if (parentCom.GetChild("comResDot") != null)
  32. {
  33. comRedDot = parentCom.GetChild("comResDot").asCom;
  34. comRedDotPool.Add(comRedDot);
  35. parentCom.RemoveChild(comRedDot);
  36. }
  37. }
  38. }
  39. }
  40. }