当前位置: 首页 > news >正文

怎么把自己的网站做自适应网站网站快速排名上

怎么把自己的网站做自适应网站,网站快速排名上,美国做礼品的网站,深圳外贸网站设计Unity 如何获取Texture 的内存大小 在Unity中,要获取Texture的内存文件大小,可以使用UnityEditor.TextureUtil类中的一些函数。这些函数提供了获取存储内存大小和运行时内存大小的方法。由于UnityEditor.TextureUtil是一个内部类,我们需要使…

Unity 如何获取Texture 的内存大小

在Unity中,要获取Texture的内存文件大小,可以使用UnityEditor.TextureUtil类中的一些函数。这些函数提供了获取存储内存大小和运行时内存大小的方法。由于UnityEditor.TextureUtil是一个内部类,我们需要使用反射来访问它。

步骤

  1. 导入UnityEditor命名空间和System.Reflection命名空间:
using UnityEditor;
using System.Reflection;
  1. 创建一个函数来获取Texture的内存文件大小:
public static long GetTextureFileSize(Texture2D texture)
{long fileSize = 0;// 使用反射获取UnityEditor.TextureUtil类的TypeType textureUtilType = typeof(TextureImporter).Assembly.GetType("UnityEditor.TextureUtil");// 使用反射获取UnityEditor.TextureUtil类的GetStorageMemorySizeLong方法MethodInfo getStorageMemorySizeLongMethod = textureUtilType.GetMethod("GetStorageMemorySizeLong", BindingFlags.Static | BindingFlags.Public);// 调用GetStorageMemorySizeLong方法获取存储内存大小fileSize = (long)getStorageMemorySizeLongMethod.Invoke(null, new object[] { texture });return fileSize;
}
  1. 创建一个函数来获取Texture的运行时内存大小:
public static long GetTextureRuntimeMemorySize(Texture2D texture)
{long memorySize = 0;// 使用反射获取UnityEditor.TextureUtil类的TypeType textureUtilType = typeof(TextureImporter).Assembly.GetType("UnityEditor.TextureUtil");// 使用反射获取UnityEditor.TextureUtil类的GetRuntimeMemorySizeLong方法MethodInfo getRuntimeMemorySizeLongMethod = textureUtilType.GetMethod("GetRuntimeMemorySizeLong", BindingFlags.Static | BindingFlags.Public);// 调用GetRuntimeMemorySizeLong方法获取运行时内存大小memorySize = (long)getRuntimeMemorySizeLongMethod.Invoke(null, new object[] { texture });return memorySize;
}

示例代码

示例 1:获取Texture的存储内存大小

using UnityEngine;
using UnityEditor;
using System.Reflection;public class TextureSizeExample : MonoBehaviour
{[SerializeField]private Texture2D texture;private void Start(){long fileSize = GetTextureFileSize(texture);Debug.Log("Texture File Size: " + fileSize + " bytes");}private static long GetTextureFileSize(Texture2D texture){long fileSize = 0;Type textureUtilType = typeof(TextureImporter).Assembly.GetType("UnityEditor.TextureUtil");MethodInfo getStorageMemorySizeLongMethod = textureUtilType.GetMethod("GetStorageMemorySizeLong", BindingFlags.Static | BindingFlags.Public);fileSize = (long)getStorageMemorySizeLongMethod.Invoke(null, new object[] { texture });return fileSize;}
}

示例 2:获取Texture的运行时内存大小

using UnityEngine;
using UnityEditor;
using System.Reflection;public class TextureSizeExample : MonoBehaviour
{[SerializeField]private Texture2D texture;private void Start(){long memorySize = GetTextureRuntimeMemorySize(texture);Debug.Log("Texture Runtime Memory Size: " + memorySize + " bytes");}private static long GetTextureRuntimeMemorySize(Texture2D texture){long memorySize = 0;Type textureUtilType = typeof(TextureImporter).Assembly.GetType("UnityEditor.TextureUtil");MethodInfo getRuntimeMemorySizeLongMethod = textureUtilType.GetMethod("GetRuntimeMemorySizeLong", BindingFlags.Static | BindingFlags.Public);memorySize = (long)getRuntimeMemorySizeLongMethod.Invoke(null, new object[] { texture });return memorySize;}
}

示例 3:同时获取Texture的存储内存大小和运行时内存大小

using UnityEngine;
using UnityEditor;
using System.Reflection;public class TextureSizeExample : MonoBehaviour
{[SerializeField]private Texture2D texture;private void Start(){long fileSize = GetTextureFileSize(texture);long memorySize = GetTextureRuntimeMemorySize(texture);Debug.Log("Texture File Size: " + fileSize + " bytes");Debug.Log("Texture Runtime Memory Size: " + memorySize + " bytes");}private static long GetTextureFileSize(Texture2D texture){long fileSize = 0;Type textureUtilType = typeof(TextureImporter).Assembly.GetType("UnityEditor.TextureUtil");MethodInfo getStorageMemorySizeLongMethod = textureUtilType.GetMethod("GetStorageMemorySizeLong", BindingFlags.Static | BindingFlags.Public);fileSize = (long)getStorageMemorySizeLongMethod.Invoke(null, new object[] { texture });return fileSize;}private static long GetTextureRuntimeMemorySize(Texture2D texture){long memorySize = 0;Type textureUtilType = typeof(TextureImporter).Assembly.GetType("UnityEditor.TextureUtil");MethodInfo getRuntimeMemorySizeLongMethod = textureUtilType.GetMethod("GetRuntimeMemorySizeLong", BindingFlags.Static | BindingFlags.Public);memorySize = (long)getRuntimeMemorySizeLongMethod.Invoke(null, new object[] { texture });return memorySize;}
}

注意事项

  • 确保在使用反射访问UnityEditor.TextureUtil类之前,已经导入了UnityEditor命名空间和System.Reflection命名空间。
  • 使用反射时,需要使用BindingFlags.Static | BindingFlags.Public来获取静态公共方法。
  • 在示例代码中,我们使用了Texture2D类型的变量来表示Texture,你可以根据实际情况修改代码以适应不同的Texture类型。
http://www.hkea.cn/news/573468/

相关文章:

  • wordpress优化版4.7.4网站seo设计
  • 网上课程网站精准客户数据采集软件
  • 专业网站建设报价外呼系统电销
  • 网站建设公司价格差别seo还有哪些方面的优化
  • 哪家公司建造了迪士尼乐园关键词优化推广排名多少钱
  • 做教育的网站有哪些内容吗湖南网站营销推广
  • wordpress 跳过ftp搜索引擎排名优化方案
  • 360做的网站北京营销推广公司
  • 我国政府网站建设的趋势宁波seo公司排名榜
  • 高端网站建设,恩愉科技专业的seo搜索引擎优化培训
  • 跨境网站开发公司网站seo思路
  • 冠县网站建设活动推广方案
  • 鲜花培训网站建设网站推广要点
  • 情趣内衣怎么做网站如何制作网页
  • 网站交互技术百度推广登陆后台
  • 网站的推广和宣传方式各行业关键词
  • 腾讯云服务器网站建设淘宝推广哪种方式最好
  • 大专网站建设论文找个免费的网站
  • 移动端网站开发流程图seopeix
  • 购物网站制作免费太原seo招聘
  • 怎么建设食品网站济南seo外包公司
  • 建设网站有哪些seopeix
  • 桂林市工程建设项目招标网站莆田百度快照优化
  • 金华网站建设大型网页建设农产品网络营销
  • wordpress free cdn长沙百度快速优化
  • 网页界面设计首页seo快速优化软件网站
  • 和凡科网类似的网站四川省人民政府
  • 北辰网站建设如何推广引流
  • ps网页模板网站seo外包公司
  • 常平镇仿做网站快速排名刷