8 [
Attribute(
"1", UIWidgets.Auto,
desc:
"Initial zoom that can be static or scaled up",
params:
"0.1 100 0.1")]
9 protected float m_fBaseZoom;
11 [
Attribute(
"0", UIWidgets.Auto,
desc:
"Max zoom, smaller zoomMax than baseZoom will result in static zoom",
params:
"0.1 100 0.1")]
12 protected float m_fZoomMax;
14 [
Attribute(
"0.5", UIWidgets.Slider,
desc:
"Zoom step size, will automatically set step count",
params:
"0.1 5 0.1")]
15 protected float m_fStepZoomSize;
18 protected float m_fInterpolationSpeed;
20 protected ref array<float> m_aFOVs =
new array<float>;
21 protected int m_iStepsCount = 1;
24 protected float m_fCurrentFOV;
27 protected int m_iCurrentIndex = 0;
29 protected ref ScriptInvoker<float, float> event_OnZoomChanged;
33 override int GetCount() {
return m_aFOVs.Count(); }
37 override int GetCurrentIndex() {
return m_iCurrentIndex; }
44 override void SetIndex(
int index)
46 m_iCurrentIndex =
index;
47 InvokeOnZoomChanged(GetCurrentZoom(), m_aFOVs[m_iCurrentIndex]);
51 protected override void OnInit(IEntity owner, BaseSightsComponent sights)
57 m_fCurrentFOV = m_aFOVs[0];
72 protected override void OnUpdate(IEntity owner, BaseSightsComponent sights,
float timeSlice)
74 if (!m_aFOVs.IsIndexValid(m_iCurrentIndex))
77 float target = m_aFOVs[m_iCurrentIndex];
79 float t = timeSlice * m_fInterpolationSpeed;
85 m_fCurrentFOV = Math.Lerp(m_fCurrentFOV, target, t);
93 protected override float GetCurrentFOV()
100 array<float> ZoomsToArray()
102 array<float> zooms =
new array<float>;
105 if (m_fBaseZoom == m_fZoomMax || m_fBaseZoom > m_fZoomMax)
107 zooms.Insert(m_fBaseZoom);
112 int count = (m_fZoomMax - m_fBaseZoom) / m_fStepZoomSize;
115 for (
int i = 0; i <= count; i++)
117 float zoom = GetZoom(i, count);
121 m_iStepsCount = zooms.Count();
127 void InsertFov(
float fov)
135 return m_iStepsCount;
139 void SetCurrentFov(
float fov)
145 protected float GetZoom(
int i,
int count)
150 return m_fBaseZoom + i * m_fStepZoomSize;
154 float GetCurrentZoom()
159 int count = m_aFOVs.Count();
164 return GetZoom(m_iCurrentIndex, count);
170 int count = m_aFOVs.Count();
172 return GetZoom(0, count);
184 override float GetBaseFOV()
186 if (!m_aFOVs.IsEmpty())
189 return m_fCurrentFOV;
194 override bool IsAdjusting()
196 if (!m_aFOVs.IsIndexValid(m_iCurrentIndex))
199 return !
float.AlmostEqual(m_fCurrentFOV, m_aFOVs[m_iCurrentIndex]);
202 void ForceUpdate(IEntity owner, BaseSightsComponent sights,
float timeSlice)
204 OnUpdate(owner, sights, timeSlice);
214 if (!event_OnZoomChanged)
215 event_OnZoomChanged =
new ScriptInvoker();
217 return event_OnZoomChanged;
223 if (event_OnZoomChanged)
224 event_OnZoomChanged.Invoke(zoom, fov);