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

Public Member Functions

void OnAwake ()
 
void Initialise (Texture2D _fadeTexture)
 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 ReleaseScreenFocus ()
 
void SetScreenFocus (Vector2 screenPosition)
 Sets the screen position of the camera's focus. It will override the attached GameCamera's cursor influence, if active More...
 
void SnapToAttached ()
 
void Crossfade (float _changeTime, _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 _timeToFade, Texture2D tempTex, bool forceCompleteTransition=true)
 Fades the camera out with a custom texture. More...
 
void FadeIn (float _timeToFade, bool forceCompleteTransition=true)
 Fades the camera in. More...
 
void FadeOut (float _timeToFade, 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 ()
 
Vector3 ForwardVector ()
 
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)
 
void LoadData (PlayerData playerData)
 

Public Attributes

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

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

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.

void AC.MainCamera._LateUpdate ( )

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

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
void AC.MainCamera.Crossfade ( float  _changeTime,
_Camera  _linkedCamera 
)

Crossfades to a new _Camera over time.

Parameters
_changeTimeThe duration, in seconds, of the crossfade
_linkedCameraThe _Camera to crossfade to
void AC.MainCamera.Disable ( )

Disables the Camera and AudioListener.

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.

void AC.MainCamera.Enable ( )

Enables the Camera and AudioListener.

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

Fades the camera in.

Parameters
_timeToFadeThe duration, in seconds, of the fade effect
forceCompleteTransitionIf True, the camera will be faded out instantly before beginning
void AC.MainCamera.FadeOut ( float  _timeToFade,
Texture2D  tempTex,
bool  forceCompleteTransition = true 
)

Fades the camera out with a custom texture.

Parameters
_timeToFadeThe duration, in seconds, of the fade effect
tempTexThe texture to display full-screen
forceCompleteTransitionIf True, the camera will be faded in instantly before beginning
void AC.MainCamera.FadeOut ( float  _timeToFade,
bool  forceCompleteTransition = true 
)

Fades the camera out.

Parameters
_timeToFadeThe duration, in seconds, of the fade effect
forceCompleteTransitionIf True, the camera will be faded in instantly before beginning
float AC.MainCamera.GetFocalDistance ( )

Gets the current focal distance.

Returns
The current focal distance
_Camera AC.MainCamera.GetLastGameplayCamera ( )

Gets the previously-used gameplay _Camera.

Returns
The previously-used gameplay _Camera
Vector2 AC.MainCamera.GetPerspectiveOffset ( )

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

Returns
The current perspective offset, as set by a GameCamera2D.
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
_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.
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.
void AC.MainCamera.HideScene ( )

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

void AC.MainCamera.Initialise ( Texture2D  _fadeTexture)

Initialises lookAtTransform if none exists and assigns fadeTexture.

Parameters
_fadeTextureThe new fadeTexture to use, if not null
bool AC.MainCamera.IsEnabled ( )

Checks if the Camera is enabled.

returns>True if the Camera is enabled

bool AC.MainCamera.isFading ( )

Checks if the Camera is fading in our out.

Returns
True if the Camera is fading in or out
bool AC.MainCamera.IsOrthographic ( )

Checks if the Camera uses orthographic perspective.

Returns
True if the Camera uses orthographic perspective
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
bool AC.MainCamera.IsShaking ( )

Checks if the Camera is shaking.

Returns
True if the Camera is shaking
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
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
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
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.
void AC.MainCamera.PrepareForBackground ( )

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

void AC.MainCamera.ReleaseScreenFocus ( )

Releases the focus set with SetScreenFocus.

void AC.MainCamera.RemoveSplitScreen ( )

Ends any active split-screen effect.

void AC.MainCamera.ResetMoving ( )

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

void AC.MainCamera.ResetProjection ( )

Resets the Camera's projection matrix.

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.
void AC.MainCamera.SetCameraRect ( )

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

void AC.MainCamera.SetCameraTag ( string  _tag)

Sets the GameObject's tag.

Parameters
_tagThe tag to give the GameObject
void AC.MainCamera.SetFirstPerson ( )

Activates the FirstPersonCamera found in the Player prefab.

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
void AC.MainCamera.SetScreenFocus ( Vector2  screenPosition)

Sets the screen position of the camera's focus. It will override the attached GameCamera's cursor influence, if active

Parameters
screenPositionThe screen position of the camera's focus.
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
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)
void AC.MainCamera.SnapToAttached ( )

Snaps the Camera to the attachedCamera instantly.

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
void AC.MainCamera.StopCrossfade ( )

Instantly ends the crossfade effect.

void AC.MainCamera.StopShaking ( )

Ends the "earthquake" shake effect.

Member Data Documentation

_Camera AC.MainCamera.attachedCamera

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

Texture2D AC.MainCamera.fadeTexture

The texture to display fullscreen when fading

bool AC.MainCamera.isSplitScreen

If True, the game window is shared with another _Camera

bool AC.MainCamera.isTopLeftSplit

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

_Camera AC.MainCamera.lastNavCamera

The last active camera during gameplay

_Camera AC.MainCamera.lastNavCamera2

The last-but-one active camera during gameplay

Transform AC.MainCamera.lookAtTransform

The object to point towards. Since this object is assumed to be a child, the "LookAt" becomes an offset to regular rotation rather than a replacement

float AC.MainCamera.splitAmountMain = 0.49f

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

float AC.MainCamera.splitAmountOther = 0.49f

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

_Camera AC.MainCamera.splitCamera

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

MenuOrientation AC.MainCamera.splitOrientation

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