这里记录一些Unity3D的API 以备不时之需。

Application.lowMemory 低内存检测 5.6+

当Andorid或者iOS内存过低会调用此函数。用来处理内存释放 官网文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

class LowMemoryTrigger : MonoBehaviour
{
List<Texture2D> _textures;

private void Start()
{
_textures = new List<Texture2D>();
Application.lowMemory += OnLowMemory;
}

private void Update()
{
// allocate textures until we run out of memory
_textures.Add(new Texture2D(256, 256));
}

private void OnLowMemory()
{
// release all cached textures
_textures = new List<Texture2D>();
Resources.UnloadUnusedAssets();
}
}