OSDN Git Service

Added more assets
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.cinemachine@2.3.4 / Runtime / Components / CinemachineBasicMultiChannelPerlin.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3
4 namespace Cinemachine
5 {
6     /// <summary>
7     /// As a part of the Cinemachine Pipeline implementing the Noise stage, this
8     /// component adds Perlin Noise to the Camera state, in the Correction
9     /// channel of the CameraState.
10     /// 
11     /// The noise is created by using a predefined noise profile asset.  This defines the 
12     /// shape of the noise over time.  You can scale this in amplitude or in time, to produce
13     /// a large family of different noises using the same profile.
14     /// </summary>
15     /// <seealso cref="NoiseSettings"/>
16     [DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
17     [AddComponentMenu("")] // Don't display in add component menu
18     [SaveDuringPlay]
19     public class CinemachineBasicMultiChannelPerlin : CinemachineComponentBase
20     {
21         /// <summary>
22         /// Serialized property for referencing a NoiseSettings asset
23         /// </summary>
24         [Tooltip("The asset containing the Noise Profile.  Define the frequencies and amplitudes there to make a characteristic noise profile.  Make your own or just use one of the many presets.")]
25         [FormerlySerializedAs("m_Definition")]
26         [NoiseSettingsProperty]
27         public NoiseSettings m_NoiseProfile;
28
29         /// <summary>
30         /// Gain to apply to the amplitudes defined in the settings asset.
31         /// </summary>
32         [Tooltip("Gain to apply to the amplitudes defined in the NoiseSettings asset.  1 is normal.  Setting this to 0 completely mutes the noise.")]
33         public float m_AmplitudeGain = 1f;
34
35         /// <summary>
36         /// Scale factor to apply to the frequencies defined in the settings asset.
37         /// </summary>
38         [Tooltip("Scale factor to apply to the frequencies defined in the NoiseSettings asset.  1 is normal.  Larger magnitudes will make the noise shake more rapidly.")]
39         public float m_FrequencyGain = 1f;
40
41         /// <summary>True if the component is valid, i.e. it has a noise definition and is enabled.</summary>
42         public override bool IsValid { get { return enabled && m_NoiseProfile != null; } }
43
44         /// <summary>Get the Cinemachine Pipeline stage that this component implements.
45         /// Always returns the Noise stage</summary>
46         public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Noise; } }
47
48         /// <summary>Applies noise to the Correction channel of the CameraState if the
49         /// delta time is greater than 0.  Otherwise, does nothing.</summary>
50         /// <param name="curState">The current camera state</param>
51         /// <param name="deltaTime">How much to advance the perlin noise generator.
52         /// Noise is only applied if this value is greater than or equal to 0</param>
53         public override void MutateCameraState(ref CameraState curState, float deltaTime)
54         {
55             if (!IsValid || deltaTime < 0)
56                 return;
57
58             if (!mInitialized)
59                 Initialize();
60
61             mNoiseTime += deltaTime * m_FrequencyGain;
62             curState.PositionCorrection += curState.CorrectedOrientation * NoiseSettings.GetCombinedFilterResults(
63                     m_NoiseProfile.PositionNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain;
64             Quaternion rotNoise = Quaternion.Euler(NoiseSettings.GetCombinedFilterResults(
65                     m_NoiseProfile.OrientationNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain);
66             curState.OrientationCorrection = curState.OrientationCorrection * rotNoise;
67         }
68
69         private bool mInitialized = false;
70         private float mNoiseTime = 0;
71
72         [SerializeField][HideInInspector]
73         private Vector3 mNoiseOffsets = Vector3.zero;
74
75         /// <summary>Generate a new random seed</summary>
76         public void ReSeed()
77         {
78             mNoiseOffsets = new Vector3(
79                     Random.Range(-1000f, 1000f),
80                     Random.Range(-1000f, 1000f),
81                     Random.Range(-1000f, 1000f));
82         }
83
84         void Initialize()
85         {
86             mInitialized = true;
87             mNoiseTime = 0;
88             if (mNoiseOffsets == Vector3.zero)
89                 ReSeed();
90         }
91     }
92 }