Yuncong Zhang
5 年前
当前提交
218e45f1
共有 14 个文件被更改,包括 90 次插入 和 82 次删除
-
2README-ZH.md
-
8README.md
-
13Runtime/Plugins/platform/android/view/UIWidgetsViewController.java
-
4Runtime/Unity.UIWidgets.asmdef
-
8Runtime/foundation/basic_types.cs
-
7Runtime/ui/txt/linebreaker.cs
-
2Runtime/InternalBridge/NoAllocHelpersBridge.cs.meta
-
8Runtime/InternalBridge.meta
-
12Runtime/InternalBridge/InternalBridge.asmdef
-
7Runtime/InternalBridge/InternalBridge.asmdef.meta
-
35Runtime/InternalBridge/NoAllocHelpersBridge.cs
-
66Runtime/ui/painting/NoAllocHelpers.cs
-
0/Runtime/InternalBridge/NoAllocHelpersBridge.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 6692331a428d6455c97baf446a850594 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{ |
|||
"name": "Unity.InternalAPIEngineBridge.024", |
|||
"references": [], |
|||
"optionalUnityReferences": [], |
|||
"includePlatforms": [], |
|||
"excludePlatforms": [], |
|||
"allowUnsafeCode": false, |
|||
"overrideReferences": false, |
|||
"precompiledReferences": [], |
|||
"autoReferenced": true, |
|||
"defineConstraints": [] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4c951e9ffe25e41eabcc32758a061e70 |
|||
AssemblyDefinitionImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace Unity.UIWidgets.InternalBridge { |
|||
public static class NoAllocHelpersBridge<T> { |
|||
public static T[] ExtractArrayFromListT(List<T> list) { |
|||
return UnityEngine.NoAllocHelpers.ExtractArrayFromListT(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; |
|||
} |
|||
|
|||
UnityEngine.NoAllocHelpers.ResizeList(list, size); |
|||
} |
|||
|
|||
public static void EnsureListElemCount(List<T> list, int size) { |
|||
list.Clear(); |
|||
if (list.Capacity < size) { |
|||
list.Capacity = size; |
|||
} |
|||
|
|||
ResizeList(list, size); |
|||
} |
|||
} |
|||
} |
|
|||
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