using System.Collections;
using System.Collections.Generic;
public class ScrollBanner: MonoBehaviour {
private int bannerCount = 4; // バナーの数
private int nowBanner = 0; // 現在のバナーの番号
private float changeBannerTime = 3.0f; // バナーが切り替わる時間
private float nowChangeBannerTime = 0f; // バナーが切り替わる現在時間
private List<Transform> bannerList; // バナーのTransformのリスト
private List<UISprite> lightList; // ライトのUISpriteのリスト
private UICenterOnChild center; // ScrollViewにアタッチされたUICenterOnChild
private string[] bannerNameList = new string[]
private string[] lightNameList = new string[]
bannerList = new List<Transform>();
lightList = new List<UISprite>();
center = GetComponent<UICenterOnChild>();
for(int i = 0; i < bannerCount; i++)
GameObject banner = Instantiate(Resources.Load("Prefabs/Banner")) as GameObject;
banner.transform.parent = transform;
banner.transform.localScale = Vector3.one;
banner.GetComponent<UISprite>().spriteName = bannerNameList[i];
banner.name = "Banner" + i;
bannerList.Add(banner.transform);
GameObject light = Instantiate(Resources.Load("Prefabs/Light")) as GameObject;
light.transform.parent = transform.parent.FindChild("Lights");
light.transform.localScale = Vector3.one;
UISprite lightSprite = light.GetComponent<UISprite>();
lightSprite.spriteName = lightNameList[(int)LightStatus.ON];
lightSprite.spriteName = lightNameList[(int)LightStatus.OFF];
lightList.Add(lightSprite);
center.onCenter = DragBanner;
nowChangeBannerTime += Time.deltaTime;
if(nowChangeBannerTime > changeBannerTime)
public void OnClickNext()
public void OnClickPrev()
// バナーがドラッグされて切り替わった際に呼ばれるイベント
public void DragBanner(GameObject obj)
int bannerNo = int.Parse(obj.name.Replace("Banner", ""));
if(bannerNo == nowBanner) return;
public void SetPage(int no)
if(no >= bannerCount) nowBanner = 0;
else if(no < 0) nowBanner = bannerCount - 1;
center.CenterOn(bannerList[nowBanner].transform);
for(int i = 0; i < bannerCount; i++)
lightList[i].spriteName = lightNameList[(int)LightStatus.ON];
lightList[i].spriteName = lightNameList[(int)LightStatus.OFF];