Add scene transition feature
This commit is contained in:
Nico 2025-07-29 23:05:46 -07:00
parent aa104db4bb
commit a74d9fc9ab
13 changed files with 1345 additions and 26 deletions

1258
Assets/Scenes/Menu.unity Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4d64280c7fd6bdc47982b68ea90aedbf
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -115,9 +115,9 @@ public class Gobler : Enemy {
case State.ChasePlayer:
AggroOnPlayer = true;
if (!AggroOnPlayer) TextPopUp.SpawnFloatingText("!", Color.red);
PathAgent.isStopped = false;
TextPopUp.SpawnFloatingText("!", Color.red);
AggroOnPlayer = true;
break;
@ -125,7 +125,7 @@ public class Gobler : Enemy {
AggroOnCrystal = false;
AggroOnPlayer = false;
PathAgent.isStopped = true;
TextPopUp.SpawnFloatingText(DamageTaken.ToString(), Color.red, 3);
TextPopUp.SpawnFloatingText(DamageTaken.ToString(), Color.white, 3);
MaterialColorOverlay.SetColor("_FlashColor", Color.white);
break;

View File

@ -6,6 +6,7 @@ using System.Linq;
public class PlayerCombatHandler : AttackerAndDamageable {
public bool TakingDamage;
protected FloatingTextSpawner TextPopUp;
public PlayerCombatHandler() {
BaseDamage = 10;
@ -18,7 +19,9 @@ public class PlayerCombatHandler : AttackerAndDamageable {
FrameFreezeDuration = 0.3f;
IsKnockable = true;
OnTakeDamage += (damage, dir) => TakingDamage = true;
TextPopUp = new FloatingTextSpawner(Player.Instance.transform, 1);
OnTakeDamage += (damage, dir) => InitializeTakenDamage();
foreach (var material in Player.Instance.GetComponentsInChildren<SpriteRenderer>().Select(x => x.material).ToList()) {
switch (material.name.Split(' ')[0]) {
@ -27,12 +30,16 @@ public class PlayerCombatHandler : AttackerAndDamageable {
}
}
private void InitializeTakenDamage() {
TextPopUp.SpawnFloatingText(DamageTaken.ToString(), Color.red, 3);
TakingDamage = true;
}
public void ApplyKnockback() {
if (IsInvincible) {
var velocity = DirectionOfDamage * Knockback * 10 * InvincibilityLeft;
var isWalkable = NavMeshUtils.IsWalkable(Player.Instance.Rigidbody.transform.position, DirectionOfDamage);
Player.Instance.Rigidbody.linearVelocity = isWalkable ? velocity : Vector2.zero;
//Rigidbody.linearVelocity = velocity;
Player.Instance.MaterialColorOverlay.SetFloat("_FlashAmount", InvincibilityLeft / InvincibilityDuration);
} else {
TakingDamage = false;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
public class FloatingTextSpawner {
@ -22,14 +23,16 @@ public class FloatingTextSpawner {
GameObject textObj = new GameObject("FloatingText");
textObj.transform.position = Transform.position + new Vector3(0, 1, 1); // offset above character
TextMesh textMesh = textObj.AddComponent<TextMesh>();
textMesh.text = message;
textMesh.characterSize = 0.2f;
textMesh.fontSize = 48;
textMesh.fontStyle = FontStyle.Bold;
textMesh.color = color;
textMesh.alignment = TextAlignment.Center;
textMesh.anchor = TextAnchor.MiddleCenter;
TextMeshPro text = textObj.AddComponent<TextMeshPro>();
text.text = message;
//text.size = 0.2f;
text.fontSize = 14;
text.fontStyle = FontStyles.Bold;
text.color = color;
text.alignment = TextAlignmentOptions.Center;
//text.anchor = TextAnchor.MiddleCenter;
text.outlineColor = Color.black;
text.outlineWidth = 0.4f;
Renderer renderer = textObj.GetComponent<Renderer>();
renderer.sortingLayerName = "UI";
@ -46,23 +49,23 @@ public class FloatingText : MonoBehaviour {
private float lifetime;
private float speed = 1f;
private Color originalColor;
private TextMesh textMesh;
private TextMeshPro text;
public void Init(float duration, ref List<Transform> textList, float yOffset) {
try {
lifetime = duration;
textMesh = GetComponent<TextMesh>();
originalColor = textMesh.color;
text = GetComponent<TextMeshPro>();
originalColor = text.color;
for (int i = textList.Count - 1; i >= 0; i--) {
if (textList[i] == null)
textList.RemoveAt(i);
else
textList[i].position += Vector3.up * yOffset;
}
//for (int i = textList.Count - 1; i >= 0; i--) {
// if (textList[i] == null)
// textList.RemoveAt(i);
// else
// textList[i].position += Vector3.up * yOffset;
//}
textList.Add(this.transform);
//textList.Add(this.transform);
} catch (Exception e) { }
}
@ -76,7 +79,7 @@ public class FloatingText : MonoBehaviour {
Destroy(gameObject);
} else {
float alpha = Mathf.Clamp01(lifetime / 1.5f);
textMesh.color = new Color(originalColor.r, originalColor.g, originalColor.b, alpha);
text.color = new Color(originalColor.r, originalColor.g, originalColor.b, alpha);
}
} catch (Exception e) { }

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class ButtonHandler : MonoBehaviour {
public void MenuStartNewGame() {
UnityEngine.SceneManagement.SceneManager.LoadScene("HomeTown");
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3afba20f3713e63469a9cfb92e9aabf3

View File

@ -0,0 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class SceneManager {
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3fcf642a990b68d4fa4a91e079df21f1

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Runtime.GameManagement {
internal class SceneTransition {
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e3d178074a821f64cb9338b7ad04b674

View File

@ -8,6 +8,9 @@ EditorBuildSettings:
- enabled: 1
path: Assets/Scenes/HomeTown.unity
guid: 2cda990e2423bbf4892e6590ba056729
- enabled: 1
path: Assets/Scenes/Menu.unity
guid: 4d64280c7fd6bdc47982b68ea90aedbf
m_configObjects:
com.unity.input.settings: {fileID: 11400000, guid: 480aae9acac4ce7498145b34771ad78a, type: 2}
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 3590b91b4603b465dbb4216d601bff33, type: 3}

View File

@ -12,10 +12,13 @@ EditorUserSettings:
value: 5554570006545b0e590f0d24457a5e444e154a7d752d72687e2a4835bab66039
flags: 0
RecentlyUsedSceneGuid-1:
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
value: 5505005f01565f095f58552144770644121540287e2e22342b2c1f67b5e26769
flags: 0
RecentlyUsedSceneGuid-2:
value: 5505005f01565f095f58552144770644121540287e2e22342b2c1f67b5e26769
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
flags: 0
RecentlyUsedSceneGuid-3:
value: 57550252570d59585a08087412275c44414e40782e7e7e352c704d32e7e4363e
flags: 0
UIBuilder.EditorExtensionModeKey:
value: 37434103