public UdonHeapValueStorage(IUdonHeap heap, IUdonSymbolTable symbolTable, string symbolKey) { this.heap = heap; bool isValid = symbolTable.TryGetAddressFromSymbol(symbolKey, out symbolAddress) && heap.GetHeapVariableType(symbolAddress) == typeof(T) && heap.TryGetHeapVariable <T>(symbolAddress, out var validityCheckPlaceholder); if (!isValid) { symbolAddress = 0xFFFFFFFF; } }
public UdonHeapValueStorage(IUdonHeap heap, IUdonSymbolTable symbolTable, string symbolKey) { this.heap = heap; bool isValid = symbolTable.TryGetAddressFromSymbol(UdonSharpUtils.UnmanglePropertyFieldName(symbolKey), out symbolAddress) && heap.GetHeapVariableType(symbolAddress) == typeof(T) && heap.TryGetHeapVariable <T>(symbolAddress, out _); if (!isValid) { symbolAddress = 0xFFFFFFFF; } }
// ReSharper disable once RedundantAssignment protected override void DeserializeImplementation(ref UdonProgram value, IDataReader reader) { reader.ReadString(out string instructionSetIdentifier); reader.ReadInt32(out int instructionSetVersion); byte[] byteCode = _byteArrayReaderWriter.ReadValue(reader); IUdonHeap heap = _udonHeapReaderWriter.ReadValue(reader); IUdonSymbolTable entryPoints = _udonSymbolTableReaderWriter.ReadValue(reader); IUdonSymbolTable symbolTable = _udonSymbolTableReaderWriter.ReadValue(reader); IUdonSyncMetadataTable syncMetadataTable = _udonSyncMetadataTableReaderWriter.ReadValue(reader); value = new UdonProgram(instructionSetIdentifier, instructionSetVersion, byteCode, heap, entryPoints, symbolTable, syncMetadataTable); RegisterReferenceID(value, reader); InvokeOnDeserializingCallbacks(ref value, reader.Context); }
private bool IsSetupReady(UdonChannelSetup UdonChannelSetup) { // Symbolテーブル取得 IUdonSymbolTable symbolTable = UdonChannelSetup.udonBehaviour?.programSource?.SerializedProgramAsset?.RetrieveProgram()?.SymbolTable; if (symbolTable == null) { return(false); } // Symbolが存在しなければFalse if (!symbolTable.HasExportedSymbol("titles")) { return(false); } // Symbolの型がstring[]でなければFalse if (symbolTable.GetSymbolType("titles") != typeof(string[])) { return(false); } return(true); }
protected void DrawPublicVariables(UdonBehaviour udonBehaviour, ref bool dirty) { IUdonVariableTable publicVariables = null; if (udonBehaviour != null) { publicVariables = udonBehaviour.publicVariables; } EditorGUILayout.LabelField("Public Variables", EditorStyles.boldLabel); EditorGUI.indentLevel++; if (program?.SymbolTable == null) { EditorGUILayout.LabelField("No public variables."); EditorGUI.indentLevel--; return; } IUdonSymbolTable symbolTable = program.SymbolTable; string[] exportedSymbolNames = symbolTable.GetExportedSymbols(); if (publicVariables != null) { foreach (string publicVariableSymbol in publicVariables.VariableSymbols.ToArray()) { if (!exportedSymbolNames.Contains(publicVariableSymbol)) { publicVariables.RemoveVariable(publicVariableSymbol); } } } if (exportedSymbolNames.Length <= 0) { EditorGUILayout.LabelField("No public variables."); EditorGUI.indentLevel--; return; } foreach (string exportedSymbol in exportedSymbolNames) { Type symbolType = symbolTable.GetSymbolType(exportedSymbol); if (publicVariables == null) { DrawPublicVariableField(exportedSymbol, GetPublicVariableDefaultValue(exportedSymbol, symbolType), symbolType, ref dirty, false); continue; } if (!publicVariables.TryGetVariableType(exportedSymbol, out Type declaredType) || declaredType != symbolType) { publicVariables.RemoveVariable(exportedSymbol); if (!publicVariables.TryAddVariable(CreateUdonVariable(exportedSymbol, GetPublicVariableDefaultValue(exportedSymbol, declaredType), symbolType))) { EditorGUILayout.LabelField($"Error drawing field for symbol '{exportedSymbol}'."); continue; } } if (!publicVariables.TryGetVariableValue(exportedSymbol, out object variableValue)) { variableValue = GetPublicVariableDefaultValue(exportedSymbol, declaredType); } variableValue = DrawPublicVariableField(exportedSymbol, variableValue, symbolType, ref dirty, true); if (!dirty) { continue; } Undo.RecordObject(udonBehaviour, "Modify Public Variable"); if (!publicVariables.TrySetVariableValue(exportedSymbol, variableValue)) { if (!publicVariables.TryAddVariable(CreateUdonVariable(exportedSymbol, variableValue, symbolType))) { Debug.LogError($"Failed to set public variable '{exportedSymbol}' value."); } } EditorSceneManager.MarkSceneDirty(udonBehaviour.gameObject.scene); if (PrefabUtility.IsPartOfPrefabInstance(udonBehaviour)) { PrefabUtility.RecordPrefabInstancePropertyModifications(udonBehaviour); } } EditorGUI.indentLevel--; }