SceneTrophyCardFade.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using UnityEngine;
  3. using wf;
  4. [RequireComponent(typeof(UIWidget))]
  5. public class SceneTrophyCardFade : WfFadeBehaviour
  6. {
  7. private void Awake()
  8. {
  9. this.contentWidget = base.GetComponent<UIWidget>();
  10. this.cardFadeMgr = this.cardWidget.GetComponent<WfFadeBehaviour>();
  11. this.cardDrawPos = this.cardSprite.transform.position;
  12. this.cardWidget.alpha = 0f;
  13. }
  14. private void OnDestroy()
  15. {
  16. if (this.cardSprite.sprite2D != null && this.cardSprite.sprite2D.texture != null)
  17. {
  18. UnityEngine.Object.DestroyImmediate(this.cardSprite.sprite2D.texture);
  19. }
  20. }
  21. public void CallCard(Trophy.Data tropheyData, Vector3 cardWorldPos)
  22. {
  23. if (this.cardSprite.sprite2D != null && this.cardSprite.sprite2D.texture != null)
  24. {
  25. UnityEngine.Object.DestroyImmediate(this.cardSprite.sprite2D.texture);
  26. }
  27. this.cardSprite.sprite2D = null;
  28. if (!string.IsNullOrEmpty(tropheyData.cardTextureFileName))
  29. {
  30. Sprite sprite = Utility.CreateTextureSprite(tropheyData.cardTextureFileName);
  31. this.cardSprite.sprite2D = sprite;
  32. this.cardSprite.SetDimensions((int)sprite.rect.width, (int)sprite.rect.height);
  33. }
  34. this.cardSprite.transform.position = cardWorldPos;
  35. this.uiCardPos = cardWorldPos;
  36. WfFadeJob.Create(null, this, this.fadeTime, iTween.EaseType.easeInOutSine);
  37. }
  38. public void CallMainContent()
  39. {
  40. WfFadeJob.Create(this, null, this.fadeTime, iTween.EaseType.easeInOutSine);
  41. }
  42. public override void OnUpdateFadeIn(float val)
  43. {
  44. this.contentWidget.alpha = val;
  45. val = 1f - val;
  46. this.cardWidget.alpha = val;
  47. float num = Mathf.SmoothStep(0f, 0.88f, val);
  48. num = ((1f >= 0.12f + num) ? (0.12f + num) : 1f);
  49. this.cardSprite.transform.localScale = new Vector3(num, num, 1f);
  50. this.cardSprite.transform.position = Vector3.Lerp(this.uiCardPos, this.cardDrawPos, val);
  51. }
  52. public override void OnUpdateFadeOut(float val)
  53. {
  54. this.contentWidget.alpha = val;
  55. val = 1f - val;
  56. this.cardWidget.alpha = val;
  57. float num = Mathf.SmoothStep(0f, 0.88f, val);
  58. num = ((1f >= 0.12f + num) ? (0.12f + num) : 1f);
  59. this.cardSprite.transform.localScale = new Vector3(num, num, 1f);
  60. this.cardSprite.transform.position = Vector3.Lerp(this.uiCardPos, this.cardDrawPos, val);
  61. }
  62. public override void OnCompleteFadeOut()
  63. {
  64. base.OnCompleteFadeOut();
  65. this.cardSprite.transform.localScale = Vector3.one;
  66. }
  67. [SerializeField]
  68. private float fadeTime;
  69. [SerializeField]
  70. private UIWidget cardWidget;
  71. [SerializeField]
  72. private UI2DSprite cardSprite;
  73. private UIWidget contentWidget;
  74. private WfFadeBehaviour cardFadeMgr;
  75. private Vector3 uiCardPos;
  76. private Vector3 cardDrawPos;
  77. }