diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity
index 80cf350fa2908209ac124d7fc59dff8fd61975c3..9af62f5f4ed097e28fb92edb48c1e2bc23d39c87 100644
--- a/Assets/Scenes/Main.unity
+++ b/Assets/Scenes/Main.unity
@@ -5255,17 +5255,14 @@ PrefabInstance:
- {fileID: 8455667667674168468, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
- {fileID: 100008, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
m_AddedGameObjects: []
- m_AddedComponents:
- - targetCorrespondingSourceObject: {fileID: 100006, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
- insertIndex: -1
- addedObject: {fileID: 2023876524}
+ m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
--- !u!114 &1641232234 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 11400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
m_PrefabInstance: {fileID: 1641232233}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1974427093}
+ m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c32067ea884548644b13cf9baddd4573, type: 3}
@@ -6735,12 +6732,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 615057aa5dd75e34383756f1bf0fa143, type: 3}
m_Name:
m_EditorClassIdentifier:
+ healingPet: {fileID: 7022846624846827769, guid: f86d09f168862644d8d36c6929850322, type: 3}
+ attackingPet: {fileID: 7022846624846827769, guid: 89d690d2254d9714f88745a7913a6bf3, type: 3}
fileName: data.game
---- !u!1 &1974427093 stripped
-GameObject:
- m_CorrespondingSourceObject: {fileID: 100006, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
- m_PrefabInstance: {fileID: 1641232233}
- m_PrefabAsset: {fileID: 0}
--- !u!1 &1979757893
GameObject:
m_ObjectHideFlags: 0
@@ -6832,18 +6826,6 @@ Animator:
m_CorrespondingSourceObject: {fileID: 9500000, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3}
m_PrefabInstance: {fileID: 1641232233}
m_PrefabAsset: {fileID: 0}
---- !u!114 &2023876524
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1974427093}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: 472ec104c593ad9439f5dbb57bd16de6, type: 3}
- m_Name:
- m_EditorClassIdentifier:
--- !u!1 &2025282751
GameObject:
m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/Camera/CameraFollow.cs b/Assets/Scripts/Camera/CameraFollow.cs
index 5e3ebe8d79067eb4752772ed47092ab68f77b7d0..e02e4fa89dec8bdb553baf29b30563fc3b4abe0e 100644
--- a/Assets/Scripts/Camera/CameraFollow.cs
+++ b/Assets/Scripts/Camera/CameraFollow.cs
@@ -3,7 +3,7 @@ using System.Collections;
namespace Nightmare
{
- public class CameraFollow : MonoBehaviour, IDataPersistance
+ public class CameraFollow : MonoBehaviour
{
public Transform target; // The position that that camera will be following.
public float smoothing = 5f; // The speed with which the camera will be following.
@@ -24,19 +24,5 @@ namespace Nightmare
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
-
- public void LoadData(GameData data)
- {
- if (data.cameraPosition != Vector3.zero)
- {
- this.transform.position = data.cameraPosition;
- }
- }
-
- public void SaveData(ref GameData data)
- {
- data.cameraPosition = this.transform.position;
- }
-
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/Camera/CameraPosition.cs b/Assets/Scripts/Camera/CameraPosition.cs
deleted file mode 100644
index d663007ef8c1f56b52b799fd5486e107b8c81097..0000000000000000000000000000000000000000
--- a/Assets/Scripts/Camera/CameraPosition.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class CameraPosition : MonoBehaviour
-{
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
-
- }
- //public void LoadData(GameData data)
- //{
- // this.transform.position = data.cameraPosition;
- //}
-
- //public void SaveData(ref GameData data)
- //{
- // data.cameraPosition = this.transform.position;
- //}
-}
diff --git a/Assets/Scripts/Camera/CameraPosition.cs.meta b/Assets/Scripts/Camera/CameraPosition.cs.meta
deleted file mode 100644
index 96dd0796cd9eb15dd49e9f7494933b7ff209614a..0000000000000000000000000000000000000000
--- a/Assets/Scripts/Camera/CameraPosition.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 0bb2d3419e085b341a2beb50ff4e439c
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/DataPersistance/Data/GameData.cs b/Assets/Scripts/DataPersistance/Data/GameData.cs
index ad5baf5415b2057622bca3960f652af62e08c1ce..6edb16289057da9aa6644f8c8cfe3bf9855412d8 100644
--- a/Assets/Scripts/DataPersistance/Data/GameData.cs
+++ b/Assets/Scripts/DataPersistance/Data/GameData.cs
@@ -8,10 +8,14 @@ public class GameData
{
// public int timer;
public int playerHealth;
+ public Vector3 playerPosition;
+ public int balance;
+
public float damagePercent;
- public Vector3 playerPosition;
- public Vector3 cameraPosition;
+ public List<int> healingPetHealths;
+ public List<int> attackingPetHealths;
+
public int score;
public int shotsFired;
@@ -29,7 +33,12 @@ public class GameData
this.playerHealth = 100;
this.damagePercent = 1;
this.playerPosition = Vector3.zero;
- this.cameraPosition = Vector3.zero;
+ this.balance = 0;
+
+
+
+ this.healingPetHealths = new List<int>();
+ this.attackingPetHealths = new List<int>();
// Statistics
this.score = 0;
diff --git a/Assets/Scripts/DataPersistance/DataPersistanceManager.cs b/Assets/Scripts/DataPersistance/DataPersistanceManager.cs
index 9944b64235eea2b349141c6818b47696e87263cf..480938e9338c2b91ce383f6b710498f3450dd7d6 100644
--- a/Assets/Scripts/DataPersistance/DataPersistanceManager.cs
+++ b/Assets/Scripts/DataPersistance/DataPersistanceManager.cs
@@ -2,9 +2,17 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
+using Nightmare;
+
public class DataPersistanceManager : MonoBehaviour
{
+ [Header("Pet Prefabs")]
+
+ [SerializeField] public GameObject healingPet;
+ [SerializeField] public GameObject attackingPet;
+
+
[Header("File Storage Config")]
[SerializeField] private string fileName;
@@ -29,7 +37,6 @@ public class DataPersistanceManager : MonoBehaviour
private void Start()
{
this.dataHandler = new FileDataHandler(Application.persistentDataPath, fileName);
- this.dataPersistanceObjects = FindAllDataPersistanceObjects();
LoadGame();
}
@@ -49,6 +56,37 @@ public class DataPersistanceManager : MonoBehaviour
{
NewGame();
}
+ else
+ {
+ if (this.gameData.healingPetHealths.Count != 0)
+ {
+ foreach (int healingPetHealth in this.gameData.healingPetHealths)
+ {
+ GameObject pet = Instantiate(healingPet, gameData.playerPosition, Quaternion.identity);
+ AllyPetHealth petHealthScript = pet.GetComponent<AllyPetHealth>();
+ if (petHealthScript != null)
+ {
+ petHealthScript.currentHealth = healingPetHealth;
+ }
+ }
+ this.gameData.healingPetHealths.Clear();
+ }
+ if (this.gameData.attackingPetHealths.Count != 0)
+ {
+ foreach (int attackingPetHealth in this.gameData.attackingPetHealths)
+ {
+ GameObject pet = Instantiate(attackingPet, gameData.playerPosition, Quaternion.identity);
+ AllyPetHealth petHealthScript = pet.GetComponent<AllyPetHealth>();
+ if (petHealthScript != null)
+ {
+ petHealthScript.currentHealth = attackingPetHealth;
+ }
+ }
+ this.gameData.attackingPetHealths.Clear();
+ }
+ }
+
+ this.dataPersistanceObjects = FindAllDataPersistanceObjects();
// push the loaded data to all other scipts that need it
foreach (IDataPersistance dataPersistanceObj in dataPersistanceObjects)
@@ -59,6 +97,8 @@ public class DataPersistanceManager : MonoBehaviour
}
public void SaveGame()
{
+ this.dataPersistanceObjects = FindAllDataPersistanceObjects();
+
// pass the data to other scripts so they can update it
foreach (IDataPersistance dataPersistanceObj in dataPersistanceObjects)
{
diff --git a/Assets/Scripts/Pets/AllyPetHealth.cs b/Assets/Scripts/Pets/AllyPetHealth.cs
index a294a6b9cefbdfa566ad98afbd8a7bfca4c86f2b..eeb2703e3c8bfaa5d3f821d74b5117ef8f1ad1ab 100644
--- a/Assets/Scripts/Pets/AllyPetHealth.cs
+++ b/Assets/Scripts/Pets/AllyPetHealth.cs
@@ -10,7 +10,7 @@ namespace Nightmare
Animator anim;
CapsuleCollider capsuleCollider;
- int currentHealth;
+ public int currentHealth;
// Cheat Full HP Pet
public bool isCheatFullHPPet = false;
diff --git a/Assets/Scripts/Pets/AttackingPetMovement.cs b/Assets/Scripts/Pets/AttackingPetMovement.cs
index 64ca5da688fe219566c2ab0943879c4ad8da6ebe..99b5210dcae7c8273580d9798487552dbb6a748a 100644
--- a/Assets/Scripts/Pets/AttackingPetMovement.cs
+++ b/Assets/Scripts/Pets/AttackingPetMovement.cs
@@ -5,29 +5,32 @@ using UnityEngine.Events;
namespace Nightmare
{
- public class AttackingPetMovement : PausibleObject
+ public class AttackingPetMovement : PausibleObject, IDataPersistance
{
public float visionRange = 10f;
public float wanderDistance = 10f;
public Vector2 idleTimeRange;
- [Range(0f,1f)]
+ [Range(0f, 1f)]
- float currentVision;
+ float currentVision;
Transform player;
PlayerHealth playerHealth;
- Animator anim;
+ Animator anim;
NavMeshAgent nav;
public float timer = 0f;
float attackTimer = 0f;
- void Awake ()
+ private AllyPetHealth allyPetHealthScript;
+
+ void Awake()
{
- player = GameObject.FindGameObjectWithTag ("Player").transform;
- playerHealth = player.GetComponent <PlayerHealth> ();
+ player = GameObject.FindGameObjectWithTag("Player").transform;
+ playerHealth = player.GetComponent<PlayerHealth>();
nav = GetComponent<NavMeshAgent>();
anim = GetComponent<Animator>();
+ allyPetHealthScript = GetComponent<AllyPetHealth>();
StartPausible();
}
@@ -46,7 +49,7 @@ namespace Nightmare
nav.ResetPath();
}
- void Update ()
+ void Update()
{
if (!isPaused)
{
@@ -95,7 +98,7 @@ namespace Nightmare
nav.isStopped = false;
}
- private GameObject getNearestEnemy()
+ private GameObject getNearestEnemy()
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
float nearestDistance = Mathf.Infinity;
@@ -140,7 +143,7 @@ namespace Nightmare
timer = -1f;
// if (!enemyHealth.IsDead()) TODO: verify pet health
// {
- SetDestination(position);
+ SetDestination(position);
// }
}
@@ -174,7 +177,7 @@ namespace Nightmare
private Vector3 GetRandomPoint(float distance, int layermask)
{
- Vector3 randomPoint = UnityEngine.Random.insideUnitSphere * distance + this.transform.position;;
+ Vector3 randomPoint = UnityEngine.Random.insideUnitSphere * distance + this.transform.position; ;
NavMeshHit navHit;
NavMesh.SamplePosition(randomPoint, out navHit, distance, layermask);
@@ -195,5 +198,18 @@ namespace Nightmare
return navHit.mask;
}
+ public void LoadData(GameData data)
+ {
+ // Do Nothing
+ }
+
+ public void SaveData(ref GameData data)
+ {
+ if (allyPetHealthScript.CurrentHealth() > 0)
+ {
+ data.attackingPetHealths.Add(allyPetHealthScript.CurrentHealth());
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/Pets/HealingPetMovement.cs b/Assets/Scripts/Pets/HealingPetMovement.cs
index 587250feafba7f4161750849cd989d0e51f6694d..ba2f49099a2a0d9694c6a35e966048c31181a090 100644
--- a/Assets/Scripts/Pets/HealingPetMovement.cs
+++ b/Assets/Scripts/Pets/HealingPetMovement.cs
@@ -5,29 +5,32 @@ using UnityEngine.Events;
namespace Nightmare
{
- public class HealingPetMovement : PausibleObject
+ public class HealingPetMovement : PausibleObject, IDataPersistance
{
public float visionRange = 10f;
public float hearingRange = 20f;
public float wanderDistance = 10f;
public Vector2 idleTimeRange;
- [Range(0f,1f)]
+ [Range(0f, 1f)]
public float psychicLevels = 0.2f;
- float currentVision;
+ float currentVision;
Transform player;
PlayerHealth playerHealth;
- Animator anim;
+ Animator anim;
NavMeshAgent nav;
public float timer = 0f;
- void Awake ()
+
+ private AllyPetHealth allyPetHealthScript;
+ void Awake()
{
anim = GetComponent<Animator>();
- player = GameObject.FindGameObjectWithTag ("Player").transform;
- playerHealth = player.GetComponent <PlayerHealth> ();
+ player = GameObject.FindGameObjectWithTag("Player").transform;
+ playerHealth = player.GetComponent<PlayerHealth>();
nav = GetComponent<NavMeshAgent>();
+ allyPetHealthScript = GetComponent<AllyPetHealth>();
StartPausible();
}
@@ -46,7 +49,7 @@ namespace Nightmare
nav.ResetPath();
}
- void Update ()
+ void Update()
{
if (!isPaused)
{
@@ -120,7 +123,7 @@ namespace Nightmare
{
timer = -1f;
SetDestination(position);
-
+
}
private void SetDestination(Vector3 position)
@@ -153,7 +156,7 @@ namespace Nightmare
private Vector3 GetRandomPoint(float distance, int layermask)
{
- Vector3 randomPoint = UnityEngine.Random.insideUnitSphere * distance + this.transform.position;;
+ Vector3 randomPoint = UnityEngine.Random.insideUnitSphere * distance + this.transform.position; ;
NavMeshHit navHit;
NavMesh.SamplePosition(randomPoint, out navHit, distance, layermask);
@@ -174,5 +177,18 @@ namespace Nightmare
return navHit.mask;
}
+ public void LoadData(GameData data)
+ {
+ // Do nothing
+ }
+
+ public void SaveData(ref GameData data)
+ {
+ if (allyPetHealthScript.CurrentHealth() > 0)
+ {
+ data.healingPetHealths.Add(allyPetHealthScript.CurrentHealth());
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/Player/PlayerCurrency.cs b/Assets/Scripts/Player/PlayerCurrency.cs
index bc6cc5765a8cf2b4715ea7811c5d8689b29a9eac..101037ddf14e4618aadc2041e135440f3fa33f63 100644
--- a/Assets/Scripts/Player/PlayerCurrency.cs
+++ b/Assets/Scripts/Player/PlayerCurrency.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
-public class PlayerCurrency : MonoBehaviour
+public class PlayerCurrency : MonoBehaviour, IDataPersistance
{
public int balance = 0;
int prevBalance;
@@ -40,4 +40,14 @@ public class PlayerCurrency : MonoBehaviour
{
balance = prevBalance;
}
+
+ public void LoadData(GameData data)
+ {
+ this.balance = data.balance;
+ }
+
+ public void SaveData(ref GameData data)
+ {
+ data.balance = this.balance;
+ }
}
diff --git a/Assets/Scripts/Player/PlayerPosition.cs b/Assets/Scripts/Player/PlayerPosition.cs
index 5562906036fad64be2c57142d0f046b8a479dd37..ad956983cd04249863f63083fa7e517b717a47b6 100644
--- a/Assets/Scripts/Player/PlayerPosition.cs
+++ b/Assets/Scripts/Player/PlayerPosition.cs
@@ -7,18 +7,18 @@ public class PlayerPosition : MonoBehaviour, IDataPersistance
// Start is called before the first frame update
void Start()
{
-
+
}
// Update is called once per frame
void Update()
{
-
+
}
public void LoadData(GameData data)
{
- this.transform.position = data.playerPosition;
+ // this.transform.position = data.playerPosition;
}
public void SaveData(ref GameData data)