From ad999d89017ab1fc2624ff05dcbd16d4ae115b48 Mon Sep 17 00:00:00 2001 From: Nestorboy <35258953+Nestorboy@users.noreply.github.com> Date: Sat, 7 May 2022 22:15:56 +0200 Subject: [PATCH] Updated NUExtensions structs and null checks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • 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. --- .../Nessie/Udon/NUExtensions/NUExtensions.cs | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Assets/Nessie/Udon/NUExtensions/NUExtensions.cs b/Assets/Nessie/Udon/NUExtensions/NUExtensions.cs index 1ba47d7..650053d 100644 --- a/Assets/Nessie/Udon/NUExtensions/NUExtensions.cs +++ b/Assets/Nessie/Udon/NUExtensions/NUExtensions.cs @@ -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] @@ -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 @@ -75,9 +89,12 @@ public Variable(string name, VariableType variableType, Type type) public static List GetEvents(this UdonBehaviour udon, EventType eventType = EventType.Any) { - IUdonSymbolTable entryTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().EntryPoints; List events = new List(); + AbstractUdonProgramSource program = udon.programSource; + if (!program) return events; + IUdonSymbolTable entryTable = program.SerializedProgramAsset.RetrieveProgram().EntryPoints; + string[] entries = entryTable.GetSymbols().ToArray(); foreach (string entry in entries) { @@ -96,9 +113,12 @@ public static List GetEvents(this UdonBehaviour udon, EventType eventType public static List GetVariables(this UdonBehaviour udon, VariableType variableType = VariableType.Any) { - IUdonSymbolTable symbolTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().SymbolTable; List variables = new List(); + AbstractUdonProgramSource program = udon.programSource; + if (!program) return variables; + IUdonSymbolTable symbolTable = program.SerializedProgramAsset.RetrieveProgram().SymbolTable; + string[] symbols = symbolTable.GetSymbols().ToArray(); Array.Sort(symbols); @@ -129,8 +149,9 @@ public static List GetVariables(this UdonBehaviour udon, VariableType public static List GetFilteredVariables(this UdonBehaviour udon, Type[] filter, VariableType variableType = VariableType.Any) { - IUdonSymbolTable symbolTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().SymbolTable; List variables = new List(); + if (!udon.programSource) return variables; + IUdonSymbolTable symbolTable = udon.programSource.SerializedProgramAsset.RetrieveProgram().SymbolTable; string[] symbols = symbolTable.GetSymbols().ToArray(); Array.Sort(symbols);