Skip to content

Commit

Permalink
Merge pull request #3 from hiyorin/feature/adx2
Browse files Browse the repository at this point in the history
Feature/adx2
  • Loading branch information
hiyorin authored Apr 23, 2020
2 parents 9c8cad9 + 31694ef commit b80ca73
Show file tree
Hide file tree
Showing 26 changed files with 1,133 additions and 268 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Gamebase integration with NodeCanvas is disabled by default. To enable, you must

Gamebase integration with CRI ADX2 is disabled by default. To enable, you must add the define `GAMEBASE_ADD_ADX2` to your project, which you can do by selecting Edit -> Project Settings -> Player and then adding `GAMEBASE_ADD_ADX2` in the `Scripting Define Symbols` section.

Create `Assembly Define File` in `Assets/Plubins/CriWare/CriWare.asmdef`.

<br><br><br><br>
## Master Audio Integration
[Master Audio](https://assetstore.unity.com/packages/tools/audio/master-audio-aaa-sound-5607) gives you tremendous ease of use, speed, power and flexibility far beyond any contender. For more details see the [Master Audio docs](https://www.dtdevtools.com/docs/masteraudio/TOC.htm).
Expand Down
67 changes: 67 additions & 0 deletions Resources/Adx2SoundPlayer.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3178856306308472706
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2491841137675613099}
- component: {fileID: 3965031960097274914}
- component: {fileID: 7266965698307310743}
m_Layer: 0
m_Name: Adx2SoundPlayer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2491841137675613099
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3178856306308472706}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3965031960097274914
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3178856306308472706}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d1e631c3b9947b54c823c6853a05529c, type: 3}
m_Name:
m_EditorClassIdentifier:
_playOnStart: 0
_cueName:
_cueSheet:
_use3dPositioning: 1
_loop: 0
_volume: 1
_pitch: 0
_androidUseLowLatencyVoicePool: 0
need_to_player_update_all: 1
--- !u!114 &7266965698307310743
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3178856306308472706}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1a44920b2cd9458b9a62a4f4992f17dc, type: 3}
m_Name:
m_EditorClassIdentifier:
7 changes: 7 additions & 0 deletions Resources/Adx2SoundPlayer.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions Resources/CRIAtom.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2408416738903461801
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1130101752212810398}
- component: {fileID: 2183310382097167902}
- component: {fileID: 6271576223373321121}
m_Layer: 0
m_Name: CRIWARE
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1130101752212810398
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2408416738903461801}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5.7423463, y: -1.4332404, z: 23.424572}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2183310382097167902
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2408416738903461801}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91f529aa944b914449d62b8c40f188fe, type: 3}
m_Name:
m_EditorClassIdentifier:
acfFile:
cueSheets: []
dspBusSetting:
dontDestroyOnLoad: 1
dontRemoveExistsCueSheet: 0
--- !u!114 &6271576223373321121
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2408416738903461801}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f154ff0ac54c142928b46e94a4ee0790, type: 3}
m_Name:
m_EditorClassIdentifier:
enableDebugPrintOnTerminal: 1
enableForceCrashOnError: 0
dontDestroyOnLoad: 1
7 changes: 7 additions & 0 deletions Resources/CRIAtom.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 30 additions & 9 deletions Runtime/ADX2/Adx2SoundInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#if GAMEBASE_ADD_ADX2
using System;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using Zenject;

namespace Gamebase.Sound.Adx2
{
[CreateAssetMenu(fileName = "Adx2SoundInstaller", menuName = "Installers/Adx2SoundInstaller")]
[CreateAssetMenu(fileName = "Adx2SoundInstaller", menuName = "Installers/Gamebase/Adx2SoundInstaller")]
public sealed class Adx2SoundInstaller : ScriptableObjectInstaller<Adx2SoundInstaller>
{
[SerializeField] private SoundSettings generalSettings = null;
Expand All @@ -18,14 +19,34 @@ public sealed class Adx2SoundInstaller : ScriptableObjectInstaller<Adx2SoundInst

public override void InstallBindings()
{
Container.BindInterfacesTo<Adx2SoundManager>().AsSingle();
Container.BindInterfacesTo<Adx2SoundVolumeController>().AsSingle();
// Container.BindInterfacesTo<SoundConfigRepository>().AsSingle();
// Container.BindInterfacesTo<SoundConfigUseCase>().AsSingle();
Container.BindInstance(generalSettings).AsSingle();
Container.BindInstance(adx2Settings).AsSingle();
Container.BindInstance(categoryVolumeSettings).AsSingle();
Container.BindInstance(criInitializer).AsSingle();
var subContainer = Container.CreateSubContainer();
InstallSubContainer(subContainer);

Container.BindInterfacesTo<Adx2SoundManager>()
.FromSubContainerResolve()
.ByInstance(subContainer)
.AsSingle();

Container.BindInterfacesTo<Adx2SoundVolumeController>()
.FromSubContainerResolve()
.ByInstance(subContainer)
.AsSingle();
}

private void InstallSubContainer(DiContainer subContainer)
{
subContainer.Bind<Adx2SoundManager>().AsSingle();
subContainer.Bind<Adx2SoundVolumeController>().AsSingle();

subContainer.BindInstance(generalSettings).AsSingle();
subContainer.BindInstance(adx2Settings).AsSingle();
subContainer.BindInstance(categoryVolumeSettings).AsSingle();
subContainer.Bind<CriAtom>().FromResources("CRIAtom").AsSingle();
subContainer.BindInstance(criInitializer).AsSingle();

// Factories
subContainer.BindMemoryPool<Adx2SoundPlayer, Adx2SoundPlayer.Pool>()
.FromNewComponentOnNewPrefabResource(nameof(Adx2SoundPlayer));
}
}

Expand Down
33 changes: 12 additions & 21 deletions Runtime/ADX2/Adx2SoundLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Gamebase.Loader.Asset;
using Gamebase.Utilities;
using UniRx.Async;
using UnityEngine;
Expand All @@ -12,14 +13,17 @@ namespace Gamebase.Sound.Adx2
{
public sealed class Adx2SoundLoader
{
private readonly IAssetLoader assetLoader;

private readonly CacheDirectory cache;

private TextAsset acbAsset;

private TextAsset awbAsset;

public Adx2SoundLoader(CacheDirectory cache)
public Adx2SoundLoader(IAssetLoader assetLoader, CacheDirectory cache)
{
this.assetLoader = assetLoader;
this.cache = cache;
}

Expand Down Expand Up @@ -49,38 +53,25 @@ public async UniTask<CriAtomCueSheet> Load(string cueSheetName, object acbKey, o

private async UniTask<byte[]> LoadAcb(object key)
{
var operation = Addressables.LoadAssetAsync<TextAsset>(key);
await operation.Task;
if (!operation.IsValid())
{
Debug.unityLogger.LogError(nameof(Adx2SoundLoader), "Load acb Error.");
throw operation.OperationException;
}

byte[] acbBytes = operation.Result.bytes;
Addressables.Release(operation);

var handle = await assetLoader.Load<TextAsset>(key);
byte[] acbBytes = handle.Result.bytes;
assetLoader.Unload(handle);
return acbBytes;
}

private async UniTask<string> LoadAwb(object key)
{
IList<string> downloadFiles;
if (AddressableUtility.FindAssetBundlePath(key, out downloadFiles))
if (AddressableUtility.FindAssetBundlePath(key, out var downloadFiles))
{
var srcPath = downloadFiles.FirstOrDefault();
var srcFileName = Path.GetFileName(srcPath);

var dstPath = cache.FullPath(srcFileName);
if (!cache.Exists(srcFileName))
{
var operation = Addressables.LoadAssetAsync<TextAsset>(key);
await operation.Task;
if (operation.IsValid())
{
await cache.SaveAsync(srcFileName, operation.Result.bytes);
Addressables.Release(operation);
}
var handle = await assetLoader.Load<TextAsset>(key);
await cache.SaveAsync(srcFileName, handle.Result.bytes);
Addressables.Release(handle);
}

return dstPath;
Expand Down
Loading

0 comments on commit b80ca73

Please sign in to comment.