CameraService

Provides camera related functions.

# Properties

[{"index":"float currentZoomRatio (ReadOnly)","0":"Current zoom ratio."}]

[{"index":"float TransitionBlendTime","0":"Defines how long the blend will take when switching cameras."}]

[{"index":"CameraBlendType TransitionBlendType","0":"Defines the animation blend type for camera transitions."}]

# Methods

[{"index":"CameraComponent GetCurrentCameraComponent() (ClientOnly)","0":"Returns the CameraComponent currently being applied."}]

[{"index":"void SwitchCameraTo(CameraComponent cameraToSwitch) (Client)","0":"Switches the camera to the target CameraComponent."}]

[{"index":"void SwitchCameraTo(CameraComponent cameraToSwitch, Entity messageOwnerEntity = nil) (Client)","0":"Switches the camera to the target CameraComponent."}]

[{"index":"void SwitchCameraTo(CameraComponent cameraToSwitch, string targetUserId = nil) (Client)","0":"Switches the camera to the target CameraComponent."}]

[{"index":"void ZoomReset() (Client)","0":"Resets camera zoom."}]

[{"index":"void ZoomReset(Entity messageOwnerEntity = nil) (Client)","0":"Resets camera zoom."}]

[{"index":"void ZoomReset(string targetUserId = nil) (Client)","0":"Resets camera zoom."}]

[{"index":"void ZoomTo(float percent, float duration) (Client)","0":"Zooms the camera view in or out for a designated duration. The value must be between the camera's ZoomRatioMin and ZoomRatioMax, and the units must be a percentage. The duration is in seconds."}]

[{"index":"void ZoomTo(float percent, float duration, Entity messageOwnerEntity = nil) (Client)","0":"Zooms the camera view in or out for a designated duration. The value must be between the camera's ZoomRatioMin and ZoomRatioMax, and the units must be a percentage. The duration is in seconds."}]

[{"index":"void ZoomTo(float percent, float duration, string targetUserId = nil) (Client)","0":"Zooms the camera view in or out for a designated duration. The value must be between the camera's ZoomRatioMin and ZoomRatioMax, and the units must be a percentage. The duration is in seconds."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Events

[{"index":"CameraSwitchEvent","0":"The event occurs when switching the target for the camera to shoot."}]

[{"index":"CameraZoomEndEvent","0":"This event is raised after completing the camera's zoom change."}]

# Examples

In this example, the camera will zoom in on the Target Entity twice as long as the LeftShift key is pressed.
    
    
    @Component
    script FocusViewSwitcher extends Component
        @EventSender("Service", "InputService")
        handler HandleKeyDownEvent(KeyDownEvent event)
        -- Parameters
        local key = event.key
        --------------------------------------------------------
    
        if key == KeyboardKey.LeftShift then
        	local targetEntity = _EntityService:GetEntityByPath(EntityPath)
        	local targetCamera = targetEntity.CameraComponent
    
        	_CameraService:SwitchCameraTo(targetCamera)
        	_CameraService:ZoomTo(200, 1.0)
        end
        end
    
        @EventSender("Service", "InputService")
        handler HandleKeyUpEvent(KeyUpEvent event)
        -- Parameters
        local key = event.key
        -------------------------------------------------------- 
        if key == KeyboardKey.LeftShift then
        	local targetCamera = _UserService.LocalPlayer.CameraComponent
    
        	_CameraService:ZoomReset()
        	_CameraService:SwitchCameraTo(targetCamera)
        end
        end
    end
    

# SeeAlso

  * CameraComponent
  * KeyboardKey
  * KeyDownEvent
  * KeyUpEvent
  * EntityService
  * InputService
  * UserService
  * [Controlling the Camera with CameraService](/docs?postId=118)
  * [Controlling the Player Camera](/docs?postId=72)