mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
WIP
This commit is contained in:
1 parent
6bc6ab7143
commit
8e6f75cfbd
5 files changed
+102
-18
No files matched your search
@@ -0,0 +1,84 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.ImGui;
|
||||
using System;
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MiraAPI.Example.Modifiers;
|
||||
public class ModifierTimerExample : TimedModifier
|
||||
{
|
||||
public override string ModifierName => "Color Changer";
|
||||
public override bool HideOnUi => true;
|
||||
public override bool HideOnUi => false;
|
||||
public override float Duration => 10f;
|
||||
public override bool AutoStart => true;
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ using UnityEngine;
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class CustomRole : ImpostorRole, ICustomRole
|
||||
public class CustomRole : CrewmateRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Custom Role";
|
||||
public string RoleLongDescription => "Eliminate everyone with your special ability!";
|
||||
public string RoleName => "Teleporter";
|
||||
public string RoleLongDescription => "Zoom out and teleport across the map!";
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Black;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
public Color RoleColor => Color.blue;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public abstract class CustomActionButton
|
||||
/// The button object in game. This is created by Mira API automatically.
|
||||
/// </summary>
|
||||
protected ActionButton? Button { get; private set; }
|
||||
|
||||
|
||||
internal void CreateButton(Transform parent)
|
||||
{
|
||||
if (Button)
|
||||
@@ -110,10 +110,10 @@ public abstract class CustomActionButton
|
||||
{
|
||||
OnEffectEnd();
|
||||
}
|
||||
|
||||
|
||||
EffectActive = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A utility function to override the sprite of the button.
|
||||
/// </summary>
|
||||
@@ -239,7 +239,7 @@ public abstract class CustomActionButton
|
||||
{
|
||||
Button?.SetDisabled();
|
||||
}
|
||||
|
||||
|
||||
Button?.SetCoolDown(Timer, EffectActive ? EffectDuration : Cooldown);
|
||||
|
||||
FixedUpdate(playerControl);
|
||||
@@ -256,12 +256,12 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
/// The target object of the button.
|
||||
/// </summary>
|
||||
public T? Target { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The distance the player must be from the target object to use the button.
|
||||
/// </summary>
|
||||
public virtual float Distance => PlayerControl.LocalPlayer.Data.Role.GetAbilityDistance();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// An optional collider tag to filter the target object by.
|
||||
/// </summary>
|
||||
@@ -274,7 +274,7 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The method used to get the target object.
|
||||
/// </summary>
|
||||
@@ -288,8 +288,8 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
/// </summary>
|
||||
/// <param name="active">Should the outline be active</param>
|
||||
public abstract void SetOutline(bool active);
|
||||
|
||||
|
||||
|
||||
|
||||
public override bool CanUse()
|
||||
{
|
||||
var newTarget = GetTarget();
|
||||
@@ -300,7 +300,7 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
|
||||
Target = newTarget;
|
||||
SetOutline(true);
|
||||
|
||||
|
||||
return base.CanUse() && Target;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user