4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CinemachineでBlendの開始終了を検知する

Last updated at Posted at 2020-07-20

#概要
CinemachineでPriority切り替え時のBlendAnimationの開始終了を検知する方法を探ってて
完成したので備忘録として投稿。
もっと簡単な方法があれば教えてください!

#バージョン
Unity2019.3.7f1
Cinemachine v2.6.0

#Blend開始の検知
CinemachineExtensionOnTransitionFromCameraメソッドがTransition元のVirtualCameraも取得できるので
Extensionを拡張するアプローチを行った。

public class CinemachineTransitionNotify : CinemachineExtension {

    public override bool OnTransitionFromCamera(ICinemachineCamera fromCam, Vector3 worldUp, float deltaTime) {
        // ここでTransitionの開始を検知できる
        // fromCamがTransition元のVirtualCamera
    }

}

#Blend終了の検知
OnTransitionFromCameraの中で自身を管理するBrainを取得し、ActiveBlendを見ることで判定できる。

// 自身を管理しているBrainを取得
CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(VirtualCamera);
// 現在動いているActiveBlendを取得
var blend = brain.ActiveBlend;
// blend.BlendWeightが1.0になれば終了なので、AsyncやCoroutineで待機してあげる。
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?