unity settexturepng texture为什么乱的

1596人阅读
Unity3D(20)
决定纹理资源大小的因素主要有三种:分辨率、格式和Mipmap是否开启。
对于纹理资源的加载建议如下:
1、严格控制RGBA32和ARGB32纹理的使用,在保证视觉效果的前提下,尽可能采用“够用就好”的原则,降低纹理资源的分辨率,以及使用硬件支持的纹理格式。
2、在硬件格式(ETC、PVRTC)无法满足视觉效果时,RGBA16格式是一种较为理想的折中选择,既可以增加视觉效果,又可以保持较低的加载耗时。
3、严格检查纹理资源的Mipmap功能,特别注意UI纹理的Mipmap是否开启。有不少项目的UI纹理均开启了Mipmap功能,不仅造成了内存占用上的浪费,同时也增加了不小的加载时间。
4、ETC2对于支持OpenGL ES3.0的Android移动设备来说,是一个很好的处理半透明的纹理格式。但是,如果你的游戏需要在大量OpenGL ES2.0的设备上进行运行,那么我们不建议使用ETC2格式纹理。因为不仅会造成大量的内存占用(ETC2转成RGBA32),同时也增加一定的加载时间。下图为测试2中所用的测试纹理在三星S3和S4设备上加载性能表现。可以看出,在OpenGL ES2.0设备上,ETC2格式纹理的加载要明显高于ETC1格式,且略高于RGBA16格式纹理。因此,建议研发团队在项目中谨慎使用ETC2格式纹理。
对图片的使用格式的方法进行了详细描述
批量检测和修改纹理格式代码如下:
using System.Collections.G
using UnityE
using UnityE
using System.IO;
public partial class ResourceExporter
static List&TextureFormatInfo& GetAllTex(bool bFilter, CheckPlatformTexFormat checkAndroid, CheckPlatformTexFormat checkIphone, ReplacePlatformTexFormat replaceAction = null)
List&string& texPathLs = new List&string&();
GetAssetsTexInSubFolderForAtlas("assets", ref texPathLs);
List&TextureFormatInfo& infoLs = new List&TextureFormatInfo&();
int totalCount = texPathLs.C
if (texPathLs.Count&0)
int iCurCount = 0;
foreach (var path in texPathLs)
TextureImporter texImporter = TextureImporter.GetAtPath(path) as TextureI
if (null != texImporter)
TextureFormatInfo texFormatInfo = new TextureFormatInfo(texImporter.assetPath);
texImporter.GetPlatformTextureSettings("Standalone", out texFormatInfo.windowsMaxSize, out texFormatInfo.texFormatWindows);
texImporter.GetPlatformTextureSettings("iPhone", out texFormatInfo.iphoneMaxSize, out texFormatInfo.texFormatIphone);
texImporter.GetPlatformTextureSettings("Android", out texFormatInfo.androidMaxSize, out texFormatInfo.texFormatAndroid);
texFormatInfo.bMipMapEnabled = texImporter.mipmapE
bool bAdd = true;
texFormatInfo.bNeedAndroidFormat = checkAndroid(texFormatInfo.texFormatAndroid);
texFormatInfo.bNeedIphoneFormat = checkIphone(texFormatInfo.texFormatIphone);
if (bFilter)
bAdd = texFormatInfo.bMipMapEnabled || (!texFormatInfo.bNeedAndroidFormat) || (!texFormatInfo.bNeedIphoneFormat);
Debug.Log(texFormatInfo.ToString());
if (null != replaceAction)
replaceAction(texImporter,texFormatInfo);
infoLs.Add(texFormatInfo);
EditorUtility.DisplayCancelableProgressBar("Check TexFormat", "Wait......", (++iCurCount) * 1f / totalCount);
totalCount = infoLs.C
Debug.Log("PathCount:" + texPathLs.Count);
Debug.Log("InfoCount:" + infoLs.Count);
EditorUtility.ClearProgressBar();
return infoLs;
static void SaveTextureFormatInfoPath(List&TextureFormatInfo& infoLs)
string fileSavePath = "../AllTextureFormatInfoPath";
int totalCount = infoLs.C
using (StreamWriter sw = File.CreateText(fileSavePath + ".html"))
sw.WriteLine("size = " + totalCount + "&/br&");
foreach (var info in infoLs)
sw.WriteLine(info.ToHtmlString());
sw.Close();
static bool CheckAndroidFormat(TextureImporterFormat format)
return format == TextureImporterFormat.ETC_RGB4;
static bool CheckIphoneFormat(TextureImporterFormat format)
return format.ToString().Contains("PVRTC");
delegate bool CheckPlatformTexFormat(TextureImporterFormat format);
delegate void ReplacePlatformTexFormat(TextureImporter textureImporter,TextureFormatInfo texInfo);
static void ReplacePlatformFormat(TextureImporter textureImporter, TextureFormatInfo texInfo)
textureImporter.mipmapEnabled = false;
textureImporter.SetPlatformTextureSettings("Android", texInfo.androidMaxSize, TextureImporterFormat.ETC_RGB4);
AssetDatabase.ImportAsset(textureImporter.assetPath);
class TextureFormatInfo
public string
public bool bMipMapE
public bool bNeedAndroidF
public bool bNeedIphoneF
public TextureImporterFormat texFormatI
public TextureImporterFormat texFormatA
public TextureImporterFormat texFormatW
public int androidMaxS
public int iphoneMaxS
public int windowsMaxS
public TextureFormatInfo(string filePath)
path = fileP
public string ToString()
string strFormat = "{0}: MipMapEnabled:{1},\nAndroid:{2},\nIphone:{3}";
return string.Format(strFormat, path, bMipMapEnabled, texFormatAndroid, texFormatIphone, texFormatWindows);
public string ToHtmlString()
string strFormat = "{0}:
&nbsp &nbsp &nbsp&nbsp &nbsp{1},
&nbsp &nbsp &nbsp &nbsp{2},
&nbsp &nbsp &nbsp &nbsp {3}&/br&";
string bMipStr = string.Format("MipMapEnabled:{0}", bMipMapEnabled);
string parm1 = bMipMapEnabled ? GetSpecialTip(bMipStr, "red") : bMipS
string androidStr = string.Format("Android:{0}", texFormatAndroid);
string parm2 = !bNeedAndroidFormat ? GetSpecialTip(androidStr, "blue") : androidS
string iphoneStr = string.Format("Iphone:{0}", texFormatIphone);
string parm3 = !bNeedIphoneFormat ? GetSpecialTip(iphoneStr, "YellowGreen") : iphoneS
return string.Format(strFormat, path, parm1, parm2, parm3);
private string GetSpecialTip(string name,string fontColor)
return string.Format("&font color=\"{0}\"&&b&{1}&/b&&/font&", fontColor, name);
static void GetAssetsTexInSubFolderForAtlas(string srcFolder, ref List&string& atlas)
string searchPattern0 = "*.png";
string searchPattern1 = "*.tga";
string searchPattern2 = "*.psd";
string searchFolder = srcFolder.Replace(@"\", @"/");
string searchDir0 = searchF
if (Directory.Exists(searchDir0))
AddFilePathToList(Directory.GetFiles(searchDir0, searchPattern0), ref atlas);
AddFilePathToList(Directory.GetFiles(searchDir0, searchPattern1),ref atlas);
AddFilePathToList(Directory.GetFiles(searchDir0, searchPattern2),ref atlas);
string[] dirs = Directory.GetDirectories(searchFolder);
foreach (string oneDir in dirs)
GetAssetsTexInSubFolderForAtlas(oneDir, ref atlas);
static void AddFilePathToList(string[] files, ref List&string& ls)
foreach (string oneFile in files)
string srcFile = oneFile.Replace(@"\", @"/");
string lowerFile = srcFile.ToLower();
ls.Add(lowerFile);
[MenuItem("MyEditor/Check Texture Format")]
public static void CheckTextureFormat()
List&TextureFormatInfo& infoLs = GetAllTex(true, CheckAndroidFormat, CheckIphoneFormat);
SaveTextureFormatInfoPath(infoLs);
[MenuItem("MyEditor/Replace Texture Format")]
public static void ReplaceTextureFormat()
GetAllTex(true, CheckAndroidFormat, CheckIphoneFormat, ReplacePlatformFormat);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:475273次
积分:3877
积分:3877
排名:第8565名
原创:77篇
转载:78篇
评论:47条
(1)(2)(6)(2)(1)(1)(1)(6)(1)(13)(9)(1)(2)(1)(8)(1)(5)(1)(1)(1)(17)(9)(9)(1)(10)(21)(24)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'同一张图png和jpg内存占用谁来的多_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:76,639贴子:
同一张图png和jpg内存占用谁来的多收藏
我刚做了一个实验, 我把一张png的图转成jpg之后,情况是这样的:为何jpg的内存占用比png来的多?
还在找人做网站吗?自己试着做一个吧!
图像质量 颜色位数 都有影响
一个压缩PNG的神站
转换后的图片大小一样不?
格式不一样,存储方式不一样,当然占用内存大小也不一样,就像你在unity改图片为压缩或者其他模式一样
我知道同等大小下,png画质比JPG高
我记得是算法不同。jpg的颜色数要比png多,所以更占空间。
然而这个问题偏离本吧
图片格式在Unity中都会转换成类似DDS的格式看你选择的压缩方式,DXT1,DXT5或者别的压缩格式才是最终格式,而不是把jpg,png这些外部格式做比较
刚刚测了下jpg比png容量大是确有其事,可能和压缩算法有关系但通过unity转换为引擎压缩格式之后,带通道的dxt5肯定比不带通道的dxt1容量要大。
车型齐全,品牌齐全,现车供应!
不小心删了一个回复贴,我本来是想修改我的回复的
内存占用应当是一样的,所有点阵图片使用是最终都要加载为bitmap,每个像素的argb用一个int长度表示
登录百度帐号推荐应用5238人阅读
游戏中图形的表现大多来自于纹理,纹理使用最多的是Texture2D,Texture2D继承自Texture,Texture里面大多是对纹理的一些参数的设置,那些设置对于2d3d纹理是通用的,本篇就来看看texture2D具体是如何工作的。
using pilerS
using UnityEngine.I
namespace UnityEngine
&&&&public
sealed class Texture2D : Texture
获取纹理的级数,这个级数首先是开启了mipmap,读取一张图片时,计算机会生成多张纹理,根据观察者与物体的远近选择不同的纹理。
&&&&&&&&public
extern int mipmapCount
&&&&&&&&&&&&[WrapperlessIcall]
&&&&&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&&&&&get;
获取纹理格式,比如RGBA32什么的
&&&&&&&&public
extern TextureFormat format
&&&&&&&&&&&&[WrapperlessIcall]
&&&&&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&&&&&get;
这是一个静态方法,获取一个纯白色的纹理,测试了一下,该纹理的尺寸为(0.3,0.3)
&&&&&&&&public
static extern Texture2D whiteTexture
&&&&&&&&&&&&[WrapperlessIcall]
&&&&&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&&&&&get;
也是个静态方法,获取一个纯黑色纹理,注意的是透明度也是0
&&&&&&&&public
static extern Texture2D blackTexture
&&&&&&&&&&&&[WrapperlessIcall]
&&&&&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&&&&&get;
创建一个自定义尺寸的纹理,当然其他都是默认值
&&&&&&&&public
Texture2D(int width,
int height)
&&&&&&&&&&&&Texture2D.Internal_Create(this, width, height, TextureFormat.ARGB32,
false, IntPtr.Zero);
通过限制尺寸,像素格式,是否多级别纹理来创建一个纹理
&&&&&&&&public
Texture2D(int width,
int height, TextureFormat format,
bool mipmap)
&&&&&&&&&&&&Texture2D.Internal_Create(this, width, height, format, mipmap,
false, IntPtr.Zero);
通过限制尺寸,像素格式,是否多级别纹理,是否使用线性滤波方式来创建一个纹理
&&&&&&&&public
Texture2D(int width,
int height, TextureFormat format,
bool mipmap,
bool linear)
&&&&&&&&&&&&Texture2D.Internal_Create(this, width, height, format, mipmap, linear, IntPtr.Zero);
与上面的创建方式不一样的地方是,传入了一个本地的纹理,利用本地纹理创建一个新的纹理,而这个nativeTex可以通过Texture中GetNativeTextureID获得
&&&&&&&&internal
Texture2D(int width,
int height, TextureFormat format,
bool mipmap,
bool linear, IntPtr nativeTex)
&&&&&&&&&&&&Texture2D.Internal_Create(this, width, height, format, mipmap, linear, nativeTex);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&private
static extern
void Internal_Create([Writable] Texture2D mono,
int width,
int height, TextureFormat format,
bool mipmap, bool linear, IntPtr nativeTex);
&&&&&&&&public
static Texture2D CreateExternalTexture(int width,
int height, TextureFormat format,
bool mipmap,
bool linear, IntPtr nativeTex)
&&&&&&&&&&&&return
new Texture2D(width, height, format, mipmap, linear, nativeTex);
利用纹理id来更新当前纹理
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern void
UpdateExternalTexture(IntPtr nativeTex);
设置纹理中指定坐标的颜色值,注意之后必须调用apply才起作用
&&&&&&&&public
void SetPixel(int x,
int y, Color color)
&&&&&&&&&&&&Texture2D.INTERNAL_CALL_SetPixel(this, x, y,
ref color);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&private
static extern
void INTERNAL_CALL_SetPixel(Texture2D self,
int y, ref Color color);
获取像素值
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern Color GetPixel(int x,
通过uv坐标值获取像素
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern Color GetPixelBilinear(float u,
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public
void SetPixels(Color[] colors)
&&&&&&&&&&&&int miplevel =
&&&&&&&&&&&&this.SetPixels(colors, miplevel);
&&&&&&&&public
void SetPixels(Color[] colors, [DefaultValue(&0&)]
int miplevel)
&&&&&&&&&&&&int num =
this.width &&
&&&&&&&&&&&&if (num &
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&num = 1;
&&&&&&&&&&&&}
&&&&&&&&&&&&int num2 =
this.height &&
&&&&&&&&&&&&if (num2 &
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&num2 = 1;
&&&&&&&&&&&&}
&&&&&&&&&&&&this.SetPixels(0,
0, num, num2, colors, miplevel);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern void
SetPixels(int x,
int blockWidth, int blockHeight, Color[] colors, [DefaultValue(&0&)]
int miplevel);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public
void SetPixels(int x,
int blockWidth, int blockHeight, Color[] colors)
&&&&&&&&&&&&int miplevel =
&&&&&&&&&&&&this.SetPixels(x, y, blockWidth, blockHeight, colors, miplevel);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern void
SetPixels32(Color32[] colors, [DefaultValue(&0&)]
int miplevel);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public
void SetPixels32(Color32[] colors)
&&&&&&&&&&&&int miplevel =
&&&&&&&&&&&&this.SetPixels32(colors, miplevel);
通过读取文件数据来加载纹理数据
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern bool
LoadImage(byte[] data);
通过读取文件数据来加载纹理数据
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern void
LoadRawTextureData(byte[] data);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public Color[]
GetPixels()
&&&&&&&&&&&&int miplevel =
&&&&&&&&&&&&return
this.GetPixels(miplevel);
&&&&&&&&public Color[]
GetPixels([DefaultValue(&0&)]
int miplevel)
&&&&&&&&&&&&int num =
this.width &&
&&&&&&&&&&&&if (num &
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&num = 1;
&&&&&&&&&&&&}
&&&&&&&&&&&&int num2 =
this.height &&
&&&&&&&&&&&&if (num2 &
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&num2 = 1;
&&&&&&&&&&&&}
&&&&&&&&&&&&return
this.GetPixels(0,
0, num, num2, miplevel);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern Color[] GetPixels(int x,
int blockWidth, int blockHeight, [DefaultValue(&0&)]
int miplevel);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public Color[]
GetPixels(int x,
int blockWidth, int blockHeight)
&&&&&&&&&&&&int miplevel =
&&&&&&&&&&&&return
this.GetPixels(x, y, blockWidth, blockHeight, miplevel);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern Color32[] GetPixels32([DefaultValue(&0&)]
int miplevel);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public Color32[]
GetPixels32()
&&&&&&&&&&&&int miplevel =
&&&&&&&&&&&&return
this.GetPixels32(miplevel);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern void
Apply([DefaultValue(&true&)]
bool updateMipmaps, [DefaultValue(&false&)]
bool makeNoLongerReadable);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public
void Apply(bool updateMipmaps)
&&&&&&&&&&&&bool makeNoLongerReadable =
&&&&&&&&&&&&this.Apply(updateMipmaps, makeNoLongerReadable);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public
void Apply()
&&&&&&&&&&&&bool makeNoLongerReadable =
&&&&&&&&&&&&bool updateMipmaps =
&&&&&&&&&&&&this.Apply(updateMipmaps, makeNoLongerReadable);
重新设定纹理参数
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern bool
Resize(int width,
int height, TextureFormat format,
bool hasMipMap);
&&&&&&&&public
bool Resize(int width,
int height)
&&&&&&&&&&&&return
this.Internal_ResizeWH(width, height);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&private
extern bool
Internal_ResizeWH(int width,
int height);
决定纹理的质量
&&&&&&&&public
void Compress(bool highQuality)
&&&&&&&&&&&&Texture2D.INTERNAL_CALL_Compress(this, highQuality);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&private
static extern
void INTERNAL_CALL_Compress(Texture2D self,
bool highQuality);
传进来一个纹理集合,把多个纹理打包为当前纹理
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern Rect[] PackTextures(Texture2D[] textures,
int padding, [DefaultValue(&2048&)]
int maximumAtlasSize, [DefaultValue(&false&)]
bool makeNoLongerReadable);
传进来一个纹理集合,把多个纹理打包为当前纹理
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public Rect[]
PackTextures(Texture2D[] textures,
int padding, int maximumAtlasSize)
&&&&&&&&&&&&bool makeNoLongerReadable =
&&&&&&&&&&&&return
this.PackTextures(textures, padding, maximumAtlasSize, makeNoLongerReadable);
传进来一个纹理集合,把多个纹理打包为当前纹理
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public Rect[]
PackTextures(Texture2D[] textures,
int padding)
&&&&&&&&&&&&bool makeNoLongerReadable =
&&&&&&&&&&&&int maximumAtlasSize =
&&&&&&&&&&&&return
this.PackTextures(textures, padding, maximumAtlasSize, makeNoLongerReadable);
&&&&&&&&public
void ReadPixels(Rect source,
int destX,
int destY, [DefaultValue(&true&)]
bool recalculateMipMaps)
&&&&&&&&&&&&Texture2D.INTERNAL_CALL_ReadPixels(this,
ref source, destX, destY, recalculateMipMaps);
&&&&&&&&[ExcludeFromDocs]
&&&&&&&&public
void ReadPixels(Rect source,
int destX,
int destY)
&&&&&&&&&&&&bool recalculateMipMaps =
&&&&&&&&&&&&Texture2D.INTERNAL_CALL_ReadPixels(this,
ref source, destX, destY, recalculateMipMaps);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&private
static extern
void INTERNAL_CALL_ReadPixels(Texture2D self,
ref Rect source,
int destX, int destY,
bool recalculateMipMaps);
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern byte[]
EncodeToPNG();
&&&&&&&&[WrapperlessIcall]
&&&&&&&&[MethodImpl(MethodImplOptions.InternalCall)]
&&&&&&&&public
extern byte[]
EncodeToJPG(int quality);
&&&&&&&&public
byte[] EncodeToJPG()
&&&&&&&&&&&&return
this.EncodeToJPG(75);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:45720次
排名:千里之外
原创:44篇
评论:21条
(2)(3)(1)(2)(1)(2)(1)(2)(4)(3)(2)(1)(2)(2)(5)(6)(1)(3)(1)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'当前位置: >
动态加载texture2D图片
时间: 09:25 来源:Unity之家 作者:unity.jb51.net 浏览:
这个需要在协成里面执行。代码如下:IEnumerator&loadImage()
WWW&www&=&new&WWW(&/template/singcere_dw/common/images/logo.png&);
yield&return&
txt2d&=&new&Texture2D(4,&4,&TextureFormat.DXT1,&false);
www.LoadImageIntoTexture(txt2d);//Resources.LoadAssetAtPath(&/template/singcere_dw/common/images/logo.png&,&typeof(Texture))&as&T
GameObject.Find(&Game1BG&).GetComponent().mainTexture&=&txt2d;
}OK。赶快测试下吧。。。
(责任编辑:脚印)
免责声明:Unity之家部分内容来源于互联网,如有侵权,请联系我们,本站将立即进行处理。
猜你也喜欢看这些 ??????
其他类型的Unity入门 ??????3449人阅读
unity(58)
使用Texture2D的LoadImage方法即可实现从jpg或png文件创建Texture2D。经验证,当发布的目标平台为iOS时,此方法也是有效的。
function&LoadImage (data : byte[]) :&boolean
Description
Loads an image from a byte array.
This function loads a JPG or PNG image from raw byte[] array.
using UnityE
using System.C
public class example :
imageTextA
void Start() {
Texture2D tex = new Texture2D(4, 4);
tex.LoadImage(imageTextAsset.bytes);
renderer.material.mainTexture =
This function replaces texture contents with new image data. After LoadImage, texture size and format might change. JPG files are loaded into&&format,
PNG files are loaded into&&format. If
texture format before calling LoadImage is&&or&,
then the loaded image will be DXT-compressed (into DXT1 for JPG images and DXT5 for PNG images).
& & & & & & & & & & & & //imagePath是jpg或png图片的路径
FileStream fs = new System.IO.FileStream(imagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] thebytes =
new byte[fs.Length];
fs.Read(thebytes,
0, (int)fs.Length);
& & & & & & & & & & & & //实例化一个Texture2D,宽和高设置可以是任意的,因为当使用LoadImage方法会对Texture2D的宽和高会做相应的调整
Texture2D texture =
new Texture2D(1,1);
texture.LoadImage(thebytes);
material.mainTexture =
material.mainTextureScale =
new Vector2(1,
material.mainTextureOffset =
new Vector2(0,
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1022390次
积分:11999
积分:11999
排名:第1297名
原创:49篇
转载:1058篇
评论:17条
(1)(3)(1)(1)(1)(1)(18)(18)(3)(5)(1)(18)(6)(56)(19)(52)(57)(86)(43)(67)(60)(18)(28)(7)(38)(32)(29)(77)(150)(112)(33)(16)(32)(4)(14)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 unity texture2d 的文章

 

随机推荐