@@ -14,7 +14,6 @@ namespace ReferenceReplacement.UI;
1414
1515public sealed class ReferenceReplacementDialog
1616{
17- private readonly User _owner ;
1817 private readonly Slot _rootSlot ;
1918 private readonly ISyncRef _processRootRef ;
2019 private readonly ISyncRef _sourceRef ;
@@ -24,15 +23,28 @@ public sealed class ReferenceReplacementDialog
2423 private Text ? _detailText ;
2524 private bool _disposed ;
2625
26+ public static void OpenFromSlot ( Slot creationSlot )
27+ {
28+ ArgumentNullException . ThrowIfNull ( creationSlot ) ;
29+
30+ User ? localUser = creationSlot . World ? . LocalUser ;
31+ if ( localUser == null )
32+ {
33+ creationSlot . Destroy ( ) ;
34+ return ;
35+ }
36+
37+ _ = Create ( localUser , creationSlot ) ;
38+ }
39+
2740 private ReferenceReplacementDialog ( User owner , Slot dialogSlot )
2841 {
29- _owner = owner ?? throw new ArgumentNullException ( nameof ( owner ) ) ;
42+ ArgumentNullException . ThrowIfNull ( owner ) ;
3043 _rootSlot = dialogSlot ?? throw new ArgumentNullException ( nameof ( dialogSlot ) ) ;
3144 _rootSlot . Destroyed += OnSlotDestroyed ;
3245 ClearSlot ( _rootSlot ) ;
3346
3447 ( _processRootRef , _sourceRef , _targetRef ) = CreateReferenceFields ( ) ;
35- ClearInputs ( ) ;
3648
3749 ConfigureRootSlot ( ) ;
3850 BuildUI ( ) ;
@@ -63,7 +75,7 @@ public void RepositionFor(User? user)
6375 return ;
6476 }
6577
66- PrepareRootSlot ( user ) ;
78+ ResetRootTransform ( ) ;
6779 _rootSlot . PositionInFrontOfUser ( float3 . Backward ) ;
6880 if ( user . LocalUserRoot != null )
6981 {
@@ -86,8 +98,6 @@ public void Close()
8698 {
8799 _rootSlot . Destroy ( ) ;
88100 }
89-
90- ReferenceReplacementDialogManager . Unregister ( this ) ;
91101 }
92102
93103 private ( ISyncRef processRoot , ISyncRef source , ISyncRef target ) CreateReferenceFields ( )
@@ -97,7 +107,7 @@ public void Close()
97107
98108 private ISyncRef CreateReferenceProxy ( )
99109 {
100- var proxy = _rootSlot . AttachComponent < ReferenceProxy > ( ) ;
110+ ReferenceProxy proxy = _rootSlot . AttachComponent < ReferenceProxy > ( ) ;
101111 proxy . Persistent = false ;
102112 return ExtractSyncRef ( proxy ) ;
103113 }
@@ -123,7 +133,6 @@ private void OnSlotDestroyed(IDestroyable _)
123133 }
124134
125135 _disposed = true ;
126- ReferenceReplacementDialogManager . Unregister ( this ) ;
127136 }
128137
129138 private void ConfigureRootSlot ( )
@@ -358,21 +367,8 @@ private static void ClearSlot(Slot slot)
358367 }
359368 }
360369
361- private void ClearInputs ( )
362- {
363- _processRootRef . Target = null ! ;
364- _sourceRef . Target = null ! ;
365- _targetRef . Target = null ! ;
366- }
367-
368- private void PrepareRootSlot ( User owner )
370+ private void ResetRootTransform ( )
369371 {
370- Slot ? parent = owner . LocalUserSpace ;
371- if ( parent != null && _rootSlot . Parent != parent )
372- {
373- _rootSlot . SetParent ( parent , false ) ;
374- }
375-
376372 _rootSlot . LocalPosition = float3 . Zero ;
377373 _rootSlot . LocalRotation = floatQ . Identity ;
378374 }
0 commit comments