mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
85 lines
2.9 KiB
C#
85 lines
2.9 KiB
C#
using MiraAPI.Example.Roles;
|
|
using MiraAPI.Hud;
|
|
using MiraAPI.Utilities.Assets;
|
|
using Reactor.Utilities;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace MiraAPI.Example.Buttons.Teleporter;
|
|
[RegisterButton]
|
|
public class TeleportButton : CustomActionButton
|
|
{
|
|
public override string Name => "Teleport";
|
|
|
|
public override float Cooldown => 3;
|
|
|
|
public override float EffectDuration => 10;
|
|
|
|
public override int MaxUses => 0;
|
|
|
|
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
|
public static bool IsZoom { get; private set; }
|
|
|
|
public override bool Enabled(RoleBehaviour role)
|
|
{
|
|
return role is CustomRole;
|
|
}
|
|
protected override void OnClick()
|
|
{
|
|
Coroutines.Start(ZoomOutCoroutine());
|
|
}
|
|
|
|
public override void OnEffectEnd()
|
|
{
|
|
Coroutines.Start(ZoomInCoroutine());
|
|
}
|
|
|
|
protected override void FixedUpdate(PlayerControl playerControl)
|
|
{
|
|
base.FixedUpdate(playerControl);
|
|
|
|
if (!HasEffect) return; // this doesnt work...
|
|
|
|
if (Input.GetKeyDown(KeyCode.Mouse0))
|
|
{
|
|
playerControl.NetTransform.RpcSnapTo(Camera.main.ScreenToWorldPoint(Input.mousePosition));
|
|
OnEffectEnd();
|
|
}
|
|
}
|
|
|
|
private static IEnumerator ZoomOutCoroutine()
|
|
{
|
|
HudManager.Instance.ShadowQuad.gameObject.SetActive(false);
|
|
IsZoom = true;
|
|
var zoomDistance = 6;
|
|
for (var ft = Camera.main!.orthographicSize; ft < zoomDistance; ft += 0.3f)
|
|
{
|
|
Camera.main.orthographicSize = MeetingHud.Instance ? 3f : ft;
|
|
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
|
foreach (var cam in Camera.allCameras) cam.orthographicSize = Camera.main.orthographicSize;
|
|
yield return null;
|
|
}
|
|
|
|
foreach (var cam in Camera.allCameras) cam.orthographicSize = zoomDistance;
|
|
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
|
}
|
|
|
|
private static IEnumerator ZoomInCoroutine()
|
|
{
|
|
for (var ft = Camera.main!.orthographicSize; ft > 3f; ft -= 0.3f)
|
|
{
|
|
Camera.main.orthographicSize = MeetingHud.Instance ? 3f : ft;
|
|
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
|
foreach (var cam in Camera.allCameras) cam.orthographicSize = Camera.main.orthographicSize;
|
|
|
|
yield return null;
|
|
}
|
|
|
|
foreach (var cam in Camera.allCameras) cam.orthographicSize = 3f;
|
|
HudManager.Instance.ShadowQuad.gameObject.SetActive(true);
|
|
IsZoom = false;
|
|
|
|
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
|
}
|
|
}
|