8 private ResourceName m_Layout;
11 private string m_sSoundEvent;
13 private bool m_bIsInit;
14 private bool m_bIsFocus;
15 private bool m_bIsFocusRequsted;
16 private bool m_bIsFocusPosLocal;
17 private vector m_vFocusPos;
18 private vector m_vFocusPosWorld;
19 private float m_fFocusDistance;
20 private IEntity m_FocusEntity;
22 private Widget m_Widget;
23 protected ref ScriptInvoker m_OnFocusChange =
new ScriptInvoker();
24 protected ref ScriptInvoker m_OnFocusDistanceChange =
new ScriptInvoker();
30 bool GetFocusPos(out vector outPos)
35 outPos = m_vFocusPosWorld;
41 float GetFocusDistance()
43 return m_fFocusDistance;
48 void SetFocusToCursor()
56 m_bIsFocusRequsted =
true;
68 void SetFocus(vector pos, IEntity entity =
null)
71 m_FocusEntity = entity;
72 m_bIsFocusRequsted =
true;
79 if (m_bIsInit && (!m_bIsFocus || !
IsEnabled()))
83 m_OnFocusChange.Invoke(
false, m_vFocusPos, m_FocusEntity);
85 m_fFocusDistance = -1;
88 m_OnFocusDistanceChange.Invoke();
90 m_Effect.SetParam(
"FocalLength", 0);
91 m_Effect.SetParam(
"FocalLengthNear", 0);
94 m_bIsFocusRequsted =
false;
95 m_bIsFocusPosLocal =
false;
96 m_vFocusPos = vector.Zero;
97 m_vFocusPosWorld = vector.Zero;
100 m_Widget.SetVisible(
false);
106 ScriptInvoker GetOnFocusChange()
108 return m_OnFocusChange;
114 ScriptInvoker GetOnFocusDistanceChange()
116 return m_OnFocusDistanceChange;
120 override void EOnCameraReset()
128 if (!param.isManualInputEnabled)
131 m_Widget.SetVisible(
false);
136 if (m_bIsFocusRequsted)
138 m_bIsFocusRequsted =
false;
141 m_bIsFocusPosLocal = m_FocusEntity !=
null;
142 if (m_bIsFocusPosLocal)
143 m_vFocusPos = m_FocusEntity.CoordToLocal(m_vFocusPos);
145 m_Effect.SetParam(
"FocalLength", 500);
146 m_Effect.SetParam(
"FocalLengthNear", 500);
148 if (!m_sSoundEvent.IsEmpty())
151 m_OnFocusChange.Invoke(
true, m_vFocusPos, m_FocusEntity);
159 m_vFocusPosWorld = m_vFocusPos;
160 if (m_bIsFocusPosLocal)
165 m_vFocusPosWorld = m_FocusEntity.CoordToParent(m_vFocusPos);
176 m_fFocusDistance = vector.Distance(m_vFocusPosWorld,
CoordFromCamera(param.transform[3]));
177 m_Effect.SetParam(
"FocusDistance", m_fFocusDistance);
179 m_OnFocusDistanceChange.Invoke();
184 m_Widget.SetVisible(
true);
185 vector screenPos = m_Widget.GetWorkspace().ProjWorldToScreen(m_vFocusPosWorld, param.world);
186 if (screenPos[2] > 0)
187 FrameSlot.SetPos(m_Widget, screenPos[0], screenPos[1]);
197 data.m_aValues = {m_vFocusPosWorld[0], m_vFocusPosWorld[1], m_vFocusPosWorld[2]};
198 data.m_Target = m_FocusEntity;
204 SetFocus(Vector(
data.m_aValues[0],
data.m_aValues[1],
data.m_aValues[2]),
data.m_Target);
208 override bool EOnCameraInit()
211 if (!postProcessManager)
213 Debug.Error(
"SCR_FocusManualCameraComponent requires SCR_PostProcessCameraComponent!");
217 m_Effect = postProcessManager.FindEffect(PostProcessEffectType.DepthOfFieldBokeh);
220 Debug.Error(
"SCR_FocusManualCameraComponent requires DepthOfField post-process effect!");
228 inputManager.AddActionListener(
"ManualCameraFocus", EActionTrigger.DOWN, SetFocusToCursor);
229 inputManager.AddActionListener(
"ManualCameraFocusReset", EActionTrigger.DOWN, ResetFocus);
242 override void EOnCameraExit()
248 inputManager.RemoveActionListener(
"ManualCameraFocus", EActionTrigger.DOWN, SetFocusToCursor);
249 inputManager.RemoveActionListener(
"ManualCameraFocusReset", EActionTrigger.DOWN, ResetFocus);
252 m_Widget.RemoveFromHierarchy();