TransformLocalizeSupport.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using I2.Loc;
  3. using UnityEngine;
  4. [DisallowMultipleComponent]
  5. public class TransformLocalizeSupport : MonoBehaviour
  6. {
  7. private void Awake()
  8. {
  9. if (this.callAwake)
  10. {
  11. return;
  12. }
  13. this.callAwake = true;
  14. this.holdPosition = base.transform.localPosition;
  15. this.holdRotation = base.transform.localRotation;
  16. this.holdScale = base.transform.localScale;
  17. LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
  18. LocalizationManager.OnLocalizeEvent += this.OnLocalize;
  19. this.OnLocalize();
  20. }
  21. public void OnDestroy()
  22. {
  23. LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
  24. }
  25. public void OnLocalize()
  26. {
  27. if (!this.callAwake)
  28. {
  29. this.Awake();
  30. }
  31. if (LocalizationManager.CurrentLanguageCode == "ja")
  32. {
  33. base.transform.localPosition = this.holdPosition;
  34. base.transform.localRotation = this.holdRotation;
  35. base.transform.localScale = this.holdScale;
  36. }
  37. else
  38. {
  39. this.Apply(this.overRidePropertys);
  40. if (this.languageOverRidePropertys != null)
  41. {
  42. foreach (TransformLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys)
  43. {
  44. if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode)
  45. {
  46. this.Apply(languageOverRideProperty.Property);
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. public void Apply(TransformLocalizeSupport.OverRideProperty property)
  54. {
  55. if (!this.callAwake)
  56. {
  57. this.Awake();
  58. }
  59. base.transform.localPosition = ((!property.position.enabled) ? this.holdPosition : property.position.value);
  60. base.transform.localRotation = ((!property.rotation.enabled) ? this.holdRotation : Quaternion.Euler(property.rotation.value));
  61. base.transform.localScale = ((!property.scale.enabled) ? this.holdScale : property.scale.value);
  62. }
  63. [SerializeField]
  64. public TransformLocalizeSupport.OverRideProperty overRidePropertys = default(TransformLocalizeSupport.OverRideProperty);
  65. [SerializeField]
  66. public TransformLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys;
  67. private Vector3 holdPosition;
  68. private Quaternion holdRotation;
  69. private Vector3 holdScale;
  70. private bool callAwake;
  71. [Serializable]
  72. public struct OverRideProperty
  73. {
  74. public TransformLocalizeSupport.OverRideProperty.Vector3Value position;
  75. public TransformLocalizeSupport.OverRideProperty.Vector3Value rotation;
  76. public TransformLocalizeSupport.OverRideProperty.Vector3Value scale;
  77. [Serializable]
  78. public struct Vector3Value
  79. {
  80. public bool enabled;
  81. public Vector3 value;
  82. }
  83. }
  84. [Serializable]
  85. public struct LanguageOverRideProperty
  86. {
  87. public string LanguageCode;
  88. public TransformLocalizeSupport.OverRideProperty Property;
  89. }
  90. }