Skip to content

Commit

Permalink
Optimize StudioObjectExtensions.GetSceneId
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Dec 13, 2023
1 parent 3da7287 commit f180a61
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Shared.CharaStudio/Studio/StudioObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ public static int GetSceneId(this ObjectCtrlInfo obj)
if (obj == null) throw new ArgumentNullException(nameof(obj));
if (Studio == null) throw new InvalidOperationException("Studio is not initialized yet!");

foreach (var info in Studio.dicObjectCtrl)
{
if (info.Value == obj)
return info.Key;
}
if (Studio.dicObjectCtrl.TryGetValue(obj.objectInfo.dicKey, out var oci) && oci == obj)
return obj.objectInfo.dicKey;

return -1;
}

Expand All @@ -53,12 +51,10 @@ public static int GetSceneId(this ObjectInfo obj)
{
if (obj == null) throw new ArgumentNullException(nameof(obj));
if (Studio == null) throw new InvalidOperationException("Studio is not initialized yet!");

if (Studio.dicObjectCtrl.TryGetValue(obj.dicKey, out var oci) && oci.objectInfo == obj)
return obj.dicKey;

foreach (var info in Studio.dicObjectCtrl)
{
if (info.Value.objectInfo == obj)
return info.Key;
}
return -1;
}

Expand Down

0 comments on commit f180a61

Please sign in to comment.