FiE-Game/Assets/Cinema Director/Cutscene Items/Actor Items/uGUI/CanvasCameraSwitchEvent.cs

51 lines
1.7 KiB
C#
Raw Permalink Normal View History

2023-07-26 21:47:00 +02:00
using UnityEngine;
namespace CinemaDirector
{
[CutsceneItemAttribute("uGUI", "Switch Canvas Camera", CutsceneItemGenre.ActorItem)]
public class CanvasCameraSwitchEvent : CinemaActorEvent
{
public Camera Camera;
Camera initialCamera;
public override void Trigger(GameObject actor)
{
Canvas canvasComponent = actor.GetComponent<Canvas>();
if (actor != null && Camera != null && canvasComponent != null)
{
if (canvasComponent.renderMode == RenderMode.ScreenSpaceOverlay)
{
Debug.LogWarning("Current canvas render mode does not target a camera");
initialCamera = Camera.main;
}
else
{
initialCamera = canvasComponent.worldCamera;
canvasComponent.worldCamera = Camera;
}
}
}
public override void Reverse(GameObject actor)
{
Canvas canvasComponent = actor.GetComponent<Canvas>();
if (actor != null && Camera != null && canvasComponent != null)
{
if (canvasComponent.renderMode == RenderMode.ScreenSpaceOverlay)
Debug.LogWarning("Current canvas render mode does not target a camera");
else
canvasComponent.worldCamera = initialCamera;
}
}
public override void Stop(GameObject actor)
{
Canvas canvasComponent = actor.GetComponent<Canvas>();
if (actor != null && canvasComponent != null)
canvasComponent.worldCamera = initialCamera;
}
}
}