Esempio n. 1
0
        private SoundElement GetSoundElement(CueInfo info, SoundType type)
        {
            // シート取得.
            var soundSheet = GetSoundSheet(info);

            if (soundSheet == null)
            {
                return(null);
            }

            // 再生するキューの名前を指定.
            player.SetCue(soundSheet.Acb, info.Cue);

            // 再生パラメータ設定.
            SetSoundParam(type);

            // セットされた音声データの再生準備を開始.
            var playback = player.Prepare();

            // 再生失敗ならRemovedが返る.
            if (playback.GetStatus() == CriAtomExPlayback.Status.Removed)
            {
                return(null);
            }

            // デフォルトに戻す.
            SetSoundParam();

            var element = new SoundElement(this, type, soundSheet, info, playback);

            return(element);
        }
Esempio n. 2
0
        //----- method -----

        public SoundElement(SoundType type, SoundSheet soundSheet, CueInfo cueInfo, CriAtomExPlayback playback)
        {
            this.playback = playback;

            this.Type       = type;
            this.SoundSheet = soundSheet;
            this.CueInfo    = cueInfo;
        }
Esempio n. 3
0
        private SoundSheet GetSoundSheet(CueInfo cueInfo)
        {
            if (cueInfo == null)
            {
                return(null);
            }

            var assetPath  = cueInfo.CueSheetPath;
            var soundSheet = managedSoundSheets.GetValueOrDefault(assetPath);

            if (soundSheet == null)
            {
                // パス情報生成.
                var acbPath = SoundSheet.AcbPath(assetPath);
                var awbPath = SoundSheet.AwbPath(assetPath);

                // ACBファイルのロード.
                CriAtomCueSheet cueSheet = null;

                try
                {
                    cueSheet = CriAtom.AddCueSheet(assetPath, acbPath, awbPath);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                    return(null);
                }

                if (cueSheet.acb == null)
                {
                    return(null);
                }

                // ロードしたACBを保持した状態で再生成.
                soundSheet = new SoundSheet(assetPath, cueSheet.acb);

                managedSoundSheets.Add(soundSheet.AssetPath, soundSheet);

                var builder = new StringBuilder();

                builder.AppendFormat("Load : {0} : {1}", cueInfo.Cue, cueInfo.CueId).AppendLine();
                builder.AppendLine();
                builder.AppendFormat("Cue : {0}", cueInfo.Cue).AppendLine();
                builder.AppendFormat("CueId : {0}", cueInfo.CueId).AppendLine();
                builder.AppendFormat("FileName : {0}", Path.GetFileName(acbPath)).AppendLine();

                if (!string.IsNullOrEmpty(cueInfo.Summary))
                {
                    builder.AppendFormat("Summary: {0}", cueInfo.Summary).AppendLine();
                }

                UnityConsole.Event(ConsoleEventName, ConsoleEventColor, builder.ToString());
            }

            return(soundSheet);
        }
Esempio n. 4
0
        /// <summary>
        /// 対象のサウンドが再生中か.
        /// </summary>
        private SoundElement FindPlayingElement(Enum type, CueInfo info)
        {
            // シート取得.
            var soundSheet = GetSoundSheet(info);

            // 再生中 + 同カテゴリ + 同アセットのサウンドを検索.
            var element = soundElements.FirstOrDefault(x =>
            {
                if (!File.Exists(x.SoundSheet.AssetPath))
                {
                    return(false);
                }

                return(x.IsPlaying && x.Type.CompareTo(type) == 0 && x.SoundSheet.AssetPath == soundSheet.AssetPath);
            });

            return(element);
        }
Esempio n. 5
0
        private SoundSheet GetSoundSheet(CueInfo cueInfo)
        {
            if (cueInfo == null)
            {
                return(null);
            }

            var assetPath  = cueInfo.CueSheetPath;
            var soundSheet = managedSoundSheets.GetValueOrDefault(assetPath);

            if (soundSheet == null)
            {
                // パス情報生成.
                var acbPath = SoundSheet.AcbPath(assetPath);
                var awbPath = SoundSheet.AwbPath(assetPath);

                // ACBファイルのロード.
                CriAtomCueSheet cueSheet = null;

                try
                {
                    cueSheet = CriAtom.AddCueSheet(assetPath, acbPath, awbPath);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                    return(null);
                }

                if (cueSheet.acb == null)
                {
                    return(null);
                }

                // ロードしたACBを保持した状態で再生成.
                soundSheet = new SoundSheet(assetPath, cueSheet.acb);

                managedSoundSheets.Add(soundSheet.AssetPath, soundSheet);

                UnityConsole.Event(ConsoleEventName, ConsoleEventColor, "Load : {0}", acbPath);
            }

            return(soundSheet);
        }
Esempio n. 6
0
        /// <summary>
        ///  ExternalResources内のサウンドを再生.
        /// </summary>
        public SoundElement Play(SoundType type, CueInfo info)
        {
            if (info == null)
            {
                return(null);
            }

            var soundParam = GetSoundParam(type);

            SoundElement element = null;

            if (soundParam.cancelIfPlaying)
            {
                element = FindPlayingElement(type, info);

                if (element != null)
                {
                    return(element);
                }
            }

            element = GetSoundElement(info, type);

            if (element == null)
            {
                return(null);
            }

            // 管理対象に追加.
            soundElements.Add(element);

            // 音量設定.
            SetVolume(element, soundParam.volume);

            Observable.FromCoroutine(() => PlaySoundElement(element)).Subscribe().AddTo(Disposable);

            if (onPlay != null)
            {
                onPlay.OnNext(element);
            }

            return(element);
        }