Version: 2017.4

AudioSource

class in UnityEngine

/

継承:Behaviour

マニュアルに切り替える

説明

3D での AudioSource の表現

An AudioSource is attached to a GameObject for playing back sounds in a 3D environment. In order to play 3D sounds you also need to have a AudioListener. The audio listener is normally attached to the camera you want to use. Whether sounds are played in 3D or 2D is determined by AudioImporter settings.

You can play a single audio clip using Play, Pause and Stop. You can also adjust its volume while playing using the volume property, or seek using time. Multiple sounds can be played on one AudioSource using PlayOneShot. You can play a clip at a static position in 3D space using PlayClipAtPoint.

See Also: AudioListener, AudioClip, AudioSource component.

//This script allows you to toggle music to play and stop.
//Assign an AudioSource to a GameObject and attach an Audio Clip in the Audio Source. Attach this script to the GameObject.

using UnityEngine;

public class Example : MonoBehaviour { AudioSource m_MyAudioSource;

//Play the music bool m_Play; //Detect when you use the toggle, ensures music isn’t played multiple times bool m_ToggleChange;

void Start() { //Fetch the AudioSource from the GameObject m_MyAudioSource = GetComponent<AudioSource>(); //Ensure the toggle is set to true for the music to play at start-up m_Play = true; }

void Update() { //Check to see if you just set the toggle to positive if (m_Play == true &amp;&amp; m_ToggleChange == true) { //Play the audio you attach to the AudioSource component m_MyAudioSource.Play(); //Ensure audio doesn’t play more than once m_ToggleChange = false; } //Check if you just set the toggle to false if (m_Play == false &amp;&amp; m_ToggleChange == true) { //Stop the audio m_MyAudioSource.Stop(); //Ensure audio doesn’t play more than once m_ToggleChange = false; } }

void OnGUI() { //Switch this toggle to activate and deactivate the parent GameObject m_Play = GUI.Toggle(new Rect(10, 10, 100, 30), m_Play, "Play Music");

//Detect if there is a change with the toggle if (GUI.changed) { //Change to true to show that there was just a change in the toggle state m_ToggleChange = true; } } }

変数

bypassEffectsBypass エフェクト (フィルターコンポーネントやグローバルリスナーのフィルターから適用)
bypassListenerEffectsAudioListener にグローバルエフェクトを設定するときは AudioSource によって生成されたオーディオ信号には適用されません。ミキサーグループで AudioSource を再生している場合は適用されません。
bypassReverbZones設定されているとき Reverb Zone に関連付けられているグローバルリバーブに AudioSource からの信号をルーティングしません。
clip再生するデフォルトの AudioClip
dopplerLevelこの AudioSource のドップラースケールを設定します。
ignoreListenerPauseAudioListener.pause が True に設定されていても AudioSource は再生することができます。これはメニューエレメントの音や一時停止メニューでの BGM に便利です。
ignoreListenerVolumeこれにより AudioSource は AudioListener の音量を考慮しません。
isPlaying今、 ::Ref::clip を再生しているか(Read Only)
isVirtualAudioSource によって再生されるすべてのサウンド (OneShot 同様、Play() か playOnAwake で開始された主サウンド) がオーディオシステムによって選択されているならば true。
loopオーディオクリップをループしているか。
maxDistance( Logarithmic Rolloff ) MaxDistance は音が減衰を停止する距離です。
minDistanceMinDistance 内にある AudioSource はボリュームで大きくならなくなります。
muteUnMute と Mute 、 AudioSource 。 Mute は Volume = 0 に設定し、 UnMute は元のボリュームの値に戻します。
outputAudioMixerGroupAudioSource がその信号をルーティングする必要があるターゲットグループ
panStereoステレオ(の左か右) で再生音をパンします。これはモノラルかステレオサウンドにのみ適用されます。
pitchAudioSource の Pitch
playOnAwakeTrue に設定した場合、 AudioSource は自動的に Play On Awake を開始します。
priority AudioSource の優先順位を設定します。
reverbZoneMixReverb Zone に関連付けられているグローバルリバーブにミックスされる AudioSource からの信号の量
rolloffModeAudioSource が距離とともにどのように減衰するかを設定し取得します。
spatialBlendこの AudioSource は 3D 立体化の計算(減衰やドップラーなど) によってどのくらい影響を受けるか設定します。 0.0 は音を完全に 2D にし、1.0 は完全に 3D になります。
spatialize空間化を有効か無効にします。
spatializePostEffectsDetermines if the spatializer effect is inserted before or after the effect filters.
spread3D ステレオが広がる角度 (度単位)かスピーカー空間のマルチチャンネルを設定します。
time秒単位での再生位置
timeSamplesPCM サンプルの再生位置
velocityUpdateModeAudioSource を固定して変更するか動的に更新するか。
volumeAudioSource の音量 ( 0.0 から 1.0 )

Public 関数

DisableDualShock4Output使用可能な DualShock4 コントローラーすべてで、オーディオソースの再生を不可能にします。
GetAmbisonicDecoderFloatReads a user-defined parameter of a custom ambisonic decoder effect that is attached to an AudioSource.
GetCustomCurve指定された AudioSourceCurveType のために現在のカスタムの Curve を取得します。
GetOutputData現在再生されているソースの出力データのブロックを提供します。
GetSpatializerFloatAudioSource にアタッチされているカスタム Spatializer エフェクトのユーザー定義パラメーターを読み出します。
GetSpectrumData現在再生されている Audio source のスペクトラムデータのブロックを提供します。
Pause clip の再生を一時停止します。
Play一定のディレイを持たせて clip を再生します。
PlayDelayed秒単位で指定した遅延で ref::clip を再生します。ユーザーは引数を 44.1 kHz のサンプリングレートを基準にして遅延時間を指定する古い Play(delay) 関数ではなくこの関数を使用することをお勧めします。
PlayOnDualShock4指定した DualShock4 コントローラーでオーディオソースの再生を可能にします。
PlayOneShot AudioClip を再生し、volumeScale で AudioSource 音量をスケールします。
PlayScheduled絶対タイムライン上から AudioSettings.dspTime が読み取った特定の時間に clip を再生します。
SetAmbisonicDecoderFloatSets a user-defined parameter of a custom ambisonic decoder effect that is attached to an AudioSource.
SetCustomCurve指定された AudioSourceCurveType のカスタムの Curve を設定します。
SetScheduledEndTimeスケジュールされているサウンドの再生を終了する時間を変更します。タイミングによってすべてのスケジュール変更要求が満たされるわけではないことに注意してください。
SetScheduledStartTimeすでに再生する予定だったサウンドを開始する時間を変更します。
SetSpatializerFloatAudioSource にアタッチされているカスタム Spatializer エフェクトのユーザー定義パラメーターを設定します。
Stop clip の再生を停止します。
UnPauseこの AudioSource の再生の一時停止を解除します。

Static 関数

PlayClipAtPointワールド空間内の指定された位置で AudioClip を再生します。

継承メンバー

変数

enabled有効であれば更新され、無効であれば更新されません。
isActiveAndEnabledBehaviour が有効かどうか
gameObjectこのコンポーネントはゲームオブジェクトにアタッチされます。コンポーネントはいつもゲームオブジェクトにアタッチされています。
tagゲームオブジェクトのタグ
transformThe Transform attached to this GameObject.
hideFlagsオブジェクトは非表示、シーンに保存、ユーザーが編集可能、などを設定する。
nameオブジェクト名

Public 関数

BroadcastMessageゲームオブジェクトまたは子オブジェクトにあるすべての MonoBehaviour を継承したクラスにある methodName 名のメソッドを呼び出します。
CompareTagこのゲームオブジェクトは tag とタグ付けされているかどうか
GetComponentゲームオブジェクトに type がアタッチされている場合は type のタイプを使用してコンポーネントを返します。ない場合は null です
GetComponentInChildren GameObject や深さ優先探索を活用して、親子関係にある子オブジェクトから type のタイプのコンポーネントを取得します。
GetComponentInParent GameObject や深さ優先探索を活用して、親子関係にある親オブジェクトから type のタイプのコンポーネントを取得します。
GetComponents GameObject から type のタイプのコンポーネントを「すべて」取得します。
GetComponentsInChildren GameObject や深さ優先探索を活用して、親子関係にある子オブジェクトから type のタイプのコンポーネントを「すべて」取得します。
GetComponentsInParent GameObject や深さ優先探索を活用して、親子関係にある親オブジェクトから type のタイプのコンポーネントを「すべて」取得します。
SendMessageゲームオブジェクトにアタッチされているすべての MonoBehaviour にある methodName と名付けたメソッドを呼び出します
SendMessageUpwardsゲームオブジェクトと親(の親、さらに親 ... )にアタッチされているすべての MonoBehaviour にある methodName と名付けたメソッドを呼び出します
GetInstanceIDオブジェクトのインスタンス ID を返します
ToStringReturns the name of the GameObject.

Static 関数

Destroyゲームオブジェクトやコンポーネント、アセットを削除します
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoad新しいシーンを読み込んでもオブジェクトが自動で破壊されないように設定します
FindObjectOfTypeタイプ type から最初に見つけたアクティブのオブジェクトを返します
FindObjectsOfTypeタイプから見つけたすべてのアクティブのオブジェクト配列を返します
Instantiateoriginal のオブジェクトをクローンします

Operator

boolオブジェクトが存在するかどうか
operator !=二つのオブジェクトが異なるオブジェクトを参照しているか比較します
operator ==2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。