movement and dialogue system
This commit is contained in:
parent
977e666577
commit
1590b5faa6
123 changed files with 62825 additions and 355 deletions
8
Assets/Scripts/Dialogue.meta
Normal file
8
Assets/Scripts/Dialogue.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fc94b77ae691ed2dc97c9cd415d3cc98
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Assets/Scripts/Dialogue/DialogueCharacter.cs
Normal file
7
Assets/Scripts/Dialogue/DialogueCharacter.cs
Normal 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;
|
||||
}
|
||||
2
Assets/Scripts/Dialogue/DialogueCharacter.cs.meta
Normal file
2
Assets/Scripts/Dialogue/DialogueCharacter.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a4c8d6e10ec0d884abbdf0ec9d2213b
|
||||
91
Assets/Scripts/Dialogue/DialogueManager.cs
Normal file
91
Assets/Scripts/Dialogue/DialogueManager.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Dialogue/DialogueManager.cs.meta
Normal file
2
Assets/Scripts/Dialogue/DialogueManager.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e15aad8b4f467043aa1dab68b726d945
|
||||
10
Assets/Scripts/Dialogue/DialogueScript.cs
Normal file
10
Assets/Scripts/Dialogue/DialogueScript.cs
Normal 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;
|
||||
}
|
||||
2
Assets/Scripts/Dialogue/DialogueScript.cs.meta
Normal file
2
Assets/Scripts/Dialogue/DialogueScript.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f22a9deacfe82225495c03952e48a825
|
||||
8
Assets/Scripts/Entity.meta
Normal file
8
Assets/Scripts/Entity.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b510697f62222350956113bd3cbd7f6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Entity/CombatEntity.cs
Normal file
32
Assets/Scripts/Entity/CombatEntity.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entity/CombatEntity.cs.meta
Normal file
2
Assets/Scripts/Entity/CombatEntity.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c45670385a48a3b59bed49dfec987a32
|
||||
5
Assets/Scripts/Entity/Enemy.cs
Normal file
5
Assets/Scripts/Entity/Enemy.cs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Enemy : CombatEntity
|
||||
{
|
||||
}
|
||||
2
Assets/Scripts/Entity/Enemy.cs.meta
Normal file
2
Assets/Scripts/Entity/Enemy.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f58572e837a31d71b911561d242ca9a5
|
||||
24
Assets/Scripts/Entity/Entity.cs
Normal file
24
Assets/Scripts/Entity/Entity.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entity/Entity.cs.meta
Normal file
2
Assets/Scripts/Entity/Entity.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c6adc30fe056ad940a67442392bffb78
|
||||
6
Assets/Scripts/Entity/NPC.cs
Normal file
6
Assets/Scripts/Entity/NPC.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class NPC : Entity
|
||||
{
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Entity/NPC.cs.meta
Normal file
2
Assets/Scripts/Entity/NPC.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 508d8a9251397eec7bc574ba38c482c9
|
||||
22
Assets/Scripts/Entity/Player.cs
Normal file
22
Assets/Scripts/Entity/Player.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entity/Player.cs.meta
Normal file
2
Assets/Scripts/Entity/Player.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 49c22a60b2d3a5d0bbd4c02c922abfe8
|
||||
8
Assets/Scripts/Inventory.meta
Normal file
8
Assets/Scripts/Inventory.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7dcb3ce3530b167ecad0f7c635a70362
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
Assets/Scripts/Inventory/InventoryManager.cs
Normal file
60
Assets/Scripts/Inventory/InventoryManager.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Inventory/InventoryManager.cs.meta
Normal file
2
Assets/Scripts/Inventory/InventoryManager.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 774be886d08d70001b075b9f5f4db7f7
|
||||
8
Assets/Scripts/Inventory/Item.cs
Normal file
8
Assets/Scripts/Inventory/Item.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Item : MonoBehaviour
|
||||
{
|
||||
public string itemName;
|
||||
public string description;
|
||||
public Sprite icon;
|
||||
}
|
||||
2
Assets/Scripts/Inventory/Item.cs.meta
Normal file
2
Assets/Scripts/Inventory/Item.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a100b9e8279440fd88e58bae66ffb885
|
||||
8
Assets/Scripts/Task.meta
Normal file
8
Assets/Scripts/Task.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a4123fc4e84450cb8d445cbda5473e7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/Task/Task.cs
Normal file
20
Assets/Scripts/Task/Task.cs
Normal 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();
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Task/Task.cs.meta
Normal file
2
Assets/Scripts/Task/Task.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c01ddc715d8c67a484f6db39ab1dea8
|
||||
33
Assets/Scripts/Task/TaskManager.cs
Normal file
33
Assets/Scripts/Task/TaskManager.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Task/TaskManager.cs.meta
Normal file
2
Assets/Scripts/Task/TaskManager.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f33e52582ba6110ea0373ae52f6ae9d
|
||||
Loading…
Add table
Add a link
Reference in a new issue