MaidAppealComment.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Kasizuki
  5. {
  6. public class MaidAppealComment : MonoBehaviour
  7. {
  8. public Action onClickRight { get; set; }
  9. public Action onClickLeft { get; set; }
  10. private void Awake()
  11. {
  12. if (this.m_ButtonRight != null)
  13. {
  14. EventDelegate.Add(this.m_ButtonRight.onClick, delegate()
  15. {
  16. if (this.onClickRight != null)
  17. {
  18. this.onClickRight();
  19. }
  20. });
  21. }
  22. if (this.m_ButtonLeft != null)
  23. {
  24. EventDelegate.Add(this.m_ButtonLeft.onClick, delegate()
  25. {
  26. if (this.onClickLeft != null)
  27. {
  28. this.onClickLeft();
  29. }
  30. });
  31. }
  32. }
  33. private void Start()
  34. {
  35. if (Product.supportMultiLanguage)
  36. {
  37. this.appealLanguageSprites.Add(Product.Language.Japanese.ToString(), this.m_ImageAppealComment);
  38. string[] names = Enum.GetNames(typeof(Product.Language));
  39. for (int i = 1; i < names.Length; i++)
  40. {
  41. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_ImageAppealComment.gameObject);
  42. gameObject.transform.SetParent(this.m_ImageAppealComment.transform.parent);
  43. gameObject.transform.localScale = Vector3.one;
  44. gameObject.transform.localPosition = this.m_ImageAppealComment.transform.localPosition;
  45. this.appealLanguageSprites.Add(names[i], gameObject.GetComponent<UI2DSprite>());
  46. gameObject.name = names[i];
  47. }
  48. this.OnLocalize();
  49. }
  50. }
  51. private void OnDestroy()
  52. {
  53. this.DestroyImage();
  54. }
  55. public void OnLocalize()
  56. {
  57. if (!Product.supportMultiLanguage)
  58. {
  59. return;
  60. }
  61. foreach (KeyValuePair<string, UI2DSprite> keyValuePair in this.appealLanguageSprites)
  62. {
  63. keyValuePair.Value.gameObject.SetActive(keyValuePair.Key == Product.systemLanguage.ToString());
  64. }
  65. }
  66. public void DestroyImage()
  67. {
  68. if (this.m_ImageAppealComment != null && this.m_ImageAppealComment.sprite2D != null)
  69. {
  70. if (this.m_ImageAppealComment.sprite2D.texture != null)
  71. {
  72. UnityEngine.Object.DestroyImmediate(this.m_ImageAppealComment.sprite2D.texture, true);
  73. }
  74. this.m_ImageAppealComment.sprite2D = null;
  75. }
  76. foreach (KeyValuePair<string, UI2DSprite> keyValuePair in this.appealLanguageSprites)
  77. {
  78. UI2DSprite value = keyValuePair.Value;
  79. if (value != null && value.sprite2D != null)
  80. {
  81. if (value.sprite2D.texture != null)
  82. {
  83. UnityEngine.Object.DestroyImmediate(value.sprite2D.texture, true);
  84. }
  85. value.sprite2D = null;
  86. }
  87. }
  88. }
  89. public void ChangeImage(Texture2D texture)
  90. {
  91. this.DestroyImage();
  92. if (texture == null)
  93. {
  94. return;
  95. }
  96. Sprite sprite = Sprite.Create(texture, new Rect(0f, 0f, (float)texture.width, (float)texture.height), default(Vector2));
  97. sprite.name = "Image _" + texture.name;
  98. this.m_ImageAppealComment.sprite2D = sprite;
  99. }
  100. public void ChangeImage(Dictionary<string, Texture2D> languageTexture)
  101. {
  102. this.DestroyImage();
  103. if (languageTexture == null || languageTexture.Count == 0)
  104. {
  105. return;
  106. }
  107. foreach (KeyValuePair<string, Texture2D> keyValuePair in languageTexture)
  108. {
  109. if (!(keyValuePair.Value == null) && this.appealLanguageSprites.ContainsKey(keyValuePair.Key))
  110. {
  111. Texture2D value = keyValuePair.Value;
  112. Sprite sprite = Sprite.Create(value, new Rect(0f, 0f, (float)value.width, (float)value.height), default(Vector2));
  113. sprite.name = "Image _" + value.name;
  114. this.appealLanguageSprites[keyValuePair.Key].sprite2D = sprite;
  115. }
  116. }
  117. }
  118. public void SetEnableEditing(bool isEnable)
  119. {
  120. if (this.m_ButtonRight != null)
  121. {
  122. this.m_ButtonRight.gameObject.SetActive(isEnable);
  123. }
  124. if (this.m_ButtonLeft != null)
  125. {
  126. this.m_ButtonLeft.gameObject.SetActive(isEnable);
  127. }
  128. }
  129. [SerializeField]
  130. private UI2DSprite m_ImageAppealComment;
  131. [SerializeField]
  132. private UIButton m_ButtonRight;
  133. [SerializeField]
  134. private UIButton m_ButtonLeft;
  135. private Dictionary<string, UI2DSprite> appealLanguageSprites = new Dictionary<string, UI2DSprite>();
  136. }
  137. }