unity3d_实现幻灯片效果2
2013-08-10 22:25
417 查看
上一篇使用的是静态方式进行的加载,采用的数据结构为 数组
该篇文章则是使用动态加载的方式实现:
this.objsOfRouses = Resources.LoadAll("images",typeof(Texture));
该方法会安排图片在文件在顺序进行加载。
如图:
加载顺序如下:
using UnityEngine;
using System.Collections;
public class imageAnimation : MonoBehaviour {
//
private Object[] objsOfRouses;
private Texture2D[] texturesLoaded;
private Material materialOfPanel;
private int frameCounter =0;
public float delayTime =0.5f;
private float currentTime=0.0f;
private float endTime =0.0f;
public GameObject dongWu;
void Awake()
{
//get the material of this panel
this.materialOfPanel = this.renderer.material;
}
// Use this for initialization
void Start ()
{
//set the starting time
currentTime =Time.time;//0.0s
//get images form the Resourse floder
//the return value is object
this.objsOfRouses = Resources.LoadAll("images",typeof(Texture));
int theLength =objsOfRouses.Length;
//put the images into material arrary
texturesLoaded =new Texture2D[theLength];
for (int i=0; i<theLength; i++)
{
this.texturesLoaded[i] =(Texture2D)this.objsOfRouses[i];
Debug.Log("the image'name is -->"+this.texturesLoaded[i].name);
}
}
// Update is called once per frame
void Update () {
changePic();
}
//
void changePic(){
endTime = Time.time;
float timeOffset = endTime - currentTime;
if (timeOffset>0.3){
if (this.frameCounter<this.objsOfRouses.Length){
this.materialOfPanel.mainTexture = texturesLoaded[frameCounter];
++frameCounter;
}else{
frameCounter=0;
this.materialOfPanel.mainTexture = texturesLoaded[frameCounter];
}
//when changge one image,get the new time
currentTime =Time.time;
}
}
}
最后效果如下:
该篇文章则是使用动态加载的方式实现:
this.objsOfRouses = Resources.LoadAll("images",typeof(Texture));
该方法会安排图片在文件在顺序进行加载。
如图:
加载顺序如下:
using UnityEngine;
using System.Collections;
public class imageAnimation : MonoBehaviour {
//
private Object[] objsOfRouses;
private Texture2D[] texturesLoaded;
private Material materialOfPanel;
private int frameCounter =0;
public float delayTime =0.5f;
private float currentTime=0.0f;
private float endTime =0.0f;
public GameObject dongWu;
void Awake()
{
//get the material of this panel
this.materialOfPanel = this.renderer.material;
}
// Use this for initialization
void Start ()
{
//set the starting time
currentTime =Time.time;//0.0s
//get images form the Resourse floder
//the return value is object
this.objsOfRouses = Resources.LoadAll("images",typeof(Texture));
int theLength =objsOfRouses.Length;
//put the images into material arrary
texturesLoaded =new Texture2D[theLength];
for (int i=0; i<theLength; i++)
{
this.texturesLoaded[i] =(Texture2D)this.objsOfRouses[i];
Debug.Log("the image'name is -->"+this.texturesLoaded[i].name);
}
}
// Update is called once per frame
void Update () {
changePic();
}
//
void changePic(){
endTime = Time.time;
float timeOffset = endTime - currentTime;
if (timeOffset>0.3){
if (this.frameCounter<this.objsOfRouses.Length){
this.materialOfPanel.mainTexture = texturesLoaded[frameCounter];
++frameCounter;
}else{
frameCounter=0;
this.materialOfPanel.mainTexture = texturesLoaded[frameCounter];
}
//when changge one image,get the new time
currentTime =Time.time;
}
}
}
最后效果如下:
相关文章推荐
- unity3d_实现幻灯片效果
- unity3d 幻灯片效果实现
- unity3d中使用Ngui实现幻灯片效果
- Unity3d中实现翻书效果(一)
- Unity3D教程:如何利用Shader实现钻石渲染效果
- JS实现FLASH幻灯片图片切换效果的方法
- easyslider,轻松实现幻灯片效果
- JS实现淘宝幻灯片效果的实现方法
- Unity教程之-Unity3d实现屏幕抖动效果
- 使用简单的jqury实现幻灯片效果(有很多问题,先记下来)
- javascript实现幻灯片效果
- 使用NSTimer实现倒计时,Iphone幻灯片效果+背景音乐,
- JS实现淘宝幻灯片效果的实现方法
- Unity3d 场景中物体渐隐效果实现
- JavaScript实现相册幻灯片效果
- Unity3d中实现点云效果
- [翻译]使用ASP.NET AJAX实现幻灯片效果
- JS 实现 图片幻灯片 效果。 兼容 FF IE
- 利用Angularjs实现幻灯片效果