From fa8fdfc4f66fba2cec46b8135214f6183a2228e2 Mon Sep 17 00:00:00 2001 From: ang-xd Date: Wed, 4 Sep 2024 17:30:08 -0400 Subject: [PATCH] Create ChameleonRole.cs --- MiraAPI.Example/Roles/ChameleonRole.cs | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 MiraAPI.Example/Roles/ChameleonRole.cs diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs new file mode 100644 index 0000000..4c10d55 --- /dev/null +++ b/MiraAPI.Example/Roles/ChameleonRole.cs @@ -0,0 +1,46 @@ +using MiraAPI.Roles; +using MiraAPI.Utilities.Assets; +using TMPro; +using UnityEngine; + +namespace MiraAPI.Example.Roles; + +[RegisterCustomRole] +public class ChameloenRole : CrewmateRole, ICustomRole +{ + public string RoleName => "Chamelon"; + public string RoleLongDescription => "Stay invisible while not moving."; + public string RoleDescription => RoleLongDescription; + public Color RoleColor => Palette.AcceptedGreen; + public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; + public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; + public int MaxPlayers => 2; + + public void PlayerControlFixedUpdate(PlayerControl playerControl) + { + if (playerControl.MyPhysics.Velocity.magnitude > 0) + { + SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite; + TextMeshPro tmp = playerControl.cosmetics.nameText; + tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, 1), Time.deltaTime * 4f); + rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, 1), Time.deltaTime * 4f); + + foreach (var cosmetic in playerControl.cosmetics.transform.GetComponentsInChildren()) + { + cosmetic.color = Color.Lerp(cosmetic.color, new Color(1, 1, 1, 1), Time.deltaTime * 4f); + } + } + else + { + SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite; + TextMeshPro tmp = playerControl.cosmetics.nameText; + tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f); + rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f); + + foreach (var cosmetic in playerControl.cosmetics.transform.GetComponentsInChildren()) + { + cosmetic.color = Color.Lerp(cosmetic.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f); + } + } + } +} \ No newline at end of file