1
Fork 0

Merge remote-tracking branch 'refs/remotes/origin/master'

This commit is contained in:
Lorenzo Balugani 2019-04-27 14:45:01 +02:00
commit f3044b96be
13 changed files with 341 additions and 25 deletions

8
Assets/Editor.meta Normal file
View file

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

View file

@ -0,0 +1,21 @@
//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(BeforeStartAttribute))]
public class BeforeStartAttributeDrawer : PropertyDrawer
{
// Necessary since some properties tend to collapse smaller than their content
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
// Draw a disabled property field
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = !Application.isPlaying;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}

View file

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

49
Assets/Prefabs/Map.prefab Normal file
View file

@ -0,0 +1,49 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7249059666095778526
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7249059666095778521}
- component: {fileID: 6907631410461015020}
m_Layer: 0
m_Name: Map
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7249059666095778521
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7249059666095778526}
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_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6907631410461015020
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7249059666095778526}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 052bc569472779a429bfc51246f723d4, type: 3}
m_Name:
m_EditorClassIdentifier:
wallSprite: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84, type: 3}
floorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
tilePrefab: {fileID: 3219556109866242471, guid: 0e0b618b5499bbb40b076c0291d55487,
type: 3}

View file

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

View file

@ -0,0 +1,96 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3219556109866242471
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3219556109866242468}
- component: {fileID: 9040756953319481538}
- component: {fileID: 1691311275711631131}
m_Layer: 0
m_Name: Tile
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3219556109866242468
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3219556109866242471}
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_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &9040756953319481538
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3219556109866242471}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4df8012d0534aea47b137c1838a5a6af, type: 3}
m_Name:
m_EditorClassIdentifier:
walkable: 0
sprite: {fileID: 0}
--- !u!212 &1691311275711631131
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3219556109866242471}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 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_Sprite: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 0
m_MaskInteraction: 0
m_SpriteSortPoint: 0

View file

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

View file

@ -272,3 +272,72 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4c25f33cb89f6624db48fc49d353a7f2, type: 3}
--- !u!1001 &7249059666254997933
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7249059666095778526, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_Name
value: Map
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: cd714ea41cb7c454994bf0f5ad99abd1, type: 3}

View file

@ -0,0 +1,5 @@
using UnityEngine;
public class BeforeStartAttribute : PropertyAttribute {
}

View file

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

View file

@ -4,8 +4,15 @@ using UnityEngine;
public class Map : MonoBehaviour
{
public const int SIZE_X = 30;
public const int SIZE_Y = 30;
[BeforeStartAttribute]
public int mapSize = 30;
[BeforeStartAttribute]
public int roomsToGenerate = 5;
[BeforeStartAttribute]
public int maxRoomSize = 8;
public GameObject[,] tiles;
public Sprite wallSprite;
public Sprite floorSprite;
@ -18,23 +25,25 @@ public class Map : MonoBehaviour
}
private void InitTile(int x, int y, bool is_walkable, Sprite tile_sprite) {
GameObject tileObject = Instantiate(tilePrefab);
tileObject.transform.position = new Vector3(x, y, 0);
tiles[x, y] = tileObject;
Tile tile = GetTile(x, y);
tile.is_walkable = is_walkable;
tile.tile_sprite = tile_sprite;
tile.walkable = is_walkable;
tile.sprite = tile_sprite;
}
private void FillWithWalls() {
for(int x = 0; x < SIZE_X; x++) {
for(int y = 0; y < SIZE_Y; y++) {
InitTile(x, y, false, wallSprite);
for(int x = 0; x < mapSize; x++) {
for(int y = 0; y < mapSize; y++) {
GameObject tileObject = Instantiate(tilePrefab, transform);
tileObject.transform.position = new Vector3(x, y, 0);
tiles[x, y] = tileObject;
Tile tile = tileObject.GetComponent<Tile>();
tile.walkable = false;
tile.sprite = wallSprite;
}
}
}
private void GenerateSquare(int start_x, int start_y, int end_x, int end_y) {
private void PlaceRoom(int start_x, int start_y, int end_x, int end_y) {
for(int x = start_x; x <= end_x; x++) {
for(int y = start_y; y <= end_y; y++) {
InitTile(x, y, true, floorSprite);
@ -42,7 +51,7 @@ public class Map : MonoBehaviour
}
}
private void GenerateCorridor(int start_x, int start_y, int end_x, int end_y, bool horizontal_priority) {
private void PlaceCorridor(int start_x, int start_y, int end_x, int end_y, bool horizontal_priority) {
if(horizontal_priority) {
for(int x = start_x; x <= end_x; x++) {
InitTile(x, start_y, true, floorSprite);
@ -63,18 +72,19 @@ public class Map : MonoBehaviour
private void GenerateMap() {
FillWithWalls();
//Generate a random Square
int start_x = Random.Range(0, SIZE_X);
int start_y = Random.Range(0, SIZE_Y);
int end_x = Random.Range(start_x, SIZE_X);
int end_y = Random.Range(start_y, SIZE_Y);
GenerateSquare(start_x, start_y, end_x, end_y);
for(int i = 0; i < roomsToGenerate; i++) {
int start_x = Random.Range(0, mapSize);
int start_y = Random.Range(0, mapSize);
int end_x = Random.Range(0, mapSize) + start_x;
int end_y = Random.Range(0, mapSize) + start_y;
PlaceRoom(start_x, start_y, end_x, end_y);
}
}
private void Start()
{
//Create the tile array
tiles = new GameObject[SIZE_X, SIZE_Y];
tiles = new GameObject[mapSize, mapSize];
//Generate the map
GenerateMap();
}

View file

@ -4,14 +4,14 @@ using UnityEngine;
public class Tile : MonoBehaviour
{
public bool is_walkable;
public Sprite tile_sprite;
public bool walkable;
public Sprite sprite;
private SpriteRenderer spriteRenderer;
private void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
spriteRenderer.sprite = tile_sprite;
spriteRenderer.sprite = sprite;
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 61345c477d96361428c3eb1bfb0c293a
guid: e0e60c9a4ff0b8e429e6cfe316da9bbf
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
@ -45,7 +45,7 @@ TextureImporter:
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spritePixelsToUnits: 40
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
@ -69,13 +69,35 @@ TextureImporter:
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 1cead1e412dade640b800b9e34ee4c89
spriteID: 9a9cdb0ef0236d64bbd871c33fd3d927
internalID: 0
vertices: []
indices: