Adventure Creator Wikia
Advertisement

When using AC's "Camera: Split-screen" Action, the screen is split into two camera views - with only one being interactive with the cursor. This script allows both views to be interactive, so that the mouse can be used in both.

To use it, create a new C# file named DynamicSplitScreen.cs, and attach to a GameObject in the scene. The "Camera: Split-screen" Action can be used as normal.

DynamicSplitScreen.cs:

using UnityEngine;
using AC;

public class DynamicSplitScreen : MonoBehaviour
{

	private Rect otherCameraRect;
	private bool isInSplitScreen;

	private void OnEnable ()
	{
		EventManager.OnCameraSplitScreenStart += OnCameraSplitScreenStart;
		EventManager.OnCameraSplitScreenStop += OnCameraSplitScreenStop;
	}

	private void OnDisable ()
	{
		EventManager.OnCameraSplitScreenStart += OnCameraSplitScreenStart;
		EventManager.OnCameraSplitScreenStop += OnCameraSplitScreenStop;
	}

	private void Update ()
	{
		if (isInSplitScreen)
		{
			Vector2 mousePosition = KickStarter.playerInput.GetMousePosition ();
			Vector2 mousePositionScreen = new Vector2 (mousePosition.x / ACScreen.width, mousePosition.y / ACScreen.height);
			
			if (otherCameraRect.Contains (mousePositionScreen))
			{
				KickStarter.mainCamera.SwapSplitScreenMainCamera ();
			}
		}
	}

	private void OnCameraSplitScreenStart (_Camera _splitCamera, CameraSplitOrientation _splitOrientation, float _splitAmountMain, float _splitAmountOther, bool _isTopLeftSplit)
	{
		if (_splitOrientation == CameraSplitOrientation.Overlay)
		{
			return;
		}

		isInSplitScreen = true;
		otherCameraRect = KickStarter.mainCamera.GetSplitScreenRect (false);
	}

	private void OnCameraSplitScreenStop (_Camera camera)
	{
		isInSplitScreen = false;
	}

}
Advertisement