Exemplo n.º 1
0
        private int PlaySound(SoundCommand command)
        {
            if (command == null)
            {
                return(-1);
            }
            if (command.data == null)
            {
                return(-1);
            }
            if (command.data.clip == null)
            {
                return(-1);
            }
            if (!IsTagCanPlay(command?.args))
            {
                return(-1);
            }

            //入队并播放
            var id   = command.id;
            var data = command.data;
            var args = command.args;

            var ctrl = GetOrCreateSoundController(command);

            ctrl.name   = string.Format("{0}|{1}", data.clip.name, id);
            ctrl.Volume = args.volume * Volume;
            ctrl.Mute   = args.mute && Mute;
            ctrl.IsLoop = args.isLoop;
            ctrl.Time   = args.startTime;

            ctrl.Play(data.clip, args.delay);
            ctrl.TweenVolume(0f, ctrl.Volume, args.fadeIn);

            m_isAbort = false;
            m_playingSounds.Add(id, new KeyValuePair <SoundArgs, SoundController>(args, ctrl));
            if (!string.IsNullOrEmpty(args.tag))
            {
                SoundPlayerRecorder recorder;
                if (!m_recorderMap.TryGetValue(args.tag, out recorder))
                {
                    recorder = new SoundPlayerRecorder();
                    m_recorderMap[args.tag] = recorder;
                }

                recorder.curCount++;
                recorder.lastTick = Time.realtimeSinceStartup;
            }

            m_lastTick = Time.realtimeSinceStartup;

            GetOrCreateSoundCommonCache().Release(command);
            return(id);
        }
Exemplo n.º 2
0
        private SoundCommand FindCommandFromReading(int id)
        {
            SoundCommand ret = null;

            foreach (var command in m_readingSounds)
            {
                if (id == command.id)
                {
                    return(command);
                }
            }
            return(ret);
        }
Exemplo n.º 3
0
        private int PushSound(SoundData data, SoundArgs args)
        {
            if (data == null)
            {
                return(-1);
            }
            if (data.clip == null)
            {
                return(-1);
            }

            SoundCommand command = NewCommand(data, args);

            m_readingSounds.AddLast(command);

            return(command.id);
        }
Exemplo n.º 4
0
        private SoundController GetOrCreateSoundController(SoundCommand command)
        {
            var key = GetPoolObjectKey(command);

            return(GetOrCreateSoundController(key));
        }
Exemplo n.º 5
0
        private string GetPoolObjectKey(SoundCommand command)
        {
            string key = string.Format("SoundCrtl");//string.Format("{0}", command?.data?.clip?.GetHashCode());

            return(key);
        }