using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
[DisallowMultipleComponent]
|
public class CalculateLayout : MonoBehaviour
|
{
|
[Header("起始位置")]
|
[SerializeField] public Vector3 starPos;
|
|
[Header("预制体大小")]
|
[SerializeField] Vector2 m_CellSize = new Vector2(100, 100);
|
public Vector2 cellSize
|
{
|
get { return m_CellSize; }
|
}
|
[Header("间隔")]
|
[SerializeField] public float m_SpacingY;
|
|
[Header("延迟时间")]
|
[SerializeField] public float delayTime = 0.1f;
|
|
List<GameObject> golist;
|
|
public void Init(List<GameObject> golist, bool _stepByStep = false)
|
{
|
this.golist = null;
|
if (golist == null) return;
|
this.gameObject.SetActive(true);
|
this.golist = golist;
|
if (_stepByStep)
|
{
|
for (int i = 0; i < golist.Count; i++)
|
{
|
golist[i].SetActive(false);
|
}
|
}
|
|
for(int i = 0; i < golist.Count;i++)
|
{
|
GameObject go = golist[i];
|
float posX = starPos.x;
|
float posY = starPos.y -(cellSize.y + m_SpacingY)*i;
|
go.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(posX,posY,0);
|
}
|
|
if(_stepByStep)
|
{
|
StartCoroutine("Co_StepByStepAppear");
|
}
|
}
|
|
IEnumerator Co_StepByStepAppear()
|
{
|
if(golist != null)
|
{
|
for (int i = 0; i < golist.Count; i++)
|
{
|
golist[i].SetActive(true);
|
yield return new WaitForSeconds(delayTime);
|
}
|
}
|
}
|
|
private void OnDisable()
|
{
|
golist = null;
|
}
|
}
|
|
}
|