예제 #1
0
    /// <summary>指定座標でサウンドを再生する</summary>
    /// <param name="key">サウンドのキー</param>
    /// <param name="position">再生する座標</param>
    /// <param name="loop">ループするか</param>
    /// <param name="spatialBlend">3Dブレンド(0f~1f)</param>
    /// <returns>チャンネルID</returns>
    public static int PlayAtPoint(string key, Vector3 position, bool loop = false, float spatialBlend = 1f)
    {
        if (!ChannelAllocator.initialized)
        {
            ChannelAllocator.Initialize();
        }

        if (!_updater)
        {
            _updater = new GameObject("Updater@TFSound");
            GameObject.DontDestroyOnLoad(_updater);
            _updater.AddComponent <Updater>();
        }

        var channel = ChannelAllocator.Allocate();

        if (channel != null)
        {
            channel.audioSrc.clip = _audioDict[key];
            channel.audioSrc.Play();
            channel.audioSrc.loop                    = loop;
            channel.audioSrc.spatialBlend            = spatialBlend;
            channel.channelObject.transform.position = position;
            channel.target = null;
            return(channel.id);
        }

        return(-1);
    }
예제 #2
0
    /// <summary>サウンドを再生する</summary>
    /// <param name="prop">オーディオプロパティ</param>
    /// <param name="trackingTarget">追跡ターゲット(オプション)</param>
    /// <returns>チャンネルID</returns>
    public static int Play(AudioProperty prop, Transform trackingTarget = null)
    {
        if (!ChannelAllocator.initialized)
        {
            ChannelAllocator.Initialize();
        }

        if (!_updater)
        {
            _updater = new GameObject("Updater@TFSound");
            GameObject.DontDestroyOnLoad(_updater);
            _updater.AddComponent <Updater>();
        }

        var channel = ChannelAllocator.Allocate();

        if (channel != null)
        {
            channel.audioSrc.clip = prop._clip;
            channel.audioSrc.Play();
            channel.audioSrc.loop         = prop._loop;
            channel.audioSrc.spatialBlend = prop._spatialBlend;
            channel.audioSrc.volume       = prop._volume;
            channel.target = trackingTarget;
            return(channel.id);
        }

        return(-1);
    }