travail sur le save et le load

problème : pas de moyen de sauvegarder et de charger les niveaux entamés

solution : fonctions save et load dans le LevelManager
This commit is contained in:
Felix Boucher 2023-05-26 22:07:14 -04:00
parent 08c9171262
commit 4fbce56853
20 changed files with 1970 additions and 802 deletions

View File

@ -1,31 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8442e6f4be8799444b7bd9703a5c88dc, type: 3}
m_Name: Database
m_EditorClassIdentifier:
database:
_prefabs:
- {fileID: 6962989255644195630, guid: 6cd87b398e7a0e94580f4fcbe2fd310a, type: 3}
- {fileID: 6962989255644195630, guid: 377c7275c0001cc47a6b8926ac57d573, type: 3}
- {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3}
- {fileID: 6962989255644195630, guid: 9b40c232eddfd1b469bea688e3c970c0, type: 3}
- {fileID: 4052934186652138539, guid: 8560e1f66d452b543a705c8a0f3e22fa, type: 3}
- {fileID: 3814095509541806390, guid: 9527f3a1482b90a48bb6c62acc70f986, type: 3}
_scriptableObjects:
- {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
- {fileID: 11400000, guid: e715669e1ed4b294c82d07ac011e89bb, type: 2}
- {fileID: 11400000, guid: a6e34739c9325da4cac4fbaea30d052c, type: 2}
- {fileID: 11400000, guid: d37561e153d6a6448a03839488fdec5e, type: 2}
_folders:
- {fileID: 102900000, guid: f3dee7994db941e47b9445cb464c69a9, type: 3}
- {fileID: 102900000, guid: 4f8284570682f8f4c954e446b35ea0ae, type: 3}
- {fileID: 102900000, guid: 0ca30b5ca281be24bb62d7e48cc2bec8, type: 3}

View File

@ -2,7 +2,6 @@
using UnityEngine.Tilemaps; using UnityEngine.Tilemaps;
using UnityEngine; using UnityEngine;
using System.IO; using System.IO;
using static UnityEngine.GraphicsBuffer;
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
namespace GatherAndDefend.LevelEditor namespace GatherAndDefend.LevelEditor

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,35 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_data: _data:
- _key: Background - _key: Background
tiles: _tiles:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -8, y: -5, z: 0} _position: {x: -10, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -10, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -10, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -10, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -10, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -10, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -10, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -9, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -8, y: -4, z: 0} _position: {x: -8, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -30,7 +56,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -8, y: 1, z: 0} _position: {x: -8, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -7, y: -5, z: 0} _position: {x: -8, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -7, y: -4, z: 0} _position: {x: -7, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -44,7 +70,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -7, y: 1, z: 0} _position: {x: -7, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -6, y: -5, z: 0} _position: {x: -7, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -6, y: -4, z: 0} _position: {x: -6, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -58,7 +84,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -6, y: 1, z: 0} _position: {x: -6, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -5, y: -5, z: 0} _position: {x: -6, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -5, y: -4, z: 0} _position: {x: -5, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -72,7 +98,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -5, y: 1, z: 0} _position: {x: -5, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: -5, z: 0} _position: {x: -5, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: -4, z: 0} _position: {x: -4, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -86,7 +112,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: 1, z: 0} _position: {x: -4, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -5, z: 0} _position: {x: -4, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -4, z: 0} _position: {x: -3, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -100,7 +126,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: 1, z: 0} _position: {x: -3, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -5, z: 0} _position: {x: -3, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -4, z: 0} _position: {x: -2, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -114,7 +140,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: 1, z: 0} _position: {x: -2, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -5, z: 0} _position: {x: -2, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -4, z: 0} _position: {x: -1, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -128,7 +154,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: 1, z: 0} _position: {x: -1, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -5, z: 0} _position: {x: -1, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -4, z: 0} _position: {x: 0, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -142,7 +168,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: 1, z: 0} _position: {x: 0, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -5, z: 0} _position: {x: 0, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -4, z: 0} _position: {x: 1, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -156,7 +182,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: 1, z: 0} _position: {x: 1, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -5, z: 0} _position: {x: 1, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -4, z: 0} _position: {x: 2, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -170,7 +196,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: 1, z: 0} _position: {x: 2, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -5, z: 0} _position: {x: 2, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -4, z: 0} _position: {x: 3, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -184,7 +210,7 @@ MonoBehaviour:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: 1, z: 0} _position: {x: 3, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: -5, z: 0} _position: {x: 3, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: -4, z: 0} _position: {x: 4, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
@ -197,71 +223,212 @@ MonoBehaviour:
_position: {x: 4, y: 0, z: 0} _position: {x: 4, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: 1, z: 0} _position: {x: 4, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 5, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 6, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 7, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 8, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 9, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 10, y: 2, z: 0}
_isInvisible: 0
_isCollidable: 0
_isTrigger: 0
_renderOrder: 0
_renderLayer: Default
- _key: Entities - _key: Entities
tiles: _tiles:
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: -5, z: 0} _position: {x: -10, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: -3, z: 0} _position: {x: -10, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: -1, z: 0} _position: {x: -10, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: 1, z: 0} _position: {x: -10, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: -5, z: 0} _position: {x: -8, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: -3, z: 0} _position: {x: -8, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: -1, z: 0} _position: {x: -8, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: 1, z: 0} _position: {x: -8, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: -5, z: 0} _position: {x: -6, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: -3, z: 0} _position: {x: -6, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: -1, z: 0} _position: {x: -6, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: 1, z: 0} _position: {x: -6, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: -5, z: 0} _position: {x: -4, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: -3, z: 0} _position: {x: -4, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: -1, z: 0} _position: {x: -4, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: 1, z: 0} _position: {x: -4, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: -5, z: 0} _position: {x: -2, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: -3, z: 0} _position: {x: -2, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: -1, z: 0} _position: {x: -2, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: 1, z: 0} _position: {x: -2, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: -5, z: 0} _position: {x: 0, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: -3, z: 0} _position: {x: 0, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: -1, z: 0} _position: {x: 0, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: 1, z: 0} _position: {x: 0, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -5, z: 0} _position: {x: 2, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -3, z: 0} _position: {x: 2, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -1, z: 0} _position: {x: 2, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2} - _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: 1, z: 0} _position: {x: 2, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 6, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 6, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 6, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 6, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 8, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 8, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 8, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 8, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 10, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 10, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 10, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 10, y: 2, z: 0}
_isInvisible: 0
_isCollidable: 0
_isTrigger: 0
_renderOrder: 0
_renderLayer: Default
- _key: Spawners - _key: Spawners
tiles: _tiles:
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2} - _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: -5, z: 0} _position: {x: -10, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2} - _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: -3, z: 0} _position: {x: -10, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2} - _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: -1, z: 0} _position: {x: -10, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2} - _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: 1, z: 0} _position: {x: -10, y: 2, z: 0}
- _tile: {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2}
_position: {x: 10, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2}
_position: {x: 10, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2}
_position: {x: 10, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2}
_position: {x: 10, y: 2, z: 0}
_isInvisible: 1
_isCollidable: 0
_isTrigger: 0
_renderOrder: 2
_renderLayer: Default

31
Assets/New Database.asset Normal file
View File

@ -0,0 +1,31 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: edb1aa3d6230b1e4c9a50056da756015, type: 3}
m_Name: New Database
m_EditorClassIdentifier:
_prefabs:
- {fileID: 6962989255644195630, guid: 6cd87b398e7a0e94580f4fcbe2fd310a, type: 3}
- {fileID: 6962989255644195630, guid: 377c7275c0001cc47a6b8926ac57d573, type: 3}
- {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3}
- {fileID: 6962989255644195630, guid: 9b40c232eddfd1b469bea688e3c970c0, type: 3}
- {fileID: 4052934186652138539, guid: 8560e1f66d452b543a705c8a0f3e22fa, type: 3}
- {fileID: 3814095509541806390, guid: 9527f3a1482b90a48bb6c62acc70f986, type: 3}
_scriptableObjects:
- {fileID: 11400000, guid: e715669e1ed4b294c82d07ac011e89bb, type: 2}
- {fileID: 11400000, guid: a6e34739c9325da4cac4fbaea30d052c, type: 2}
- {fileID: 11400000, guid: d37561e153d6a6448a03839488fdec5e, type: 2}
- {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2}
- {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_folders:
- {fileID: 102900000, guid: 0ca30b5ca281be24bb62d7e48cc2bec8, type: 3}
- {fileID: 102900000, guid: f3dee7994db941e47b9445cb464c69a9, type: 3}
- {fileID: 102900000, guid: 4f8284570682f8f4c954e446b35ea0ae, type: 3}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a4bf69f8ff62be443a8177430eb8e28a guid: 8fac5b907c0463e4590e43f7fedee816
NativeFormatImporter: NativeFormatImporter:
externalObjects: {} externalObjects: {}
mainObjectFileID: 11400000 mainObjectFileID: 11400000

View File

@ -67,11 +67,9 @@ public class Entity : LevelObject
#region [LevelManager code] #region [LevelManager code]
public override bool Equals(ILevelObject other) public override bool Equals(ILevelObject other)
{ {
if (!(other is Entity)) return false; return other is Entity otherEntity
var otherEntity = other as Entity; && base.Equals(otherEntity)
return otherEntity._hp == _hp && otherEntity._hp == _hp
&& otherEntity.Position == Position
&& otherEntity.Name == Name
&& otherEntity._speed == _speed && otherEntity._speed == _speed
&& otherEntity._attack_speed == _attack_speed && otherEntity._attack_speed == _attack_speed
&& otherEntity._attack_damage == _attack_damage; && otherEntity._attack_damage == _attack_damage;
@ -79,7 +77,14 @@ public class Entity : LevelObject
public override Dictionary<string, object> ToDictionary() public override Dictionary<string, object> ToDictionary()
{ {
return Extensions.ToDictionary(this); var dict = base.ToDictionary();
dict[nameof(_hp)] = _hp;
dict[nameof(_speed)] = _speed;
dict[nameof(_attack_speed)] = _attack_speed;
dict[nameof(_attack_damage)] = _attack_damage;
return dict;
} }
#endregion #endregion
} }

View File

@ -8,7 +8,7 @@ using System;
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
[CustomEditor(typeof(DatabaseSO))] [CustomEditor(typeof(Database))]
public class DatabaseEditor : Editor public class DatabaseEditor : Editor
{ {
public override void OnInspectorGUI() public override void OnInspectorGUI()
@ -17,7 +17,7 @@ public class DatabaseEditor : Editor
if (GUILayout.Button("fetch assets")) if (GUILayout.Button("fetch assets"))
{ {
var targ = target as DatabaseSO; var targ = target as Database;
@ -54,9 +54,16 @@ public class DatabaseEditor : Editor
} }
#endif #endif
[Serializable] [CreateAssetMenu(menuName = "Gather And Defend/Database")]
public class Database : Singleton<Database> public class Database : ScriptableObject
{ {
public static Database Instance
{
get;
private set;
}
public const string TYPE = nameof(TYPE);
[Serializable] [Serializable]
public class DataList<T> : IEnumerable<T> where T : UnityEngine.Object public class DataList<T> : IEnumerable<T> where T : UnityEngine.Object
{ {
@ -89,19 +96,13 @@ public class Database : Singleton<Database>
public DataList<GameObject> Prefabs => _prefabs; public DataList<GameObject> Prefabs => _prefabs;
public DataList<ScriptableObject> ScriptableObjects => _scriptableObjects; public DataList<ScriptableObject> ScriptableObjects => _scriptableObjects;
public Database() public Database()
{ {
if (!Instance) Instance = this;
_prefabs = new List<GameObject>(); _prefabs = new List<GameObject>();
_scriptableObjects = new List<ScriptableObject>(); _scriptableObjects = new List<ScriptableObject>();
} }
}
[CreateAssetMenu(menuName = "Gather And Defend/Database")]
public class DatabaseSO : ScriptableObject
{
[SerializeField]
private Database database = Database.Instance;
[Header("Editor section")] [Header("Editor section")]
[SerializeField] [SerializeField]
private List<DefaultAsset> _folders; private List<DefaultAsset> _folders;

View File

@ -1,11 +1,11 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8442e6f4be8799444b7bd9703a5c88dc guid: edb1aa3d6230b1e4c9a50056da756015
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {fileID: 2800000, guid: b6a96c7c65795c94abf54a62adbf5c38, type: 3} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:

View File

@ -5,6 +5,14 @@ using UnityEngine;
public static class Extensions public static class Extensions
{ {
public static T GetComponentInChildren<T>(this Component obj, string name) where T : Component
{
foreach (var comp in obj.GetComponentsInChildren<T>())
{
if (comp.name == name) return comp;
}
return null;
}
public enum LevelObjectType { GameObject, Tile } public enum LevelObjectType { GameObject, Tile }
public static bool Approximately(this Vector3 vect, Vector3 other) public static bool Approximately(this Vector3 vect, Vector3 other)
{ {

View File

@ -0,0 +1,17 @@
using UnityEngine;
public class SingletonSO<T> : ScriptableObject where T : SingletonSO<T>
{
private static T _instance;
public static T Instance
{
get
{
if (!_instance)
{
_instance = CreateInstance<T>();
}
return _instance;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d7329f36f451bd2479a760e1fc38e1a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,4 +10,6 @@ public interface ILevelObject
void LevelDestroy(); void LevelDestroy();
bool Equals(ILevelObject other); bool Equals(ILevelObject other);
Dictionary<string, object> ToDictionary(); Dictionary<string, object> ToDictionary();
void LoadDictionary(Dictionary<string, object> dict);
void RemoveFromLevel();
} }

View File

@ -2,7 +2,33 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Unity.Plastic.Newtonsoft.Json; using Unity.Plastic.Newtonsoft.Json;
using UnityEngine; using UnityEngine;
using UnityEngine.Tilemaps;
using GatherAndDefend.LevelEditor;
#region [custom inspector]
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(LevelManagerScript))]
public class LevelManagerEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (GUILayout.Button("Save"))
{
LevelManager.Instance.SaveLevel();
}
if (GUILayout.Button("Load"))
{
LevelManager.Instance.LoadSave();
}
}
}
#endif
#endregion
#region [singleton level manager]
public class LevelManager : Singleton<LevelManager> public class LevelManager : Singleton<LevelManager>
{ {
public delegate void LevelAction(ILevelObject levelObject); public delegate void LevelAction(ILevelObject levelObject);
@ -10,9 +36,11 @@ public class LevelManager : Singleton<LevelManager>
public event LevelAction Added; public event LevelAction Added;
public event LevelAction Removed; public event LevelAction Removed;
private readonly List<ILevelObject> toAdd; private readonly List<ILevelObject> _toAdd;
private readonly List<ILevelObject> toRemove; private readonly List<ILevelObject> _toRemove;
private readonly List<ILevelObject> levelObjects; private readonly List<ILevelObject> _levelObjects;
public Level _currentLevel;
public Transform LevelTransform public Transform LevelTransform
{ {
@ -20,88 +48,173 @@ public class LevelManager : Singleton<LevelManager>
} }
public LevelManager() public LevelManager()
{ {
toAdd = new List<ILevelObject>(); _toAdd = new List<ILevelObject>();
toRemove = new List<ILevelObject>(); _toRemove = new List<ILevelObject>();
levelObjects = new List<ILevelObject>(); _levelObjects = new List<ILevelObject>();
var mgrScript = Object.FindObjectOfType<LevelManagerScript>(); var mgrScript = Object.FindObjectOfType<LevelManagerScript>();
if (!mgrScript) mgrScript = new GameObject(nameof(LevelManager)).AddComponent<LevelManagerScript>(); if (!mgrScript) mgrScript = new GameObject(nameof(LevelManager)).AddComponent<LevelManagerScript>();
LevelTransform = mgrScript.transform; LevelTransform = mgrScript.transform;
} }
#region [~CRUD~]
public void Add(ILevelObject levelObject) public void Add(ILevelObject levelObject)
{ {
toAdd.Add(levelObject); _toAdd.Add(levelObject);
} }
public void Remove(ILevelObject levelObject) public void Remove(ILevelObject levelObject)
{ {
toRemove.Add(levelObject); _toRemove.Add(levelObject);
} }
public void Clear() public void Clear()
{ {
toAdd.Clear(); _toAdd.Clear();
toRemove.Clear(); _toRemove.Clear();
levelObjects.Clear(); _levelObjects.Clear();
} }
public T Get<T>(LevelPredicate<T> predicate = null) where T : ILevelObject public T Get<T>(LevelPredicate<T> predicate = null) where T : ILevelObject
{ {
if (predicate == null) predicate = (generic) => true; if (predicate == null) predicate = (generic) => true;
return (T)levelObjects.Find(levelObject => levelObject is T generic && predicate(generic)); return (T)_levelObjects.Find(levelObject => levelObject is T generic && predicate(generic));
} }
public List<T> GetAll<T>(LevelPredicate<T> predicate = null) where T : ILevelObject public List<T> GetAll<T>(LevelPredicate<T> predicate = null) where T : ILevelObject
{ {
if (predicate == null) predicate = (generic) => true; if (predicate == null) predicate = (generic) => true;
List<T> ret = new(); List<T> ret = new();
foreach (var levelObject in levelObjects) if (levelObject is T generic && predicate(generic)) ret.Add(generic); foreach (var levelObject in _levelObjects) if (levelObject is T generic && predicate(generic)) ret.Add(generic);
return ret; return ret;
} }
public int Count<T>(LevelPredicate<T> predicate = null) where T : ILevelObject public int Count<T>(LevelPredicate<T> predicate = null) where T : ILevelObject
{ {
return GetAll(predicate).Count; return GetAll(predicate).Count;
} }
public bool Has<T>(LevelPredicate<T> predicate = null) where T : ILevelObject public bool Has<T>(LevelPredicate<T> predicate = null) where T : ILevelObject
{ {
if (predicate == null) predicate = (generic) => true; if (predicate == null) predicate = (generic) => true;
return levelObjects.Exists(levelObject => levelObject is T generic && predicate(generic)); return _levelObjects.Exists(levelObject => levelObject is T generic && predicate(generic));
} }
#endregion
#region [Level management]
public void UpdateLevel() public void UpdateLevel()
{ {
levelObjects.ForEach(levelObject => levelObject.LevelUpdate()); _levelObjects.ForEach(levelObject => levelObject.LevelUpdate());
var toAdd = new List<ILevelObject>(this.toAdd); var toAdd = new List<ILevelObject>(this._toAdd);
toAdd.ForEach(addedObject => toAdd.ForEach(addedObject =>
{ {
this.toAdd.Remove(addedObject); this._toAdd.Remove(addedObject);
levelObjects.Add(addedObject); _levelObjects.Add(addedObject);
Added?.Invoke(addedObject); Added?.Invoke(addedObject);
addedObject.LevelStart(); addedObject.LevelStart();
}); });
var toRemove = new List<ILevelObject>(this.toRemove); var toRemove = new List<ILevelObject>(this._toRemove);
toRemove.ForEach(removedObject => toRemove.ForEach(removedObject =>
{ {
this.toRemove.Remove(removedObject); this._toRemove.Remove(removedObject);
levelObjects.Remove(removedObject); _levelObjects.Remove(removedObject);
Removed?.Invoke(removedObject); Removed?.Invoke(removedObject);
removedObject.LevelDestroy(); removedObject.LevelDestroy();
}); });
toRemove.Clear(); toRemove.Clear();
} }
void SaveLevel()
{
var list = levelObjects.Select(obj => obj.ToDictionary()).ToList();
Debug.Log(JsonConvert.SerializeObject(list));
}
void LoadLevel()
{
private string saved;
public void ClearLevel()
{
foreach (var obj in _levelObjects)
{
obj.RemoveFromLevel();
}
Clear();
} }
public void SaveLevel()
{
var list = _levelObjects.Select(obj => obj.ToDictionary()).ToList();
list.Add(new Dictionary<string, object>()
{
{Database.TYPE, "Level" },
{"Name", _currentLevel.name }
});
saved = JsonConvert.SerializeObject(list);
Debug.Log("game saved successfully");
}
public void LoadLevel(string levelName, bool clear = false)
{
if (clear)
{
ClearLevel();
}
//fetch level from database
_currentLevel = Database.Instance.ScriptableObjects[levelName] as Level;
Grid grid = Object.FindObjectOfType<Grid>();
//create new grid if there is none
if (!grid)
{
grid = new GameObject("Grid").AddComponent<Grid>();
}
//remove all tilemaps if there is a grid
else
{
foreach (Transform child in grid.transform)
{
Object.Destroy(child.gameObject);
}
}
//generate all tilemaps
foreach (TilemapData tilemapData in _currentLevel)
{
var tilemap = new GameObject(tilemapData.Key).AddComponent<Tilemap>();
tilemap.gameObject.AddComponent<TilemapRenderer>();
tilemapData.LoadToTilemap(tilemap);
tilemap.transform.SetParent(grid.transform);
}
Debug.Log("level loaded successfully");
}
public void LoadSave()
{
ClearLevel();
var dicts = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(saved);
//instantiate all prefabs
foreach (var dict in JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(saved))
{
switch (dict[Database.TYPE].ToString())
{
case nameof(Database.Prefabs):
CreatePrefab(dict);
break;
case nameof(Level):
LoadLevel(dict["Name"].ToString());
break;
}
}
Debug.Log("game loaded successfully");
}
private void CreatePrefab(Dictionary<string, object> dict)
{
var name = dict["Name"].ToString();
var prefab = Database.Instance.Prefabs[name];
var instance = Object.Instantiate(prefab, LevelTransform);
var comp = instance.GetComponent<LevelObject>();
comp.LoadDictionary(dict);
}
#endregion
} }
#endregion
#region [mono behaviour]
public class LevelManagerScript : MonoBehaviour public class LevelManagerScript : MonoBehaviour
{ {
public Level firstLevel;
private static LevelManagerScript _instance; private static LevelManagerScript _instance;
void Awake() void Awake()
{ {
@ -109,9 +222,11 @@ public class LevelManagerScript : MonoBehaviour
else Destroy(gameObject); else Destroy(gameObject);
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
LevelManager.Instance.LoadLevel(firstLevel.name, true);
} }
void Update() void Update()
{ {
LevelManager.Instance.UpdateLevel(); LevelManager.Instance.UpdateLevel();
} }
} }
#endregion

View File

@ -8,9 +8,9 @@ using static Extensions;
public abstract class LevelObject : MonoBehaviour, ILevelObject public abstract class LevelObject : MonoBehaviour, ILevelObject
{ {
[LevelSerialize] [LevelSerialize]
public Vector3 Position => transform.position; public Vector3 Position { get => transform.position; protected set => transform.position = value; }
[LevelSerialize] [LevelSerialize]
public string Name => name; public string Name { get => name; protected set => name = value; }
void Awake() void Awake()
{ {
@ -20,7 +20,7 @@ public abstract class LevelObject : MonoBehaviour, ILevelObject
} }
public virtual void LevelStart() public virtual void LevelStart()
{ {
} }
public virtual void LevelDestroy() public virtual void LevelDestroy()
{ {
@ -31,11 +31,28 @@ public abstract class LevelObject : MonoBehaviour, ILevelObject
public virtual bool Equals(ILevelObject other) public virtual bool Equals(ILevelObject other)
{ {
if (!other.GetType().Equals(this.GetType())) return false; return other is LevelObject otherObject
&& otherObject.Name == Name
var otherObject = other as LevelObject;
return otherObject.Name == Name
&& otherObject.Position == Position; && otherObject.Position == Position;
} }
public abstract Dictionary<string, object> ToDictionary(); public virtual Dictionary<string, object> ToDictionary()
{
return new Dictionary<string, object>()
{
{nameof(Name), Name },
{nameof(Position), new float[]{Position.x, Position.y, Position.z } },
{Database.TYPE, nameof(Database.Instance.Prefabs) }
};
}
public virtual void LoadDictionary(Dictionary<string, object> dict)
{
Name = dict[nameof(Name)].ToString();
var p_array = (float[])dict[nameof(Position)];
Position = new Vector3(p_array[0], p_array[1], p_array[2]);
}
public void RemoveFromLevel()
{
Destroy(gameObject);
}
} }

View File

@ -14,21 +14,22 @@ public abstract class LevelTile : TileBase, ILevelObject
[LevelSerialize] [LevelSerialize]
public Vector3 Position { get; protected set; } public Vector3 Position { get; protected set; }
private Tilemap _tilemap;
[LevelSerialize] [LevelSerialize]
public string Tilemap { get; protected set; } public string Tilemap
{
get => _tilemap.name;
}
[LevelSerialize] [LevelSerialize]
public string Name => name; public string Name { get => name; protected set => name = value; }
public virtual void LevelStart() { } public virtual void LevelStart() { }
public virtual void LevelDestroy() { } public virtual void LevelDestroy() { }
public virtual void LevelUpdate() { } public virtual void LevelUpdate() { }
public virtual bool Equals(ILevelObject other) public virtual bool Equals(ILevelObject other)
{ {
if (!other.GetType().Equals(GetType())) return false; return other is LevelTile otherTile
&& Name == otherTile.Name
var otherTile = other as LevelTile;
return Name == otherTile.Name
&& Position == otherTile.Position && Position == otherTile.Position
&& Tilemap == otherTile.Tilemap; && Tilemap == otherTile.Tilemap;
} }
@ -46,7 +47,7 @@ public abstract class LevelTile : TileBase, ILevelObject
var instance = Instantiate(this); var instance = Instantiate(this);
instance.name = name; instance.name = name;
instance.Position = position; instance.Position = position;
instance.Tilemap = comp.name; instance._tilemap = comp;
//if tile already exists, dont add to level manager //if tile already exists, dont add to level manager
if (LevelManager.Instance.Has<LevelTile>(tile => tile.Equals(instance))) if (LevelManager.Instance.Has<LevelTile>(tile => tile.Equals(instance)))
@ -64,5 +65,28 @@ public abstract class LevelTile : TileBase, ILevelObject
tileData.color = Color.white; tileData.color = Color.white;
} }
public abstract Dictionary<string, object> ToDictionary(); public virtual Dictionary<string, object> ToDictionary()
{
return new Dictionary<string, object>()
{
{nameof(Name), Name },
{nameof(Position), new float[]{Position.x, Position.y, Position.z } },
{nameof(Tilemap), Tilemap },
{Database.TYPE, nameof(Database.Instance.Prefabs) }
};
}
public virtual void LoadDictionary(Dictionary<string, object> dict)
{
Name = dict[nameof(Name)].ToString();
float[] pArray = (float[])dict[nameof(Position)];
Position = new Vector3(pArray[0], pArray[1], pArray[2]);
var tilemap = FindObjectOfType<Grid>().GetComponentInChildren<Tilemap>(Tilemap);
}
public void RemoveFromLevel()
{
_tilemap.SetTile(Vector3Int.RoundToInt(Position), null);
}
} }

View File

@ -1,7 +1,5 @@
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Tilemaps;
using static Extensions; using static Extensions;
[CreateAssetMenu(menuName = "Gather And Defend/Resource Tile")] [CreateAssetMenu(menuName = "Gather And Defend/Resource Tile")]
@ -16,21 +14,10 @@ public class ResourceTile : LevelTile
[SerializeField, LevelSerialize] [SerializeField, LevelSerialize]
private float _yieldSpeed = 1; //resource per second private float _yieldSpeed = 1; //resource per second
[LevelSerialize]
private float _yieldCounter = 0; private float _yieldCounter = 0;
[LevelSerialize] [LevelSerialize]
public bool Occupied { get; set; } public bool Occupied { get; set; }
public override void LevelDestroy()
{
//nothing
}
public override void LevelStart()
{
//nothing
}
public override void LevelUpdate() public override void LevelUpdate()
{ {
if (!Occupied) return; if (!Occupied) return;
@ -45,14 +32,27 @@ public class ResourceTile : LevelTile
} }
public override bool Equals(ILevelObject other) public override bool Equals(ILevelObject other)
{ {
return other is ResourceTile otherRes && return other is ResourceTile otherRes
Position == otherRes.Position && base.Equals(otherRes)
&& Tilemap == otherRes.Tilemap
&& _yieldPrefab == otherRes._yieldPrefab && _yieldPrefab == otherRes._yieldPrefab
&& _yieldCounter == otherRes._yieldCounter; && _yieldSpeed == otherRes._yieldSpeed
&& Occupied == otherRes.Occupied;
} }
public override Dictionary<string, object> ToDictionary() public override Dictionary<string, object> ToDictionary()
{ {
return Extensions.ToDictionary(this); var dict = base.ToDictionary();
dict[nameof(YieldPrefabName)] = YieldPrefabName;
dict[nameof(_yieldSpeed)] = _yieldSpeed;
dict[nameof(Occupied)] = Occupied;
return dict;
}
public override void LoadDictionary(Dictionary<string, object> dict)
{
base.LoadDictionary(dict);
var prefabName = dict[nameof(YieldPrefabName)].ToString();
_yieldPrefab = Database.Instance.Prefabs[prefabName];
_yieldSpeed = (float)dict[nameof(_yieldSpeed)];
Occupied = (bool)dict[nameof(Occupied)];
} }
} }

View File

@ -13,21 +13,6 @@ public class SpawnerTile : LevelTile
private float _spawnSpeed = 0; private float _spawnSpeed = 0;
private float _spawnCounter = 0; private float _spawnCounter = 0;
public override bool Equals(ILevelObject other)
{
return other is SpawnerTile spawner
&& spawner.Position == Position
&& spawner.Tilemap == Tilemap
&& spawner._prefab == _prefab
&& spawner._spawnOnStart == _spawnOnStart
&& spawner._spawnSpeed == _spawnSpeed;
}
public override void LevelDestroy()
{
//nothing
}
public override void LevelStart() public override void LevelStart()
{ {
if (!_spawnOnStart) return; if (!_spawnOnStart) return;
@ -44,8 +29,31 @@ public class SpawnerTile : LevelTile
var instance = Instantiate(_prefab, Position, Quaternion.identity); var instance = Instantiate(_prefab, Position, Quaternion.identity);
instance.transform.SetParent(LevelManager.Instance.LevelTransform); instance.transform.SetParent(LevelManager.Instance.LevelTransform);
} }
public override bool Equals(ILevelObject other)
{
return other is SpawnerTile spawner
&& base.Equals(spawner)
&& spawner._prefab == _prefab
&& spawner._spawnOnStart == _spawnOnStart
&& spawner._spawnSpeed == _spawnSpeed;
}
public override Dictionary<string, object> ToDictionary() public override Dictionary<string, object> ToDictionary()
{ {
return Extensions.ToDictionary(this); var dict = base.ToDictionary();
dict[nameof(_prefab)] = _prefab.name;
dict[nameof(_spawnOnStart)] = _spawnOnStart;
dict[nameof(_spawnSpeed)] = _spawnSpeed;
return dict;
}
public override void LoadDictionary(Dictionary<string, object> dict)
{
base.LoadDictionary(dict);
var prefabName = dict[nameof(_prefab)].ToString();
_prefab = Database.Instance.Prefabs[prefabName];
_spawnOnStart = (bool)dict[nameof(_spawnOnStart)];
_spawnSpeed = (float)dict[nameof(_spawnSpeed)];
} }
} }

1
Assets/test.txt Normal file
View File

@ -0,0 +1 @@
[{"Name":"StickSpawner","Position":[-8.0,-5.0,0.0],"Tilemap":"Spawners","_prefab":"baseArcher","_spawnOnStart":true,"_spawnSpeed":0.0},{"Name":"StickSpawner","Position":[-8.0,-3.0,0.0],"Tilemap":"Spawners","_prefab":"baseArcher","_spawnOnStart":true,"_spawnSpeed":0.0},{"Name":"StickSpawner","Position":[-8.0,-1.0,0.0],"Tilemap":"Spawners","_prefab":"baseArcher","_spawnOnStart":true,"_spawnSpeed":0.0},{"Name":"StickSpawner","Position":[-8.0,1.0,0.0],"Tilemap":"Spawners","_prefab":"baseArcher","_spawnOnStart":true,"_spawnSpeed":0.0},{"Name":"baseArcher(Clone)","Position":[-8.0,-5.0,0.0],"_hp":100,"_speed":0.0,"_attack_speed":2.0,"_attack_damage":10},{"Name":"baseArcher(Clone)","Position":[-8.0,-3.0,0.0],"_hp":100,"_speed":0.0,"_attack_speed":2.0,"_attack_damage":10},{"Name":"baseArcher(Clone)","Position":[-8.0,-1.0,0.0],"_hp":100,"_speed":0.0,"_attack_speed":2.0,"_attack_damage":10},{"Name":"baseArcher(Clone)","Position":[-8.0,1.0,0.0],"_hp":100,"_speed":0.0,"_attack_speed":2.0,"_attack_damage":10}]

7
Assets/test.txt.meta Normal file
View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0e51df1fc98540b49abfd724a8df0eb6
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: