1010using UdonSharp . Compiler ;
1111using UnityEditor ;
1212using UnityEngine ;
13+ using VRC . SDKBase ;
1314using VRC . Udon ;
1415using VRC . Udon . Common ;
1516using VRC . Udon . Common . Interfaces ;
@@ -28,11 +29,12 @@ internal class SyncModeMenu : EditorWindow
2829 private static GUIStyle descriptionStyle ;
2930
3031 private static readonly List < ( GUIContent , GUIContent ) > Labels = new List < ( GUIContent , GUIContent ) > ( new [ ] {
32+ ( new GUIContent ( "None" ) , new GUIContent ( "Replication will be disabled. Variables cannot be synced, and this behaviour will not receive network events." ) ) ,
3133 ( new GUIContent ( "Continuous" ) , new GUIContent ( "Continuous replication is intended for frequently-updated variables of small size, and will be tweened." ) ) ,
3234 ( new GUIContent ( "Manual" ) , new GUIContent ( "Manual replication is intended for infrequently-updated variables of small or large size, and will not be tweened." ) ) ,
3335 } ) ;
34-
35- static Rect GetAreaRect ( Rect rect )
36+
37+ private static Rect GetAreaRect ( Rect rect )
3638 {
3739 const float borderWidth = 1f ;
3840
@@ -68,7 +70,7 @@ void DrawSelectionOption(GUIContent title, GUIContent descriptor, int index)
6870 checkboxStyle . padding . right = 0 ;
6971 checkboxStyle . margin . right = 0 ;
7072
71- if ( udonBehaviour . Reliable == ( index == 1 ) )
73+ if ( udonBehaviour . SyncMethod == ( Networking . SyncType ) ( index + 1 ) )
7274 EditorGUILayout . LabelField ( "✔" , checkboxStyle , GUILayout . Width ( 10f ) ) ;
7375 else
7476 EditorGUILayout . LabelField ( "" , checkboxStyle , GUILayout . Width ( 10f ) ) ;
@@ -103,14 +105,14 @@ void DrawSelectionOption(GUIContent title, GUIContent descriptor, int index)
103105 }
104106 }
105107
106- void SelectIndex ( int idx )
108+ private void SelectIndex ( int idx )
107109 {
108110 selectedIdx = idx ;
109111
110- if ( udonBehaviour . Reliable != ( selectedIdx == 1 ) )
112+ if ( udonBehaviour . SyncMethod != ( Networking . SyncType ) ( selectedIdx + 1 ) )
111113 {
112114 Undo . RecordObject ( udonBehaviour , "Change sync mode" ) ;
113- udonBehaviour . Reliable = selectedIdx == 1 ;
115+ udonBehaviour . SyncMethod = ( Networking . SyncType ) ( selectedIdx + 1 ) ;
114116
115117 PrefabUtility . RecordPrefabInstancePropertyModifications ( udonBehaviour ) ;
116118 }
@@ -141,7 +143,7 @@ void DrawSelectionOutline(Rect rect)
141143 GUI . Box ( new Rect ( rect . x - outlineWidth , rect . y + rect . height + outlineWidth + 1f , rect . width + outlineWidth * 2f , outlineWidth ) , GUIContent . none , outlineStyle ) ;
142144 }
143145
144- internal static Rect GUIToScreenRect ( Rect rect )
146+ private static Rect GUIToScreenRect ( Rect rect )
145147 {
146148 Vector2 point = GUIUtility . GUIToScreenPoint ( new Vector2 ( rect . x , rect . y ) ) ;
147149 rect . x = point . x ;
@@ -190,7 +192,7 @@ public static void Show(Rect controlRect, UdonBehaviour[] behaviours)
190192 menu . ShowDropDown ( controlRect , dropdownSize ) ;
191193 }
192194
193- static Vector2 CalculateDropdownSize ( Rect controlRect )
195+ private static Vector2 CalculateDropdownSize ( Rect controlRect )
194196 {
195197 Rect areaRect = GetAreaRect ( controlRect ) ;
196198 areaRect . width -= 30f ; // Checkbox width
@@ -200,7 +202,7 @@ static Vector2 CalculateDropdownSize(Rect controlRect)
200202 for ( int i = 0 ; i < Labels . Count ; ++ i )
201203 {
202204 totalHeight += EditorStyles . boldLabel . CalcHeight ( Labels [ i ] . Item1 , areaRect . width ) ;
203- totalHeight += 6f ; // Space()
205+ totalHeight += 13f ; // Space()
204206 totalHeight += descriptionStyle . CalcHeight ( Labels [ i ] . Item2 , areaRect . width ) ;
205207 totalHeight += selectionStyle . margin . vertical ;
206208 totalHeight += selectionStyle . padding . vertical ;
@@ -211,22 +213,22 @@ static Vector2 CalculateDropdownSize(Rect controlRect)
211213 return new Vector2 ( controlRect . width , totalHeight ) ;
212214 }
213215
214- static Array popupLocationArray ;
216+ private static Array _popupLocationArray ;
215217
216218 void ShowDropDown ( Rect controlRect , Vector2 size )
217219 {
218- if ( popupLocationArray == null )
220+ if ( _popupLocationArray == null )
219221 {
220222 System . Type popupLocationType = AppDomain . CurrentDomain . GetAssemblies ( ) . First ( e => e . GetName ( ) . Name == "UnityEditor" ) . GetType ( "UnityEditor.PopupLocation" ) ;
221223
222- popupLocationArray = ( Array ) Activator . CreateInstance ( popupLocationType . MakeArrayType ( ) , 2 ) ;
223- popupLocationArray . SetValue ( 0 , 0 ) ; // PopupLocation.Below
224- popupLocationArray . SetValue ( 4 , 1 ) ; // PopupLocation.Overlay
224+ _popupLocationArray = ( Array ) Activator . CreateInstance ( popupLocationType . MakeArrayType ( ) , 2 ) ;
225+ _popupLocationArray . SetValue ( 0 , 0 ) ; // PopupLocation.Below
226+ _popupLocationArray . SetValue ( 4 , 1 ) ; // PopupLocation.Overlay
225227 }
226228
227229 MethodInfo showAsDropDownMethod = typeof ( EditorWindow ) . GetMethods ( BindingFlags . NonPublic | BindingFlags . Instance ) . First ( e => e . GetParameters ( ) . Length == 3 ) ;
228230
229- showAsDropDownMethod . Invoke ( this , new object [ ] { controlRect , size , popupLocationArray } ) ;
231+ showAsDropDownMethod . Invoke ( this , new object [ ] { controlRect , size , _popupLocationArray } ) ;
230232 }
231233 }
232234 #endregion
@@ -1364,7 +1366,7 @@ internal static void DrawSyncSettings(UdonBehaviour behaviour)
13641366 if ( otherBehaviour . programSource is UdonSharpProgramAsset otherBehaviourProgram && otherBehaviourProgram . behaviourSyncMode == BehaviourSyncMode . NoVariableSync )
13651367 continue ;
13661368
1367- if ( otherBehaviour . Reliable )
1369+ if ( otherBehaviour . SyncMethod == Networking . SyncType . Manual )
13681370 hasReliableSync = true ;
13691371 else
13701372 hasContinuousSync = true ;
@@ -1381,7 +1383,7 @@ internal static void DrawSyncSettings(UdonBehaviour behaviour)
13811383 }
13821384
13831385 // Dropdown for the sync settings
1384- if ( programAsset . behaviourSyncMode != BehaviourSyncMode . NoVariableSync )
1386+ if ( programAsset . behaviourSyncMode != BehaviourSyncMode . NoVariableSync && programAsset . behaviourSyncMode != BehaviourSyncMode . None )
13851387 {
13861388 bool allowsSyncConfig = programAsset . behaviourSyncMode == BehaviourSyncMode . Any ;
13871389
@@ -1396,7 +1398,21 @@ internal static void DrawSyncSettings(UdonBehaviour behaviour)
13961398 if ( dropdownButtonMethod == null )
13971399 dropdownButtonMethod = typeof ( EditorGUI ) . GetMethod ( "DropdownButton" , BindingFlags . NonPublic | BindingFlags . Static , null , new Type [ ] { typeof ( int ) , typeof ( Rect ) , typeof ( GUIContent ) , typeof ( GUIStyle ) } , null ) ;
13981400
1399- if ( ( bool ) dropdownButtonMethod . Invoke ( null , new object [ ] { id , dropdownRect , new GUIContent ( behaviour . Reliable ? "Manual" : "Continuous" ) , EditorStyles . miniPullDown } ) )
1401+ string dropdownText ;
1402+ switch ( behaviour . SyncMethod )
1403+ {
1404+ case Networking . SyncType . Continuous :
1405+ dropdownText = "Continuous" ;
1406+ break ;
1407+ case Networking . SyncType . Manual :
1408+ dropdownText = "Manual" ;
1409+ break ;
1410+ default :
1411+ dropdownText = "None" ;
1412+ break ;
1413+ }
1414+
1415+ if ( ( bool ) dropdownButtonMethod . Invoke ( null , new object [ ] { id , dropdownRect , new GUIContent ( dropdownText ) , EditorStyles . miniPullDown } ) )
14001416 {
14011417 SyncModeMenu . Show ( syncMethodRect , new UdonBehaviour [ ] { behaviour } ) ;
14021418
@@ -1405,18 +1421,18 @@ internal static void DrawSyncSettings(UdonBehaviour behaviour)
14051421
14061422 EditorGUI . EndDisabledGroup ( ) ;
14071423
1408- bool newReliableState = behaviour . Reliable ;
1424+ bool newReliableState = behaviour . SyncMethod == Networking . SyncType . Manual ;
14091425
14101426 // Handle auto setting of sync mode if the component has just been created
1411- if ( programAsset . behaviourSyncMode == BehaviourSyncMode . Continuous && behaviour . Reliable )
1427+ if ( programAsset . behaviourSyncMode == BehaviourSyncMode . Continuous && behaviour . SyncMethod == Networking . SyncType . Manual )
14121428 newReliableState = false ;
1413- else if ( programAsset . behaviourSyncMode == BehaviourSyncMode . Manual && ! behaviour . Reliable )
1429+ else if ( programAsset . behaviourSyncMode == BehaviourSyncMode . Manual && behaviour . SyncMethod != Networking . SyncType . Manual )
14141430 newReliableState = true ;
14151431
1416- if ( newReliableState != behaviour . Reliable )
1432+ if ( newReliableState != ( behaviour . SyncMethod == Networking . SyncType . Manual ) )
14171433 {
14181434 Undo . RecordObject ( behaviour , "Update sync mode" ) ;
1419- behaviour . Reliable = newReliableState ;
1435+ behaviour . SyncMethod = newReliableState ? Networking . SyncType . Manual : Networking . SyncType . Continuous ;
14201436 }
14211437 }
14221438
0 commit comments