Skip to content

Commit

Permalink
Add animation to secret names in weapon select
Browse files Browse the repository at this point in the history
  • Loading branch information
Fueredoriku committed May 18, 2024
1 parent f67ed3b commit bd77e85
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 5 deletions.
21 changes: 18 additions & 3 deletions Assets/Prefabs/Input/ItemSelectPlayer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ GameObject:
- component: {fileID: 4211975233605593382}
- component: {fileID: 8418915769774603709}
- component: {fileID: 3316381399893442416}
- component: {fileID: 5078958741745354244}
m_Layer: 5
m_Name: SecretName
m_TagString: Untagged
Expand Down Expand Up @@ -572,7 +573,7 @@ MonoBehaviour:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 1
m_enableVertexGradient: 0
m_colorMode: 0
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
Expand All @@ -584,7 +585,7 @@ MonoBehaviour:
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_overrideHtmlColors: 1
m_faceColor:
serializedVersion: 2
rgba: 4294967295
Expand Down Expand Up @@ -630,6 +631,20 @@ MonoBehaviour:
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!114 &5078958741745354244
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5328186668431144849}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bf224422e4b57df4b861b374a0006e4a, type: 3}
m_Name:
m_EditorClassIdentifier:
textMesh: {fileID: 3316381399893442416}
AnimateText: 0
--- !u!1 &6006424913092988723
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1120,7 +1135,7 @@ MonoBehaviour:
barrelSlot: {fileID: 2486123476282149344}
extensionSlot: {fileID: 6440613788510747136}
playerStatUI: {fileID: 5425617339122362748}
secretName: {fileID: 3316381399893442416}
secretName: {fileID: 5078958741745354244}
readyIndicator: {fileID: 351594924326642278}
switchAudio: {fileID: 8300000, guid: cacd836afb9e3f643837bd6598f137b1, type: 3}
scrollAudio: {fileID: 8300000, guid: a5a4cf79a7503d34da12bd3969f9ddfe, type: 3}
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/Augment/GunFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ public static string GetGunName(Item body, Item barrel, Item extension)
return $"The {body.secretName.Capitalized()} {extension.secretName.Capitalized()} {barrel.secretName.Capitalized()}";
}

public static string GetGunName(Item body, Item barrel, Item extension, out bool isSecret)
{
OverrideName result = StaticInfo.Singleton.SecretNames
.FirstOrDefault(x => x.Body == body && x.Barrel == barrel && x.Extension == extension);
isSecret = result.Name is not null;
if (isSecret)
return result.Name;

if (extension == null)
return $"The {body.secretName.Capitalized()} {barrel.secretName.Capitalized()}";

return $"The {body.secretName.Capitalized()} {extension.secretName.Capitalized()} {barrel.secretName.Capitalized()}";
}

public static bool TryGetGunAchievement(Item body, Item barrel, Item extension, out AchievementType achievement)
{
OverrideName result = StaticInfo.Singleton.SecretNames
Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Control&Input/ItemSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ItemSelectMenu : MonoBehaviour
private PlayerStatUI playerStatUI;

[SerializeField]
private TMP_Text secretName;
private SecretNameTextAnimator secretName;

[SerializeField]
private RectTransform readyIndicator;
Expand Down Expand Up @@ -244,7 +244,9 @@ public void SetLoadout()
barrelSlot.SelectedItem,
extensionSlot.SelectedItem);
playerStatUI.UpdateStats();
secretName.text = player.GetGunName();
secretName.textMesh.text = player.GetGunName(out bool isSecret);
bool isInteresting = isSecret && !secretName.textMesh.text.Equals("The Starter");
secretName.IsAnimated = isInteresting;
}

private void SelectPerformed(InputAction.CallbackContext ctx)
Expand Down
57 changes: 57 additions & 0 deletions Assets/Scripts/UI/SecretNameTextAnimator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class SecretNameTextAnimator : MonoBehaviour
{
public TMP_Text textMesh;
private bool isAnimated;
public bool IsAnimated
{
get
{
return isAnimated;
}
set
{
if (value)
StartCoroutine(AnimateText());
if (!value)
StopAllCoroutines();
isAnimated = value;
}
}

private IEnumerator AnimateText()
{
while (true)
{
textMesh.ForceMeshUpdate();
var textInfo = textMesh.textInfo;
for (int i = 0; i < textInfo.characterCount; i++)
{
var charInfo = textInfo.characterInfo[i];
if (!charInfo.isVisible)
continue;

var charVertices = textInfo.meshInfo[charInfo.materialReferenceIndex].vertices;
for (int j = 0; j < 4; j++)
{
var position = charVertices[charInfo.vertexIndex + j];
charVertices[charInfo.vertexIndex + j] = position + new Vector3(0f, Mathf.Sin(Time.time * 2f + position.x * 0.01f) * 10f, 0f);
Color32 rainbow = Color.HSVToRGB(Mathf.Abs(Mathf.Sin(Time.time * 0.5f + position.x * 0.1f)), 0.8f, 1.0f);
textInfo.meshInfo[charInfo.materialReferenceIndex].colors32[charInfo.vertexIndex + j] = rainbow;
}
}
textMesh.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
var meshInfo = textInfo.meshInfo[i];
meshInfo.mesh.vertices = meshInfo.vertices;
textMesh.UpdateGeometry(meshInfo.mesh, i);
}
yield return null;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/UI/SecretNameTextAnimator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Assets/Scripts/Utils/SecretName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public static string GetGunName(this PlayerManager playerManager)
return playerManager.identity.GetGunName();
}

public static string GetGunName(this PlayerIdentity playerIdentity, out bool isSecret)
{
string name = GunFactory.GetGunName(playerIdentity.Body, playerIdentity.Barrel, playerIdentity.Extension, out var secret);
isSecret = secret;
return name;
}

public static string Capitalized(this string s)
{
return $"{s.Substring(0, 1).ToUpper()}{s.Substring(1).ToLower()}";
Expand Down

0 comments on commit bd77e85

Please sign in to comment.