Files
RaindropViewer/Assets/ButtonTriggerViewTransition.cs
T
2022-02-06 13:03:21 +08:00

54 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Lean.Gui;
using Raindrop;
using Raindrop.ServiceLocator;
using Raindrop.Services;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
using Logger = OpenMetaverse.Logger;
// This component allows you to bring up the scene that the button is supposed to lead to.
public class ButtonTriggerViewTransition : MonoBehaviour
{
public CanvasType canvasTypeToPush;
[FormerlySerializedAs("popCurrent")] public bool popAndPush;
private void Start()
{
try
{
if (this.GetComponent<LeanButton>())
{
this.GetComponent<LeanButton>().OnClick.AddListener(OnClick);
}
if (this.GetComponent<Button>())
{
this.GetComponent<Button>().onClick.AddListener(OnClick);
}
}
catch (Exception e)
{
Logger.DebugLog(e.ToString());
}
}
private void OnClick()
{
if (canvasTypeToPush == CanvasType.POP)
{
ServiceLocator.Instance.Get<UIService>().ScreensManager.PopCanvas();
return;
}
if (popAndPush)
{
ServiceLocator.Instance.Get<UIService>().ScreensManager.PopAndPush(canvasTypeToPush);
} else
{
ServiceLocator.Instance.Get<UIService>().ScreensManager.Push(canvasTypeToPush);
}
}
}