0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【23日目】25日間でCocos Creatorでゲームを作る

0
Posted at

SEを再生する

AudioManager.tsにSEを設定する

  1. assets/soundsに開く用、閉じる用のSEを格納する
  2. AudioManager.tsに追記する
    AudioManager.ts
      @property(AudioSource)
      bgmSource: AudioSource = null;
    
      // 追記 -ここから-
      @property(AudioSource)
      seSource: AudioSource = null;
    
      @property(AudioClip)
      openSE: AudioClip = null;
    
      @property(AudioClip)
      closeSE: AudioClip = null;
    
      private bgmVolume: number = 1.0;
      private seVolume: number = 1.0;
      // 追記 -ここまで- 
    
    AudioManager.ts
      private playSE(clip: AudioClip) {
        if (this.seSource && clip) {
          this.seSource.playOneShot(clip, this.seVolume);
        }
      }
      public playOpenSE() {
        this.playSE(this.openSE);
      }
      public playOloseSE() {
        this.playSE(this.closeSE);
      }
    
  3. ヒエラルキーパネルでAudioManagerを選択
  4. インスペクターのOpen SEとClose SEにそれぞれassets/soundsからドラッグ&ドロップする
  5. Add CompornentからAudioSourceを追加する
  6. Play On Awakeのチェックを外す
  7. 追加したAudioSourceをSe Sourceにドラッグ&ドロップする
  8. SceneRootをアセットパネルのassets/prefabsにドラッグ&ドロップし上書きする

AuthPopupにSEを設定する

  1. PopupAnimation.tsを修正する
    PopupAnimation.ts
    import { _decorator, Component, Node, Vec3, tween, UIOpacity, find } from 'cc'; // findを追加
        
    import { AudioManager } from './AudioManager'; // 追記
    
    // ...
    
    public showMe() {
        // ...
        const audio = find("AudioManager")?.getComponent(AudioManager);
        audio?.playOpenSE();
    }
    
    public hideMe() {
        // ...
        const audio = find("AudioManager")?.getComponent(AudioManager);
        audio?.playCloseSE();
    }
    

まとめ

これでポップアップを開いた時にSEが再生されればOK。
※現状の作りだとAudioManagerがシーン遷移で破棄されるので、addPersistRootNodeを用いる調整が必要

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?