直接上脚本,需要用的时候在需要的地方调用就好。

如:

//获取设别的最大内存,作为判断LOD等级和决定1G以下设备不能进游戏
#if UNITY_ANDROID && !UNITY_EDITOR
meminfo.gc_Collect();
#endif

meminfo脚本

using UnityEngine;
using System;
using System.Collections; #if UNITY_ANDROID
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
#endif #if UNITY_IPHONE || UNITY_IOS
using System.Runtime.InteropServices;
#endif public class meminfo {
#if !UNITY_EDITOR && !UNITY_WEBPLAYER #if UNITY_ANDROID
public struct meminf{
//all numbers are in kiloBytes
public int memtotal;
public int memfree;
public int active;
public int inactive;
public int cached;
public int swapcached;
public int swaptotal;
public int swapfree;
} public static meminf minf = new meminf(); private static Regex re = new Regex(@"\d+"); public static bool getMemInfo(){ if(!File.Exists("/proc/meminfo")) return false; FileStream fs = new FileStream("/proc/meminfo", FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(fs); string line;
while((line = sr.ReadLine())!=null){
line = line.ToLower().Replace(" ","");
if(line.Contains("memtotal")){ minf.memtotal = mVal(line); }
if(line.Contains("memfree")){ minf.memfree = mVal(line); }
if(line.Contains("active")){ minf.active = mVal(line); }
if(line.Contains("inactive")){ minf.inactive = mVal(line); }
if(line.Contains("cached") && !line.Contains("swapcached")){ minf.cached = mVal(line); }
if(line.Contains("swapcached")){ minf.swapcached = mVal(line); }
if(line.Contains("swaptotal")){ minf.swaptotal = mVal(line); }
if(line.Contains("swapfree")){ minf.swapfree = mVal(line); }
} sr.Close(); fs.Close(); fs.Dispose();
return true;
} private static int mVal(string s){
Match m = re.Match(s); return int.Parse(m.Value);
} public static void gc_Collect() {
var jc = new AndroidJavaClass("java.lang.System");
jc.CallStatic("gc");
jc.Dispose();
} #endif #if UNITY_IPHONE || UNITY_IOS public struct meminf{
//all numbers are in bytes
public int memtotal;
public int memfree;
public int memused;
} public static meminf minf = new meminf(); [DllImport("__Internal")]
private static extern int igetRam(bool what); public static bool getMemInfo(){ int rt; rt = minf.memfree = igetRam(true);//free
rt = minf.memused = igetRam(false);//used
if(rt==-) return false; minf.memtotal = minf.memfree + minf.memused; return true; } #endif #endif
}

Unity_如何判断应用设备内存小于1G(内容可定制为根据机器配置进行不同LOD)的更多相关文章

  1. js判断当前设备

    最近用bootstrap做自适应,发现仍然很难很好的兼容web端和PC端的现实. 仔细观察百度,淘宝,京东等大型网站,发现这些网站都有对应不同客户端的子站. 例如: 站点 PC端url web端url ...

  2. Java判断访问设备为手机、微信、PC工具类

    package com.lwj.util; import javax.servlet.http.HttpServletRequest; /** * 判断访问设备为PC或者手机--工具类 * * @de ...

  3. Android 编程下判断当前设备是手机还是平板

    /** * 判断当前设备是手机还是平板,代码来自 Google I/O App for Android * @param context * @return 平板返回 True,手机返回 False ...

  4. Android 判断当前设备是手机还是平板

    Android开发需要适配手机和平板,有些需求实现时就要求判断设备是手机还是平板.网上很多说通过设备尺寸.DPI.版本号.是否具备电话功能等进行判断,不过都不算太精确.这里分享一个简洁给力的方法(官方 ...

  5. JS判断访问设备、客户端操作系统类型

    先给出一个实例:判断windows.linux.android 复制以下代码另存为html文件即可. <html> <head> <title>判断操作系统< ...

  6. PHP简单判断手机设备的方法

    本文实例讲述了PHP简单判断手机设备的方法.分享给大家供大家参考,具体如下: 现在移动互联网越来越发到,很多的网站都普及了手机端浏览,为了更好的让网页在手机端显示,我们都选择了使用CSS媒体查询制作响 ...

  7. JSP判断移动设备

    日期: 2014年3月6日 人员::铁锚 看到了一篇很好的文章, <在天猫,前端做什么?>,里面有天猫php判断移动设备的正则(个人猜测),觉得很好用,于是就决定移植到JSP里面. jsp ...

  8. JS判断当前设备是 PC IOS Andriod

    JS判断当前设备是 PC IOS Andriod <script > window.onload = function(){ var isPc = IsPC(); var isAndroi ...

  9. 【Android】Android 代码判断当前设备是否为模拟器

    [Android]Android 代码判断当前设备是否为模拟器 方法比较简单,直接粘贴代码 //判断当前设备是否是模拟器.如果返回TRUE,则当前是模拟器,不是返回FALSE public stati ...

随机推荐

  1. 使用NGINX+LUA实现WAF功能 和nginx 防盗链

    使用NGINX+LUA实现WAF功能 一.了解WAF 1.1 什么是WAF Web应用防护系统(也称:网站应用级入侵防御系统 .英文:Web Application Firewall,简称: WAF) ...

  2. 006 GET API

    1.说明 The get API allows to get a JSON document from the index based on its id. GET通过基于id的索引获取JSON文档. ...

  3. (E2E_L2)GOMfcTemplate在vs2017上的运行并融合Dnn模块

    GOMfcTemplate一直运行在VS2012上运行的,并且开发出来了多个产品.在技术不断发展的过程中,出现了一些新的矛盾:1.由于需要使用DNN模块,而这个模块到了4.0以上的OpenCV才支持的 ...

  4. IOS CocoaPods基本使用技巧

    目录: 什么是CocoaPods 如何下载并安装CocoaPods 如何使用CocoaPods 什么是CocoaPods 当开发iOS应用时,或多或少的都会引用第三方类库,例如AFNetworking ...

  5. Linux_CentOS 打包压缩和别名管理

    Linux 打包压缩命令 目前 linux 中打包和压缩的命令很多,最常用的方法有 zip.gzip.bzip2.xz.tar 1.zip 压缩包 1.制作 zip -r public.zip pub ...

  6. pls_integer类型

    转: pls_integer类型 2011-08-22 16:49:06 heqiyu34 阅读数 13413更多 分类专栏: Oracle   今天在看一个触发器代码的时候碰到了一个pls_inte ...

  7. 算法习题---5.2木块问题(UVa101)

    一:题目 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. .move a onto b:把木块a.b上的木块放回各自的原位,再把a放 ...

  8. VUE中事件修饰符:stop prevent self capture

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  9. k8s SLUB: Unable to allocate memory on node -1 错误

    Try to Fix Two Linux Kernel Bugs While Testing TiDB Operator in K8sWed, May 1, 2019 Wenbo Zhang Auth ...

  10. CF1228D Complete Tripartite

    思路: 任选一点a,和a没有边直接相连的点一定和a在同一个集合,由此构造得到一个集合A.用类似的方法再构造一个集合B,并将剩下的点放在集合C中,就得到了三个集合A,B,C.再检查A,B,C是否符合要求 ...