kg
6 年前
当前提交
a2e4c27c
共有 19 个文件被更改,包括 270 次插入 和 262 次删除
-
27Runtime/foundation/basic_types.cs
-
2Runtime/material/user_accounts_drawer_header.cs
-
2Runtime/physics/friction_simulation.cs
-
16Runtime/physics/spring_simulation.cs
-
10Runtime/rendering/editable.cs
-
4Runtime/rendering/paragraph.cs
-
5Runtime/service/text_formatter.cs
-
2Runtime/ui/painting/canvas_impl.cs
-
112Runtime/ui/painting/path.cs
-
187Runtime/ui/painting/txt/font_manager.cs
-
12Runtime/ui/painting/txt/mesh_generator.cs
-
2Runtime/ui/text.cs
-
58Runtime/ui/txt/layout.cs
-
10Runtime/ui/txt/linebreaker.cs
-
4Runtime/ui/txt/paint_record.cs
-
7Runtime/ui/txt/paragraph.cs
-
4Runtime/ui/txt/text_buff.cs
-
2Runtime/ui/txt/wordbreaker.cs
-
66Runtime/ui/painting/NoAllocHelpers.cs
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.ui { |
|||
public static class NoAllocHelpers<T> { |
|||
|
|||
static Func<List<T>, T[]> _extractArrayFromListDelegate; |
|||
|
|||
static Action<List<T>, int> _resizeListDelegate; |
|||
|
|||
public static T[] ExtractArrayFromListT(List<T> list) { |
|||
if (_extractArrayFromListDelegate == null) { |
|||
var ass = Assembly.GetAssembly(typeof(Mesh)); |
|||
var type = ass.GetType("UnityEngine.NoAllocHelpers"); |
|||
var methodInfo = type.GetMethod( |
|||
"ExtractArrayFromListT", |
|||
BindingFlags.Static | BindingFlags.Public) |
|||
.MakeGenericMethod(typeof(T)); |
|||
|
|||
_extractArrayFromListDelegate = (Func<List<T>, T[]>) |
|||
Delegate.CreateDelegate(typeof(Func<List<T>, T[]>), methodInfo); |
|||
} |
|||
|
|||
return _extractArrayFromListDelegate(list); |
|||
} |
|||
|
|||
public static void ResizeList(List<T> list, int size) { |
|||
if (size < list.Count) { |
|||
list.RemoveRange(size, list.Count - size); |
|||
return; |
|||
} |
|||
|
|||
if (size == list.Count) { |
|||
return; |
|||
} |
|||
|
|||
if (list.Capacity < size) { |
|||
list.Capacity = size; |
|||
} |
|||
|
|||
if (_resizeListDelegate == null) { |
|||
var ass = Assembly.GetAssembly(typeof(Mesh)); // any class in UnityEngine
|
|||
var type = ass.GetType("UnityEngine.NoAllocHelpers"); |
|||
var methodInfo = type.GetMethod( |
|||
"ResizeList", |
|||
BindingFlags.Static | BindingFlags.Public) |
|||
.MakeGenericMethod(typeof(T)); |
|||
_resizeListDelegate = (Action<List<T>, int>) |
|||
Delegate.CreateDelegate(typeof(Action<List<T>, int>), methodInfo); |
|||
} |
|||
|
|||
_resizeListDelegate(list, size); |
|||
} |
|||
|
|||
public static void EnsureListElemCount(List<T> list, int size) { |
|||
list.Clear(); |
|||
if (list.Capacity < size) { |
|||
list.Capacity = size; |
|||
} |
|||
|
|||
ResizeList(list, size); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue