上下文加载优化
This commit is contained in:
@@ -175,12 +175,12 @@ namespace Demo
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
public readonly Dictionary<string, float> ScriptableObjectContents = new();
|
||||
private NativeHashMap<int, float> ScriptableObjectContents;
|
||||
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public float GetContent(string key)
|
||||
{
|
||||
if (ScriptableObjectContents.TryGetValue(key, out var result))
|
||||
if (ScriptableObjectContents.IsCreated && ScriptableObjectContents.TryGetValue(key.GetHashCode(), out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -190,7 +190,11 @@ namespace Demo
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public float SetContent(string key, float value)
|
||||
{
|
||||
ScriptableObjectContents[key] = value;
|
||||
if (ScriptableObjectContents.IsCreated == false)
|
||||
{
|
||||
ScriptableObjectContents = new(8, AllocatorManager.Persistent);
|
||||
}
|
||||
ScriptableObjectContents[key.GetHashCode()] = value;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -315,7 +319,12 @@ namespace Demo
|
||||
}
|
||||
this.Parent = parent;
|
||||
if (parent != null)
|
||||
this.ScriptableObjectContents.AddRange(parent.ScriptableObjectContents);
|
||||
{
|
||||
foreach (var item in parent.ScriptableObjectContents)
|
||||
{
|
||||
this.ScriptableObjectContents[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
|
||||
this.name = ScriptName;
|
||||
|
||||
@@ -603,7 +612,7 @@ namespace Demo
|
||||
}
|
||||
// 释放资源
|
||||
{
|
||||
this.ScriptableObjectContents.Clear();
|
||||
this.ScriptableObjectContents.Dispose();
|
||||
}
|
||||
IsScriptApply = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user