Adventure Creator  1.65.2
An adventure game toolkit for Unity, by Chris Burton, ICEBOX Studios 2013-2018
AC.MainCamera Class Reference
Inheritance diagram for AC.MainCamera:

Public Member Functions

void OnAwake (bool hideWhileLoading=true)
 
void Initialise (Texture2D _fadeTexture=null)
 Initialises lookAtTransform if none exists and assigns fadeTexture. More...
 
void OnStart ()
 
void PauseGame (bool canWait=false)
 Pauses the game. More...
 
void CancelPauseGame ()
 
void HideScene ()
 
void Shake (float _shakeIntensity, float _duration, CameraShakeEffect _shakeEffect)
 Shakes the Camera, creating an "earthquake" effect. More...
 
bool IsShaking ()
 Checks if the Camera is shaking. More...
 
void StopShaking ()
 
void PrepareForBackground ()
 
void SetFirstPerson ()
 
void DrawCameraFade ()
 Draws the Camera's fade texture. This is called every OnGUI call by StateHandler.
 
void ResetProjection ()
 
void ResetMoving ()
 
void _LateUpdate ()
 
void SnapToAttached ()
 
void Crossfade (float _transitionDuration, _Camera _linkedCamera)
 Crossfades to a new _Camera over time. More...
 
void StopCrossfade ()
 
void _ExitSceneWithOverlay ()
 
_Camera GetTransitionFromCamera ()
 Gets the _Camera being transitioned from, if the MainCamera is transitioning between two _Cameras. More...
 
void SetGameCamera (_Camera newCamera, float transitionTime=0f, MoveMethod _moveMethod=MoveMethod.Linear, AnimationCurve _animationCurve=null, bool _retainPreviousSpeed=false)
 Sets a _Camera as the new attachedCamera to follow. More...
 
void FadeOut (float _fadeDuration, Texture2D tempTex, bool forceCompleteTransition=true)
 Fades the camera out with a custom texture. More...
 
void FadeIn (float _fadeDuration, bool forceCompleteTransition=true)
 Fades the camera in. More...
 
void FadeOut (float _fadeDuration, bool forceCompleteTransition=true)
 Fades the camera out. More...
 
bool isFading ()
 Checks if the Camera is fading in our out. More...
 
Vector3 PositionRelativeToCamera (Vector3 _position)
 Converts a point in world space to one relative to the Camera's forward vector. More...
 
Vector3 RightVector ()
 Gets the Camera's right vector. More...
 
Vector3 ForwardVector ()
 Gets the Camera's forward vector, not accounting for pitch. More...
 
void SetCameraRect ()
 
Vector2 CorrectScreenPositionForUnityUI (Vector2 screenPosition)
 Corrects a screen position Vector to account for the MainCamera's viewport Rect. This is necessary when positioning Unity UI RectTransforms while an aspect ratio is enforced, because the original screen position assumes a default Rect. More...
 
Vector2 GetWindowViewportDifference ()
 Gets the difference between the window size and the game's viewport. More...
 
void DrawBorders ()
 
bool IsOrthographic ()
 Checks if the Camera uses orthographic perspective. More...
 
Vector2 LimitToAspect (Vector2 position)
 Limits a point in screen-space to stay within the Camera's rect boundary, if forceAspectRatio in SettingsManager = True. More...
 
bool IsPointInCamera (Vector2 point)
 Checks if a point in screen-space is within the Camera's viewport More...
 
Rect LimitMenuToAspect (Rect rect)
 Resizes an OnGUI Rect so that it fits within the Camera's rect, if forceAspectRatio = True in SettingsManager. More...
 
void SetSplitScreen (_Camera _camera1, _Camera _camera2, MenuOrientation _splitOrientation, bool _isTopLeft, float _splitAmountMain, float _splitAmountOther)
 Creates a new split-screen effect. More...
 
void StartSplitScreen (float _splitAmountMain, float _splitAmountOther)
 Adjusts the screen ratio of any active split-screen effect. More...
 
void RemoveSplitScreen ()
 
Rect GetSplitScreenRect (bool isMainCamera)
 Gets a screen Rect of the split-screen camera. More...
 
float GetFocalDistance ()
 Gets the current focal distance. More...
 
void Disable ()
 
void Enable ()
 
bool IsEnabled ()
 Checks if the Camera is enabled. More...
 
void SetCameraTag (string _tag)
 Sets the GameObject's tag. More...
 
void SetAudioState (bool state)
 Sets the state of the AudioListener component. More...
 
_Camera GetLastGameplayCamera ()
 Gets the previously-used gameplay _Camera. More...
 
Vector2 GetPerspectiveOffset ()
 Gets the current perspective offset, as set by a GameCamera2D. More...
 
PlayerData SaveData (PlayerData playerData)
 Saves data related to the camera. More...
 
void LoadData (PlayerData playerData)
 Restores the camera state from saved data More...
 
void SetTimelineOverride (_Camera cam1, _Camera cam2, float cam2Weight)
 
void ReleaseTimelineOverride ()
 

Static Public Member Functions

static bool AllowProjectionShifting (Camera _camera)
 

Public Attributes

Texture2D fadeTexture
 
_Camera attachedCamera
 
_Camera lastNavCamera
 
_Camera lastNavCamera2
 
bool isSplitScreen
 
bool isTopLeftSplit
 
MenuOrientation splitOrientation
 
_Camera splitCamera
 
float splitAmountMain = 0.49f
 
float splitAmountOther = 0.49f
 

Properties

Camera Camera [get]
 

Detailed Description

This is attached to the scene's Main Camera, and must be tagged as "MainCamera". The camera system works by having the MainCamera attach itself to the "active" _Camera component. Each _Camera component is merely used for reference - only the MainCamera actually performs any rendering. Shake code adapted from Mike Jasper's code: http://www.mikedoesweb.com/2012/camera-shake-in-unity/ Aspect-ratio code adapated from Eric Haines' code: http://wiki.unity3d.com/index.php?title=AspectRatioEnforcer

Member Function Documentation

◆ _ExitSceneWithOverlay()

void AC.MainCamera._ExitSceneWithOverlay ( )

Places a full-screen texture of the current game window over the screen, allowing for a scene change to have no visible transition.

◆ _LateUpdate()

void AC.MainCamera._LateUpdate ( )

Updates the Camera's position. This is called every frame by StateHandler.

◆ CorrectScreenPositionForUnityUI()

Vector2 AC.MainCamera.CorrectScreenPositionForUnityUI ( Vector2  screenPosition)

Corrects a screen position Vector to account for the MainCamera's viewport Rect. This is necessary when positioning Unity UI RectTransforms while an aspect ratio is enforced, because the original screen position assumes a default Rect.

Parameters
screenPositionThe screen position to correct.
Returns
The corrected screen position

◆ Crossfade()

void AC.MainCamera.Crossfade ( float  _transitionDuration,
_Camera  _linkedCamera 
)

Crossfades to a new _Camera over time.

Parameters
_transitionDurationThe duration, in seconds, of the crossfade
_linkedCameraThe _Camera to crossfade to

◆ Disable()

void AC.MainCamera.Disable ( )

Disables the Camera and AudioListener.

◆ DrawBorders()

void AC.MainCamera.DrawBorders ( )

Draws any borders generated by a fixed aspect ratio, as set with forceAspectRatio in SettingsManager. This will be called every OnGUI call by StateHandler.

◆ Enable()

void AC.MainCamera.Enable ( )

Enables the Camera and AudioListener.

◆ FadeIn()

void AC.MainCamera.FadeIn ( float  _fadeDuration,
bool  forceCompleteTransition = true 
)

Fades the camera in.

Parameters
_fadeDurationThe duration, in seconds, of the fade effect
forceCompleteTransitionIf True, the camera will be faded out instantly before beginning

◆ FadeOut() [1/2]

void AC.MainCamera.FadeOut ( float  _fadeDuration,
Texture2D  tempTex,
bool  forceCompleteTransition = true 
)

Fades the camera out with a custom texture.

Parameters
_fadeDurationThe duration, in seconds, of the fade effect
tempTexThe texture to display full-screen
forceCompleteTransitionIf True, the camera will be faded in instantly before beginning

◆ FadeOut() [2/2]

void AC.MainCamera.FadeOut ( float  _fadeDuration,
bool  forceCompleteTransition = true 
)

Fades the camera out.

Parameters
_fadeDurationThe duration, in seconds, of the fade effect
forceCompleteTransitionIf True, the camera will be faded in instantly before beginning

◆ ForwardVector()

Vector3 AC.MainCamera.ForwardVector ( )

Gets the Camera's forward vector, not accounting for pitch.

Returns
The Camera's forward vector, not accounting for pitch

◆ GetFocalDistance()

float AC.MainCamera.GetFocalDistance ( )

Gets the current focal distance.

Returns
The current focal distance

◆ GetLastGameplayCamera()

_Camera AC.MainCamera.GetLastGameplayCamera ( )

Gets the previously-used gameplay _Camera.

Returns
The previously-used gameplay _Camera

◆ GetPerspectiveOffset()

Vector2 AC.MainCamera.GetPerspectiveOffset ( )

Gets the current perspective offset, as set by a GameCamera2D.

Returns
The current perspective offset, as set by a GameCamera2D.

◆ GetSplitScreenRect()

Rect AC.MainCamera.GetSplitScreenRect ( bool  isMainCamera)

Gets a screen Rect of the split-screen camera.

Parameters
isMainCameraIf True, then the Rect of the MainCamera's view will be returned. Otherwise, the Rect of the other split-screen _Camera's view will be returned
Returns
A screen Rect of the split-screen camera

◆ GetTransitionFromCamera()

_Camera AC.MainCamera.GetTransitionFromCamera ( )

Gets the _Camera being transitioned from, if the MainCamera is transitioning between two _Cameras.

Returns
The _Camera being transitioned from, if the MainCamera is transitioning between two _Cameras.

◆ GetWindowViewportDifference()

Vector2 AC.MainCamera.GetWindowViewportDifference ( )

Gets the difference between the window size and the game's viewport.

Returns
The difference between the window size and the game's viewport.

◆ HideScene()

void AC.MainCamera.HideScene ( )

Displays the fadeTexture full-screen for a brief moment while the scene loads.

◆ Initialise()

void AC.MainCamera.Initialise ( Texture2D  _fadeTexture = null)

Initialises lookAtTransform if none exists and assigns fadeTexture.

Parameters
_fadeTextureThe new fadeTexture to use, if not null

◆ IsEnabled()

bool AC.MainCamera.IsEnabled ( )

Checks if the Camera is enabled.

returns>True if the Camera is enabled

◆ isFading()

bool AC.MainCamera.isFading ( )

Checks if the Camera is fading in our out.

Returns
True if the Camera is fading in or out

◆ IsOrthographic()

bool AC.MainCamera.IsOrthographic ( )

Checks if the Camera uses orthographic perspective.

Returns
True if the Camera uses orthographic perspective

◆ IsPointInCamera()

bool AC.MainCamera.IsPointInCamera ( Vector2  point)

Checks if a point in screen-space is within the Camera's viewport

Parameters
pointThe point to check the position of
Returns
True if the point is within the Camera's viewport

◆ IsShaking()

bool AC.MainCamera.IsShaking ( )

Checks if the Camera is shaking.

Returns
True if the Camera is shaking

◆ LimitMenuToAspect()

Rect AC.MainCamera.LimitMenuToAspect ( Rect  rect)

Resizes an OnGUI Rect so that it fits within the Camera's rect, if forceAspectRatio = True in SettingsManager.

Parameters
rectThe OnGUI Rect to resize
Returns
The resized OnGUI Rect

◆ LimitToAspect()

Vector2 AC.MainCamera.LimitToAspect ( Vector2  position)

Limits a point in screen-space to stay within the Camera's rect boundary, if forceAspectRatio in SettingsManager = True.

Parameters
positionThe original position in screen-space
Returns
The point, repositioned to stay within the Camera's rect boundary

◆ LoadData()

void AC.MainCamera.LoadData ( PlayerData  playerData)

Restores the camera state from saved data

Parameters
playerDataThe data class to load from

◆ PauseGame()

void AC.MainCamera.PauseGame ( bool  canWait = false)

Pauses the game.

Parameters
canWaitIf True and the game cannot currently be paused, the game will paused at the next possible time

◆ PositionRelativeToCamera()

Vector3 AC.MainCamera.PositionRelativeToCamera ( Vector3  _position)

Converts a point in world space to one relative to the Camera's forward vector.

Returns
Converts a point in world space to one relative to the Camera's forward vector.

◆ PrepareForBackground()

void AC.MainCamera.PrepareForBackground ( )

Prepares the Camera for being able to render a BackgroundImage underneath scene objects.

◆ RemoveSplitScreen()

void AC.MainCamera.RemoveSplitScreen ( )

Ends any active split-screen effect.

◆ ResetMoving()

void AC.MainCamera.ResetMoving ( )

Resets the transition effect when moving from one _Camera to another.

◆ ResetProjection()

void AC.MainCamera.ResetProjection ( )

Resets the Camera's projection matrix.

◆ RightVector()

Vector3 AC.MainCamera.RightVector ( )

Gets the Camera's right vector.

Returns
The Camera's right vector

◆ SaveData()

PlayerData AC.MainCamera.SaveData ( PlayerData  playerData)

Saves data related to the camera.

Parameters
playerDataThe PlayerData class to update with current data
Returns
A PlayerData class, updated with current camera data

◆ SetAudioState()

void AC.MainCamera.SetAudioState ( bool  state)

Sets the state of the AudioListener component.

Parameters
stateIf True, the AudioListener will be enabled. If False, it will be disabled.

◆ SetCameraRect()

void AC.MainCamera.SetCameraRect ( )

Updates the camera's rect values according to the aspect ratio and split-screen settings.

◆ SetCameraTag()

void AC.MainCamera.SetCameraTag ( string  _tag)

Sets the GameObject's tag.

Parameters
_tagThe tag to give the GameObject

◆ SetFirstPerson()

void AC.MainCamera.SetFirstPerson ( )

Activates the FirstPersonCamera found in the Player prefab.

◆ SetGameCamera()

void AC.MainCamera.SetGameCamera ( _Camera  newCamera,
float  transitionTime = 0f,
MoveMethod  _moveMethod = MoveMethod.Linear,
AnimationCurve  _animationCurve = null,
bool  _retainPreviousSpeed = false 
)

Sets a _Camera as the new attachedCamera to follow.

Parameters
newCameraThe new _Camera to follow
transitionTimeThe time, in seconds, that it will take to move towards the new _Camera
_moveMethodHow the Camera should move towards the new _Camera, if transitionTime > 0f (Linear, Smooth, Curved, EaseIn, EaseOut, CustomCurve)
_animationCurveThe AnimationCurve that dictates movement over time, if _moveMethod = MoveMethod.CustomCurve
_retainPreviousSpeedIf True, and transitionTime > 0, then the previous _Camera's speed will influence the transition, allowing for a smoother effect

◆ SetSplitScreen()

void AC.MainCamera.SetSplitScreen ( _Camera  _camera1,
_Camera  _camera2,
MenuOrientation  _splitOrientation,
bool  _isTopLeft,
float  _splitAmountMain,
float  _splitAmountOther 
)

Creates a new split-screen effect.

Parameters
_camera1The first _Camera to use in the effect
_camera2The second _Camera to use in the effect
_splitOrientationHow the two _Cameras are arranged (Horizontal, Vertical)
_isTopLeftIf True, the MainCamera will take the position of _camera1
_splitAmountMainThe proportion of the screen taken up by this Camera
_splitAmountOtherThe proportion of the screen take up by the other _Camera

◆ Shake()

void AC.MainCamera.Shake ( float  _shakeIntensity,
float  _duration,
CameraShakeEffect  _shakeEffect 
)

Shakes the Camera, creating an "earthquake" effect.

Parameters
_shakeIntensityThe shake intensity
_durationThe duration of the effect, in sectonds
_shakeEffectThe type of shaking to make (Translate, Rotate, TranslateAndRotate)

◆ SnapToAttached()

void AC.MainCamera.SnapToAttached ( )

Snaps the Camera to the attachedCamera instantly.

◆ StartSplitScreen()

void AC.MainCamera.StartSplitScreen ( float  _splitAmountMain,
float  _splitAmountOther 
)

Adjusts the screen ratio of any active split-screen effect.

Parameters
_splitAmountMainThe proportion of the screen taken up by this Camera
_splitAmountOtherThe proportion of the screen take up by the other _Camera

◆ StopCrossfade()

void AC.MainCamera.StopCrossfade ( )

Instantly ends the crossfade effect.

◆ StopShaking()

void AC.MainCamera.StopShaking ( )

Ends the "earthquake" shake effect.

Member Data Documentation

◆ attachedCamera

_Camera AC.MainCamera.attachedCamera

The current active camera, i.e. the one that the MainCamera is attaching itself to

◆ fadeTexture

Texture2D AC.MainCamera.fadeTexture

The texture to display fullscreen when fading

◆ isSplitScreen

bool AC.MainCamera.isSplitScreen

If True, the game window is shared with another _Camera

◆ isTopLeftSplit

bool AC.MainCamera.isTopLeftSplit

If True, then this Camera takes up the left or top half of a split-screen effect, if isSplitScreen = True

◆ lastNavCamera

_Camera AC.MainCamera.lastNavCamera

The last active camera during gameplay

◆ lastNavCamera2

_Camera AC.MainCamera.lastNavCamera2

The last-but-one active camera during gameplay

◆ splitAmountMain

float AC.MainCamera.splitAmountMain = 0.49f

The portion of the screen that this Camera takes up, if isSplitScreen = True

◆ splitAmountOther

float AC.MainCamera.splitAmountOther = 0.49f

The portion of the screen that splitCamera takes up, if isSplitScreen = True

◆ splitCamera

_Camera AC.MainCamera.splitCamera

The _Camera to share the game window with, if isSplitScreen = True

◆ splitOrientation

MenuOrientation AC.MainCamera.splitOrientation

The orientation of the split-screen divider, if isSplitScreen = True (Horizontal, Vertical)

Property Documentation

◆ Camera

Camera AC.MainCamera.Camera
get

The MainCamera's Camera component.