博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unity3d 幻灯片效果实现
阅读量:4605 次
发布时间:2019-06-09

本文共 1614 字,大约阅读时间需要 5 分钟。

上一篇使用的是静态方式进行的加载,采用的数据结构为 数组

该篇文章则是使用动态加载的方式实现:

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;
}
 
}

}

 

最后效果如下:

转载于:https://www.cnblogs.com/alongu3d/p/3252668.html

你可能感兴趣的文章
How to Notify Command to evaluate in mvvmlight
查看>>
33. Search in Rotated Sorted Array
查看>>
461. Hamming Distance
查看>>
Python垃圾回收机制详解
查看>>
jquery 编程的最佳实践
查看>>
MeetMe
查看>>
IP报文格式及各字段意义
查看>>
(转载)rabbitmq与springboot的安装与集成
查看>>
C2. Power Transmission (Hard Edition)(线段相交)
查看>>
STM32F0使用LL库实现SHT70通讯
查看>>
Atitit. Xss 漏洞的原理and应用xss木马
查看>>
MySQL源码 数据结构array
查看>>
(文件过多时)删除目录下全部文件
查看>>
T-SQL函数总结
查看>>
python 序列:列表
查看>>
web移动端
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>