1 [
ComponentEditorProps(
category:
"GameScripted/Editor", description:
"Camera for in-game editor. Works only with SCR_EditorBaseEntity!", icon:
"WBData/ComponentEditorProps/componentEditor.png")]
15 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Prefab of class SCR_ManualCamera",
"et",
category:
"Camera")]
16 protected ResourceName m_CameraPrefab;
18 [
Attribute(defvalue:
"1",
category:
"Init",
desc:
"Should the camera move above player when it initializes?")]
19 protected bool m_bMoveUpOnInit;
22 protected float m_fDistance;
25 protected vector m_vDefaultOffset;
28 protected vector m_vDefaultAngle;
30 protected CameraManager m_CameraManager;
33 protected vector m_vInitCameraTransform[4];
34 protected vector m_vPreActivateCameraTransform[4];
35 protected IEntity m_PreActivateControlledEntity;
36 protected bool m_bIsReplacingCamera;
37 protected ref ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated> m_OnCameraCreate =
new ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated>();
67 if (cameraManager)
return cameraManager.GetCamera();
74 ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated> GetOnCameraCreate()
76 return m_OnCameraCreate;
83 void SetInitTransform(vector transform[4])
85 m_vInitCameraTransform = transform;
90 protected void InitCameraTransform()
96 CameraBase currentCamera = m_CameraManager.CurrentCamera();
103 if (cameraDefaults.GetRandomPosition(m_vInitCameraTransform))
108 BaseWorld world =
GetGame().GetWorld();
112 world.GetBoundBox(mins, maxs);
113 vector center = mins + (maxs - mins) / 2;
114 center[1] = world.GetSurfaceY(center[0], center[2]);
115 center += m_vDefaultOffset;
116 m_vInitCameraTransform[3] = center;
117 Math3D.AnglesToMatrix(m_vDefaultAngle, m_vInitCameraTransform);
122 if (currentCamera.GetParent() && currentCamera.GetLocalTransformAxis(3).Length() > 100)
125 currentCamera.GetWorldTransform(m_vInitCameraTransform);
127 protected void TryCreateCamera()
129 if ((!m_CameraData || !m_CameraData.IsSave()) && m_vInitCameraTransform[3] == vector.Zero)
131 InitCameraTransform();
138 protected bool TryForceCamera()
143 if (
m_Camera != m_CameraManager.CurrentCamera())
145 array<CameraBase> cameras = {};
146 m_CameraManager.GetCamerasList(cameras);
148 m_CameraManager.SetCamera(
m_Camera);
153 protected void ReplaceCamera()
155 m_bIsReplacingCamera =
true;
157 m_CameraData.SaveComponents(
m_Camera);
160 protected void CreateCamera()
167 EntitySpawnParams spawnParams =
new EntitySpawnParams();
168 spawnParams.Transform = m_vInitCameraTransform;
170 ResourceName prefab = GetCameraPrefab();
171 if (prefab.IsEmpty())
180 m_Camera.GetOnCameraDeactivate().Insert(OnCameraDectivate);
181 Math3D.MatrixIdentity4(m_vInitCameraTransform);
184 m_CameraData.LoadComponents(
m_Camera);
189 if (m_bMoveUpOnInit && !m_bIsReplacingCamera)
191 if (m_PreActivateControlledEntity)
194 if (teleportComponent)
196 if (m_vPreActivateCameraTransform[3] == vector.Zero)
197 m_Camera.GetWorldTransform(m_vPreActivateCameraTransform);
200 vector angles = Math3D.MatrixToAngles(m_vPreActivateCameraTransform);
202 Math3D.AnglesToMatrix(angles, m_vPreActivateCameraTransform);
204 m_Camera.SetTransform(m_vPreActivateCameraTransform);
205 bool disableInterruption = !
GetGame().GetInputManager().IsUsingMouseAndKeyboard();
206 teleportComponent.TeleportCamera(m_vPreActivateCameraTransform[3],
true,
true,
true, disableInterruption,
m_fDistance,
true);
210 m_bIsReplacingCamera =
false;
211 m_PreActivateControlledEntity =
null;
213 protected void OnCameraDectivate()
218 protected ResourceName GetCameraPrefab()
220 return m_CameraPrefab;
225 override void ResetEditorComponent()
229 override protected void EOnEditorInit()
231 m_CameraManager =
GetGame().GetCameraManager();
234 override protected void EOnEditorPreActivate()
236 if (!m_CameraManager)
239 CameraBase currentCamera = m_CameraManager.CurrentCamera();
240 m_bIsReplacingCamera = currentCamera && currentCamera.IsInherited(
SCR_ManualCamera);
242 GetGame().GetWorld().GetCurrentCamera(m_vPreActivateCameraTransform);
244 override protected void EOnEditorPostActivate()
246 SetEventMask(
GetOwner(), EntityEvent.FRAME);
249 override void EOnFrame(IEntity owner,
float timeSlice)
256 override protected void EOnEditorDeactivate()
259 m_CameraData.SaveComponents(
m_Camera);
264 override protected void EOnEditorPostDeactivate()
267 ClearEventMask(
GetOwner(), EntityEvent.FRAME);
271 m_Camera.TrySwitchToControlledEntityCamera();