using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class UIArrowMove : MonoBehaviour
{
public int ji;
public int chengji;
int id;//ID
public Text text;//页数显示
int a;//一次显示多少元素
public Vector2[] pos;
List<GameObject> itemSX = new List<GameObject>();//剩下的item不够一篇的
int anjici;
[Tooltip("XY间距")]
public float x;
public float y;
[Tooltip("position 调节")]
public float xOffect;
public float yOffect;
List<GameObject> list = new List<GameObject>();
// Start is called before the first frame update
void Start()
{
for (int i = 1; i <=80; i++)
{
id++;
GameObject aa = Instantiate(Resources.Load("Button"), transform) as GameObject;
aa.transform.GetChild(0).GetComponent<Text>().text = id.ToString();
aa.SetActive(false);
list.Add(aa);
}
//记录位置
for (int i = 1; i <= chengji; i++)
{
for (int j = 1; j <= ji; j++)
{
pos[a]= new Vector2(j * x + xOffect, i * y + yOffect);
a++;
#region MyRegion
//id++;
//GameObject aa = Instantiate(Resources.Load("Button"), transform) as GameObject;
//aa.transform.GetChild(0).GetComponent<Text>().text = id.ToString();
//aa.GetComponent<RectTransform>().localPosition = new Vector2(j * x + xOffect, i * y + yOffect);
#endregion
}
}
for (int i =0; i <a; i++)
{
list[i].SetActive(true);
list[i].transform.localPosition = pos[i];
}
anjici = list.Count / a;
for (int i = anjici*a; i < list.Count; i++)
{
itemSX.Add(list[i]);
}
}
int iitem=0;
public void RightClickToMove()
{
RightClickFunction();
}
public void LeftClickToMove()
{
LeftFunction();
}
void RightClickFunction()
{
List<GameObject> guodu = new List<GameObject>();
if (anjici > 0 && itemSX.Count != 0)
{
anjici--;
iitem++;
for (int i = 0; i < list.Count; i++)
{
list[i].SetActive(false);
}
if (anjici > 0)
{
for (int i = iitem * a; i < a + (iitem * a); i++)
{
guodu.Add(list[i]);
//list[i].SetActive(true);
//list[i].transform.localPosition = pos[1];
}
for (int i = 0; i < guodu.Count; i++)
{
guodu[i].SetActive(true);
guodu[i].transform.localPosition = pos[i];
}
}
else if (anjici == 0)
{
for (int i = 0; i < itemSX.Count; i++)
{
itemSX[i].SetActive(true);
itemSX[i].transform.localPosition = pos[i];
}
}
text.text = (iitem + 1).ToString();
print(anjici);
}
if (anjici > 1 && itemSX.Count == 0)
{
anjici--;
iitem++;
for (int i = 0; i < list.Count; i++)
{
list[i].SetActive(false);
}
if (anjici > 0)
{
for (int i = iitem * a; i < a + (iitem * a); i++)
{
guodu.Add(list[i]);
//list[i].SetActive(true);
//list[i].transform.localPosition = pos[1];
}
for (int i = 0; i < guodu.Count; i++)
{
guodu[i].SetActive(true);
guodu[i].transform.localPosition = pos[i];
}
}
text.text = (iitem + 1).ToString();
print(anjici);
}
}
void LeftFunction()
{
List<GameObject> guodu = new List<GameObject>();
if (anjici < list.Count / a)
{
anjici++;
iitem--;
for (int i = 0; i < list.Count; i++)
{
list[i].SetActive(false);
}
if (anjici < list.Count / a)
{
for (int i = iitem * a; i <a + (iitem * a); i++)
{
guodu.Add(list[i]);
}
for (int i = 0; i < guodu.Count; i++)
{
guodu[i].SetActive(true);
guodu[i].transform.localPosition = pos[i];
}
}
else if (anjici == list.Count / a)
{
for (int i = 0; i < a; i++)
{
list[i].SetActive(true);
list[i].transform.localPosition = pos[i];
}
}
text.text = (iitem + 1).ToString();
print(anjici);
}
}
}