RedDotController.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.SetPosition(parentCom.width - comRedDot.width + left, top, 0);
  25. return;
  26. }
  27. if (comRedDotPool.Count > 0)
  28. {
  29. comRedDot = comRedDotPool[0];
  30. comRedDotPool.RemoveAt(0);
  31. }
  32. else
  33. {
  34. comRedDot = UIPackage.CreateObject("CommonGame", "ComRedDot").asCom;
  35. }
  36. parentCom.AddChild(comRedDot);
  37. comRedDot.name = "comResDot";
  38. comRedDot.SetPosition(parentCom.width - comRedDot.width + left, top, 0);
  39. // comRedDot.AddRelation(comRedDot, RelationType.TopExt_Top);
  40. // comRedDot.AddRelation(comRedDot, RelationType.RightExt_Right);
  41. string path = ResPathUtil.GetCommonGameResPath(res == "" ? "zx_hogndian" : res);
  42. GLoader loaIcon = comRedDot.GetChild("loaIcon").asLoader;
  43. loaIcon.url = path;
  44. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  45. }
  46. else
  47. {
  48. if (parentCom.GetChild("comResDot") != null)
  49. {
  50. comRedDot = parentCom.GetChild("comResDot").asCom;
  51. comRedDotPool.Add(comRedDot);
  52. parentCom.RemoveChild(comRedDot);
  53. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  54. }
  55. }
  56. }
  57. }
  58. }