- BGM を再生するための UseCase を提供します
- CAFU Core v2.0.0
npm install github:umm/cafu_music
public static class Enumerates {
public enum MusicName {
Title,
Menu,
Game,
}
}
using System;
using CAFU.Music.Data.Entity;
namespace SampleProject.Data.Entity {
[Serializable]
public class MusicEntity : MusicEntity<MusicName> {}
}
- Unity の仕様により Generic クラスを Serialize できないため、プロジェクトごとに継承する必要があります😢
- Unity の仕様により Generic クラスを Serialize できないため、プロジェクトごとに継承する必要があります😢
using CAFU.Music.Data.DataStore;
using SampleProject.Data.Entity;
namespace SampleProject.Data.DataStore {
public class MusicDataStore : MusicDataStoreSingle<MusicEntity> {}
}
using CAFU.Music.Data.DataStore;
using SampleProject.Data.Entity;
namespace SampleProject.Data.DataStore {
public class MusicDataStore : MusicDataStoreMultiple<MusicEntity> {}
}
using CAFU.Core.Presentation.Presenter;
using CAFU.Music.Presentation.Presenter;
namespace SampleProject.Presentation.Presenter {
public class SampleScenePresenter : IPresenter, IMusicPresenter {
public class Factory : DefaultPresenterFactory<SampleScenePresenter> {
protected override void Initialize(SampleScenePresenter instance) {
base.Initialize(instance);
instance.MusicUseCase = new MusicUseCase<MusicName>.Factory().Create();
}
}
public IMusicUseCase MusicUseCase { get; private set; }
}
}
- 拡張メソッドから利用するため、
MusicUseCase
のプロパティ定義が必須です。
- これにより、実行順制御が可能になります。
this.GetPresenter().PlayMusic(MusicName.Title, true, true);
- 再生する BGM を表す enum
- ループするかどうか (default:
true
) - 既に同一の BGM が再生中の場合は、再生を止めずにそのままキープするかどうか (default:
true
)
this.GetPresenter().Stop();
this.GetPresenter().Pause();
this.GetPresenter().Resume();
this.GetPresenter().SetVolume(0.5f);
this.GetPresenter().SetPitch(0.5f);
Copyright (c) 2018 Tetsuya Mori
Released under the MIT license, see LICENSE.txt