wangguan
2020-12-29 452c75675679c44cc39b04bdb7d330d7c5c14d5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace MoreMountains.NiceVibrations
{
    public class Pagination : MonoBehaviour
    {
        public GameObject PaginationDotPrefab;
        public Color ActiveColor;
        public Color InactiveColor;
        protected List<Image> _images;
        
        public virtual void InitializePagination(int numberOfPages)
        {
            _images = new List<Image>();
            for (int i = 0; i < numberOfPages; i++)
            {
                GameObject dotPrefab = Instantiate(PaginationDotPrefab);
                dotPrefab.transform.SetParent(this.transform);
                dotPrefab.name = "PaginationDot" + i;
                _images.Add(dotPrefab.GetComponent<Image>());
            }
            foreach(Image image in _images)
            {
                image.color = InactiveColor;
                image.rectTransform.localScale = Vector3.one;
                image.rectTransform.localPosition = Vector3.zero;
                image.SetNativeSize();
            }
        }    
        
        public virtual void SetCurrentPage(int numberOfPages, int currentPage)
        {
            for (int i = 0; i < numberOfPages; i++)
            {
                if (i == currentPage)
                {
                    _images[i].color = ActiveColor;
                }
                else
                {
                    _images[i].color = InactiveColor;
                }
            }
        }
    }
}