Skip to content

Commit f667bb2

Browse files
committed
Fix compatibility with UdonSDK 2020.02.23.13.54
1 parent 910a7b9 commit f667bb2

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ public override void VisitReturnStatement(ReturnStatementSyntax node)
14981498
}
14991499

15001500
visitorContext.uasmBuilder.AddJumpIndirect(visitorContext.returnJumpTarget);
1501+
//visitorContext.uasmBuilder.AddJumpToExit();
15011502
}
15021503

15031504
public override void VisitBreakStatement(BreakStatementSyntax node)

Assets/UdonSharp/Editor/UdonSharpCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void Compile()
5858
{
5959
AssignHeapConstants(module);
6060

61-
EditorUtility.SetDirty(module.programAsset);
61+
module.programAsset.ApplyProgram();
6262
}
6363
}
6464
}

Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using UnityEngine.Experimental.UIElements;
99
using VRC.Udon;
1010
using VRC.Udon.Common.Interfaces;
11+
using VRC.Udon.Editor.ProgramSources;
12+
using VRC.Udon.Editor.ProgramSources.Attributes;
1113
using 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

Assets/UdonSharp/Editor/UdonSharpUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static int GetUdonInstructionSize(string instruction)
2222
case "NOP":
2323
case "POP":
2424
case "COPY":
25-
return 1;
25+
return 4;
2626
case "PUSH":
2727
case "JUMP_IF_FALSE":
2828
case "JUMP":
@@ -32,7 +32,7 @@ public static int GetUdonInstructionSize(string instruction)
3232
// they get replaced towards the end of compilation with jumps to concrete addresses
3333
case "JUMP_LABEL":
3434
case "JUMP_IF_FALSE_LABEL":
35-
return 5;
35+
return 8;
3636
case "ANNOTATION":
3737
throw new System.NotImplementedException("ANNOTATION instruction is not yet implemented in Udon");
3838
default:

0 commit comments

Comments
 (0)