GearAnimation.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 GearAnimationValue(bool playing, int frame)
  10. {
  11. this.playing = playing;
  12. this.frame = frame;
  13. }
  14. }
  15. /// <summary>
  16. /// Gear is a connection between object and controller.
  17. /// </summary>
  18. public class GearAnimation : GearBase
  19. {
  20. Dictionary<string, GearAnimationValue> _storage;
  21. GearAnimationValue _default;
  22. public GearAnimation(GObject owner)
  23. : base(owner)
  24. {
  25. }
  26. protected override void Init()
  27. {
  28. _default = new GearAnimationValue(((IAnimationGear)_owner).playing, ((IAnimationGear)_owner).frame);
  29. _storage = new Dictionary<string, GearAnimationValue>();
  30. }
  31. override protected void AddStatus(string pageId, ByteBuffer buffer)
  32. {
  33. GearAnimationValue gv;
  34. if (pageId == null)
  35. gv = _default;
  36. else
  37. {
  38. gv = new GearAnimationValue(false, 0);
  39. _storage[pageId] = gv;
  40. }
  41. gv.playing = buffer.ReadBool();
  42. gv.frame = buffer.ReadInt();
  43. }
  44. override public void Apply()
  45. {
  46. _owner._gearLocked = true;
  47. GearAnimationValue gv;
  48. if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
  49. gv = _default;
  50. IAnimationGear mc = (IAnimationGear)_owner;
  51. mc.frame = gv.frame;
  52. mc.playing = gv.playing;
  53. _owner._gearLocked = false;
  54. }
  55. override public void UpdateState()
  56. {
  57. IAnimationGear mc = (IAnimationGear)_owner;
  58. GearAnimationValue gv;
  59. if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
  60. _storage[_controller.selectedPageId] = new GearAnimationValue(mc.playing, mc.frame);
  61. else
  62. {
  63. gv.playing = mc.playing;
  64. gv.frame = mc.frame;
  65. }
  66. }
  67. }
  68. }