Skip to content

Commit

Permalink
Fix a potential bug on auto binding U# events
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed Nov 19, 2023
1 parent 0063ac3 commit 4e0ccea
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public override void OnProcessScene(Scene scene, BuildReport report) {
AddEntry(unityObject, usharp);
}
}
var remapped = new List<UdonSharpBehaviour>();
var duplicateCheck = new HashSet<UdonSharpBehaviour>();
var remapped = new HashSet<UdonSharpBehaviour>();
foreach (var kv in eventSenders) {
var sender = kv.Key;
if (sender == null) {
Expand All @@ -46,16 +45,16 @@ public override void OnProcessScene(Scene scene, BuildReport report) {
using (var so = new SerializedObject(sender)) {
var prop = so.FindProperty("targets");
for (int i = 0, count = prop.arraySize; i < count; i++)
if (prop.GetArrayElementAtIndex(i).objectReferenceValue is UdonSharpBehaviour ub && ub != null && duplicateCheck.Add(ub))
if (prop.GetArrayElementAtIndex(i).objectReferenceValue is UdonSharpBehaviour ub && ub != null)
remapped.Add(ub);
foreach (var entry in kv.Value)
if (entry != null && duplicateCheck.Add(entry))
remapped.Add(entry);
prop.arraySize += remapped.Count;
for (int i = 0, count = remapped.Count; i < count; i++)
prop.GetArrayElementAtIndex(i).objectReferenceValue = remapped[i];
remapped.UnionWith(kv.Value);
prop.arraySize = remapped.Count;
{
int i = 0;
foreach (var entry in remapped)
prop.GetArrayElementAtIndex(i++).objectReferenceValue = entry;
}
remapped.Clear();
duplicateCheck.Clear();
so.ApplyModifiedPropertiesWithoutUndo();
}
UdonSharpEditorUtility.CopyProxyToUdon(sender);
Expand Down

0 comments on commit 4e0ccea

Please sign in to comment.