Card.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using FairyGUI;
  2. public class Card : GButton
  3. {
  4. GObject _back;
  5. GObject _front;
  6. public override void ConstructFromXML(FairyGUI.Utils.XML xml)
  7. {
  8. base.ConstructFromXML(xml);
  9. _back = GetChild("n0");
  10. _front = GetChild("icon");
  11. _front.visible = false;
  12. }
  13. public bool opened
  14. {
  15. get
  16. {
  17. return _front.visible;
  18. }
  19. set
  20. {
  21. GTween.Kill(this);
  22. _front.visible = value;
  23. _back.visible = !value;
  24. }
  25. }
  26. public void SetPerspective()
  27. {
  28. _front.displayObject.perspective = true;
  29. _back.displayObject.perspective = true;
  30. }
  31. public void Turn()
  32. {
  33. //if (GTween.IsTweening(this))
  34. // return;
  35. bool toOpen = !_front.visible;
  36. GTween.To(0, 180, 0.5f).SetTarget(this).SetEase(EaseType.QuadOut).OnUpdate(TurnInTween).SetUserData(toOpen);
  37. }
  38. void TurnInTween(GTweener tweener)
  39. {
  40. bool toOpen = (bool)tweener.userData;
  41. float v = tweener.value.x;
  42. if (toOpen)
  43. {
  44. _back.rotationY = v;
  45. _front.rotationY = -180 + v;
  46. if (v > 90)
  47. {
  48. _front.visible = true;
  49. _back.visible = false;
  50. }
  51. }
  52. else
  53. {
  54. _back.rotationY = -180 + v;
  55. _front.rotationY = v;
  56. if (v > 90)
  57. {
  58. _front.visible = false;
  59. _back.visible = true;
  60. }
  61. }
  62. }
  63. }