DangerCamera  1.2
The most dangerous of Unity cameras. Copyright 2016-2017 Subaltern Games, LLC all rights reserved
DangerCamera Class Reference

DangerCamera is the most dangerous of all cameras. Creators: Seth Alter (subal.nosp@m.tern.nosp@m.games.nosp@m.@gma.nosp@m.il.co.nosp@m.m) Danger Donaghey (dange.nosp@m.rdon.nosp@m.aghey.nosp@m.@gma.nosp@m.il.co.nosp@m.m) Copyright 2016-2017 Subaltern Games, LLC all rights reserved. More...

Inherits MonoBehaviour.

Classes

class  DangerCameraZoomLevel
 Danger camera zoom level data. More...
 

Public Member Functions

virtual float GetDistance ()
 Returns the camera distance. More...
 
virtual int GetZoomLevel ()
 Returns the index of the current DangerZoomLevel in zoomLevels. More...
 
int AddZoomLevel (DangerCameraZoomLevel dzl)
 Adds the zoom level to the list in order of defined distance parameter. Returns the index of the added zoom level. More...
 
DangerCameraZoomLevel GetZoomLevel (int i)
 Gets the sorted zoom level. Returns the zoom level at a given index. More...
 
bool StartTracking (Transform target)
 Begin tracking to this target. Returns true if tracking was sucessful. More...
 
void StartTrackingAndZoom (Transform target)
 Start tracking a target and also zoom towards it. More...
 
void StartTracking (Vector3 position)
 Track to this position. More...
 
void TrackAndSnapMouseTo (Vector3 position)
 Track an object. Rotate the camera such that the mouse falls on top of the object. More...
 
void StopTracking ()
 Set the tracking target to backupTarget (meaning we track nothing). More...
 
bool IsTrackingTarget (Transform target)
 Returns true if we are tracking this target. More...
 
bool AddFramingTarget (Transform t)
 Add a framing target. Returns true if the target was added to the HashSet, and false if it is already there. More...
 

Public Attributes

UnityEvent OnZoom
 Trigger this event when the camera zooms. More...
 
UnityEvent OnWASD
 Trigger this event when player uses WASD. More...
 
UnityEvent OnRotate
 Trigger this event when camera rotates. More...
 
UnityEvent OnMousePan
 Trigger this event when the mouse pans the camera. More...
 
UnityEvent OnTrack
 Trigger this event when the camera is tracking. More...
 
float MouseAngleMinY = 23.00f * Mathf.Deg2Rad
 The minimum angle the mouse can bring the camera towards the floor. Lower numbers bring it increasingly parallel to the floor. Clamped to avoid camera inverting. More...
 
float MouseAngleMaxY = 89.00f * Mathf.Deg2Rad
 The maximum angle of the camera. Clamped to avoid camera inverting. More...
 
bool allowWASDPan = true
 Whether this camera listens for panning (WASD) input. More...
 
bool allowZoom = true
 Whether this camera listens to zooming (scroll wheel) input. More...
 
bool allowRotation = true
 Whether this camera listens to rotational (right click + drag) input. More...
 
bool allowFraming = true
 Whether this camera will attempt to frame objects. More...
 
bool allowMousePan = true
 Whether this camera listens to mouse pan. More...
 
float panSensitivity = 1f
 Adjust how sensitive (fast) panning is (WASD and mouse). More...
 
KeyCode KeyZoomIn = KeyCode.LeftBracket
 Key used to zoom in. More...
 
KeyCode KeyZoomOut = KeyCode.RightBracket
 Key used to zoom out. More...
 
float minDistance = 5
 Minimal distance from camera to the floor. More...
 
float maxDistance = 50
 Maximum distance from camera to the floor. More...
 
float trackZoomDistance = 6
 When tracking and zooming, zoom to this distance. More...
 
float zoomLerpSensitivity = 0.5f
 Lerp the distance from the camera to the floor at this rate. More...
 
bool invertRotationX = false
 Whether to invert the x axis. More...
 
bool invertRotationY = false
 Whether to invert the y axis. More...
 
float rotationSensitivity = 1f
 Mouse sensitivity when rotating. More...
 
float rotationLerpSensitivity = 0.5f
 When rotating, how fast the camera will move to follow the mouse. 0 - prevents camera rotation updates 1 - prevents camera rotation smoothing More...
 
float mousePanEdgePercent = 0.05f
 Detect mouse panning when the distance from the mouse to a viewport edge is less than or equal to this. Must be between 0 and 1. More...
 
float boundsX = 500f
 The x value of the bounds beyond which the camera will not pan. More...
 
float boundsZ = 500f
 The z value of the bounds beyond which the camera will not pan. More...
 
Vector2 boundsCenter = new Vector2 ()
 The center of the bounds. More...
 
float trackLerpSensitivity = 0.5f
 How fast camera moves when tracking. More...
 

Static Public Attributes

static DangerCamera instance
 

Protected Member Functions

virtual void Awake ()
 
virtual void Start ()
 
virtual float GetBackupTargetZ ()
 Returns the starting backup target z value. More...
 
virtual float GetBackupTargetY ()
 Returns the starting backup target y value. More...
 
virtual float WASDZoomCoefficient ()
 Returns the percent of the way between min and max distance from the camera focal point. This is used to modify the translation speed based on zoom level. More...
 
virtual Vector3 TranslationToFloor (Vector3 translation)
 Returns the new direction to move the camera, modified by the camera's orientation and constrained in regards to horizontal movement. More...
 
virtual void TrackToTarget ()
 Move transform towards trackingTarget. More...
 
virtual bool CheckLevelBoundsWhileTracking ()
 Returns true if the camera should check if it is out of bounds before tracking to target. More...
 
Vector3 GetTrackingAngledVector ()
 Returns the angled vector at which the camera should track. More...
 
void MouseRotation ()
 Update the angle of mouse movement. More...
 
Vector3 GetWASD ()
 Pan with WASD. More...
 
Vector3 GetMousePan ()
 Pan with the mouse when it is close to the edges of the screen. More...
 
virtual bool IsWithinLevelBounds (Vector3 newPosition)
 Returns true if position is within level bounds. More...
 
bool IsRotation ()
 Is the player rotating the camera? More...
 
virtual bool IsRotationInput ()
 Returns true if the user is entering the correct input for rotation. More...
 
virtual int GetDefaultZoomLevel ()
 The default zoom level for the camera. Used in WaitAndThenZoom. More...
 
IEnumerator WaitAndZoom ()
 Wait a bit, and then zoom. More...
 
virtual void ZoomTo (int zoom)
 Set distance given the index of zoomLevels. More...
 
void HandleZoom ()
 Trigger events given the distance. More...
 
void SetZoom ()
 Sets distance based on scroll wheel movement. More...
 
virtual bool SetDistanceByZoom (float d)
 Given a zoom increment, set the camera distance. Returns true if we are at the min or max possible distance. More...
 
virtual void HandleTranslation ()
 Handles the translation of the camera. It takes the raw translation, modifies that to fit the floor and angle, then moves only if the camera is within level bounds. More...
 
virtual Vector3 GetRawTranslation ()
 Returns the raw translation of the camera. More...
 
void FrameInViewport ()
 If we have any viewport targets and they are not within the viewport, pull the camera away. More...
 
bool IsInViewport (Transform t)
 Returns true if the object is in the viewport. More...
 
virtual void Update ()
 

Protected Attributes

const string INPUT_HORIZONTAL = "Horizontal"
 
const string INPUT_VERTICAL = "Vertical"
 
const string INPUT_SCROLLWHEEL = "Mouse ScrollWheel"
 
List< DangerCameraZoomLevelzoomLevels
 A list of all zoom levels. More...
 
Vector3 expectedFloorPosition = new Vector3(0, -100, 0)
 The position used to calculate the raycast direction to find the camera's starting focal point. More...
 

Properties

Camera Cam [get]
 The camera associated with this DangerCamera object. If DangerCamera.cam is not assigned, this will assign it first. More...
 
Transform TrackingTarget [get, set]
 Returns the target the camera is currently tracking. Can also set the target. Always set the target here! More...
 
float ZoomSpeed [get]
 Returns the speed at which the camera will zoom. The speed is dependent on the distance, and defined in zoomLevels. More...
 

Detailed Description

DangerCamera is the most dangerous of all cameras. Creators: Seth Alter (subal.nosp@m.tern.nosp@m.games.nosp@m.@gma.nosp@m.il.co.nosp@m.m) Danger Donaghey (dange.nosp@m.rdon.nosp@m.aghey.nosp@m.@gma.nosp@m.il.co.nosp@m.m) Copyright 2016-2017 Subaltern Games, LLC all rights reserved.

Member Function Documentation

bool DangerCamera.AddFramingTarget ( Transform  t)

Add a framing target. Returns true if the target was added to the HashSet, and false if it is already there.

Parameters
tThe Transform we want to frame
int DangerCamera.AddZoomLevel ( DangerCameraZoomLevel  dzl)

Adds the zoom level to the list in order of defined distance parameter. Returns the index of the added zoom level.

Parameters
dzlThe new zoom level being added.
virtual void DangerCamera.Awake ( )
protectedvirtual
virtual bool DangerCamera.CheckLevelBoundsWhileTracking ( )
protectedvirtual

Returns true if the camera should check if it is out of bounds before tracking to target.

void DangerCamera.FrameInViewport ( )
protected

If we have any viewport targets and they are not within the viewport, pull the camera away.

virtual float DangerCamera.GetBackupTargetY ( )
protectedvirtual

Returns the starting backup target y value.

virtual float DangerCamera.GetBackupTargetZ ( )
protectedvirtual

Returns the starting backup target z value.

virtual int DangerCamera.GetDefaultZoomLevel ( )
protectedvirtual

The default zoom level for the camera. Used in WaitAndThenZoom.

virtual float DangerCamera.GetDistance ( )
virtual

Returns the camera distance.

Vector3 DangerCamera.GetMousePan ( )
protected

Pan with the mouse when it is close to the edges of the screen.

virtual Vector3 DangerCamera.GetRawTranslation ( )
protectedvirtual

Returns the raw translation of the camera.

Returns
Vector3 DangerCamera.GetTrackingAngledVector ( )
protected

Returns the angled vector at which the camera should track.

Vector3 DangerCamera.GetWASD ( )
protected

Pan with WASD.

virtual int DangerCamera.GetZoomLevel ( )
virtual

Returns the index of the current DangerZoomLevel in zoomLevels.

DangerCameraZoomLevel DangerCamera.GetZoomLevel ( int  i)

Gets the sorted zoom level. Returns the zoom level at a given index.

Parameters
iThe index of the zoom level desired.
virtual void DangerCamera.HandleTranslation ( )
protectedvirtual

Handles the translation of the camera. It takes the raw translation, modifies that to fit the floor and angle, then moves only if the camera is within level bounds.

void DangerCamera.HandleZoom ( )
protected

Trigger events given the distance.

bool DangerCamera.IsInViewport ( Transform  t)
protected

Returns true if the object is in the viewport.

Parameters
tThe object we want to be in the viewport
bool DangerCamera.IsRotation ( )
protected

Is the player rotating the camera?

virtual bool DangerCamera.IsRotationInput ( )
protectedvirtual

Returns true if the user is entering the correct input for rotation.

bool DangerCamera.IsTrackingTarget ( Transform  target)

Returns true if we are tracking this target.

Parameters
targetTransform that we might be tracking
virtual bool DangerCamera.IsWithinLevelBounds ( Vector3  newPosition)
protectedvirtual

Returns true if position is within level bounds.

void DangerCamera.MouseRotation ( )
protected

Update the angle of mouse movement.

virtual bool DangerCamera.SetDistanceByZoom ( float  d)
protectedvirtual

Given a zoom increment, set the camera distance. Returns true if we are at the min or max possible distance.

Parameters
dThe increment at which we want to adjust the zoom.
void DangerCamera.SetZoom ( )
protected

Sets distance based on scroll wheel movement.

virtual void DangerCamera.Start ( )
protectedvirtual
bool DangerCamera.StartTracking ( Transform  target)

Begin tracking to this target. Returns true if tracking was sucessful.

Parameters
targetTarget to track
void DangerCamera.StartTracking ( Vector3  position)

Track to this position.

Parameters
positionPosition to track to
void DangerCamera.StartTrackingAndZoom ( Transform  target)

Start tracking a target and also zoom towards it.

Parameters
targetTarget to track
void DangerCamera.StopTracking ( )

Set the tracking target to backupTarget (meaning we track nothing).

void DangerCamera.TrackAndSnapMouseTo ( Vector3  position)

Track an object. Rotate the camera such that the mouse falls on top of the object.

Parameters
positionPosition to track to and to snap mouse to
virtual void DangerCamera.TrackToTarget ( )
protectedvirtual

Move transform towards trackingTarget.

virtual Vector3 DangerCamera.TranslationToFloor ( Vector3  translation)
protectedvirtual

Returns the new direction to move the camera, modified by the camera's orientation and constrained in regards to horizontal movement.

Parameters
translationThe raw translation input vector.
virtual void DangerCamera.Update ( )
protectedvirtual
IEnumerator DangerCamera.WaitAndZoom ( )
protected

Wait a bit, and then zoom.

virtual float DangerCamera.WASDZoomCoefficient ( )
protectedvirtual

Returns the percent of the way between min and max distance from the camera focal point. This is used to modify the translation speed based on zoom level.

virtual void DangerCamera.ZoomTo ( int  zoom)
protectedvirtual

Set distance given the index of zoomLevels.

Member Data Documentation

bool DangerCamera.allowFraming = true

Whether this camera will attempt to frame objects.

bool DangerCamera.allowMousePan = true

Whether this camera listens to mouse pan.

bool DangerCamera.allowRotation = true

Whether this camera listens to rotational (right click + drag) input.

bool DangerCamera.allowWASDPan = true

Whether this camera listens for panning (WASD) input.

bool DangerCamera.allowZoom = true

Whether this camera listens to zooming (scroll wheel) input.

Vector2 DangerCamera.boundsCenter = new Vector2 ()

The center of the bounds.

float DangerCamera.boundsX = 500f

The x value of the bounds beyond which the camera will not pan.

float DangerCamera.boundsZ = 500f

The z value of the bounds beyond which the camera will not pan.

Vector3 DangerCamera.expectedFloorPosition = new Vector3(0, -100, 0)
protected

The position used to calculate the raycast direction to find the camera's starting focal point.

const string DangerCamera.INPUT_HORIZONTAL = "Horizontal"
protected
const string DangerCamera.INPUT_SCROLLWHEEL = "Mouse ScrollWheel"
protected
const string DangerCamera.INPUT_VERTICAL = "Vertical"
protected
DangerCamera DangerCamera.instance
static
bool DangerCamera.invertRotationX = false

Whether to invert the x axis.

bool DangerCamera.invertRotationY = false

Whether to invert the y axis.

KeyCode DangerCamera.KeyZoomIn = KeyCode.LeftBracket

Key used to zoom in.

KeyCode DangerCamera.KeyZoomOut = KeyCode.RightBracket

Key used to zoom out.

float DangerCamera.maxDistance = 50

Maximum distance from camera to the floor.

float DangerCamera.minDistance = 5

Minimal distance from camera to the floor.

float DangerCamera.MouseAngleMaxY = 89.00f * Mathf.Deg2Rad

The maximum angle of the camera. Clamped to avoid camera inverting.

float DangerCamera.MouseAngleMinY = 23.00f * Mathf.Deg2Rad

The minimum angle the mouse can bring the camera towards the floor. Lower numbers bring it increasingly parallel to the floor. Clamped to avoid camera inverting.

float DangerCamera.mousePanEdgePercent = 0.05f

Detect mouse panning when the distance from the mouse to a viewport edge is less than or equal to this. Must be between 0 and 1.

UnityEvent DangerCamera.OnMousePan

Trigger this event when the mouse pans the camera.

UnityEvent DangerCamera.OnRotate

Trigger this event when camera rotates.

UnityEvent DangerCamera.OnTrack

Trigger this event when the camera is tracking.

UnityEvent DangerCamera.OnWASD

Trigger this event when player uses WASD.

UnityEvent DangerCamera.OnZoom

Trigger this event when the camera zooms.

float DangerCamera.panSensitivity = 1f

Adjust how sensitive (fast) panning is (WASD and mouse).

float DangerCamera.rotationLerpSensitivity = 0.5f

When rotating, how fast the camera will move to follow the mouse. 0 - prevents camera rotation updates 1 - prevents camera rotation smoothing

float DangerCamera.rotationSensitivity = 1f

Mouse sensitivity when rotating.

float DangerCamera.trackLerpSensitivity = 0.5f

How fast camera moves when tracking.

float DangerCamera.trackZoomDistance = 6

When tracking and zooming, zoom to this distance.

float DangerCamera.zoomLerpSensitivity = 0.5f

Lerp the distance from the camera to the floor at this rate.

List<DangerCameraZoomLevel> DangerCamera.zoomLevels
protected
Initial value:
= new List<DangerCameraZoomLevel>
{
new DangerCameraZoomLevel { distance = 20, speed = 20 },
new DangerCameraZoomLevel { distance = 25, speed = 25 },
new DangerCameraZoomLevel { distance = 30, speed = 30 },
new DangerCameraZoomLevel { distance = 40, speed = 40 },
new DangerCameraZoomLevel { distance = 50, speed = 50 },
}

A list of all zoom levels.

Property Documentation

Camera DangerCamera.Cam
getprotected

The camera associated with this DangerCamera object. If DangerCamera.cam is not assigned, this will assign it first.

Transform DangerCamera.TrackingTarget
getsetprotected

Returns the target the camera is currently tracking. Can also set the target. Always set the target here!

float DangerCamera.ZoomSpeed
get

Returns the speed at which the camera will zoom. The speed is dependent on the distance, and defined in zoomLevels.


The documentation for this class was generated from the following file: