Guest User

Untitled

a guest
Jan 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class MapLevel : MonoBehaviour
  4. {
  5. public static MapLevel ML;
  6. private Vector3 _originalScale;
  7. private bool _isScaled;
  8. public float OverScale = 1.05f;
  9. public float ClickScale = 0.95f;
  10.  
  11. public int Number;
  12. public bool IsLocked;
  13. public Transform Lock;
  14. public Transform PathPivot;
  15. public Object LevelScene;
  16. public string SceneName;
  17.  
  18. public int StarsCount;
  19. public Transform StarsHoster;
  20. public Transform Star1;
  21. public Transform Star2;
  22. public Transform Star3;
  23.  
  24. public Transform SolidStarsHoster;
  25. public Transform SolidStars0;
  26. public Transform SolidStars1;
  27. public Transform SolidStars2;
  28. public Transform SolidStars3;
  29.  
  30. public void Awake()
  31. {
  32. _originalScale = transform.localScale;
  33. }
  34.  
  35. #region Enable click
  36.  
  37. public void OnMouseEnter()
  38. {
  39. if (LevelsMap.GetIsClickEnabled())
  40. Scale(OverScale);
  41. }
  42.  
  43. public void OnMouseDown()
  44. {
  45. if (LevelsMap.GetIsClickEnabled())
  46. Scale(ClickScale);
  47. }
  48.  
  49. public void OnMouseExit()
  50. {
  51. if (LevelsMap.GetIsClickEnabled())
  52. ResetScale();
  53. }
  54.  
  55. private void Scale(float scaleValue)
  56. {
  57. transform.localScale = _originalScale * scaleValue;
  58. _isScaled = true;
  59. }
  60.  
  61. public void OnDisable()
  62. {
  63. if (LevelsMap.GetIsClickEnabled())
  64. ResetScale();
  65. }
  66.  
  67. public void OnMouseUpAsButton()
  68. {
  69. if (LevelsMap.GetIsClickEnabled() && !GameObject.Find("MenuPlay") && !GameObject.Find("BoostersLeftInfo") && !GameObject.Find("BoostersLeft") && !GameObject.Find("MenuTimerOn"))
  70. {
  71. ResetScale();
  72. LevelsMap.OnLevelSelected(Number);
  73. foreach (int lvl in LevelManager.THIS.keyLvl)
  74. {
  75. if (LevelsMap.IsLevelLocked(LevelManager.THIS.currentLevel + 1)) //если следующий уровень закрыт, значит этот еще не пройден.
  76. {
  77. if (LevelManager.THIS.currentLevel == lvl)// если входит в уровни с ключами и он еще не пройден, тогда открывается Меню таймера
  78. {
  79. if (GameObject.Find("MenuPlay"))
  80. {
  81. GameObject.Find("MenuPlay").SetActive(false);
  82. }
  83. GameObject.Find("CanvasGlobal").transform.Find("TimerPanel").transform.Find("MenuTimerOn").gameObject.SetActive(true);
  84. return;
  85. }
  86. }
  87. }
  88. }
  89. }
  90.  
  91.  
  92.  
  93. private void ResetScale()
  94. {
  95. if (_isScaled)
  96. transform.localScale = _originalScale;
  97. }
  98.  
  99. #endregion
  100.  
  101. public void UpdateState(int starsCount, bool isLocked)
  102. {
  103. StarsCount = starsCount;
  104. UpdateStars(starsCount);
  105. IsLocked = isLocked;
  106. Lock.gameObject.SetActive(isLocked);
  107. }
  108.  
  109. public void UpdateStars(int starsCount)
  110. {
  111. Star1.gameObject.SetActive(starsCount >= 1);
  112. Star2.gameObject.SetActive(starsCount >= 2);
  113. Star3.gameObject.SetActive(starsCount >= 3);
  114.  
  115. SolidStars0.gameObject.SetActive(starsCount == 0);
  116. SolidStars1.gameObject.SetActive(starsCount == 1);
  117. SolidStars2.gameObject.SetActive(starsCount == 2);
  118. SolidStars3.gameObject.SetActive(starsCount == 3);
  119. }
  120.  
  121. public void UpdateStarsType(StarsType starsType)
  122. {
  123. StarsHoster.gameObject.SetActive(starsType == StarsType.Separated);
  124. SolidStarsHoster.gameObject.SetActive(starsType == StarsType.Solid);
  125. }
  126. }
Add Comment
Please, Sign In to add comment