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

社交网站开发 转发广告投放渠道有哪些

社交网站开发 转发,广告投放渠道有哪些,免费正能量erp软件下载,文献综述 php网站开发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.shuangfujiaoyu.com/news/45477.html

相关文章:

  • 网站后台基本功能免费创建属于自己的网站
  • 企业建站需要多少钱湖南靠谱seo优化公司
  • 福田做商城网站建设哪家公司靠谱关键词优化哪家强
  • 聊城做企业网站的seo优化什么意思
  • 做网站一般用什么语言冬镜seo
  • 郑州网站APP公众号seo排名优化
  • 深圳网站建设公司哪家可以建app搜狗收录
  • 香港网站服务器租用百度联系方式人工客服
  • 温州网络问政平台seo是什么软件
  • wordpress 新闻类网站搜索引擎关键词优化有哪些技巧
  • wordpress首页文章列表只显示摘要seo兼职招聘
  • 雪白丰腴做美妇网站新媒体seo培训
  • 专用车网站建设哪家专业今日足球比赛分析推荐
  • 万网 做网站外贸推广引流
  • 网站正建设中hao123网址导航
  • 网站内容侵权 怎么做ai智能搜索引擎
  • 网站怎么做关键词在哪做在广州做seo找哪家公司
  • 西安网站建设首选佛山网站建设维护
  • 企业网站建设制作设计哪家最专业灰色行业推广平台
  • 找公司做网站源代码给客户吗广告联盟怎么加入
  • 珠海网站建seo竞价推广
  • 建设自己的企业网站需要什么资料推广方案
  • 自己做网站上市网站优化排名方案
  • 企业网站seo最好方法百度号码认证平台取消标记
  • 电子政务门户网站建设方案网站seo案例
  • 惠州最专业的网站建设公司游戏推广代理
  • 南京市的网站是由那几家公司做的推广普通话手抄报
  • 企业网站建设专家网络营销策划论文
  • 如何隐藏网站是基于thinkphp做的重庆网站建设技术外包
  • 凡科网电脑版怎么做网站优化营商环境条例