电子相册V2代码
2015-10-19 23:38
225 查看
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;
public class ChangePic : MonoBehaviour {
// Use this for initialization
Image img;
string[] picName = {"1","2","3","4","5","6"};
string[] buttonName = {"Uper","Down"};
string[] picImageName = {"Pic1","Pic","Pic2"};
int x = 0;
void Start () {
for (int i = 0; i<buttonName.Length; i++) {
GameObject obj = GameObject.Find (buttonName[i]);
Button but = obj.GetComponent<Button> ();
but.onClick.AddListener (
delegate() {
//this.Upper(but.name);
//this.Down(but.name);
this.UpAndDown(but.name);
});
}
for (int i = 0; i<picImageName.Length; i++) {
img = GameObject.Find (picImageName[i]).GetComponent<Image> ();
img.sprite = Resources.Load (picName [x+i], typeof(Sprite)) as Sprite;
}
}
public void UpAndDown(string str)
{
if (str == "Uper") {
x++;
if (x > picName.Length - 1) {
x = 0;
}
for (int i = 0; i<picImageName.Length; i++) {
int num = x+i;
if(num>picName.Length-1)num-=picName.Length;
img = GameObject.Find (picImageName[i]).GetComponent<Image> ();
img.sprite = Resources.Load (picName [num], typeof(Sprite)) as Sprite;
}
//img.sprite = Resources.Load (picName [x], typeof(Sprite))as Sprite;
}
if (str == "Down") {
x--;
if (x < 0) {
x = picName.Length - 1;
}
for (int i = 0; i<picImageName.Length; i++) {
int num = x+i;
if(num>picName.Length-1)num-=picName.Length;
img = GameObject.Find (picImageName[i]).GetComponent<Image> ();
img.sprite = Resources.Load (picName [num], typeof(Sprite)) as Sprite;
}
//img.sprite = Resources.Load (picName [x], typeof(Sprite))as Sprite;
}
}
// Update is called once per frame
void Update () {
}
}
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;
public class ChangePic : MonoBehaviour {
// Use this for initialization
Image img;
string[] picName = {"1","2","3","4","5","6"};
string[] buttonName = {"Uper","Down"};
string[] picImageName = {"Pic1","Pic","Pic2"};
int x = 0;
void Start () {
for (int i = 0; i<buttonName.Length; i++) {
GameObject obj = GameObject.Find (buttonName[i]);
Button but = obj.GetComponent<Button> ();
but.onClick.AddListener (
delegate() {
//this.Upper(but.name);
//this.Down(but.name);
this.UpAndDown(but.name);
});
}
for (int i = 0; i<picImageName.Length; i++) {
img = GameObject.Find (picImageName[i]).GetComponent<Image> ();
img.sprite = Resources.Load (picName [x+i], typeof(Sprite)) as Sprite;
}
}
public void UpAndDown(string str)
{
if (str == "Uper") {
x++;
if (x > picName.Length - 1) {
x = 0;
}
for (int i = 0; i<picImageName.Length; i++) {
int num = x+i;
if(num>picName.Length-1)num-=picName.Length;
img = GameObject.Find (picImageName[i]).GetComponent<Image> ();
img.sprite = Resources.Load (picName [num], typeof(Sprite)) as Sprite;
}
//img.sprite = Resources.Load (picName [x], typeof(Sprite))as Sprite;
}
if (str == "Down") {
x--;
if (x < 0) {
x = picName.Length - 1;
}
for (int i = 0; i<picImageName.Length; i++) {
int num = x+i;
if(num>picName.Length-1)num-=picName.Length;
img = GameObject.Find (picImageName[i]).GetComponent<Image> ();
img.sprite = Resources.Load (picName [num], typeof(Sprite)) as Sprite;
}
//img.sprite = Resources.Load (picName [x], typeof(Sprite))as Sprite;
}
}
// Update is called once per frame
void Update () {
}
}
相关文章推荐
- java基础部分:数据类型转换和一些标示符的应用
- poco c++框架:本质概述
- django book 阅读笔记
- Java中使用DOM解析XML
- python备忘
- Qt学习之路(24): QPainter
- YII 获取系统级请求参数的常用方法
- [Django模板系统]用render_to_response()简化views层
- java数据库连接池实现原理
- window7下git管理项目基本命令
- php使用session来保存用户登录信息
- java中map的用法
- TP best practice
- 关键字static在c语言下的理解
- 安装jdk目录下有jdk 和jre连个文件夹的解析
- Qt Style Sheet实践(四):行文本编辑框QLineEdit及自动补全
- [Django模板系统]在视图中使用模板
- 字符串判等
- c++以POST方式向网页提交数据流
- Qt Style Sheet实践(三):QCheckBox和QRadioButton