using Assets.Scripts; using Assets.Scripts.Apis.Models; using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class BannerController : MonoBehaviour { // Start is called before the first frame update private List itemList; private List standardPositions; private List list; private int currentIndex = 1; void Awake() { UIManager.AddEvent(transform.Find("L").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { Left(); }); UIManager.AddEvent(transform.Find("R").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { Right(); }); itemList = new List { transform.Find("1").GetComponent(), transform.Find("2").GetComponent(), transform.Find("3").GetComponent() }; standardPositions = new List { transform.Find("1").localPosition,transform.Find("2").localPosition,transform.Find("3").localPosition }; GetList(); Debug.Log(standardPositions[0]); Debug.Log(standardPositions[1]); Debug.Log(standardPositions[2]); } async void GetList() { var res = await ConfigHelper.mapApi.GetRecommendAreaList(); if (res.result) { Initial(res.data); } } public void Initial(List list) { int index = 0; foreach (CanvasGroup c in itemList) { c.GetComponent().Initial(list[index++]); } currentIndex = 1; this.list = list; } private void Right() { int center = GetCenterIndex(), left = GetSideIndex(true), right = GetSideIndex(false); if (center == -1 || left == -1 || right == -1) return; itemList[center].DOFade(0.5f, 0.5f); itemList[center].GetComponent().DOScale(Vector3.one * 0.8f, 0.5f); itemList[center].GetComponent().DOLocalMoveX(43, 0.5f); itemList[right].GetComponent().DOLocalMoveX(-43, 0.5f); itemList[right].GetComponent().Initial(list[((currentIndex++) + list.Count)% list.Count]); if (currentIndex >= list.Count) currentIndex = 0; itemList[left].DOFade(1, 0.5f); itemList[left].GetComponent().DOScale(Vector3.one, 0.5f); itemList[left].GetComponent().DOLocalMoveX(0, 0.5f); itemList[left].transform.SetAsLastSibling(); } private void Left() { int center = GetCenterIndex(), left = GetSideIndex(true), right = GetSideIndex(false); if (center == -1 || left == -1 || right == -1) return; itemList[center].DOFade(0.5f, 0.5f); itemList[center].GetComponent().DOScale(Vector3.one*0.8f, 0.5f); itemList[center].GetComponent().DOLocalMoveX(-43, 0.5f); itemList[left].GetComponent().DOLocalMoveX(43, 0.5f); itemList[left].GetComponent().Initial(list[((currentIndex--) + list.Count) % list.Count]); if (currentIndex < 0) currentIndex = list.Count - 1; itemList[right].DOFade(1, 0.5f); itemList[right].GetComponent().DOScale(Vector3.one, 0.5f); itemList[right].GetComponent().DOLocalMoveX(0, 0.5f); itemList[right].transform.SetAsLastSibling(); } int GetCenterIndex() { return itemList.FindIndex(x => x.transform.localPosition.x == 0); } int GetSideIndex(bool left) { return itemList.FindIndex(x => left ? x.transform.localPosition.x < 0 : x.transform.localPosition.x > 0); } // Update is called once per frame void Update() { } }