VRChat 非公式日本語ドキュメント

Virtual Tweens

Virtual tweensは、値(floatやcolorなど)を時間経過とともに滑らかにアニメーションさせ、その結果をUdonBehaviour上の変数に書き込みます。毎フレームコールバックが実行されるため、更新された値を自由な方法で適用できます。組み込みのTween型(位置、回転、スケールなど)で対応できないものにはVirtual tweensを使用してください。例えば、スコアカウンターのアニメーションや、カメラの視野角、Animatorのパラメーター操作などに適しています。

Method Example
TweenFloat VRCTween.TweenFloat(0f, 100f, 2f, this, nameof(myValue), nameof(OnUpdate), VRCTweenEase.Linear)
TweenInt VRCTween.TweenInt(0, 100, 5f, this, nameof(myValue), nameof(OnUpdate), VRCTweenEase.Linear)
TweenColor VRCTween.TweenColor(Color.red, Color.blue, 2f, this, nameof(myValue), nameof(OnUpdate), VRCTweenEase.Linear)
TweenVector3 VRCTween.TweenVector3(Vector3.zero, Vector3.one, 2f, this, nameof(myValue), nameof(OnUpdate), VRCTweenEase.Linear)
DelayedCall VRCTween.DelayedCall(this, nameof(OnTimer), 5f)
DelayedSetActive VRCTween.DelayedSetActive(myObject, false, 2f)

すべてのメソッドは、tweenを制御するために使用できる VRCTweenHandle を返します。

TweenFloat

float 値をアニメーションさせます:

[System.NonSerialized] public float fovValue;

VRCTweenHandle tweenHandle = VRCTween.TweenFloat(60f, 90f, 2f, this, nameof(fovValue), nameof(OnFovUpdate), VRCTweenEase.OutQuad);

public void OnFovUpdate()
{
    myCamera.fieldOfView = fovValue;  // smoothly widens the camera's field of view
}

TweenInt

整数値をアニメーションさせます。カウンターやスコアなどに最適です。

[System.NonSerialized] public int scoreValue;

VRCTweenHandle tweenHandle = VRCTween.TweenInt(0, 100, 5f, this, nameof(scoreValue), nameof(OnCountUpdate), VRCTweenEase.Linear);

public void OnCountUpdate()
{
    scoreText.text = scoreValue.ToString();  // updates scoreValue smoothly as it ticks up
}

TweenColor

Color 値をアニメーションさせます。

[System.NonSerialized] public Color lightColor;

VRCTweenHandle tweenHandle = VRCTween.TweenColor(Color.red, Color.blue, 2f, this, nameof(lightColor), nameof(OnColorUpdate), VRCTweenEase.Linear);

public void OnColorUpdate()
{
    myLight.color = lightColor;  // Value is stored in lightColor.
}

TweenVector3

Vector3 値をアニメーション化します。これは、カスタム位置、方向、または3つのコンポーネントを持つ任意の値を1つの単位としてトゥイーンする場合に便利です(軸ごとではなく、ベクトル全体にイージング曲線が適用されます)。

[System.NonSerialized] public Vector3 targetPosition;

VRCTweenHandle tweenHandle = VRCTween.TweenVector3(Vector3.zero, new Vector3(5, 10, 0), 2f, this, nameof(targetPosition), nameof(OnPositionUpdate), VRCTweenEase.OutQuad);

public void OnPositionUpdate()
{
    // Use the interpolated value however you like.
    myParticleSystem.transform.position = targetPosition;
}
tip

仮想トゥイーンを機能させるには、変数を public として宣言する必要があります。Unityが一時的なトゥイーン値をシーンに保存しないようにするには、[System.NonSerialized] を使用してください。適切な型(float、int、Color、Vector3)の変数を使用し、異なる変数名を使うことで、複数のトゥイーンを同時に実行できます。

DelayedCall

キャンセル可能な遅延イベントを作成します。これは SendCustomEventDelayedSeconds の代替手段です:

VRCTweenHandle timerHandle = VRCTween.DelayedCall(this, nameof(OnTimerFinished), 5.0f);

// Cancel the timer anytime.
timerHandle.Kill();

public void OnTimerFinished()
{
    Debug.Log("5 seconds elapsed!");
}

DelayedSetActive

指定した遅延時間の経過後に GameObject を有効または無効にします。これは、DelayedCall を使用し、SetActive を呼び出すだけのコールバックを組み合わせる一般的な手法を簡略化したものです。遅延時間が経過する前にターゲットが破棄された場合、そのアクションは何も行われずにスキップされます。

// Disable an object after 3 seconds.
VRCTweenHandle handle = VRCTween.DelayedSetActive(myObject, false, 3f);

// Cancel it if needed.
handle.Kill();

最終更新: