Skip to content

Commit

Permalink
packaging: Add sound serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Feb 8, 2025
1 parent cefbc82 commit 85ac173
Show file tree
Hide file tree
Showing 19 changed files with 455 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private async Task ReadAssets()
{
_packageFiles.UnpackAssets(_assetPath);
await _packageFiles.UnpackMeshes(_assetPath);
_packageFiles.UnpackSounds(_assetPath);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public async Task WritePackage(string path)
// write assets & co
sw1 = Stopwatch.StartNew();
_files.PackAssets();
Logger.Info($"Assets written in {sw1.ElapsedMilliseconds}ms.");
_files.PackSoundMetas();
Logger.Info($"Assets and files written in {sw1.ElapsedMilliseconds}ms.");

storage.Close();
sw.Stop();
Expand Down Expand Up @@ -180,7 +181,7 @@ private async Task WriteColliderMeshes()
Format = GltfFormat.Binary,
};
var export = new GameObjectExport(exportSettings, logger: logger);
export.AddScene(meshGos.ToArray(), _table.transform.worldToLocalMatrix, "VPE Table");
export.AddScene(meshGos.ToArray(), _table.transform.worldToLocalMatrix, "Colliders");
await export.SaveToStreamAndDispose(glbFile.AsStream());

var glbMeta = _metaFolder.AddFile(PackageApi.ColliderMeshesMeta, PackageApi.Packer.FileExtension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
using System;
using System.Threading;
using UnityEditor;
using UnityEngine.UIElements;
using UnityEngine;
using UnityEditor.UIElements;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

namespace VisualPinball.Unity.Editor
{
Expand Down Expand Up @@ -70,7 +69,7 @@ private void OnDisable()

private void RemoveNullClips()
{
var clipsProp = serializedObject.FindProperty("_clips");
var clipsProp = serializedObject.FindProperty(nameof(SoundAsset.Clips));
for (var i = clipsProp.arraySize -1; i >= 0; i--) {
if (clipsProp.GetArrayElementAtIndex(i).objectReferenceValue == null)
clipsProp.DeleteArrayElementAtIndex(i);
Expand Down Expand Up @@ -112,4 +111,3 @@ private void OnStopForrealButtonClicked()
}
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<Style src="project://database/Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/Common/MultilineTextField.uss?fileID=7433441132597879392&amp;guid=443092b513c6ebc4bbfbfe7de8daa864&amp;type=3#MultilineTextField" />
<ui:TextField picking-mode="Ignore" label="Description" multiline="true" binding-path="_description" name="description" class="multiline-textfield unity-base-field__aligned" />
<uie:PropertyField binding-path="_volume" label="Volume" name="volume" />
<uie:PropertyField name="clips" binding-path="_clips" label="Clips" />
<uie:PropertyField name="clip-selection-method" binding-path="_clipSelectionMethod" label="Clip Selection Method" />
<ui:MinMaxSlider label="Volume Range" min-value="1" max-value="1" low-limit="0" high-limit="1" tooltip="Volume will be randomized within this range (0 - 1)" binding-path="_volumeRange" name="volume-range" class="unity-base-field__aligned" />
<ui:MinMaxSlider label="Pitch Range" min-value="1" max-value="1" low-limit="0.5" high-limit="1.5" binding-path="_pitchRange" name="pitch-range" tooltip="Pitch will be randomized within this range (0.5 - 1.5)" class="unity-base-field__aligned" />
<uie:PropertyField name="loop" binding-path="_loop" label="Loop" />
<uie:PropertyField name="fade-in-time" binding-path="_fadeInTime" label="Fade In Time" />
<uie:PropertyField name="fade-out-time" binding-path="_fadeOutTime" label="Fade Out Time" />
<uie:PropertyField name="is-spatial" binding-path="_isSpatial" label="Is Spatial" />
<uie:ObjectField label="Audio Mixer Group" binding-path="_audioMixerGroup" name="audio-mixer-group" type="UnityEngine.Audio.AudioMixerGroup, UnityEngine.AudioModule" class="unity-base-field__aligned" />
<ui:TextField picking-mode="Ignore" label="Description" multiline="true" binding-path="Description" name="description" class="multiline-textfield unity-base-field__aligned" />
<uie:PropertyField binding-path="Volume" label="Volume" name="volume" />
<uie:PropertyField name="clips" binding-path="Clips" label="Clips" />
<uie:PropertyField name="clip-selection-method" binding-path="ClipSelectionMethod" label="Clip Selection Method" />
<ui:MinMaxSlider label="Volume Range" min-value="1" max-value="1" low-limit="0" high-limit="1" tooltip="Volume will be randomized within this range (0 - 1)" binding-path="VolumeRange" name="volume-range" class="unity-base-field__aligned" />
<ui:MinMaxSlider label="Pitch Range" min-value="1" max-value="1" low-limit="0.5" high-limit="1.5" binding-path="PitchRange" name="pitch-range" tooltip="Pitch will be randomized within this range (0.5 - 1.5)" class="unity-base-field__aligned" />
<uie:PropertyField name="loop" binding-path="Loop" label="Loop" />
<uie:PropertyField name="fade-in-time" binding-path="FadeInTime" label="Fade In Time" />
<uie:PropertyField name="fade-out-time" binding-path="FadeOutTime" label="Fade Out Time" />
<uie:PropertyField name="is-spatial" binding-path="IsSpatial" label="Is Spatial" />
<uie:ObjectField label="Audio Mixer Group" binding-path="AudioMixerGroup" name="audio-mixer-group" type="UnityEngine.Audio.AudioMixerGroup, UnityEngine.AudioModule" class="unity-base-field__aligned" />
<ui:Button text="Play" parse-escape-sequences="true" display-tooltip-when-elided="true" enable-rich-text="false" name="play-button" />
</ui:UXML>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void InvalidSoundAssetHelpBox(VisualElement container)
"The selected sound asset is invalid. Make sure it has at least one audio clip.",
HelpBoxMessageType.Warning);
container.Add(helpBox);
var soundAssetProp = serializedObject.FindProperty(nameof(SoundComponent._soundAsset));
var soundAssetProp = serializedObject.FindProperty(nameof(SoundComponent.SoundAsset));
UpdateVisibility(soundAssetProp);
helpBox.TrackPropertyValue(soundAssetProp, UpdateVisibility);

Expand Down Expand Up @@ -106,7 +106,7 @@ protected void InfiniteLoopHelpBox(VisualElement container)

void UpdateVisbility(SerializedObject obj)
{
var prop = obj.FindProperty(nameof(SoundComponent._soundAsset));
var prop = obj.FindProperty(nameof(SoundComponent.SoundAsset));
var soundAsset = prop.objectReferenceValue as SoundAsset;
if (soundAsset && soundAsset.Loop && !AllTargetsSupportLoopingSoundAssets()) {
helpBox.style.display = DisplayStyle.Flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class JsonPacker : IDataPacker
public byte[] Pack<T>(T obj)
{
try {
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj, Formatting.Indented));
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));
} catch (Exception e) {
Debug.LogError(e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static class PackageApi
public const string WiresFile = "wires";
public const string LampsFile = "lamps";
public const string AssetFolder = "assets";
public const string SoundFolder = "sounds";

public static readonly IStorageManager StorageManager = new SharpZipStorageManager();
// public static IStorageManager StorageManager => new OpenMcdfStorageManager();
Expand Down
Loading

0 comments on commit 85ac173

Please sign in to comment.