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 Config public static int TotalPage { get { return GardenManager.SlotPageList.Count - 1; } } public static int CurrentPage; public static bool MoveFlag1 = true; public static bool MoveFlag2 = true; public static float SlideSpeed = 0.1f; public static float BK2MoveRatio = 0.25f; public static float BK3MoveRatio = 0.5f; public static float BK4MoveRatio = 0.75f; public static float PlayerMoveRatio = 0.75f; public static Garden Instance; public static Direction Direction; public static Transform Player; public static Transform GardenBK2; public static Transform GardenBK3; public static Transform GardenBK4; public static Transform GardenPage; public static List PagePos = new List(); public static List PlayerPos = new List(); public static List GardenBK2Pos = new List(); public static List GardenBK3Pos = new List(); public static List GardenBK4Pos = new List(); #endregion public override bool InitAtOnce() { if (base.InitAtOnce()) { return true; } Instance = this; #region Item ResourceManager.Get(GardenLabel.BirdPivot).CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad, false, true); ResourceManager.Get(GardenLabel.GardenLeftTree).CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad); ResourceManager.Get(GardenLabel.GardenRightTree).CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad); ResourceManager.Get(GardenLabel.GardenRainbow).CreateTweenSr(0, 1, 2f, false, true, Curve.EaseOutQuad); #endregion #region Cloud1 Transform tra = ResourceManager.Get(GardenLabel.GardenCloud1); TweenRoot tween = tra.CreateTweenVec2D(new Vector3(-14, tra.localPosition.y, tra.localPosition.z), 85f, true, false, true, Curve.Linear); tween.Repeat = true; tween.StartForward(); #endregion #region Cloud2 tra = ResourceManager.Get(GardenLabel.GardenCloud2); tween = tra.CreateTweenVec2D(new Vector3(-14, tra.localPosition.y, tra.localPosition.z), 127.5f, true, false, true, Curve.Linear); tween.Repeat = true; tween.StartForward(); #endregion #region Cloud3 tra = ResourceManager.Get(GardenLabel.GardenCloud3); tween = tra.CreateTweenVec2D(new Vector3(-14, tra.localPosition.y, tra.localPosition.z), 170f, true, false, true, Curve.Linear); tween.Repeat = true; tween.StartForward(); #endregion #region Garden transform.CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad, false, true); #endregion #region GardenMini ResourceManager.Get(GardenLabel.Minigame).CreateTweenVec2D ( ResourceManager.Get(GardenLabel.MinigameLeftPos).position, 0.5f, false, false, true, Curve.EaseOutQuad ); #endregion #region GardenPage GardenPage = ResourceManager.Get(GardenLabel.SlotPage); Move2D move2D = GardenPage.CreateMove2D(); move2D.OnForwardStart += () => { MoveFlag2 = false; }; move2D.OnForwardFinish += () => { MoveFlag2 = true; }; #endregion return false; } public override void RegistReference() { GardenBK2 = ResourceManager.Get(GardenLabel.GardenBK2); GardenBK3 = ResourceManager.Get(GardenLabel.GardenBK3); GardenBK4 = ResourceManager.Get(GardenLabel.GardenBK4); GardenBK2Pos.Add(ResourceManager.Get(GardenLabel.BK2RightPos).position); GardenBK2Pos.Add(ResourceManager.Get(GardenLabel.BK2LeftPos).position); GardenBK3Pos.Add(ResourceManager.Get(GardenLabel.BK3RightPos).position); GardenBK3Pos.Add(ResourceManager.Get(GardenLabel.BK3LeftPos).position); GardenBK4Pos.Add(ResourceManager.Get(GardenLabel.BK4RightPos).position); GardenBK4Pos.Add(ResourceManager.Get(GardenLabel.BK4LeftPos).position); if (!TutorialManager.NewplayerTutorial) { Player = ResourceManager.Get(PlayerLabel.Player); PlayerPos.Add(PlayerManager.Player.ChildDic[PlayerLabel.RightPos].position); PlayerPos.Add(PlayerManager.Player.ChildDic[PlayerLabel.LeftPos].position); } } public override void FirstInit() { ResetPage(); } public override void TutorialToRegular() { Player = ResourceManager.Get(PlayerLabel.Player); PlayerPos.Add(PlayerManager.Player.ChildDic[PlayerLabel.RightPos].position); PlayerPos.Add(PlayerManager.Player.ChildDic[PlayerLabel.LeftPos].position); } public void OnDrag(PointerEventData eventData) { if (MoveFlag1 && MoveFlag2) { 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 (CurrentPage < TotalPage - 1) { float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2); if (TotalPage == 1) { tempX *= SlideSpeed; } else { tempX *= SlideSpeed / (TotalPage - 1); } Player.Translate(Player.right * tempX * PlayerMoveRatio, Space.World); GardenBK2.Translate(GardenBK2.right * tempX * BK2MoveRatio, Space.World); GardenBK3.Translate(GardenBK3.right * tempX * BK3MoveRatio, Space.World); GardenBK4.Translate(GardenBK4.right * tempX * BK4MoveRatio, Space.World); GardenPage.Translate(GardenPage.right * tempX, Space.World); if (rawDeltaX < -300) { NextPage(); } } else { float ratio = Mathf.Abs(GardenPage.position.x - PagePos.Back(1).x)/0.7f; float sensi = Mathf.Lerp(SlideSpeed, 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 (CurrentPage > 0) { float tempX = Mathf.Clamp(eventData.delta.x / 10, -2, 2); if (TotalPage == 1) { tempX *= SlideSpeed; } else { tempX *= SlideSpeed / (TotalPage - 1); } Player.Translate(Player.right * tempX * PlayerMoveRatio, Space.World); GardenBK2.Translate(GardenBK2.right * tempX * BK2MoveRatio, Space.World); GardenBK3.Translate(GardenBK3.right * tempX * BK3MoveRatio, Space.World); GardenBK4.Translate(GardenBK4.right * tempX * BK4MoveRatio, 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(SlideSpeed, 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 (MoveFlag1 && MoveFlag2) { Return(); } MoveFlag1 = 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(SlotLabel.Slot)) { if (VisitManager.InVisit) { return; } Slot slot = eventData.rawPointerPress.GetComponentInParent(); if (slot.Lock == false) { Toast.Show(1.5f, Language.GetStr(LanguageLabel.Common__UnlockSlot)); } else { ResourceManager.Get(CanvasLabel.G_Flower).TweenForCG(); } } } public static void Return() { MoveFlag1 = false; float ratio; if (TotalPage == 1) { ratio = 0; } else { ratio = CurrentPage / (TotalPage - 1f); } Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio); Vector3 gardenPos2 = Vector3.Lerp(GardenBK2Pos[0], GardenBK2Pos[1], ratio); Vector3 gardenPos3 = Vector3.Lerp(GardenBK3Pos[0], GardenBK3Pos[1], ratio); Vector3 gardenPos4 = Vector3.Lerp(GardenBK4Pos[0], GardenBK4Pos[1], ratio); Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad); GardenBK2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad); GardenBK3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad); GardenBK4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad); GardenPage.Move2D(PagePos[CurrentPage], 0.5f, false, Curve.EaseOutQuad); } public static void PrevPage() { CurrentPage--; MoveFlag1 = false; float ratio = CurrentPage / (TotalPage - 1f); Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio); Vector3 gardenPos2 = Vector3.Lerp(GardenBK2Pos[0], GardenBK2Pos[1], ratio); Vector3 gardenPos3 = Vector3.Lerp(GardenBK3Pos[0], GardenBK3Pos[1], ratio); Vector3 gardenPos4 = Vector3.Lerp(GardenBK4Pos[0], GardenBK4Pos[1], ratio); Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad); GardenBK2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad); GardenBK3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad); GardenBK4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad); GardenPage.Move2D(PagePos[CurrentPage], 0.5f, false, Curve.EaseOutQuad); } public static void NextPage() { CurrentPage++; MoveFlag1 = false; float ratio = CurrentPage / (TotalPage - 1f); Vector3 playerPos = Vector3.Lerp(PlayerPos[0], PlayerPos[1], ratio); Vector3 gardenPos2 = Vector3.Lerp(GardenBK2Pos[0], GardenBK2Pos[1], ratio); Vector3 gardenPos3 = Vector3.Lerp(GardenBK3Pos[0], GardenBK3Pos[1], ratio); Vector3 gardenPos4 = Vector3.Lerp(GardenBK4Pos[0], GardenBK4Pos[1], ratio); Player.Move2D(playerPos, 0.5f, false, Curve.EaseOutQuad); GardenBK2.Move2D(gardenPos2, 0.5f, false, Curve.EaseOutQuad); GardenBK3.Move2D(gardenPos3, 0.5f, false, Curve.EaseOutQuad); GardenBK4.Move2D(gardenPos4, 0.5f, false, Curve.EaseOutQuad); GardenPage.Move2D(PagePos[CurrentPage], 0.5f, false, Curve.EaseOutQuad); } public static void ResetPage() { CurrentPage = 0; GardenBK2.position = GardenBK2Pos[0]; GardenBK3.position = GardenBK3Pos[0]; GardenBK4.position = GardenBK4Pos[0]; GardenPage.position = PagePos[0]; } }