VirusInfoScreen.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Collections;
  5. /// <summary>
  6. /// This component is responsible for setting the background and text according
  7. /// to a virus which is set through the <code>SetVirus</code> method
  8. /// </summary>
  9. [Serializable]
  10. public class VirusDescription
  11. {
  12. public string Name;
  13. public Texture2D Textures;
  14. public string Description;
  15. public Transform TrParent;
  16. public Color ColorText;
  17. }
  18. [ExecuteInEditMode]
  19. public class VirusInfoScreen : MonoBehaviour
  20. {
  21. public static VirusInfoScreen Instance;
  22. public UITexture background;
  23. public UILabel label;
  24. public UILabel Name;
  25. public Texture2D[] textures;
  26. public UILabel man;
  27. public UILabel woman;
  28. private int curVirese;
  29. public float scaleY;
  30. public List<VirusDescription> ListDescription;
  31. //private EnemyType _enemy;
  32. void Start()
  33. {
  34. Instance = this;
  35. }
  36. private void ResetInfo()
  37. {
  38. foreach(var item in ListDescription)
  39. {
  40. if(item.TrParent!=null)
  41. {
  42. item.TrParent.gameObject.SetActive(false);
  43. }
  44. }
  45. }
  46. public void NextPage()
  47. {
  48. curVirese++;
  49. if(curVirese>textures.Length)
  50. {
  51. curVirese = 0;
  52. }
  53. ResetInfo();
  54. Texture2D texture = ListDescription[curVirese].Textures;
  55. background.mainTexture = texture;
  56. background.transform.localScale = new Vector3(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), Screen.height * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), background.transform.localScale.z);
  57. Debug.Log(Screen.height +" " + Screen.dpi);
  58. label.text = Localization.instance.Get(ListDescription[curVirese].Description);
  59. Name.text = Localization.instance.Get(ListDescription[curVirese].Name);
  60. }
  61. public void BackPage()
  62. {
  63. curVirese--;
  64. if (curVirese < 0)
  65. {
  66. curVirese = ListDescription.Count;
  67. }
  68. ResetInfo();
  69. Texture2D texture = ListDescription[curVirese-1].Textures;
  70. background.mainTexture = texture;
  71. background.transform.localScale = new Vector3(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), Screen.height * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), background.transform.localScale.z);
  72. //Debug.Log(Screen.height + " " + Screen.dpi);
  73. label.text = Localization.instance.Get(ListDescription[curVirese - 1].Description);
  74. Name.text = Localization.instance.Get(ListDescription[curVirese - 1].Name);
  75. }
  76. public void SetVirus(EnemyType virus)
  77. {
  78. //_enemy = virus;
  79. if(virus == EnemyType.herpes)
  80. {
  81. label.color = Color.white;
  82. }
  83. else
  84. {
  85. label.color = Color.yellow;
  86. }
  87. ResetInfo();
  88. curVirese = (int) virus;
  89. Texture2D texture = ListDescription[(int)virus].Textures;
  90. background.mainTexture = texture;
  91. background.transform.localScale = new Vector3(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), Screen.height * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), background.transform.localScale.z);
  92. AVDebug.Assert(virus.ToString() == texture.name, "The textures in the info screen need to be in the same order as in the VirusType enum. Also name needs to be exact for this assert to stop annoying you :). Found "+texture.name+" but virus is "+virus.ToString());
  93. label.lineWidth = 760;
  94. label.text = Localization.instance.Get(ListDescription[(int)virus].Description);
  95. Name.text = Localization.instance.Get(ListDescription[(int)virus].Name);
  96. ListDescription[(int)virus].TrParent.gameObject.SetActive(true);
  97. //Debug.Log(Screen.height + " " + Screen.dpi);
  98. }
  99. void Update()
  100. {
  101. background.transform.localScale = new Vector3(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), Screen.height * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height), background.transform.localScale.z);
  102. }
  103. }