88using UnityEngine . Experimental . UIElements ;
99using VRC . Udon ;
1010using VRC . Udon . Common . Interfaces ;
11+ using VRC . Udon . Editor . ProgramSources ;
12+ using VRC . Udon . Editor . ProgramSources . Attributes ;
1113using VRC . Udon . Serialization . OdinSerializer ;
1214
1315[ assembly: UdonProgramSourceNewMenu ( typeof ( UdonSharp . UdonSharpProgramAsset ) , "Udon C# Program Asset" ) ]
@@ -41,7 +43,7 @@ void Start()
4143
4244 private static bool showProgramUasm = false ;
4345
44- public override void RunProgramSourceEditor ( Dictionary < string , ( object value , Type declaredType ) > publicVariables , ref bool dirty )
46+ protected override void DrawProgramSourceGUI ( UdonBehaviour udonBehaviour , ref bool dirty )
4547 {
4648 EditorGUI . BeginChangeCheck ( ) ;
4749 MonoScript newSourceCsScript = ( MonoScript ) EditorGUILayout . ObjectField ( "Source Script" , sourceCsScript , typeof ( MonoScript ) , false ) ;
@@ -58,7 +60,7 @@ public override void RunProgramSourceEditor(Dictionary<string, (object value, Ty
5860 return ;
5961 }
6062
61- DrawPublicVariables ( publicVariables , ref dirty ) ;
63+ DrawPublicVariables ( udonBehaviour , ref dirty ) ;
6264
6365 DrawAssemblyErrorTextArea ( ) ;
6466
@@ -90,22 +92,21 @@ public override void RunProgramSourceEditor(Dictionary<string, (object value, Ty
9092 //base.RunProgramSourceEditor(publicVariables, ref dirty);
9193 }
9294
93- protected override void DoRefreshProgramActions ( )
95+ protected override void RefreshProgramImpl ( )
9496 {
9597 CompileCsProgram ( ) ;
9698 }
97-
98- protected override ( object value , Type declaredType ) InitializePublicVariable ( Type type , string symbol )
99+
100+ protected override object GetPublicVariableDefaultValue ( string symbol , Type type )
99101 {
100- return ( program . Heap . GetHeapVariable ( program . SymbolTable . GetAddressFromSymbol ( symbol ) ) , type ) ;
102+ return program . Heap . GetHeapVariable ( program . SymbolTable . GetAddressFromSymbol ( symbol ) ) ;
101103 }
102104
103105 public void CompileCsProgram ( )
104106 {
105107 UdonSharpCompiler compiler = new UdonSharpCompiler ( this ) ;
106108 compiler . Compile ( ) ;
107-
108- EditorUtility . SetDirty ( this ) ;
109+ SerializedProgramAsset . StoreProgram ( program ) ;
109110 }
110111
111112 private void CompileAllCsPrograms ( )
@@ -128,6 +129,12 @@ public void AssembleCsProgram()
128129 AssembleProgram ( ) ;
129130 }
130131
132+ public void ApplyProgram ( )
133+ {
134+ SerializedProgramAsset . StoreProgram ( program ) ;
135+ EditorUtility . SetDirty ( this ) ;
136+ }
137+
131138 public void SetUdonAssembly ( string assembly )
132139 {
133140 udonAssembly = assembly ;
@@ -452,13 +459,15 @@ private object DrawFieldForType(string fieldName, string symbol, (object value,
452459
453460 return value ;
454461 }
455-
456- protected override void DrawFieldForTypeString ( string symbol , ref ( object value , Type declaredType ) publicVariable , ref bool dirty , bool enabled )
462+
463+ protected override object DrawPublicVariableField ( string symbol , object variableValue , Type variableType , ref bool dirty , bool enabled )
457464 {
465+ object newValue = variableValue ;
466+
458467 EditorGUI . BeginDisabledGroup ( ! enabled ) ;
459468
460469 bool shouldDraw = true ;
461- bool isArray = publicVariable . declaredType . IsArray ;
470+ bool isArray = variableType . IsArray ;
462471
463472 FieldDefinition symbolField ;
464473 if ( fieldDefinitions != null && fieldDefinitions . TryGetValue ( symbol , out symbolField ) )
@@ -481,12 +490,12 @@ protected override void DrawFieldForTypeString(string symbol, ref (object value,
481490 EditorGUILayout . BeginHorizontal ( ) ;
482491
483492 EditorGUI . BeginChangeCheck ( ) ;
484- object newValue = DrawFieldForType ( null , symbol , publicVariable , ref dirty , enabled ) ;
493+ newValue = DrawFieldForType ( null , symbol , ( variableValue , variableType ) , ref dirty , enabled ) ;
485494
486495 if ( EditorGUI . EndChangeCheck ( ) )
487496 {
488497 dirty = true ;
489- publicVariable . value = newValue ;
498+ variableValue = newValue ;
490499 }
491500
492501 if ( symbolField . fieldSymbol != null && symbolField . fieldSymbol . syncMode != UdonSyncMode . NotSynced )
@@ -502,6 +511,8 @@ protected override void DrawFieldForTypeString(string symbol, ref (object value,
502511 }
503512
504513 EditorGUI . EndDisabledGroup ( ) ;
514+
515+ return variableValue ;
505516 }
506517 }
507518
0 commit comments