Garden.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.EventSystems;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. public enum Direction
  7. {
  8. Left,
  9. Null,
  10. Right,
  11. }
  12. public class Garden : Regist, IDragHandler, IPointerClickHandler, IEndDragHandler, IBeginDragHandler
  13. {
  14. #region 变量
  15. public static int Page
  16. {
  17. get
  18. {
  19. return ManaGarden.PageList.Count - 1;
  20. }
  21. }
  22. public static int CurPage;
  23. public static bool Flag1 = true;
  24. public static bool Flag2 = true;
  25. public static float SlideSensi = 0.1f;
  26. public static float Ratio2 = 0.25f;
  27. public static float Ratio3 = 0.5f;
  28. public static float Ratio4 = 0.75f;
  29. public static float RatioPlayer = 0.75f;
  30. public static Garden Instance;
  31. public static Direction Direction;
  32. public static Transform Player;
  33. public static Transform Garden2;
  34. public static Transform Garden3;
  35. public static Transform Garden4;
  36. public static Transform GardenPage;
  37. public static List<Vector3> PagePos = new List<Vector3>();
  38. public static List<Vector3> PlayerPos = new List<Vector3>();
  39. public static List<Vector3> GardenPos2 = new List<Vector3>();
  40. public static List<Vector3> GardenPos3 = new List<Vector3>();
  41. public static List<Vector3> GardenPos4 = new List<Vector3>();
  42. #endregion
  43. public static void Reload()
  44. {
  45. ResetPage();
  46. CurPage = 0;
  47. PagePos = new List<Vector3>();
  48. }
  49. public override void RegistValueA()
  50. {
  51. Instance = this;
  52. #region Item
  53. ManaReso.Get("Bird0").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad, false, true);
  54. ManaReso.Get("Tree1").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad);
  55. ManaReso.Get("Tree2").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad);
  56. ManaReso.Get("Rainbow").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad);
  57. #endregion
  58. #region Cloud1
  59. Transform tra = ManaReso.Get("Cloud1");
  60. TweenRoot tween = tra.CreateTweenVec2D(new Vector3(-12, tra.position.y, tra.position.z), 50f, false, false, true, Curve.Linear);
  61. tween.Repeat = true;
  62. tween.StartForward();
  63. #endregion
  64. #region Cloud2
  65. tra = ManaReso.Get("Cloud2");
  66. tween = tra.CreateTweenVec2D(new Vector3(-12, tra.position.y, tra.position.z), 75f, false, false, true, Curve.Linear);
  67. tween.Repeat = true;
  68. tween.StartForward();
  69. #endregion
  70. #region Cloud3
  71. tra = ManaReso.Get("Cloud3");
  72. tween = tra.CreateTweenVec2D(new Vector3(-12, tra.position.y, tra.position.z), 100, false, false, true, Curve.Linear);
  73. tween.Repeat = true;
  74. tween.StartForward();
  75. #endregion
  76. #region GardenMini
  77. ManaReso.Get("GardenMini").CreateTweenVec2D
  78. (
  79. ManaReso.Get("MiniPos").position,
  80. 0.5f,
  81. false,
  82. false,
  83. true,
  84. Curve.EaseOutQuad
  85. );
  86. #endregion
  87. #region GardenPage
  88. Move2D move2D = GardenPage.CreateMove2D();
  89. move2D.OnForwardStart += () =>
  90. {
  91. Flag2 = false;
  92. };
  93. move2D.OnForwardFinish += () =>
  94. {
  95. Flag2 = true;
  96. };
  97. #endregion
  98. }
  99. public override void RegistReference()
  100. {
  101. Garden2 = ManaReso.Get("Garden2");
  102. Garden3 = ManaReso.Get("Garden3");
  103. Garden4 = ManaReso.Get("Garden4");
  104. GardenPage = ManaReso.Get("GardenPage");
  105. GardenPos2.Add(ManaReso.Get("Pos21").position);
  106. GardenPos2.Add(ManaReso.Get("Pos22").position);
  107. GardenPos3.Add(ManaReso.Get("Pos31").position);
  108. GardenPos3.Add(ManaReso.Get("Pos32").position);
  109. GardenPos4.Add(ManaReso.Get("Pos41").position);
  110. GardenPos4.Add(ManaReso.Get("Pos42").position);
  111. if (!ManaTutorial.TutorialA)
  112. {
  113. Player = ManaReso.Get("Player");
  114. PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  115. PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  116. }
  117. }
  118. public override void TutorialToRegular()
  119. {
  120. Player = ManaReso.Get("Player");
  121. PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  122. PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  123. }
  124. public void OnDrag(PointerEventData eventData)
  125. {
  126. if (Flag1 && Flag2)
  127. {
  128. if (Direction == Direction.Null)
  129. {
  130. if (eventData.delta.x > 0)
  131. {
  132. Direction = Direction.Right;
  133. }
  134. else
  135. {
  136. Direction = Direction.Left;
  137. }
  138. }
  139. if (Direction == Direction.Left)
  140. {
  141. if (eventData.delta.x > 0)
  142. {
  143. Return();
  144. }
  145. else
  146. {
  147. #region MyRegion
  148. float rawDeltaX = eventData.position.x - eventData.pressPosition.x;
  149. if (CurPage < Page - 1)
  150. {
  151. float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2);
  152. if (Page == 1)
  153. {
  154. tempX *= SlideSensi;
  155. }
  156. else
  157. {
  158. tempX *= SlideSensi / (Page - 1);
  159. }
  160. Player.Translate(Player.right * tempX * RatioPlayer, Space.World);
  161. Garden2.Translate(Garden2.right * tempX * Ratio2, Space.World);
  162. Garden3.Translate(Garden3.right * tempX * Ratio3, Space.World);
  163. Garden4.Translate(Garden4.right * tempX * Ratio4, Space.World);
  164. GardenPage.Translate(GardenPage.right * tempX, Space.World);
  165. if (rawDeltaX < -300)
  166. {
  167. NextPage();
  168. }
  169. }
  170. else
  171. {
  172. float ratio = Mathf.Abs(GardenPage.position.x - PagePos.Last(1).x)/0.7f;
  173. float sensi = Mathf.Lerp(SlideSensi, 0, ratio);
  174. float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2) * sensi;
  175. GardenPage.Translate(GardenPage.right * tempX, Space.World);
  176. }
  177. #endregion
  178. }
  179. }
  180. else if (Direction == Direction.Right)
  181. {
  182. if (eventData.delta.x < 0)
  183. {
  184. Return();
  185. }
  186. else
  187. {
  188. #region MyRegion
  189. float rawDeltaX = eventData.position.x - eventData.pressPosition.x;
  190. if (CurPage > 0)
  191. {
  192. float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2);
  193. if (Page == 1)
  194. {
  195. tempX *= SlideSensi;
  196. }
  197. else
  198. {
  199. tempX *= SlideSensi / (Page - 1);
  200. }
  201. Player.Translate(Player.right * tempX * RatioPlayer, Space.World);
  202. Garden2.Translate(Garden2.right * tempX * Ratio2, Space.World);
  203. Garden3.Translate(Garden3.right * tempX * Ratio3, Space.World);
  204. Garden4.Translate(Garden4.right * tempX * Ratio4, Space.World);
  205. GardenPage.Translate(GardenPage.right * tempX, Space.World);
  206. if (rawDeltaX > 300)
  207. {
  208. PrevPage();
  209. }
  210. }
  211. else
  212. {
  213. float ratio = Mathf.Abs(GardenPage.position.x - PagePos[0].x) / 0.7f;
  214. float sensi = Mathf.Lerp(SlideSensi, 0, ratio);
  215. float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2) * sensi;
  216. GardenPage.Translate(GardenPage.right * tempX, Space.World);
  217. }
  218. #endregion
  219. }
  220. }
  221. }
  222. }
  223. public void OnEndDrag(PointerEventData eventData)
  224. {
  225. if (Flag1 && Flag2)
  226. {
  227. Return();
  228. }
  229. Flag1 = true;
  230. Direction = Direction.Null;
  231. }
  232. public void OnBeginDrag(PointerEventData eventData)
  233. {
  234. Direction = Direction.Null;
  235. }
  236. public void OnPointerClick(PointerEventData eventData)
  237. {
  238. if (!eventData.hovered.Contains(eventData.rawPointerPress))
  239. {
  240. return;
  241. }
  242. if (eventData.rawPointerPress.transform.name.Contains("Slot"))
  243. {
  244. if (ManaVisit.InVisit)
  245. {
  246. return;
  247. }
  248. Slot slot = eventData.rawPointerPress.GetComponentInParent<Slot>();
  249. if (slot.Lock == false)
  250. {
  251. Toast.Show(1.5f, Language.GetStr("Common", "UnlockSlot"));
  252. }
  253. else
  254. {
  255. ManaReso.Get("G_Flower").TweenForCG();
  256. }
  257. }
  258. }
  259. public static void Return()
  260. {
  261. Flag1 = false;
  262. float ratio;
  263. if (Page == 1)
  264. {
  265. ratio = 0;
  266. }
  267. else
  268. {
  269. ratio = CurPage / (Page - 1f);
  270. }
  271. Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio);
  272. Vector3 gardenPos2 = Vector3.Lerp(GardenPos2[0], GardenPos2[1], ratio);
  273. Vector3 gardenPos3 = Vector3.Lerp(GardenPos3[0], GardenPos3[1], ratio);
  274. Vector3 gardenPos4 = Vector3.Lerp(GardenPos4[0], GardenPos4[1], ratio);
  275. Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad);
  276. Garden2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad);
  277. Garden3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad);
  278. Garden4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad);
  279. GardenPage.Move2D(PagePos[CurPage], 0.5f, false, Curve.EaseOutQuad);
  280. }
  281. public static void PrevPage()
  282. {
  283. CurPage--;
  284. Flag1 = false;
  285. float ratio = CurPage / (Page - 1f);
  286. Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio);
  287. Vector3 gardenPos2 = Vector3.Lerp(GardenPos2[0], GardenPos2[1], ratio);
  288. Vector3 gardenPos3 = Vector3.Lerp(GardenPos3[0], GardenPos3[1], ratio);
  289. Vector3 gardenPos4 = Vector3.Lerp(GardenPos4[0], GardenPos4[1], ratio);
  290. Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad);
  291. Garden2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad);
  292. Garden3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad);
  293. Garden4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad);
  294. GardenPage.Move2D(PagePos[CurPage], 0.5f, false, Curve.EaseOutQuad);
  295. }
  296. public static void NextPage()
  297. {
  298. CurPage++;
  299. Flag1 = false;
  300. float ratio = CurPage / (Page - 1f);
  301. Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio);
  302. Vector3 gardenPos2 = Vector3.Lerp(GardenPos2[0], GardenPos2[1], ratio);
  303. Vector3 gardenPos3 = Vector3.Lerp(GardenPos3[0], GardenPos3[1], ratio);
  304. Vector3 gardenPos4 = Vector3.Lerp(GardenPos4[0], GardenPos4[1], ratio);
  305. Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad);
  306. Garden2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad);
  307. Garden3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad);
  308. Garden4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad);
  309. GardenPage.Move2D(PagePos[CurPage], 0.5f, false, Curve.EaseOutQuad);
  310. }
  311. public static void ResetPage()
  312. {
  313. Garden2.position = GardenPos2[0];
  314. Garden3.position = GardenPos3[0];
  315. Garden4.position = GardenPos4[0];
  316. GardenPage.position = PagePos[0];
  317. }
  318. }