restructure script folder

This commit is contained in:
2026-03-07 14:42:14 -06:00
parent 94fa81168d
commit 1e08b70e2c
33 changed files with 40 additions and 17 deletions
@@ -0,0 +1,13 @@
using UnityEngine;
public class BurriedItem : Diggable
{
public GameObject ItemToSpawn;
public Transform Spawnpoint;
public override void Dig()
{
Instantiate(ItemToSpawn, Spawnpoint.position, Spawnpoint.rotation, null);
Destroy(gameObject);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 086f0ec780ccd914cb5cdc02852d9254
@@ -0,0 +1,6 @@
using UnityEngine;
public abstract class Diggable : MonoBehaviour
{
public abstract void Dig();
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b927d0dd24f719438bf4d72abbab1fa
@@ -0,0 +1,11 @@
using UnityEngine;
public abstract class Interactable : MonoBehaviour
{
public abstract void Interact();
// for entering/exiting trigger regions
public abstract void MoveInsideRange();
public abstract void MoveOutsideRange();
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 93469a9daba3a934aa97867b44cc5ecb
+58
View File
@@ -0,0 +1,58 @@
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
// This is the actual ITEM data structure for keeping track of inventory/item actions
public class Item
{
public string itemName;
public ItemIdEnum id;
public int maxStack = 10;
public string description = "";
public string itemImagePath = "";
public Item(string itemName, ItemIdEnum id, int maxStack, string description, string itemImagePath)
{
this.itemName = itemName;
this.id = id;
this.maxStack = maxStack;
this.description = description;
this.itemImagePath = itemImagePath;
}
public Item(ItemIdEnum id)
{
Item newItem = ItemUtilities.GetItemFromId(id);
this.itemName = newItem.itemName;
this.id = newItem.id;
this.maxStack = newItem.maxStack;
this.description = newItem.description;
this.itemImagePath= newItem.itemImagePath;
}
}
public enum ItemIdEnum
{
NONE = 0,
STAR_SHARD = 1
}
public static class ItemUtilities
{
// THIS IS WHERE ALL THE ITEMS ARE DEFINED
public static Item GetItemFromId(ItemIdEnum itemId)
{
switch (itemId)
{
case ItemIdEnum.STAR_SHARD:
return new Item(
itemName: "Star Shard",
id: itemId,
maxStack: 10,
description: "A rare material that can only be found here in the valley.",
itemImagePath: "ItemSprites/starShard");
}
return new Item("", itemId, 0, "", "ItemSprites/noneItem"); ;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: aa43c795f1a58fa4785593558036d0b3
@@ -0,0 +1,35 @@
using UnityEngine;
// this class is specifically referring to items in the world that can be picked up
public class PickupableItem : Interactable
{
public ItemIdEnum itemId;
public int quantity;
private Item itemObj;
private void Start()
{
itemObj = new Item(itemId);
Debug.Log(itemObj.itemName);
}
public override void Interact()
{
if (GameManager.Instance.Inventory.AddItem(itemObj, quantity))
{
MoveOutsideRange(); // I don't love this but if we destroy the object we probably need to do this first
Destroy(gameObject);
}
}
public override void MoveInsideRange()
{
GameManager.Instance.DialogueManager.ShowItemText(itemObj.itemName);
}
public override void MoveOutsideRange()
{
GameManager.Instance.DialogueManager.HideItemText();
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e3bb397f7c2c8ee47bc71df7f8d491bf
@@ -0,0 +1,57 @@
using UnityEngine;
public class RoomDoor : Interactable
{
public RoomDoor linkedDoor;
public bool requiresInteraction; // Do we need to press a button to enter?
// transform that the character should walk towards when entering the room
// through this door
public Transform WalkDirection;
TeleportHandler teleportHandler;
// not required and only plays if interaction is required
public Animation doorAnimator;
public AnimationClip openDoor;
public AnimationClip closeDoor;
private void Start()
{
teleportHandler = GameObject.FindWithTag("Player").GetComponent<TeleportHandler>();
}
public override void Interact()
{
if (requiresInteraction)
{
if (doorAnimator && openDoor)
{
doorAnimator.clip = openDoor;
doorAnimator.Play();
}
teleportHandler.EnterRoom(this);
}
}
public void CloseDoor()
{
if (doorAnimator && closeDoor)
{
doorAnimator.clip = closeDoor;
doorAnimator.Play();
}
}
public override void MoveInsideRange()
{
if (!requiresInteraction)
{
teleportHandler.EnterRoom(this);
}
}
public override void MoveOutsideRange()
{
// Do nothing
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f99c228d7f83ab54fb3a97a8f13fb239
@@ -0,0 +1,33 @@
using UnityEngine;
public class SceneDoor : Interactable
{
// ID of THIS door
public int DoorId = 0;
// What scene does this door take us to?
public string SceneToLoad = "";
// Which door does this lead to in the scene this door takes us to?
public int IdOfCorrespondingDoor = 0;
// transform that the character should walk towards when entering the room
// through this door
public Transform WalkDirection;
public override void Interact()
{
// Do nothing
}
public override void MoveInsideRange()
{
if (!GameManager.Instance.InSceneTransition())
GameManager.Instance.EnterSceneDoor(SceneToLoad, DoorId);
}
public override void MoveOutsideRange()
{
// Do nothing
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8e99e84716dcf704abb5593bc6c91a40
+102
View File
@@ -0,0 +1,102 @@
using UnityEngine;
public class Talkable : Interactable
{
// this is a character or object that will talk upon interaction
public Dialogue defaultDialogue;
public GameObject talkIndicator;
public Quest[] quests;
Dialogue currentDialogue;
public void Start()
{
talkIndicator.SetActive(false);
}
void DetermineDialogue()
{
// based on if we have any open quests and where we're at in the quest,
// determine what dialogue to show
Quest currentQuest = null;
// Grab the first ACTIVE quest
// If none active, grab the first AVAILABLE quest
// If none available, revert to default dialogue
if (quests.Length > 0)
{
// check for ACTIVE quests
foreach (Quest q in quests)
{
if (q.hasStarted && !q.hasCompleted)
{
currentQuest = q;
}
}
// check for AVAILABLE quests
if (currentQuest == null)
{
foreach (Quest q in quests)
{
if (!q.hasStarted && !q.hasCompleted)
{
currentQuest = q;
}
}
}
}
// revert to default if no suitable quest found
if (currentQuest == null)
{
currentDialogue = defaultDialogue;
}
else
{
if (currentQuest.hasStarted)
currentQuest.CheckComplete(); // don't check for completion before asking player for help
currentDialogue = new Dialogue();
currentDialogue.charName = defaultDialogue.charName;
// set up dialogue based on quest
if (currentQuest.hasStarted && !currentQuest.hasCompleted)
{
currentDialogue.sentences = currentQuest.duringText;
}
else if (!currentQuest.hasStarted && !currentQuest.hasCompleted)
{
currentDialogue.sentences = currentQuest.askText;
currentQuest.StartQuest();
}
else
{
currentDialogue.sentences = currentQuest.completionText;
}
}
}
public override void Interact()
{
if (currentDialogue == null || !currentDialogue.isActive)
{
DetermineDialogue();
GameManager.Instance.DialogueManager.StartDialogue(currentDialogue);
}
else
GameManager.Instance.DialogueManager.DisplayNextSentence();
talkIndicator.SetActive(false);
}
public override void MoveInsideRange()
{
talkIndicator.SetActive(true);
}
public override void MoveOutsideRange()
{
GameManager.Instance.DialogueManager.EndDialogue();
talkIndicator.SetActive(false);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e85641f45d2eb9b458bbba38374b1360