Camera
SplitScreen
(prefab)
MagicSplitscreen.cs
(var)
(func)
private
Vector3
SetCentralPosition(){ ... }
var centralPosition = Vector3.zero;
if (this.player1){ ... }
centralPosition += this.player1.position;
if (this.player2){ ... }
centralPosition += this.player2.position;
return centralPosition /= this.NumPlayers;
void
MoveCamera(Camera camera, Vector3 targetPos){ ... }
camera.transform.localRotation = this.cameraQuaternion;
camera.transform.position = targetPos - (camera.transform.forward * this.cameraDistance);
PerformSplitscreenCheck(){ ... }
var distThreshold = this.triggerDistance * this.triggerDistance;
if (!this.IsSplitscreenOn && this.distanceBetweenPlayers.sqrMagnitude > distThreshold){ ... }
this.StartSplitscreenCamera();
else if (this.IsSplitscreenOn && this.distanceBetweenPlayers.sqrMagnitude < distThreshold){ ... }
this.StopSplitscreenCamera();
// Activate splitscreen
StartSplitscreenCamera(){ ... }
// Disable splitscreen
StopSplitscreenCamera(){ ... }
LateUpdate(){ ... }
(return)
if (!this.IsInitialized){ return; }
// If there were issues during initial validation, trying to continue will just spam the console with unnecessary errors, so don't bother
if (this.NumPlayers == 0){ ... }
// There must be at least one player assigned for the camera(s) to have something to track
Debug.LogWarning("MagicSplitscreen: No players are assigned. There is nothing to do.");
return;
// Find the average location of all tracked players
var centralPosition = SetCentralPosition();
// Place the AudioListener in the central position
this.audioListener.transform.position = centralPosition;
// Determine if players are far enough apart to use splitscreen
this.distanceBetweenPlayers = centralPosition - this.MainPlayer.position;
this.PerformSplitscreenCheck();
// Position camera(s)
if (this.IsSplitscreenOn){ ... }
this.cameraDisplacement2d = this.distanceBetweenPlayers.normalized * this.triggerDistance;
// Adjust displacement to be in the direction of the central point but not at it
// Aim cameras at players
this.cameraTarget1 = this.player1.position + this.cameraDisplacement2d;
this.cameraTarget2 = this.player2.position - this.cameraDisplacement2d;
this.MoveCamera(this.primaryCamera, this.cameraTarget1);
this.MoveCamera(this.secondaryCamera, this.cameraTarget2);
// Position the splitscreen mask in front of the second camera
this.PositionSplitscreenMask(this.secondaryCamera, this.player2.position, this.player2.position + this.cameraDisplacement2d);
this.separatorRenderer.enabled = this.isSeparatorUsable && this.showSeparator;
else{ ... }
this.MoveCamera(this.primaryCamera, this.MainPlayer.position + this.distanceBetweenPlayers);
(mesh)
Splitscreen Mask
//a small plane which is positioned in front of the secondary camera when the screen is split
(material)
Splitscreen Mask
//prevent the secondary camera from rendering on the whole screen
//By default, the Mask is set to Layer 31, which has been named “SplitscreenMask.”
//You are free to set this to a different, otherwise unused Layer, and the Magic Splitscreen will still work properly
Separator Stripe
//stripe that appears along the division between the screens when split
//quad that is scaled and rotated to match Splitscreen Mask
ZDEPTH_CARD
DepthMask.shader
SetRenderQueue.cs
(instructions)
A mask object using the Depth Mask shader. This object will be drawn just after regular opaque objects, and will prevent subsequent objects from being drawn behind it.
Objects you wish to be masked must have the SetRenderQueue script attached to them. In the Inspector, change their queue from 3000 (regular geometry) to 3020 (just after the mask shader)
(alt)
In most common scenarios, you will only need a few objects to be masked. If, however, you find that you have more objects that need to be masked than objects that do not, you might find it useful to attach the SetRenderQueue script to the masks themselves, and set their queues to 2090 (just before regular geometry). Objects that you don't want masked should have their queues set to 2080 (just before the mask shader).
MasterCamera
(var)
Collision Layer Mask
//will not collide or clip through object with selected layers => MCScroll
Camera Rotation Mode
Follow
MouseHorizontal
MouseHorizontalAndVertical
MouseVertical
None
Smooth
Position
Rotation
Horizontal
Mouse Sensitivity
Minimum Angle
Maximum Angle
Vertical
Mouse Sensitivity
Minimum Angle
Maximum Angle
Preferred Distance
//How far away is the camera from the player
//Not per frame...on init only???
(func)
TestLOS(LayerMask)
//Test line of sight between camera and player, ignoring anything in the layer mask
(cam rotation)
GetLocalRotationZ
SetLocalRotationZ
(Addons)
//To use drag and drop onto MasterCameraRig object in the Hiearchy => Adds additional functionality
MCButtonLook
MCLOSFade
MCScroll
MCStrafe