@@ -191,41 +191,49 @@ protected override void OnValidate()
191
191
[ HideInInspector , NoSaveDuringPlay ]
192
192
public bool m_HeadingIsSlave = false ;
193
193
194
- internal delegate float GetXAxisValue ( ) ;
195
- internal GetXAxisValue PreUpdateXAxisValueOverride ;
194
+ /// <summary>
195
+ /// Delegate that allows the the m_XAxis object to be replaced with another one.
196
+ /// </summary>
197
+ internal delegate float UpdateHeadingDelegate (
198
+ CinemachineOrbitalTransposer orbital , float deltaTime , Vector3 up ) ;
199
+
200
+ /// <summary>
201
+ /// Delegate that allows the the XAxis object to be replaced with another one.
202
+ /// To use it, just call orbital.UpdateHeading() with a reference to a
203
+ /// private AxisState object, and that AxisState object will be updated and
204
+ /// used to calculate the heading.
205
+ /// </summary>
206
+ internal UpdateHeadingDelegate HeadingUpdater
207
+ = ( CinemachineOrbitalTransposer orbital , float deltaTime , Vector3 up )
208
+ => { return orbital . UpdateHeading ( deltaTime , up , ref orbital . m_XAxis ) ; } ;
196
209
197
210
/// <summary>
198
- /// When in slave mode, this should be called once and only
199
- /// once every hrame to update the heading. When not in slave mode, this is called automatically.
211
+ /// Update the X axis and calculate the heading. This can be called by a delegate
212
+ /// with a custom axis.
213
+ /// <param name="deltaTime">Used for damping. If less than 0, no damping is done.</param>
214
+ /// <param name="up">World Up, set by the CinemachineBrain</param>
215
+ /// <param name="axis"></param>
216
+ /// <returns>Axis value</returns>
200
217
/// </summary>
201
- public void UpdateHeading ( float deltaTime , Vector3 up )
218
+ public float UpdateHeading ( float deltaTime , Vector3 up , ref AxisState axis )
202
219
{
203
220
// Only read joystick when game is playing
204
221
if ( deltaTime >= 0 || CinemachineCore . Instance . IsLive ( VirtualCamera ) )
205
222
{
206
223
bool xAxisInput = false ;
207
- if ( PreUpdateXAxisValueOverride != null )
208
- {
209
- float value = PreUpdateXAxisValueOverride ( ) ;
210
- if ( value != m_XAxis . Value )
211
- {
212
- xAxisInput = true ;
213
- m_XAxis . Value = value ;
214
- }
215
- }
216
- xAxisInput |= m_XAxis . Update ( deltaTime ) ;
224
+ xAxisInput |= axis . Update ( deltaTime ) ;
217
225
if ( xAxisInput )
218
226
{
219
227
mLastHeadingAxisInputTime = Time . time ;
220
228
mHeadingRecenteringVelocity = 0 ;
221
229
}
222
230
}
223
- float targetHeading = GetTargetHeading ( m_XAxis . Value , GetReferenceOrientation ( up ) , deltaTime ) ;
231
+ float targetHeading = GetTargetHeading ( axis . Value , GetReferenceOrientation ( up ) , deltaTime ) ;
224
232
if ( deltaTime < 0 )
225
233
{
226
234
mHeadingRecenteringVelocity = 0 ;
227
235
if ( m_RecenterToTargetHeading . m_enabled )
228
- m_XAxis . Value = targetHeading ;
236
+ axis . Value = targetHeading ;
229
237
}
230
238
else
231
239
{
@@ -237,14 +245,14 @@ public void UpdateHeading(float deltaTime, Vector3 up)
237
245
// Scale value determined heuristically, to account for accel/decel
238
246
float recenterTime = m_RecenterToTargetHeading . m_RecenteringTime / 3f ;
239
247
if ( recenterTime <= deltaTime )
240
- m_XAxis . Value = targetHeading ;
248
+ axis . Value = targetHeading ;
241
249
else
242
250
{
243
- float headingError = Mathf . DeltaAngle ( m_XAxis . Value , targetHeading ) ;
251
+ float headingError = Mathf . DeltaAngle ( axis . Value , targetHeading ) ;
244
252
float absHeadingError = Mathf . Abs ( headingError ) ;
245
253
if ( absHeadingError < UnityVectorExtensions . Epsilon )
246
254
{
247
- m_XAxis . Value = targetHeading ;
255
+ axis . Value = targetHeading ;
248
256
mHeadingRecenteringVelocity = 0 ;
249
257
}
250
258
else
@@ -256,12 +264,16 @@ public void UpdateHeading(float deltaTime, Vector3 up)
256
264
float accel = desiredVelocity - mHeadingRecenteringVelocity ;
257
265
if ( ( desiredVelocity < 0 && accel < 0 ) || ( desiredVelocity > 0 && accel > 0 ) )
258
266
desiredVelocity = mHeadingRecenteringVelocity + desiredVelocity * scale ;
259
- m_XAxis . Value += desiredVelocity ;
267
+ axis . Value += desiredVelocity ;
260
268
mHeadingRecenteringVelocity = desiredVelocity ;
261
269
}
262
270
}
263
271
}
264
272
}
273
+ float finalHeading = axis . Value ;
274
+ if ( m_BindingMode == BindingMode . SimpleFollowWithWorldUp )
275
+ axis . Value = 0 ;
276
+ return finalHeading ;
265
277
}
266
278
267
279
private void OnEnable ( )
@@ -296,17 +308,14 @@ public override void MutateCameraState(ref CameraState curState, float deltaTime
296
308
mLastTargetPosition = ( PreviousTarget == null ) ? Vector3 . zero : PreviousTarget . position ;
297
309
mHeadingTracker = null ;
298
310
}
299
- UpdateHeading ( deltaTime , curState . ReferenceUp ) ;
311
+ float heading = HeadingUpdater ( this , deltaTime , curState . ReferenceUp ) ;
300
312
301
313
if ( IsValid )
302
314
{
303
315
mLastTargetPosition = FollowTarget . position ;
304
316
305
317
// Calculate the heading
306
- float heading = m_XAxis . Value ;
307
- if ( m_BindingMode == BindingMode . SimpleFollowWithWorldUp )
308
- m_XAxis . Value = 0 ;
309
- else
318
+ if ( m_BindingMode != BindingMode . SimpleFollowWithWorldUp )
310
319
heading += m_Heading . m_HeadingBias ;
311
320
Quaternion headingRot = Quaternion . AngleAxis ( heading , curState . ReferenceUp ) ;
312
321
0 commit comments