版本: Unity 6 (6000.0)
语言English
  • C#

ListPool<T0>

UnityEngine.Pool 中的类

/

继承自:Pool.CollectionPool_2

/

实现于:UnityEngine.CoreModule

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法采纳所有提交,但我们确实会阅读用户提出的每一项修改建议,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的修改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

描述

List 的 CollectionPool<T0,T1> 版本。

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;

// This example shows how both version of Get could be used to simplify a line of points. public class Simplify2DLine { public List<Vector2> SimplifyLine(Vector2[] points) { // This version will only be returned to the pool if we call Release on it. var simplifiedPoints = ListPool<Vector2>.Get();

// Copy the points into a temp list so we can pass them into the Simplify method // When the pooled object leaves the scope it will be Disposed and returned to the pool automatically. // This version is ideal for working with temporary lists. using (var pooledObject = ListPool<Vector2>.Get(out List<Vector2> tempList)) { for (int i = 0; i < points.Length; ++i) { tempList.Add(points[i]); }

LineUtility.Simplify(tempList, 1.5f, simplifiedPoints); } return simplifiedPoints; } }

继承的成员

静态方法

Get从池中获取一个实例。如果池为空,则会创建一个新的实例。
Release将实例返回到池中。