예제 #1
0
    private int AudioSourceComparison2D(EffectAudioSourceItem a, EffectAudioSourceItem b)
    {
        // 是否在播放中
        if (!a.IsPlaying() && b.IsPlaying())
        {
            return(-1);
        }
        else if (a.IsPlaying() && !b.IsPlaying())
        {
            return(1);
        }
        else if (a.IsPlaying() && b.IsPlaying())
        {
            // 按照播放优先级, 小在前
            if (a.priority != b.priority)
            {
                return(a.priority > b.priority ? 1 : -1);
            }

            // 按照距离远近
            return(0);
        }

        return(0);
    }
예제 #2
0
    //3D 音效按优先级和距离排序
    private int AudioSourceComparison(EffectAudioSourceItem a, EffectAudioSourceItem b)
    {
        // 是否在播放中
        if (!a.IsPlaying() && b.IsPlaying())
        {
            return(-1);
        }
        else if (a.IsPlaying() && !b.IsPlaying())
        {
            return(1);
        }
        else if (a.IsPlaying() && b.IsPlaying())
        {
            // 按照播放优先级, 小在前
            if (a.priority != b.priority)
            {
                return(a.priority > b.priority ? 1 : -1);
            }

            // 按照距离远近
            return(DistanceComparison(a.attachedObj.transform.position, b.attachedObj.transform.position));
        }

        return(0);
    }
예제 #3
0
    private void UpdateAudioState(EffectAudioSourceItem item, PlayState ps, bool useSwitch)
    {
        if (item == null)
        {
            return;
        }

        if (ps == PlayState.Resume)
        {
            if (item.attachedObj != null && !item.IsPlaying())
            {
                if (useSwitch)
                {
                    item.PlayWithSwitch(item.audioName, item.switchGroup, item.switchState);
                }
                else
                {
                    item.Play(item.audioName);
                }
            }
        }
        else if (ps == PlayState.Stop || ps == PlayState.Pause)
        {
            if (item.attachedObj != null)
            {
                item.Stop();
            }
        }
    }
예제 #4
0
    private EffectAudioSourceItem _PlaySFX(string audioName, AudioType aType, Transform point, Vector3 pos, int sortId, EffectSoundType type)
    {
        if (string.IsNullOrEmpty(audioName))
        {
            return(null);
        }

        if (_IsEffectAudioEnabled)
        {
            CheckAudioListener();

            SafeInitSFX();

            EffectAudioSourceItem item_arranged = GetUsableItem(aType, sortId, pos, type);

            if (item_arranged != null)
            {
                item_arranged.audioName = audioName;
                if (item_arranged.id != -1 && item_arranged.attachedObj != null)
                {
                    if (type == EffectSoundType.Effect3D || type == EffectSoundType.AttachEffect3D || type == EffectSoundType.Effect2D || type == EffectSoundType.FootStep3D)
                    {
                        if (item_arranged.IsPlaying())
                        {
                            item_arranged.Stop();
                        }
                    }
                    else
                    {
                        item_arranged.Stop();
                    }

                    GetProperSettingOfItem(item_arranged, aType, audioName, sortId);

                    if (aType == AudioType.AttS3D)
                    {
                        item_arranged.attachedPos = point;
                        item_arranged.attachedObj.transform.position = point.position;
                    }
                    if (aType == AudioType.S3D)
                    {
                        item_arranged.attachedObj.transform.position = pos;
                    }

                    if (item_arranged.attachedObj != null)
                    {
                        item_arranged.Play(audioName);
                    }

                    return(item_arranged);
                }
            }
        }

        return(null);
    }
예제 #5
0
 private bool IsStaticAudioPlaying(string audioName)
 {
     for (int i = 0; i < _static3DAudioSourceList.Count; ++i)
     {
         EffectAudioSourceItem item = _static3DAudioSourceList[i];
         if (item.audioName == audioName && item.IsPlaying())
         {
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
    private EffectAudioSourceItem GetUsableItem(AudioType aType, int priority, Vector3 pos, EffectSoundType type)
    {
        List <EffectAudioSourceItem> soundList = null;
        bool bSkipCompare = false;

        switch (type)
        {
        case EffectSoundType.Effect3D:
            soundList = _effect3DAudioSourceList;
            break;

        case EffectSoundType.AttachEffect3D:
            soundList = _attachedEffect3DAudioSourceList;
            break;

        case EffectSoundType.Effect2D:
            soundList = _effect2DAudioSourceList;
            break;

        case EffectSoundType.Static3D:
            soundList = _static3DAudioSourceList;
            break;

        case EffectSoundType.FootStep3D:
            soundList = _footStep3DAudioSourceList;
            break;

        case EffectSoundType.NpcVoice3D:
            soundList    = _npcVoice3DAudioSourceList;
            bSkipCompare = true;
            break;

        case EffectSoundType.NpcShout3D:
            soundList    = _npcShout3DAndioSourceList;
            bSkipCompare = true;
            break;

        case EffectSoundType.Heartbeat2D:
            soundList    = _heartbeat2DAudioSourceList;
            bSkipCompare = true;
            break;

        default:
            break;
        }

        if (soundList != null && soundList.Count > 0)
        {
            EffectAudioSourceItem item = GetFirstItem(soundList, aType != AudioType.S2D);
            if (item != null && item.attachedObj != null)
            {
                if (bSkipCompare)
                {
                    return(item);
                }
                else if (item.IsPlaying())
                {
                    if (item.priority > priority)
                    {
                        return(null);
                    }
                    else if (item.priority == priority && aType != AudioType.S2D)
                    {
                        if (DistanceComparison(item.attachedObj.transform.position, pos) > 0)
                        {
                            return(null);
                        }
                    }
                }
            }
            return(item);
        }

        return(null);
    }