xingwei.zhu
6 年前
当前提交
401a5864
共有 8 个文件被更改,包括 127 次插入 和 15 次删除
-
43Runtime/ui/painting/path.cs
-
10Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
-
6Runtime/ui/utils/renderer/common/draw_cmd.cs
-
15Runtime/ui/utils/renderer/common/geometry/path/path.cs
-
1Runtime/widgets/binding.cs
-
2Samples/UIWidgetSample/NavigationSample.cs
-
2Samples/UIWidgetSample/TextInput.unity
-
63Runtime/ui/utils/renderer/allocUtils/uipath_cache_manager.cs
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.ui { |
|||
|
|||
public static class uiPathCacheManager { |
|||
static Dictionary<uint, uiPath> cache = new Dictionary<uint, uiPath>(256); |
|||
|
|||
//remove unused cache items every 30 frame
|
|||
static Dictionary<uint, bool> touched = new Dictionary<uint, bool>(256); |
|||
|
|||
static float curFrame; |
|||
|
|||
static readonly List<uint> untouched = new List<uint>(); |
|||
|
|||
public static void tickNextFrame() { |
|||
curFrame++; |
|||
if (curFrame < 30) { |
|||
return; |
|||
} |
|||
|
|||
curFrame = 0; |
|||
|
|||
untouched.Clear(); |
|||
foreach (var key in cache.Keys) { |
|||
if (!touched.ContainsKey(key)) { |
|||
untouched.Add(key); |
|||
} |
|||
} |
|||
|
|||
foreach (var key in untouched) { |
|||
ObjectPool<uiPath>.release(cache[key]); |
|||
cache.Remove(key); |
|||
} |
|||
|
|||
touched.Clear(); |
|||
} |
|||
|
|||
public static void putToCache(uiPath uipath) { |
|||
if (!uipath.needCache) { |
|||
ObjectPool<uiPath>.release(uipath); |
|||
} |
|||
} |
|||
|
|||
public static bool tryGetUiPath(uint pathKey, out uiPath outpath) { |
|||
if (cache.ContainsKey(pathKey)) { |
|||
touched[pathKey] = true; |
|||
outpath = cache[pathKey]; |
|||
return true; |
|||
} |
|||
|
|||
var uipath = uiPath.create(); |
|||
cache[pathKey] = uipath; |
|||
touched[pathKey] = true; |
|||
|
|||
uipath.needCache = true; |
|||
uipath.pathKey = pathKey; |
|||
|
|||
outpath = uipath; |
|||
return false; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue