Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

umm/cafu_music

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CAFU Music

What

  • BGM を再生するための UseCase を提供します

Requirement

  • CAFU Core v2.0.0

Install

npm install github:umm/cafu_music

Usage

スクリプト準備編

1. BGM の AudioClip を表現する enum を定義

public static class Enumerates {
    public enum MusicName {
        Title,
        Menu,
        Game,
    }
}

2. CAFU.Music.Data.Entity.MusicEntity<TEnum> を継承した Entity クラスを作成

using System;
using CAFU.Music.Data.Entity;
namespace SampleProject.Data.Entity {
    [Serializable]
    public class MusicEntity : MusicEntity<MusicName> {}
}
  • Unity の仕様により Generic クラスを Serialize できないため、プロジェクトごとに継承する必要があります😢

3. CAFU.Music.Data.DataStore.MusicDataStore***<TMusicEntity> を継承した DataStore クラスを作成

  • Unity の仕様により Generic クラスを Serialize できないため、プロジェクトごとに継承する必要があります😢
シーン内で単一の BGM を再生する場合
using CAFU.Music.Data.DataStore;
using SampleProject.Data.Entity;
namespace SampleProject.Data.DataStore {
    public class MusicDataStore : MusicDataStoreSingle<MusicEntity> {}
}
シーン内で複数の BGM を切り替えて再生する場合
using CAFU.Music.Data.DataStore;
using SampleProject.Data.Entity;
namespace SampleProject.Data.DataStore {
    public class MusicDataStore : MusicDataStoreMultiple<MusicEntity> {}
}

シーン準備編

1. CAFU.Music.Presentation.Presenter.IMusicPresenter を Presenter クラスに実装

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 のプロパティ定義が必須です。

2. Scene の任意の GameObject に MusicDataStore をアタッチ

  • Hierarchy ルートの DataStore とかがヨサソウです。
  • image
  • image

3. アタッチされている ControllerMusic Data Store フィールドに 2. の GameObject を D&D

  • これにより、実行順制御が可能になります。

4. Scene で用いる BGM を MusicDataStore のフィールドに設定

  • image

利用編

再生

this.GetPresenter().PlayMusic(MusicName.Title, true, true);
引数
  1. 再生する BGM を表す enum
  2. ループするかどうか (default: true)
  3. 既に同一の BGM が再生中の場合は、再生を止めずにそのままキープするかどうか (default: true)

停止

this.GetPresenter().Stop();

中断

this.GetPresenter().Pause();

再開

this.GetPresenter().Resume();

ボリューム操作

this.GetPresenter().SetVolume(0.5f);

ピッチ操作

this.GetPresenter().SetPitch(0.5f);

License

Copyright (c) 2018 Tetsuya Mori

Released under the MIT license, see LICENSE.txt