Sorting 3D characters in 2D scenes

3D characters are possible in 2D games and scenes. However, since Follow Sorting Maps are only able to control the dislay order of sprite shaders, it's not possible to properly control their depth display (relative to other scene objects and characters) without relying on a custom shader.

This script offers an alternative approach - by having each object and character rendered by a separate camera, and then controlling the display order of each camera.

(Note: This script requires AC v1.64.0 or later)

To use this method:
 * 1) Set up the scene's Sorting Map as normal, and place Follow Sorting Maps on your character(s).
 * 2) Place each character, and mid-scene sprite (i.e. objects the characters can move in front of and behind) on separate, dedicated layers - e.g. place the Player on a layer named "Player", a chair object on "Chair" etc.
 * 3) Create a new Camera for each new layer as a child of the MainCamera.  Set the Clear Flags to Depth only, and the Culling Mask to just one of these new layers each.
 * 4) Attach the script below onto each new Camera.  For cameras that render characters, assign that character's Follow Sorting Map in the script's Inspector.
 * 5) For cameras that render scene sprites, set the Camera's Depth value to match that sprite's Sorting Order value.
 * 6) Remove these new layers from the MainCamera's Culling Mask field.

SortingDepthCam.cs: using UnityEngine; using System.Collections; using AC; public class SortingDepthCam : MonoBehaviour { 	private Camera ownCamera; public FollowSortingMap followSortingMap; private void Start { 		ownCamera = GetComponent ; } 	private void LateUpdate { 		ownCamera.transform.position = Camera.main.transform.position; ownCamera.transform.rotation = Camera.main.transform.rotation; ownCamera.projectionMatrix = Camera.main.projectionMatrix; ownCamera.orthographicSize = Camera.main.orthographicSize; ownCamera.fieldOfView = Camera.main.fieldOfView; if (followSortingMap != null) { 			ownCamera.depth = followSortingMap.SortingOrder - ((float) followSortingMap.SharedDepth / 10f); } 	}  }