blob: a993882620d6f69a2357fe71e7f7cbb7b7ec58c7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
using System.Collections.Generic;
using UnityEngine;
namespace Cinemachine
{
/// <summary>
/// Base class for a Cinemachine Virtual Camera extension module.
/// Hooks into the Cinemachine Pipeline.
/// </summary>
[DocumentationSorting(23, DocumentationSortingAttribute.Level.API)]
public abstract class CinemachineExtension : MonoBehaviour
{
/// <summary>Useful constant for very small floats</summary>
protected const float Epsilon = Utility.UnityVectorExtensions.Epsilon;
/// <summary>Get the associated CinemachineVirtualCameraBase</summary>
public CinemachineVirtualCameraBase VirtualCamera
{
get
{
if (m_vcamOwner == null)
m_vcamOwner = GetComponent<CinemachineVirtualCameraBase>();
return m_vcamOwner;
}
}
CinemachineVirtualCameraBase m_vcamOwner;
/// <summary>Connect to virtual camera pipeline.
/// Override implementations must call this base implementation</summary>
protected virtual void Awake()
{
ConnectToVcam();
}
/// <summary>Disconnect from virtual camera pipeline.
/// Override implementations must call this base implementation</summary>
protected virtual void OnDestroy()
{
if (VirtualCamera != null)
VirtualCamera.RemovePostPipelineStageHook(PostPipelineStageCallback);
}
void ConnectToVcam()
{
if (VirtualCamera == null)
Debug.LogError("CinemachineExtension requires a Cinemachine Virtual Camera component");
else
VirtualCamera.AddPostPipelineStageHook(PostPipelineStageCallback);
mExtraState = null;
}
/// <summary>
/// This callback will be called after the virtual camera has implemented
/// each stage in the pipeline. This method may modify the referenced state.
/// If deltaTime less than 0, reset all state info and perform no damping.
/// </summary>
protected abstract void PostPipelineStageCallback(
CinemachineVirtualCameraBase vcam,
CinemachineCore.Stage stage, ref CameraState state, float deltaTime);
/// <summary>Because extensions can be placed on manager cams and will in that
/// case be called for all the vcam children, vcam-specific state information
/// should be stored here. Just define a class to hold your state info
/// and use it exclusively when calling this.</summary>
protected T GetExtraState<T>(ICinemachineCamera vcam) where T : class, new()
{
if (mExtraState == null)
mExtraState = new Dictionary<ICinemachineCamera, System.Object>();
System.Object extra = null;
if (!mExtraState.TryGetValue(vcam, out extra))
extra = mExtraState[vcam] = new T();
return extra as T;
}
/// <summary>Ineffeicient method to get all extra state infor for all vcams.
/// Intended for Editor use only, not runtime!
/// </summary>
protected List<T> GetAllExtraStates<T>() where T : class, new()
{
var list = new List<T>();
if (mExtraState != null)
foreach (var v in mExtraState)
list.Add(v.Value as T);
return list;
}
private Dictionary<ICinemachineCamera, System.Object> mExtraState;
}
}
|