123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- using System.Collections;
- using System.Collections.Generic;
- public enum Direction
- {
- Left,
- Null,
- Right,
- }
- public class Garden : Regist, IDragHandler, IPointerClickHandler, IEndDragHandler, IBeginDragHandler
- {
- #region 变量
- public static int Page
- {
- get
- {
- return ManaGarden.PageList.Count - 1;
- }
- }
- public static int CurPage;
- public static bool Flag1 = true;
- public static bool Flag2 = true;
- public static float SlideSensi = 0.1f;
- public static float Ratio2 = 0.25f;
- public static float Ratio3 = 0.5f;
- public static float Ratio4 = 0.75f;
- public static float RatioPlayer = 0.75f;
- public static Garden Instance;
- public static Direction Direction;
- public static Transform Player;
- public static Transform Garden2;
- public static Transform Garden3;
- public static Transform Garden4;
- public static Transform GardenPage;
- public static List<Vector3> PagePos = new List<Vector3>();
- public static List<Vector3> PlayerPos = new List<Vector3>();
- public static List<Vector3> GardenPos2 = new List<Vector3>();
- public static List<Vector3> GardenPos3 = new List<Vector3>();
- public static List<Vector3> GardenPos4 = new List<Vector3>();
- #endregion
- public static void Reload()
- {
- ResetPage();
- CurPage = 0;
- PagePos = new List<Vector3>();
- }
- public override void RegistValueA()
- {
- Instance = this;
- #region Item
- ManaReso.Get("Bird0").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad, false, true);
- ManaReso.Get("Tree1").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad);
- ManaReso.Get("Tree2").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad);
- ManaReso.Get("Rainbow").CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad);
- #endregion
- #region Cloud1
- Transform tra = ManaReso.Get("Cloud1");
- TweenRoot tween = tra.CreateTweenVec2D(new Vector3(-12, tra.position.y, tra.position.z), 50f, false, false, true, Curve.Linear);
- tween.Repeat = true;
- tween.StartForward();
- #endregion
- #region Cloud2
- tra = ManaReso.Get("Cloud2");
- tween = tra.CreateTweenVec2D(new Vector3(-12, tra.position.y, tra.position.z), 75f, false, false, true, Curve.Linear);
- tween.Repeat = true;
- tween.StartForward();
- #endregion
- #region Cloud3
- tra = ManaReso.Get("Cloud3");
- tween = tra.CreateTweenVec2D(new Vector3(-12, tra.position.y, tra.position.z), 100, false, false, true, Curve.Linear);
- tween.Repeat = true;
- tween.StartForward();
- #endregion
- #region GardenMini
- ManaReso.Get("GardenMini").CreateTweenVec2D
- (
- ManaReso.Get("MiniPos").position,
- 0.5f,
- false,
- false,
- true,
- Curve.EaseOutQuad
- );
- #endregion
- #region GardenPage
- Move2D move2D = GardenPage.CreateMove2D();
- move2D.OnForwardStart += () =>
- {
- Flag2 = false;
- };
- move2D.OnForwardFinish += () =>
- {
- Flag2 = true;
- };
- #endregion
- }
- public override void RegistReference()
- {
- Garden2 = ManaReso.Get("Garden2");
- Garden3 = ManaReso.Get("Garden3");
- Garden4 = ManaReso.Get("Garden4");
- GardenPage = ManaReso.Get("GardenPage");
- GardenPos2.Add(ManaReso.Get("Pos21").position);
- GardenPos2.Add(ManaReso.Get("Pos22").position);
- GardenPos3.Add(ManaReso.Get("Pos31").position);
- GardenPos3.Add(ManaReso.Get("Pos32").position);
- GardenPos4.Add(ManaReso.Get("Pos41").position);
- GardenPos4.Add(ManaReso.Get("Pos42").position);
- if (!ManaTutorial.TutorialA)
- {
- Player = ManaReso.Get("Player");
- PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
- PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
- }
- }
- public override void TutorialToRegular()
- {
- Player = ManaReso.Get("Player");
- PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
- PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
- }
- public void OnDrag(PointerEventData eventData)
- {
- if (Flag1 && Flag2)
- {
- if (Direction == Direction.Null)
- {
- if (eventData.delta.x > 0)
- {
- Direction = Direction.Right;
- }
- else
- {
- Direction = Direction.Left;
- }
- }
-
- if (Direction == Direction.Left)
- {
- if (eventData.delta.x > 0)
- {
- Return();
- }
- else
- {
- #region MyRegion
- float rawDeltaX = eventData.position.x - eventData.pressPosition.x;
- if (CurPage < Page - 1)
- {
- float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2);
- if (Page == 1)
- {
- tempX *= SlideSensi;
- }
- else
- {
- tempX *= SlideSensi / (Page - 1);
- }
- Player.Translate(Player.right * tempX * RatioPlayer, Space.World);
- Garden2.Translate(Garden2.right * tempX * Ratio2, Space.World);
- Garden3.Translate(Garden3.right * tempX * Ratio3, Space.World);
- Garden4.Translate(Garden4.right * tempX * Ratio4, Space.World);
- GardenPage.Translate(GardenPage.right * tempX, Space.World);
- if (rawDeltaX < -300)
- {
- NextPage();
- }
- }
- else
- {
- float ratio = Mathf.Abs(GardenPage.position.x - PagePos.Last(1).x)/0.7f;
- float sensi = Mathf.Lerp(SlideSensi, 0, ratio);
- float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2) * sensi;
- GardenPage.Translate(GardenPage.right * tempX, Space.World);
- }
- #endregion
- }
- }
- else if (Direction == Direction.Right)
- {
- if (eventData.delta.x < 0)
- {
- Return();
- }
- else
- {
- #region MyRegion
- float rawDeltaX = eventData.position.x - eventData.pressPosition.x;
- if (CurPage > 0)
- {
- float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2);
- if (Page == 1)
- {
- tempX *= SlideSensi;
- }
- else
- {
- tempX *= SlideSensi / (Page - 1);
- }
- Player.Translate(Player.right * tempX * RatioPlayer, Space.World);
- Garden2.Translate(Garden2.right * tempX * Ratio2, Space.World);
- Garden3.Translate(Garden3.right * tempX * Ratio3, Space.World);
- Garden4.Translate(Garden4.right * tempX * Ratio4, Space.World);
- GardenPage.Translate(GardenPage.right * tempX, Space.World);
- if (rawDeltaX > 300)
- {
- PrevPage();
- }
- }
- else
- {
- float ratio = Mathf.Abs(GardenPage.position.x - PagePos[0].x) / 0.7f;
- float sensi = Mathf.Lerp(SlideSensi, 0, ratio);
- float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2) * sensi;
- GardenPage.Translate(GardenPage.right * tempX, Space.World);
- }
- #endregion
- }
- }
- }
- }
- public void OnEndDrag(PointerEventData eventData)
- {
- if (Flag1 && Flag2)
- {
- Return();
- }
- Flag1 = true;
- Direction = Direction.Null;
- }
- public void OnBeginDrag(PointerEventData eventData)
- {
- Direction = Direction.Null;
- }
- public void OnPointerClick(PointerEventData eventData)
- {
- if (!eventData.hovered.Contains(eventData.rawPointerPress))
- {
- return;
- }
-
- if (eventData.rawPointerPress.transform.name.Contains("Slot"))
- {
- if (ManaVisit.InVisit)
- {
- return;
- }
- Slot slot = eventData.rawPointerPress.GetComponentInParent<Slot>();
- if (slot.Lock == false)
- {
- Toast.Show(1.5f, Language.GetStr("Common", "UnlockSlot"));
- }
- else
- {
- ManaReso.Get("G_Flower").TweenForCG();
- }
- }
- }
- public static void Return()
- {
- Flag1 = false;
- float ratio;
- if (Page == 1)
- {
- ratio = 0;
- }
- else
- {
- ratio = CurPage / (Page - 1f);
- }
- Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio);
- Vector3 gardenPos2 = Vector3.Lerp(GardenPos2[0], GardenPos2[1], ratio);
- Vector3 gardenPos3 = Vector3.Lerp(GardenPos3[0], GardenPos3[1], ratio);
- Vector3 gardenPos4 = Vector3.Lerp(GardenPos4[0], GardenPos4[1], ratio);
- Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad);
- Garden2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad);
- Garden3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad);
- Garden4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad);
- GardenPage.Move2D(PagePos[CurPage], 0.5f, false, Curve.EaseOutQuad);
- }
- public static void PrevPage()
- {
- CurPage--;
-
- Flag1 = false;
- float ratio = CurPage / (Page - 1f);
- Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio);
- Vector3 gardenPos2 = Vector3.Lerp(GardenPos2[0], GardenPos2[1], ratio);
- Vector3 gardenPos3 = Vector3.Lerp(GardenPos3[0], GardenPos3[1], ratio);
- Vector3 gardenPos4 = Vector3.Lerp(GardenPos4[0], GardenPos4[1], ratio);
- Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad);
- Garden2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad);
- Garden3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad);
- Garden4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad);
- GardenPage.Move2D(PagePos[CurPage], 0.5f, false, Curve.EaseOutQuad);
- }
- public static void NextPage()
- {
- CurPage++;
-
- Flag1 = false;
- float ratio = CurPage / (Page - 1f);
- Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio);
- Vector3 gardenPos2 = Vector3.Lerp(GardenPos2[0], GardenPos2[1], ratio);
- Vector3 gardenPos3 = Vector3.Lerp(GardenPos3[0], GardenPos3[1], ratio);
- Vector3 gardenPos4 = Vector3.Lerp(GardenPos4[0], GardenPos4[1], ratio);
- Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad);
- Garden2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad);
- Garden3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad);
- Garden4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad);
- GardenPage.Move2D(PagePos[CurPage], 0.5f, false, Curve.EaseOutQuad);
- }
- public static void ResetPage()
- {
- Garden2.position = GardenPos2[0];
- Garden3.position = GardenPos3[0];
- Garden4.position = GardenPos4[0];
- GardenPage.position = PagePos[0];
- }
- }
|