From d20edc3663beca09721c25b2ba4ba0fbc9728dfe Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 14:21:33 +0200 Subject: [PATCH] Update a lot of stuff --- Assets/Editor.meta | 8 ++ Assets/Editor/BeforeStartAttributeDrawer.cs | 21 ++++ .../Editor/BeforeStartAttributeDrawer.cs.meta | 11 ++ Assets/Prefabs/Map.prefab | 49 ++++++++ Assets/Prefabs/Map.prefab.meta | 7 ++ Assets/Prefabs/Tile.prefab | 96 +++++++++++++++ Assets/Prefabs/Tile.prefab.meta | 7 ++ Assets/Scenes/Steffo.unity | 69 +++++++++++ Assets/Scripts/BeforeStartAttribute.cs | 5 + Assets/Scripts/BeforeStartAttribute.cs.meta | 11 ++ Assets/Scripts/Map.cs | 48 +++++--- Assets/Scripts/Tile.cs | 6 +- Assets/Sprites/PurpleTileset.png.meta | 112 ++++++++++++++++++ 13 files changed, 428 insertions(+), 22 deletions(-) create mode 100644 Assets/Editor.meta create mode 100644 Assets/Editor/BeforeStartAttributeDrawer.cs create mode 100644 Assets/Editor/BeforeStartAttributeDrawer.cs.meta create mode 100644 Assets/Prefabs/Map.prefab create mode 100644 Assets/Prefabs/Map.prefab.meta create mode 100644 Assets/Prefabs/Tile.prefab create mode 100644 Assets/Prefabs/Tile.prefab.meta create mode 100644 Assets/Scripts/BeforeStartAttribute.cs create mode 100644 Assets/Scripts/BeforeStartAttribute.cs.meta create mode 100644 Assets/Sprites/PurpleTileset.png.meta diff --git a/Assets/Editor.meta b/Assets/Editor.meta new file mode 100644 index 0000000..b718f6a --- /dev/null +++ b/Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fd1b080c01a34694793e8f2ff140bfc0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/BeforeStartAttributeDrawer.cs b/Assets/Editor/BeforeStartAttributeDrawer.cs new file mode 100644 index 0000000..19006b1 --- /dev/null +++ b/Assets/Editor/BeforeStartAttributeDrawer.cs @@ -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; + } +} \ No newline at end of file diff --git a/Assets/Editor/BeforeStartAttributeDrawer.cs.meta b/Assets/Editor/BeforeStartAttributeDrawer.cs.meta new file mode 100644 index 0000000..4216c56 --- /dev/null +++ b/Assets/Editor/BeforeStartAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13bad693cf0c2634ea1e2be679edf00f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Map.prefab b/Assets/Prefabs/Map.prefab new file mode 100644 index 0000000..aa46ee0 --- /dev/null +++ b/Assets/Prefabs/Map.prefab @@ -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} diff --git a/Assets/Prefabs/Map.prefab.meta b/Assets/Prefabs/Map.prefab.meta new file mode 100644 index 0000000..f5813e2 --- /dev/null +++ b/Assets/Prefabs/Map.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: cd714ea41cb7c454994bf0f5ad99abd1 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Tile.prefab b/Assets/Prefabs/Tile.prefab new file mode 100644 index 0000000..7104d56 --- /dev/null +++ b/Assets/Prefabs/Tile.prefab @@ -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 diff --git a/Assets/Prefabs/Tile.prefab.meta b/Assets/Prefabs/Tile.prefab.meta new file mode 100644 index 0000000..493ffc6 --- /dev/null +++ b/Assets/Prefabs/Tile.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0e0b618b5499bbb40b076c0291d55487 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Steffo.unity b/Assets/Scenes/Steffo.unity index ccc28e4..3b2ac89 100644 --- a/Assets/Scenes/Steffo.unity +++ b/Assets/Scenes/Steffo.unity @@ -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} diff --git a/Assets/Scripts/BeforeStartAttribute.cs b/Assets/Scripts/BeforeStartAttribute.cs new file mode 100644 index 0000000..cd1cf30 --- /dev/null +++ b/Assets/Scripts/BeforeStartAttribute.cs @@ -0,0 +1,5 @@ +using UnityEngine; + +public class BeforeStartAttribute : PropertyAttribute { + +} \ No newline at end of file diff --git a/Assets/Scripts/BeforeStartAttribute.cs.meta b/Assets/Scripts/BeforeStartAttribute.cs.meta new file mode 100644 index 0000000..68df79c --- /dev/null +++ b/Assets/Scripts/BeforeStartAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ec73aa347f0168f4f95e1acbd3072646 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index be6b013..2ca3da7 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -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.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(); } diff --git a/Assets/Scripts/Tile.cs b/Assets/Scripts/Tile.cs index 3de0bc6..c699f9c 100644 --- a/Assets/Scripts/Tile.cs +++ b/Assets/Scripts/Tile.cs @@ -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.sprite = tile_sprite; + spriteRenderer.sprite = sprite; } } diff --git a/Assets/Sprites/PurpleTileset.png.meta b/Assets/Sprites/PurpleTileset.png.meta new file mode 100644 index 0000000..2135d63 --- /dev/null +++ b/Assets/Sprites/PurpleTileset.png.meta @@ -0,0 +1,112 @@ +fileFormatVersion: 2 +guid: e0e60c9a4ff0b8e429e6cfe316da9bbf +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 10 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 40 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + 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: 9a9cdb0ef0236d64bbd871c33fd3d927 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: