movement and dialogue system

This commit is contained in:
Sylvia 2026-07-25 02:23:50 -07:00
parent 977e666577
commit 1590b5faa6
123 changed files with 62825 additions and 355 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fc94b77ae691ed2dc97c9cd415d3cc98
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
using UnityEngine;
[CreateAssetMenu(fileName = "New Dialogue Character", menuName = "Dialogue/Character")]
public class DialogueCharacter : ScriptableObject
{
public string characterName;
public Sprite portrait;
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6a4c8d6e10ec0d884abbdf0ec9d2213b

View file

@ -0,0 +1,91 @@
using System;
using System.IO;
using TMPro;
using UnityEngine;
public class DialogueManager : MonoBehaviour
{
#region Statication
public static DialogueManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
}
#endregion
[Header("Dialogue Script")]
[SerializeField] private DialogueScript currentDialogueScript;
private int textProgress;
public string[] scriptLines;
[Header("UI")]
public GameObject uiCanvas;
public TextMeshProUGUI nameText;
public TextMeshProUGUI dialogueText;
private void Start()
{
StartDialogue(currentDialogueScript);
}
public void StartDialogue(DialogueScript scriptToShow)
{
uiCanvas.SetActive(true);
currentDialogueScript = scriptToShow;
scriptLines = currentDialogueScript.script.text.Split("\n");
UpdateDialogue();
}
private void ContinueDialogue()
{
textProgress++;
UpdateDialogue();
}
private void UpdateDialogue()
{
string[] words = scriptLines[textProgress].Split(" ");
switch (words[0].ToUpper())
{
case "END":
EndDialogue();
break;
case "TEXT":
foreach (DialogueCharacter character in currentDialogueScript.characters)
{
if (string.Equals(character.name, words[1], StringComparison.CurrentCultureIgnoreCase))
{
nameText.text = character.name;
string text = string.Join(" ", words[2..]);
text = text.Replace("\"", "");
dialogueText.text = text;
break;
}
}
break;
}
}
public void EndDialogue()
{
//TaskManager.instance.AddTask(currentDialogueScript.taskToStart);
uiCanvas.SetActive(false);
currentDialogueScript = null;
scriptLines = null;
}
private void Update()
{
if (currentDialogueScript && Input.GetMouseButtonDown(0))
{
ContinueDialogue();
}
}
}

View file

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

View file

@ -0,0 +1,10 @@
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Dialogue Script", menuName = "Dialogue/Script")]
public class DialogueScript : ScriptableObject
{
public List<DialogueCharacter> characters;
public TextAsset script;
public Task taskToStart;
}

View file

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

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6b510697f62222350956113bd3cbd7f6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,32 @@
using UnityEngine;
public class CombatEntity : Entity
{
[Header("Health")]
public float maxHealth;
public float health;
public bool invulnerable;
public void TakeDamage(float damage)
{
if (!invulnerable)
{
health -= damage;
if (health <= 0)
{
OnDeath();
}
}
}
protected virtual void OnDeath()
{
}
public void Heal(float healing)
{
health += healing;
health = Mathf.Clamp(health, 0, maxHealth);
}
}

View file

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

View file

@ -0,0 +1,5 @@
using UnityEngine;
public class Enemy : CombatEntity
{
}

View file

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

View file

@ -0,0 +1,24 @@
using System;
using UnityEngine;
public class Entity : MonoBehaviour
{
[Header("Movement")]
public float speed;
[SerializeField] protected Rigidbody2D rb;
public Vector3 moveDirection;
public bool noMovement;
protected virtual void Movement()
{
}
private void FixedUpdate()
{
if (!noMovement)
{
Movement();
rb.linearVelocity = moveDirection * speed;
}
}
}

View file

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

View file

@ -0,0 +1,6 @@
using UnityEngine;
public class NPC : Entity
{
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 508d8a9251397eec7bc574ba38c482c9

View file

@ -0,0 +1,22 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : CombatEntity
{
//[Header("Input")]
//private InputAction moveAction;
/*private void Start()
{
//moveAction = InputSystem.actions.FindAction("Move");
}*/
protected override void Movement()
{
base.Movement();
//Debug.Log(moveAction.actionMap);
//moveDirection = moveAction.ReadValue<Vector2>();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 49c22a60b2d3a5d0bbd4c02c922abfe8

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7dcb3ce3530b167ecad0f7c635a70362
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,60 @@
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public class InventoryManager : MonoBehaviour
{
public int maxCapacity;
public int currentlyStored;
public Dictionary<Item, int> storedItems = new();
public Item[] itemList;
public int money;
public bool RemoveMoney(int change)
{
if (money - change >= 0)
{
money -= change;
return true;
}
return false;
}
public void AddMoney(int change)
{
money += change;
}
public int AddItem(Item itemToAdd, int amount = 1)
{
if (currentlyStored < maxCapacity)
{
if (!storedItems.ContainsKey(itemToAdd))
{
storedItems[itemToAdd] = 0;
}
if (currentlyStored + amount <= maxCapacity)
{
storedItems[itemToAdd] += amount;
currentlyStored += amount;
return 0;
}
//return the amount that wasn't able to be stored.
int stored = maxCapacity - currentlyStored;
storedItems[itemToAdd] += stored;
currentlyStored += stored;
amount -= stored;
return amount;
}
return -1;
}
public bool RemoveItem(Item itemToRemove, int amount = 1)
{
if (!storedItems.ContainsKey(itemToRemove) || storedItems[itemToRemove] < amount)
{
return false;
}
storedItems[itemToRemove] -= amount;
return true;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 774be886d08d70001b075b9f5f4db7f7

View file

@ -0,0 +1,8 @@
using UnityEngine;
public class Item : MonoBehaviour
{
public string itemName;
public string description;
public Sprite icon;
}

View file

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

8
Assets/Scripts/Task.meta Normal file
View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a4123fc4e84450cb8d445cbda5473e7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Task", menuName = "Task")]
public class Task : ScriptableObject
{
[Serializable]
public class ItemRequirment
{
public Item item;
public int amount;
}
public string taskName;
public string description;
public bool completed;
public ItemRequirment[] requirements;
public Dictionary<Item, int> itemProgress = new();
}

View file

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

View file

@ -0,0 +1,33 @@
using System.Collections.Generic;
using UnityEngine;
public class TaskManager : MonoBehaviour
{
#region Statication
public static TaskManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
}
#endregion
public List<Task> activeTasks = new();
public int maxTasksActive;
public bool AddTask(Task taskToAdd)
{
if (activeTasks.Count >= maxTasksActive)
{
return false;
}
activeTasks.Add(taskToAdd);
return true;
}
}

View file

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