LocalizationParamsManager.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace I2.Loc
  5. {
  6. public class LocalizationParamsManager : MonoBehaviour, ILocalizationParamsManager
  7. {
  8. public string GetParameterValue(string ParamName)
  9. {
  10. if (this._Params != null)
  11. {
  12. int i = 0;
  13. int count = this._Params.Count;
  14. while (i < count)
  15. {
  16. if (this._Params[i].Name == ParamName)
  17. {
  18. return this._Params[i].Value;
  19. }
  20. i++;
  21. }
  22. }
  23. return null;
  24. }
  25. public void SetParameterValue(string ParamName, string ParamValue, bool localize = true)
  26. {
  27. bool flag = false;
  28. int i = 0;
  29. int count = this._Params.Count;
  30. while (i < count)
  31. {
  32. if (this._Params[i].Name == ParamName)
  33. {
  34. LocalizationParamsManager.ParamValue value = this._Params[i];
  35. value.Value = ParamValue;
  36. this._Params[i] = value;
  37. flag = true;
  38. break;
  39. }
  40. i++;
  41. }
  42. if (!flag)
  43. {
  44. this._Params.Add(new LocalizationParamsManager.ParamValue
  45. {
  46. Name = ParamName,
  47. Value = ParamValue
  48. });
  49. }
  50. if (localize)
  51. {
  52. this.OnLocalize();
  53. }
  54. }
  55. public void OnLocalize()
  56. {
  57. Localize component = base.GetComponent<Localize>();
  58. if (component != null)
  59. {
  60. component.OnLocalize(true);
  61. }
  62. }
  63. public virtual void OnEnable()
  64. {
  65. this.DoAutoRegister();
  66. }
  67. public void DoAutoRegister()
  68. {
  69. if (!LocalizationManager.ParamManagers.Contains(this))
  70. {
  71. LocalizationManager.ParamManagers.Add(this);
  72. LocalizationManager.LocalizeAll(true);
  73. }
  74. }
  75. public void OnDisable()
  76. {
  77. LocalizationManager.ParamManagers.Remove(this);
  78. }
  79. [SerializeField]
  80. public List<LocalizationParamsManager.ParamValue> _Params = new List<LocalizationParamsManager.ParamValue>();
  81. [Serializable]
  82. public struct ParamValue
  83. {
  84. public string Name;
  85. public string Value;
  86. }
  87. }
  88. }