Garden.cs 12 KB

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