1. unity 2017 新版本 https://docs.unity3d.com/ScriptReference/Application-lowMemory.html 直接注册一下事件
2. 5.5 左右的 需要自己和IOS关联起来。
方法一.用 XUPorter 工具 修改代码
让 UnityAppController 发个消息过来。
方法二、https://answers.unity.com/questions/291788/is-there-a-way-to-tell-in-unity-ios-when-ondidrece.html
Unity 项目的 Plugins\iOS\随便建个.mm
加一下代码
#import "UnityAppController.h"
@interface iOSMemoryManager : UnityAppController {}
@end
@implementation iOSMemoryManager
- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {
printf_console("WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning()\n");
UnitySendMessage("GameMain", "ReceiveMemoryWarning", "");
}
@end
IMPL_APP_CONTROLLER_SUBCLASS(iOSMemoryManager)
Unity里
挂在指定名字的脚本上 实现一下函数
float lastunload = 0;
//接收ios抛过来的内存不够警告, 打错误日志,上报到bugly
public void ReceiveMemoryWarning(string msg)
{
Log.Error("LowMemory! GameMain ReceiveMemoryWarning");
if (lastunload + 10 < Time.time)
{
Resources.UnloadUnusedAssets();
lastunload = Time.time;
}
}