SceneTrophyCardFade.cs 2.8 KB

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