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