From eb84bb298d2b95aec7b2ae12cbf25ac64f25379a Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 6 Nov 2022 15:12:42 -0500 Subject: move to self host --- .../ProgramSources/SerializedUdonProgramAsset.cs | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 VRCSDK3Worlds/Assets/Udon/ProgramSources/SerializedUdonProgramAsset.cs (limited to 'VRCSDK3Worlds/Assets/Udon/ProgramSources/SerializedUdonProgramAsset.cs') diff --git a/VRCSDK3Worlds/Assets/Udon/ProgramSources/SerializedUdonProgramAsset.cs b/VRCSDK3Worlds/Assets/Udon/ProgramSources/SerializedUdonProgramAsset.cs new file mode 100644 index 00000000..d1bdcb5b --- /dev/null +++ b/VRCSDK3Worlds/Assets/Udon/ProgramSources/SerializedUdonProgramAsset.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Profiling; +using VRC.Udon.Common; +using VRC.Udon.Common.Interfaces; +using VRC.Udon.Serialization.OdinSerializer; + +namespace VRC.Udon.ProgramSources +{ + public sealed class SerializedUdonProgramAsset : AbstractSerializedUdonProgramAsset + { + private const DataFormat DEFAULT_SERIALIZATION_DATA_FORMAT = DataFormat.Binary; + + [SerializeField, HideInInspector] + private string serializedProgramBytesString; + + [SerializeField, HideInInspector] + private List programUnityEngineObjects; + + // Store the serialization DataFormat that was actually used to serialize the program. + // This allows us to change the DataFormat later (ex. switch to binary) without causing already serialized programs to use the wrong DataFormat. + // Programs will be deserialized using the previous format and will switch to the new format if StoreProgram is called again later. + [SerializeField, HideInInspector] + private DataFormat serializationDataFormat = DEFAULT_SERIALIZATION_DATA_FORMAT; + + public override void StoreProgram(IUdonProgram udonProgram) + { + if (this == null) return; + + byte[] serializedProgramBytes = SerializationUtility.SerializeValue(udonProgram, DEFAULT_SERIALIZATION_DATA_FORMAT, out programUnityEngineObjects); + serializedProgramBytesString = Convert.ToBase64String(serializedProgramBytes); + serializationDataFormat = DEFAULT_SERIALIZATION_DATA_FORMAT; + + #if UNITY_EDITOR + UnityEditor.EditorUtility.SetDirty(this); + #endif + } + + public override IUdonProgram RetrieveProgram() + { + byte[] serializedProgramBytes = Convert.FromBase64String(serializedProgramBytesString ?? ""); + return SerializationUtility.DeserializeValue(serializedProgramBytes, serializationDataFormat, programUnityEngineObjects); + } + } +} -- cgit v1.2.3-freya