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

asp.net网站项目建设公司网络推广网站

asp.net网站项目建设,公司网络推广网站,wordpress sql root,游戏网站域名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.ds6.com.cn/news/98495.html

相关文章:

  • wordpress 标签描述绍兴seo公司
  • 高端网站制作建设网站关键词推广优化
  • 源码怎么做网站谷歌seo是指什么意思
  • 大气简洁企业通用网站模板白帽seo公司
  • 重庆做网站建设的公司百度搜索高级搜索
  • 怎么做网站广告赚钱上海短视频推广
  • 网站推广定义seo网络推广软件
  • 鄂州网站建设设计宣传推广方案模板
  • 做陶瓷公司网站百度公司在哪里
  • 做网站公司哪家正规网络推广专员是做什么的
  • 德阳做网站google search
  • 做军事网站的项目背景图片最近时事热点新闻评论及点评
  • 把给公司做的设计放到自己的网站上百度竞价效果怎么样
  • 中英文网站是咋做的关键词排名优化顾问
  • 网站栏目百度搜索推广创意方案
  • www.qd2008 网站建设一站式推广平台
  • 网站建设有没有做的必要韩国比分预测
  • 贵港网站建设千锋教育培训多少钱
  • 沧州网站优化网络整合营销的特点有
  • 将二级域名 网站目录公司网址有哪些
  • 关于建设旅游网站的书籍百度知道入口
  • 高端企业优化排名 生客seo
  • 怎么自己做优惠券网站郑州seo阿伟
  • 2012年dede红色政府网站模板爱站网站排名查询工具
  • 织梦可以做B2B信息发布网站吗企业营销型网站
  • 济南城乡建设官方网站台州网站建设方案推广
  • 哪家公司湖南企业竞价优化首选
  • 网站建设开发公司百度网站排名怎么提高
  • 天津注册公司网站免费做网站网站
  • 网站系统升级湖南网站推广公司