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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityStandardAssets.ImageEffects;
public class CameraEffects : MonoBehaviour
{
private static CameraEffects m_instance;
public bool m_forceDof;
public LayerMask m_dofRayMask;
public bool m_dofAutoFocus;
public float m_dofMinDistance = 50f;
public float m_dofMinDistanceShip = 50f;
public float m_dofMaxDistance = 3000f;
private PostProcessingBehaviour m_postProcessing;
private DepthOfField m_dof;
public static CameraEffects instance => m_instance;
private void Awake()
{
m_instance = this;
m_postProcessing = GetComponent<PostProcessingBehaviour>();
m_dof = GetComponent<DepthOfField>();
ApplySettings();
}
private void OnDestroy()
{
if (m_instance == this)
{
m_instance = null;
}
}
public void ApplySettings()
{
SetDof(PlayerPrefs.GetInt("DOF", 1) == 1);
SetBloom(PlayerPrefs.GetInt("Bloom", 1) == 1);
SetSSAO(PlayerPrefs.GetInt("SSAO", 1) == 1);
SetSunShafts(PlayerPrefs.GetInt("SunShafts", 1) == 1);
SetAntiAliasing(PlayerPrefs.GetInt("AntiAliasing", 1) == 1);
SetCA(PlayerPrefs.GetInt("ChromaticAberration", 1) == 1);
SetMotionBlur(PlayerPrefs.GetInt("MotionBlur", 1) == 1);
}
public void SetSunShafts(bool enabled)
{
SunShafts component = GetComponent<SunShafts>();
if (component != null)
{
component.enabled = enabled;
}
}
private void SetBloom(bool enabled)
{
m_postProcessing.profile.bloom.enabled = enabled;
}
private void SetSSAO(bool enabled)
{
m_postProcessing.profile.ambientOcclusion.enabled = enabled;
}
private void SetMotionBlur(bool enabled)
{
m_postProcessing.profile.motionBlur.enabled = enabled;
}
private void SetAntiAliasing(bool enabled)
{
m_postProcessing.profile.antialiasing.enabled = enabled;
}
private void SetCA(bool enabled)
{
m_postProcessing.profile.chromaticAberration.enabled = enabled;
}
private void SetDof(bool enabled)
{
m_dof.enabled = enabled || m_forceDof;
}
private void LateUpdate()
{
UpdateDOF();
}
private bool ControllingShip()
{
if (Player.m_localPlayer == null || Player.m_localPlayer.GetControlledShip() != null)
{
return true;
}
return false;
}
private void UpdateDOF()
{
if (m_dof.enabled && m_dofAutoFocus)
{
float num = m_dofMaxDistance;
if (Physics.Raycast(base.transform.position, base.transform.forward, out var hitInfo, m_dofMaxDistance, m_dofRayMask))
{
num = hitInfo.distance;
}
if (ControllingShip() && num < m_dofMinDistanceShip)
{
num = m_dofMinDistanceShip;
}
if (num < m_dofMinDistance)
{
num = m_dofMinDistance;
}
m_dof.focalLength = Mathf.Lerp(m_dof.focalLength, num, 0.2f);
}
}
}
|