@@ -43,6 +43,100 @@ public Transform LookAtTarget
43
43
}
44
44
}
45
45
46
+ private Transform mCachedFollowTarget ;
47
+ private CinemachineVirtualCameraBase mCachedFollowTargetVcam ;
48
+
49
+ /// <summary>Get the position of the Follow target. Special handling: If the Follow target is
50
+ /// a VirtualCamera, returns the vcam State's position, not the transform's position</summary>
51
+ public Vector3 FollowTargetPosition
52
+ {
53
+ get
54
+ {
55
+ Transform target = FollowTarget ;
56
+ if ( target != mCachedFollowTarget )
57
+ {
58
+ mCachedFollowTargetVcam = null ;
59
+ mCachedFollowTarget = target ;
60
+ if ( target != null )
61
+ mCachedFollowTargetVcam = target . GetComponent < CinemachineVirtualCameraBase > ( ) ;
62
+ }
63
+ if ( mCachedFollowTargetVcam != null )
64
+ return mCachedFollowTargetVcam . State . FinalPosition ;
65
+ if ( target != null )
66
+ return target . position ;
67
+ return Vector3 . zero ;
68
+ }
69
+ }
70
+
71
+ /// <summary>Get the rotation of the Follow target. Special handling: If the Follow target is
72
+ /// a VirtualCamera, returns the vcam State's rotation, not the transform's rotation</summary>
73
+ public Quaternion FollowTargetRotation
74
+ {
75
+ get
76
+ {
77
+ Transform target = FollowTarget ;
78
+ if ( target != mCachedFollowTarget )
79
+ {
80
+ mCachedFollowTargetVcam = null ;
81
+ mCachedFollowTarget = target ;
82
+ if ( target != null )
83
+ mCachedFollowTargetVcam = target . GetComponent < CinemachineVirtualCameraBase > ( ) ;
84
+ }
85
+ if ( mCachedFollowTargetVcam != null )
86
+ return mCachedFollowTargetVcam . State . FinalOrientation ;
87
+ if ( target != null )
88
+ return target . rotation ;
89
+ return Quaternion . identity ;
90
+ }
91
+ }
92
+
93
+ private Transform mCachedLookAtTarget ;
94
+ private CinemachineVirtualCameraBase mCachedLookAtTargetVcam ;
95
+
96
+ /// <summary>Get the position of the LookAt target. Special handling: If the LookAt target is
97
+ /// a VirtualCamera, returns the vcam State's position, not the transform's position</summary>
98
+ public Vector3 LookAtTargetPosition
99
+ {
100
+ get
101
+ {
102
+ Transform target = LookAtTarget ;
103
+ if ( target != mCachedLookAtTarget )
104
+ {
105
+ mCachedLookAtTargetVcam = null ;
106
+ mCachedLookAtTarget = target ;
107
+ if ( target != null )
108
+ mCachedLookAtTargetVcam = target . GetComponent < CinemachineVirtualCameraBase > ( ) ;
109
+ }
110
+ if ( mCachedLookAtTargetVcam != null )
111
+ return mCachedLookAtTargetVcam . State . FinalPosition ;
112
+ if ( target != null )
113
+ return target . position ;
114
+ return Vector3 . zero ;
115
+ }
116
+ }
117
+
118
+ /// <summary>Get the rotation of the LookAt target. Special handling: If the LookAt target is
119
+ /// a VirtualCamera, returns the vcam State's rotation, not the transform's rotation</summary>
120
+ public Quaternion LookAtTargetRotation
121
+ {
122
+ get
123
+ {
124
+ Transform target = LookAtTarget ;
125
+ if ( target != mCachedLookAtTarget )
126
+ {
127
+ mCachedLookAtTargetVcam = null ;
128
+ mCachedLookAtTarget = target ;
129
+ if ( target != null )
130
+ mCachedLookAtTargetVcam = target . GetComponent < CinemachineVirtualCameraBase > ( ) ;
131
+ }
132
+ if ( mCachedLookAtTargetVcam != null )
133
+ return mCachedLookAtTargetVcam . State . FinalOrientation ;
134
+ if ( target != null )
135
+ return target . rotation ;
136
+ return Quaternion . identity ;
137
+ }
138
+ }
139
+
46
140
/// <summary>Returns the owner vcam's CameraState.</summary>
47
141
public CameraState VcamState
48
142
{
0 commit comments