Pull request #3: First draft pour level editor

Merge in CGD/gather-and-defend from feature/levelEditor to main

* commit 'ebe035840cc062c26e9d5bfff0592841f676280d':
  tidy up + add test tiles + small doc
  load et save feature pour level
This commit is contained in:
Felix-gabriel Boucher-luneau 2023-05-11 17:31:15 +00:00
commit 77ab3229e1
29 changed files with 2941 additions and 1 deletions

8
Assets/LevelEditor.meta Normal file
View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -0,0 +1,267 @@
%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: 2b25d284985e65e48b50826c522a5ec3, type: 3}
m_Name: Level
m_EditorClassIdentifier:
_data:
- _key: Background
tiles:
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -8, y: -5, 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: -7, y: -5, 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: -6, y: -5, 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: -5, y: -5, 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: -4, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: -3, 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: -4, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -4, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -3, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -2, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: -1, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 0, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 1, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 2, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -2, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 3, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: -4, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: -3, 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: 4, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: 0, z: 0}
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
_position: {x: 4, y: 1, z: 0}
- _key: Entities
tiles:
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -8, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -6, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -4, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: -2, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 0, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 2, y: 1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
_position: {x: 4, y: 1, z: 0}
- _key: Spawners
tiles:
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: -5, z: 0}
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: -3, z: 0}
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: -1, z: 0}
- _tile: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
_position: {x: -8, y: 1, z: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e715669e1ed4b294c82d07ac011e89bb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

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

View File

@ -0,0 +1,127 @@
using UnityEditor;
using UnityEngine.Tilemaps;
using UnityEngine;
using System.IO;
using static UnityEngine.GraphicsBuffer;
using UnityEditor.SceneManagement;
namespace GatherAndDefend.LevelEditor
{
[CustomEditor(typeof(LevelEditor))]
public class LevelEditorCustomInspector : Editor
{
const string defaultName = "Level";
const string extension = ".asset";
string _infoText = string.Empty;
public override void OnInspectorGUI()
{
EditorGUILayout.HelpBox(@"How to use :
- Path : you can optionally assign a folder in order to change the path to which the Level files will be created and saved
- Level : the level file you're currently working on (for saving and loading purposes).
- Create button : creates an empty level at given path, and assign it to the Level field in inspector.
- Save button : saves all scene tilemaps' contents to the assigned level file.
- Load button : iterates through all scene tilemaps and fills them according to what data can be found in the level file.
Important considerations :
- the save and load buttons won't work if there is no Level assigned.
- the loading won't work if the scene tilemap names aren't the same as the tilemap data keys in the Level file", MessageType.None);
DrawDefaultInspector();
if (GUILayout.Button(nameof(Create)))
{
Create();
}
if (GUILayout.Button(nameof(Save)))
{
Save();
}
if (GUILayout.Button(nameof(Load)))
{
Load();
}
if (_infoText != string.Empty)
{
EditorGUILayout.HelpBox(_infoText, MessageType.Error);
}
}
private string GetPath()
{
var targ = (LevelEditor)target;
var asset = EditorGUILayout.ObjectField(targ.Path, typeof(DefaultAsset), false);
if (!asset) return "Assets";
return AssetDatabase.GetAssetPath(asset);
}
private void Create()
{
string path = GetPath();
if (!Directory.Exists(path))
{
_infoText = "the object assigned to Path is not a directory!";
}
LevelEditor targ = (LevelEditor)target;
_infoText = string.Empty;
string name = defaultName;
if (File.Exists(path + "/" + name + extension))
{
var i = 0;
while (File.Exists(path + "/" + name + i + extension)) i++;
name += i;
}
var map = CreateInstance<Level>();
map.name = name;
AssetDatabase.CreateAsset(map, path + "/" + name + extension);
targ.Level = map;
}
private void Save()
{
string path = GetPath();
if (!Directory.Exists(path))
{
_infoText = "the object assigned to Path is not a directory!";
return;
}
LevelEditor targ = (LevelEditor)target;
if (!targ.Level)
{
_infoText = "no level to save to. please assign the Level field in the inspector.";
return;
}
string name = targ.Level.name;
var map = CreateInstance<Level>();
map.name = name;
foreach (Tilemap tilemap in targ.GetComponentsInChildren<Tilemap>())
{
map.Write(tilemap);
}
AssetDatabase.CreateAsset(map, path + "/" + name + extension);
targ.Level = map;
_infoText = string.Empty;
}
private void Load()
{
var targ = (LevelEditor)target;
if (!targ.Level)
{
_infoText = "no level to save to. please assign the Level field in the inspector.";
return;
}
foreach (Tilemap tilemap in targ.GetComponentsInChildren<Tilemap>())
{
tilemap.ClearAllTiles();
targ.Level.Read(tilemap);
}
_infoText = string.Empty;
EditorSceneManager.MarkAllScenesDirty();
}
}
}

View File

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

View File

@ -0,0 +1,24 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace GatherAndDefend.LevelEditor
{
public class LevelEditor : MonoBehaviour
{
[SerializeField]
private DefaultAsset _path;
[SerializeField]
private Level _level;
public Level Level
{
get => _level;
set => _level = value;
}
public DefaultAsset Path
{
get => _path;
set => _path = value;
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,25 @@
using System.Collections.Generic;
using UnityEngine.Tilemaps;
using UnityEngine;
namespace GatherAndDefend.LevelEditor
{
public class Level : ScriptableObject
{
[SerializeField]
private List<TilemapData> _data = new List<TilemapData>();
public void Write(Tilemap tilemap)
{
var data = new TilemapData();
data.SaveFromTilemap(tilemap);
_data.Add(data);
}
public void Read(Tilemap tilemap)
{
var data = _data.Find(x => x.Key == tilemap.name);
if (data == null) return;
data.LoadToTilemap(tilemap);
}
}
}

View File

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

View File

@ -0,0 +1,24 @@
using UnityEngine;
using UnityEngine.Tilemaps;
[CreateAssetMenu(menuName = "Gather And Defend/Spawner Tile")]
public class SpawnerTile : TileBase
{
[SerializeField]
private Sprite _sprite;
[SerializeField]
private GameObject _prefab;
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
tileData.sprite = _sprite;
tileData.transform.SetTRS(Vector3.zero, Quaternion.identity, Vector3.one);
tileData.color = Color.white;
}
public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
{
if (!Application.isPlaying) return base.StartUp(position, tilemap, go);
Instantiate(_prefab, new Vector3(0.5f, 0.5f) + position, Quaternion.identity);
return base.StartUp(position, tilemap, go);
}
}

View File

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

View File

@ -0,0 +1,24 @@
using UnityEngine.Tilemaps;
using UnityEngine;
using System;
namespace GatherAndDefend.LevelEditor
{
[Serializable]
public class TileData
{
[SerializeField]
private TileBase _tile;
[SerializeField]
private Vector3Int _position;
public TileBase Tile => _tile;
public Vector3Int Position => _position;
public TileData(Vector3Int position, TileBase tile)
{
this._position = position;
this._tile = tile;
}
}
}

View File

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

View File

@ -0,0 +1,47 @@
using System.Collections.Generic;
using UnityEngine.Tilemaps;
using UnityEngine;
using System;
namespace GatherAndDefend.LevelEditor
{
[Serializable]
public class TilemapData
{
[SerializeField]
private string _key;
[SerializeField]
private List<TileData> tiles;
public string Key => _key;
public void LoadToTilemap(Tilemap reference)
{
foreach (TileData data in tiles)
{
reference.SetTile(data.Position, data.Tile);
}
}
public void SaveFromTilemap(Tilemap reference)
{
_key = reference.name;
tiles = new List<TileData>();
BoundsInt bounds = reference.cellBounds;
for (int i = bounds.xMin; i <= bounds.xMax; i++)
{
for (int j = bounds.yMin; j <= bounds.yMax; j++)
{
Vector3Int position = new Vector3Int(i, j);
TileBase tile = reference.GetTile(position);
if (!tile) continue;
var tileData = new TileData(position, tile);
tiles.Add(tileData);
}
}
}
public TilemapData()
{
tiles = new List<TileData>();
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,17 @@
%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: b28b3004abb3723498a355747c7cd899, type: 3}
m_Name: StickSpawner
m_EditorClassIdentifier:
_sprite: {fileID: 21300000, guid: 77a39e873655d3c4b93d0b7696397b83, type: 3}
_prefab: {fileID: 6962989255644195630, guid: 9b40c232eddfd1b469bea688e3c970c0, type: 3}
_repeat: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4aaf448680c7f8a438a9a5861c622a55
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Tilemaps.meta Normal file
View File

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

View File

@ -0,0 +1,244 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &86010431647272150
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2398097493298623612}
- component: {fileID: 7313241872231566393}
m_Layer: 0
m_Name: LevelEditorPalette
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2398097493298623612
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 86010431647272150}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4542880158922887027}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!156049354 &7313241872231566393
Grid:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 86010431647272150}
m_Enabled: 1
m_CellSize: {x: 1, y: 1, z: 0}
m_CellGap: {x: 0, y: 0, z: 0}
m_CellLayout: 0
m_CellSwizzle: 0
--- !u!1 &5890485537825364348
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4542880158922887027}
- component: {fileID: 6447175569849153967}
- component: {fileID: 5651166066249042033}
m_Layer: 0
m_Name: Layer1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4542880158922887027
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5890485537825364348}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2398097493298623612}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1839735485 &6447175569849153967
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5890485537825364348}
m_Enabled: 1
m_Tiles:
- first: {x: -1, y: 0, z: 0}
second:
serializedVersion: 2
m_TileIndex: 0
m_TileSpriteIndex: 0
m_TileMatrixIndex: 0
m_TileColorIndex: 0
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 1073741825
- first: {x: 0, y: 0, z: 0}
second:
serializedVersion: 2
m_TileIndex: 1
m_TileSpriteIndex: 1
m_TileMatrixIndex: 0
m_TileColorIndex: 0
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 1073741825
- first: {x: -1, y: 1, z: 0}
second:
serializedVersion: 2
m_TileIndex: 2
m_TileSpriteIndex: 2
m_TileMatrixIndex: 0
m_TileColorIndex: 0
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 0
m_AnimatedTiles: {}
m_TileAssetArray:
- m_RefCount: 1
m_Data: {fileID: 11400000, guid: a387250a316b97e43be83b85980101e1, type: 2}
- m_RefCount: 1
m_Data: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
- m_RefCount: 1
m_Data: {fileID: 11400000, guid: 4aaf448680c7f8a438a9a5861c622a55, type: 2}
m_TileSpriteArray:
- m_RefCount: 1
m_Data: {fileID: 21300000, guid: ccca3e050cb082b45af0a099790463f6, type: 3}
- m_RefCount: 1
m_Data: {fileID: 21300000, guid: 1f8a7d27b012449499d5316045662e1e, type: 3}
- m_RefCount: 1
m_Data: {fileID: 21300000, guid: 77a39e873655d3c4b93d0b7696397b83, type: 3}
m_TileMatrixArray:
- m_RefCount: 3
m_Data:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_TileColorArray:
- m_RefCount: 3
m_Data: {r: 1, g: 1, b: 1, a: 1}
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: -1, y: 0, z: 0}
m_Size: {x: 2, y: 2, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!483693784 &5651166066249042033
TilemapRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5890485537825364348}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 0
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_ChunkSize: {x: 32, y: 32, z: 32}
m_ChunkCullingBounds: {x: 0, y: 0, z: 0}
m_MaxChunkCount: 16
m_MaxFrameAge: 16
m_SortOrder: 0
m_Mode: 0
m_DetectChunkCullingBounds: 0
m_MaskInteraction: 0
--- !u!114 &5479319524895914250
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: 12395, guid: 0000000000000000e000000000000000, type: 0}
m_Name: Palette Settings
m_EditorClassIdentifier:
cellSizing: 0
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 638fe5717ed2f7d4e840158211fdddbf
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 61
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: de02f9e1d18f588468e474319d09a723, type: 3}
m_Name:
m_EditorClassIdentifier:
customInterpolatorErrorThreshold: 32
customInterpolatorWarningThreshold: 16

View File

@ -11,7 +11,7 @@ TagManager:
-
- Water
- UI
-
- InvisibleToCamera
-
-
-