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); }
private SoundCommand FindCommandFromReading(int id) { SoundCommand ret = null; foreach (var command in m_readingSounds) { if (id == command.id) { return(command); } } return(ret); }
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); }
private SoundController GetOrCreateSoundController(SoundCommand command) { var key = GetPoolObjectKey(command); return(GetOrCreateSoundController(key)); }
private string GetPoolObjectKey(SoundCommand command) { string key = string.Format("SoundCrtl");//string.Format("{0}", command?.data?.clip?.GetHashCode()); return(key); }