Card.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. {
  35. ET.Log.Debug("toopen,this");
  36. GTween.To(180, 360, 0.5f).SetTarget(this).SetEase(EaseType.QuadOut).OnUpdate(TurnInTween).SetUserData(false);
  37. return;
  38. }
  39. bool toOpen = !_front.visible;
  40. ET.Log.Debug("toopen:" + toOpen);
  41. GTween.To(0, 180, 0.5f).SetTarget(this).SetEase(EaseType.QuadOut).OnUpdate(TurnInTween).SetUserData(toOpen);
  42. }
  43. void TurnInTween(GTweener tweener)
  44. {
  45. bool toOpen = (bool)tweener.userData;
  46. float v = tweener.value.x;
  47. if (toOpen)
  48. {
  49. _back.rotationY = v;
  50. _front.rotationY = -180 + v;
  51. if (v > 90)
  52. {
  53. _front.visible = true;
  54. _back.visible = false;
  55. }
  56. }
  57. else
  58. {
  59. _back.rotationY = -180 + v;
  60. _front.rotationY = v;
  61. if (v > 90)
  62. {
  63. _front.visible = false;
  64. _back.visible = true;
  65. }
  66. }
  67. }
  68. }