Skip to content

Commit

Permalink
Updated NUExtensions structs and null checks.
Browse files Browse the repository at this point in the history
• Added copy constructors to the Event and Variable structs.
• Fixed an issue where trying to get the variables or events from an Udon Behaviour without a program source would throw an error.
  • Loading branch information
Nestorboy committed May 7, 2022
1 parent 540b681 commit ad999d8
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Assets/Nessie/Udon/NUExtensions/NUExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public Event (string name, EventType eventType)
Name = name;
EventType = eventType;
}

public Event(Event source)
{
Name = source.Name;
EventType = source.EventType;
}
}

[Serializable]
Expand All @@ -67,6 +73,14 @@ public Variable(string name, VariableType variableType, Type type)

typeAssemblyName = type.AssemblyQualifiedName;
}

public Variable(Variable source)
{
Name = source.Name;
VariableType = source.VariableType;

typeAssemblyName = source.typeAssemblyName;
}
}

#endregion Public Structs
Expand All @@ -75,9 +89,12 @@ public Variable(string name, VariableType variableType, Type type)

public static List<Event> GetEvents(this UdonBehaviour udon, EventType eventType = EventType.Any)
{
IUdonSymbolTable entryTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().EntryPoints;
List<Event> events = new List<Event>();

AbstractUdonProgramSource program = udon.programSource;
if (!program) return events;
IUdonSymbolTable entryTable = program.SerializedProgramAsset.RetrieveProgram().EntryPoints;

string[] entries = entryTable.GetSymbols().ToArray();
foreach (string entry in entries)
{
Expand All @@ -96,9 +113,12 @@ public static List<Event> GetEvents(this UdonBehaviour udon, EventType eventType

public static List<Variable> GetVariables(this UdonBehaviour udon, VariableType variableType = VariableType.Any)
{
IUdonSymbolTable symbolTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().SymbolTable;
List<Variable> variables = new List<Variable>();

AbstractUdonProgramSource program = udon.programSource;
if (!program) return variables;
IUdonSymbolTable symbolTable = program.SerializedProgramAsset.RetrieveProgram().SymbolTable;

string[] symbols = symbolTable.GetSymbols().ToArray();
Array.Sort(symbols);

Expand Down Expand Up @@ -129,8 +149,9 @@ public static List<Variable> GetVariables(this UdonBehaviour udon, VariableType

public static List<Variable> GetFilteredVariables(this UdonBehaviour udon, Type[] filter, VariableType variableType = VariableType.Any)
{
IUdonSymbolTable symbolTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().SymbolTable;
List<Variable> variables = new List<Variable>();
if (!udon.programSource) return variables;
IUdonSymbolTable symbolTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().SymbolTable;

string[] symbols = symbolTable.GetSymbols().ToArray();
Array.Sort(symbols);
Expand Down

0 comments on commit ad999d8

Please sign in to comment.