GearAnimation.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections.Generic;
  2. using FairyGUI.Utils;
  3. namespace FairyGUI
  4. {
  5. class GearAnimationValue
  6. {
  7. public bool playing;
  8. public int frame;
  9. public string animationName;
  10. public string skinName;
  11. public GearAnimationValue(bool playing, int frame)
  12. {
  13. this.playing = playing;
  14. this.frame = frame;
  15. }
  16. }
  17. /// <summary>
  18. /// Gear is a connection between object and controller.
  19. /// </summary>
  20. public class GearAnimation : GearBase
  21. {
  22. Dictionary<string, GearAnimationValue> _storage;
  23. GearAnimationValue _default;
  24. public GearAnimation(GObject owner)
  25. : base(owner)
  26. {
  27. }
  28. protected override void Init()
  29. {
  30. _default = new GearAnimationValue(((IAnimationGear)_owner).playing, ((IAnimationGear)_owner).frame);
  31. if (_owner is GLoader3D)
  32. {
  33. _default.animationName = ((GLoader3D)_owner).animationName;
  34. _default.skinName = ((GLoader3D)_owner).skinName;
  35. }
  36. _storage = new Dictionary<string, GearAnimationValue>();
  37. }
  38. override protected void AddStatus(string pageId, ByteBuffer buffer)
  39. {
  40. GearAnimationValue gv;
  41. if (pageId == null)
  42. gv = _default;
  43. else
  44. {
  45. gv = new GearAnimationValue(false, 0);
  46. _storage[pageId] = gv;
  47. }
  48. gv.playing = buffer.ReadBool();
  49. gv.frame = buffer.ReadInt();
  50. }
  51. public void AddExtStatus(string pageId, ByteBuffer buffer)
  52. {
  53. GearAnimationValue gv;
  54. if (pageId == null)
  55. gv = _default;
  56. else
  57. gv = _storage[pageId];
  58. gv.animationName = buffer.ReadS();
  59. gv.skinName = buffer.ReadS();
  60. }
  61. override public void Apply()
  62. {
  63. _owner._gearLocked = true;
  64. GearAnimationValue gv;
  65. if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
  66. gv = _default;
  67. IAnimationGear mc = (IAnimationGear)_owner;
  68. mc.frame = gv.frame;
  69. mc.playing = gv.playing;
  70. if (_owner is GLoader3D)
  71. {
  72. ((GLoader3D)_owner).animationName = gv.animationName;
  73. ((GLoader3D)_owner).skinName = gv.skinName;
  74. }
  75. _owner._gearLocked = false;
  76. }
  77. override public void UpdateState()
  78. {
  79. IAnimationGear mc = (IAnimationGear)_owner;
  80. GearAnimationValue gv;
  81. if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
  82. _storage[_controller.selectedPageId] = gv = new GearAnimationValue(mc.playing, mc.frame);
  83. else
  84. {
  85. gv.playing = mc.playing;
  86. gv.frame = mc.frame;
  87. }
  88. if (_owner is GLoader3D)
  89. {
  90. gv.animationName = ((GLoader3D)_owner).animationName;
  91. gv.skinName = ((GLoader3D)_owner).skinName;
  92. }
  93. }
  94. }
  95. }