#pragma strict var str:String; //接收外部复制贴图 var imageTexture:Texture; private var imageWidth:int; private var imageHeight:int; private var screenWidth:int; private var screenHeight:int; function Start () { //得到屏幕宽高 screenWidth=Screen.width; screenHeigh
unity里的图片在生成时会压缩成资源文件,有时客户想自己放一些图片用unity显示,就必须载入外部图片. 大体思路:用Application.streamingAssetsPath或Application.dataPath来指定存放图片的相对路径.用DirectoryInfo获得目录.遍历后FileInfo获得全部文件,然后推断后缀名是否为图片,是的话用www.texture转为图片并存入集合. 完整代码: using UnityEngine; using System.Collections