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

View File

@ -6,6 +6,7 @@ using System.Linq;
public class PlayerCombatHandler : AttackerAndDamageable { public class PlayerCombatHandler : AttackerAndDamageable {
public bool TakingDamage; public bool TakingDamage;
protected FloatingTextSpawner TextPopUp;
public PlayerCombatHandler() { public PlayerCombatHandler() {
BaseDamage = 10; BaseDamage = 10;
@ -18,7 +19,9 @@ public class PlayerCombatHandler : AttackerAndDamageable {
FrameFreezeDuration = 0.3f; FrameFreezeDuration = 0.3f;
IsKnockable = true; 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()) { foreach (var material in Player.Instance.GetComponentsInChildren<SpriteRenderer>().Select(x => x.material).ToList()) {
switch (material.name.Split(' ')[0]) { 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() { public void ApplyKnockback() {
if (IsInvincible) { if (IsInvincible) {
var velocity = DirectionOfDamage * Knockback * 10 * InvincibilityLeft; var velocity = DirectionOfDamage * Knockback * 10 * InvincibilityLeft;
var isWalkable = NavMeshUtils.IsWalkable(Player.Instance.Rigidbody.transform.position, DirectionOfDamage); var isWalkable = NavMeshUtils.IsWalkable(Player.Instance.Rigidbody.transform.position, DirectionOfDamage);
Player.Instance.Rigidbody.linearVelocity = isWalkable ? velocity : Vector2.zero; Player.Instance.Rigidbody.linearVelocity = isWalkable ? velocity : Vector2.zero;
//Rigidbody.linearVelocity = velocity;
Player.Instance.MaterialColorOverlay.SetFloat("_FlashAmount", InvincibilityLeft / InvincibilityDuration); Player.Instance.MaterialColorOverlay.SetFloat("_FlashAmount", InvincibilityLeft / InvincibilityDuration);
} else { } else {
TakingDamage = false; TakingDamage = false;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TMPro;
using UnityEngine; using UnityEngine;
public class FloatingTextSpawner { public class FloatingTextSpawner {
@ -22,14 +23,16 @@ public class FloatingTextSpawner {
GameObject textObj = new GameObject("FloatingText"); GameObject textObj = new GameObject("FloatingText");
textObj.transform.position = Transform.position + new Vector3(0, 1, 1); // offset above character textObj.transform.position = Transform.position + new Vector3(0, 1, 1); // offset above character
TextMesh textMesh = textObj.AddComponent<TextMesh>(); TextMeshPro text = textObj.AddComponent<TextMeshPro>();
textMesh.text = message; text.text = message;
textMesh.characterSize = 0.2f; //text.size = 0.2f;
textMesh.fontSize = 48; text.fontSize = 14;
textMesh.fontStyle = FontStyle.Bold; text.fontStyle = FontStyles.Bold;
textMesh.color = color; text.color = color;
textMesh.alignment = TextAlignment.Center; text.alignment = TextAlignmentOptions.Center;
textMesh.anchor = TextAnchor.MiddleCenter; //text.anchor = TextAnchor.MiddleCenter;
text.outlineColor = Color.black;
text.outlineWidth = 0.4f;
Renderer renderer = textObj.GetComponent<Renderer>(); Renderer renderer = textObj.GetComponent<Renderer>();
renderer.sortingLayerName = "UI"; renderer.sortingLayerName = "UI";
@ -46,23 +49,23 @@ public class FloatingText : MonoBehaviour {
private float lifetime; private float lifetime;
private float speed = 1f; private float speed = 1f;
private Color originalColor; private Color originalColor;
private TextMesh textMesh; private TextMeshPro text;
public void Init(float duration, ref List<Transform> textList, float yOffset) { public void Init(float duration, ref List<Transform> textList, float yOffset) {
try { try {
lifetime = duration; lifetime = duration;
textMesh = GetComponent<TextMesh>(); text = GetComponent<TextMeshPro>();
originalColor = textMesh.color; originalColor = text.color;
for (int i = textList.Count - 1; i >= 0; i--) { //for (int i = textList.Count - 1; i >= 0; i--) {
if (textList[i] == null) // if (textList[i] == null)
textList.RemoveAt(i); // textList.RemoveAt(i);
else // else
textList[i].position += Vector3.up * yOffset; // textList[i].position += Vector3.up * yOffset;
} //}
textList.Add(this.transform); //textList.Add(this.transform);
} catch (Exception e) { } } catch (Exception e) { }
} }
@ -76,7 +79,7 @@ public class FloatingText : MonoBehaviour {
Destroy(gameObject); Destroy(gameObject);
} else { } else {
float alpha = Mathf.Clamp01(lifetime / 1.5f); 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) { } } 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 - enabled: 1
path: Assets/Scenes/HomeTown.unity path: Assets/Scenes/HomeTown.unity
guid: 2cda990e2423bbf4892e6590ba056729 guid: 2cda990e2423bbf4892e6590ba056729
- enabled: 1
path: Assets/Scenes/Menu.unity
guid: 4d64280c7fd6bdc47982b68ea90aedbf
m_configObjects: m_configObjects:
com.unity.input.settings: {fileID: 11400000, guid: 480aae9acac4ce7498145b34771ad78a, type: 2} com.unity.input.settings: {fileID: 11400000, guid: 480aae9acac4ce7498145b34771ad78a, type: 2}
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 3590b91b4603b465dbb4216d601bff33, type: 3} com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 3590b91b4603b465dbb4216d601bff33, type: 3}

View File

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