From e270f02baef84dcc98fd9ee7b1226072d6dca9ed Mon Sep 17 00:00:00 2001 From: Bas Date: Sun, 17 May 2020 14:29:16 +0200 Subject: [PATCH] Refactored map generation --- .../Assets/Scenes/ParkScene.unity | 103 ++++++--- .../Assets/Scripts/Generation.meta | 8 + .../Scripts/Generation/IElementGenerator.cs | 28 +++ .../IElementGenerator.cs.meta} | 2 +- .../Scripts/Generation/Miscellaneous.meta | 8 + .../Miscellaneous/PrefabGenerator.cs | 40 ++++ .../Miscellaneous/PrefabGenerator.cs.meta} | 2 +- .../Assets/Scripts/Generation/Retro.meta | 8 + .../Generation/Retro/SmallSceneryGenerator.cs | 92 ++++++++ .../Retro/SmallSceneryGenerator.cs.meta | 11 + .../Retro/SurfaceGenerator.Textures.cs} | 15 +- .../Retro/SurfaceGenerator.Textures.cs.meta | 11 + .../Retro/SurfaceGenerator.cs} | 85 +++---- .../Generation/Retro/SurfaceGenerator.cs.meta | 11 + .../Scripts/Generation/Retro/WallGenerator.cs | 51 +++++ .../Generation/Retro/WallGenerator.cs.meta | 11 + .../Assets/Scripts/Maths.cs.meta | 2 +- .../Assets/Scripts/OpenRCT2/Configuration.cs | 2 +- .../Scripts/OpenRCT2/Editor/OpenRCT2Editor.cs | 2 +- .../Scripts/OpenRCT2/Enums/Ownership.cs | 2 +- .../Scripts/OpenRCT2/Enums/PeepAction.cs | 2 +- .../OpenRCT2/Enums/PeepActionSprite.cs | 2 +- .../Scripts/OpenRCT2/Enums/PeepSpriteType.cs | 2 +- .../Scripts/OpenRCT2/Enums/PeepState.cs | 2 +- .../Scripts/OpenRCT2/Enums/PeepSubState.cs | 2 +- .../Assets/Scripts/OpenRCT2/Enums/PeepType.cs | 2 +- .../OpenRCT2/Enums/SmallSceneryFlags.cs | 2 +- .../Scripts/OpenRCT2/Enums/SpriteType.cs | 2 +- .../Scripts/OpenRCT2/Enums/SurfaceSlope.cs | 2 +- .../OpenRCT2/Enums/TerrainEdgeStyle.cs | 2 +- .../OpenRCT2/Enums/TerrainSurfaceStyle.cs | 2 +- .../Scripts/OpenRCT2/Enums/TileElementType.cs | 2 +- .../Scripts/OpenRCT2/Graphics/Graphic.cs | 2 +- .../OpenRCT2/Graphics/GraphicExtensions.cs | 2 +- .../OpenRCT2/Graphics/GraphicsFactory.cs | 2 +- .../Scripts/OpenRCT2/Graphics/PaletteEntry.cs | 2 +- .../Scripts/OpenRCT2/Imports/OpenRCT2.Game.cs | 2 +- .../OpenRCT2/Imports/OpenRCT2.Graphics.cs | 2 +- .../Scripts/OpenRCT2/Imports/OpenRCT2.Map.cs | 2 +- .../OpenRCT2/Imports/OpenRCT2.Sprites.cs | 2 +- .../Scripts/OpenRCT2/Imports/OpenRCT2.cs | 2 +- .../Assets/Scripts/OpenRCT2/Imports/Ptr.cs | 2 +- .../Scripts/OpenRCT2/Map/Map.Generation.cs | 213 +++++++----------- .../Scripts/OpenRCT2/Map/Map.Helpers.cs | 55 +++++ .../Scripts/OpenRCT2/Map/Map.Helpers.cs.meta | 11 + .../Assets/Scripts/OpenRCT2/Map/Map.cs | 139 ++++-------- .../Assets/Scripts/OpenRCT2/Map/MapTile.cs | 79 +++++++ .../Scripts/OpenRCT2/Map/MapTile.cs.meta | 11 + .../Scripts/OpenRCT2/Map/PeepController.cs | 2 +- .../Scripts/OpenRCT2/Map/SpriteController.cs | 2 +- .../Scripts/OpenRCT2/Map/VehicleController.cs | 2 +- .../Scripts/OpenRCT2/Sprites/ISprite.cs | 2 +- .../Assets/Scripts/OpenRCT2/Sprites/Peep.cs | 2 +- .../Scripts/OpenRCT2/Sprites/SpriteBase.cs | 2 +- .../Scripts/OpenRCT2/Sprites/SpriteSize.cs | 2 +- .../Scripts/OpenRCT2/Sprites/Vehicle.cs | 2 +- .../TileElements/Entries/SmallSceneryEntry.cs | 2 +- .../OpenRCT2/TileElements/PathElement.cs | 2 +- .../TileElements/SmallSceneryElement.cs | 2 +- .../OpenRCT2/TileElements/SurfaceElement.cs | 2 +- .../OpenRCT2/TileElements/TileElement.cs | 2 +- .../TileElements/TileElementExtensions.cs | 2 +- .../OpenRCT2/TileElements/TrackElement.cs | 2 +- .../OpenRCT2/TileElements/WallElement.cs | 2 +- .../Assets/Scripts/Tools/SelectionTool.cs | 63 +++--- .../Assets/Scripts/UI/PeepWindow.cs | 81 ++++--- .../Assets/Scripts/UI/WindowManager.cs | 28 +-- src/openrct2-unity/Assets/csc.rsp | 2 +- .../ProjectSettings/QualitySettings.asset | 2 +- 69 files changed, 815 insertions(+), 439 deletions(-) create mode 100644 src/openrct2-unity/Assets/Scripts/Generation.meta create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs rename src/openrct2-unity/Assets/Scripts/{OpenRCT2/Map/Map.Materials.cs.meta => Generation/IElementGenerator.cs.meta} (83%) create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous.meta create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs rename src/openrct2-unity/Assets/Scripts/{OpenRCT2/Map/Map.Surface.cs.meta => Generation/Miscellaneous/PrefabGenerator.cs.meta} (83%) create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro.meta create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs.meta rename src/openrct2-unity/Assets/Scripts/{OpenRCT2/Map/Map.Materials.cs => Generation/Retro/SurfaceGenerator.Textures.cs} (89%) create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs.meta rename src/openrct2-unity/Assets/Scripts/{OpenRCT2/Map/Map.Surface.cs => Generation/Retro/SurfaceGenerator.cs} (74%) create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs.meta create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs create mode 100644 src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs.meta create mode 100644 src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs create mode 100644 src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs.meta create mode 100644 src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs create mode 100644 src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs.meta diff --git a/src/openrct2-unity/Assets/Scenes/ParkScene.unity b/src/openrct2-unity/Assets/Scenes/ParkScene.unity index 0a07541706..f0dcf47bbf 100644 --- a/src/openrct2-unity/Assets/Scenes/ParkScene.unity +++ b/src/openrct2-unity/Assets/Scenes/ParkScene.unity @@ -98,7 +98,7 @@ LightmapSettings: m_TrainingDataDestination: TrainingData m_LightProbeSampleCountMultiplier: 4 m_LightingDataAsset: {fileID: 0} - m_UseShadowmask: 1 + m_UseShadowmask: 0 --- !u!196 &4 NavMeshSettings: serializedVersion: 2 @@ -464,7 +464,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 79be679884da2154dacd80be9669d5dc, type: 3} m_Name: m_EditorClassIdentifier: - selectedPark: Crazy Castle.sv6 + selectedPark: Blackpool.sv6 --- !u!4 &1347800243 Transform: m_ObjectHideFlags: 0 @@ -514,37 +514,74 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8f4353bcde699fe4dbc7f9641bcd509e, type: 3} m_Name: m_EditorClassIdentifier: - pathPrefab: {fileID: 6681454114598486694, guid: d5e4b199bf0e87b47b14b43c86d8c12f, - type: 3} - trackPrefab: {fileID: 3460111253241373034, guid: ac7c5b20c9776c2458a7c5f077e645f0, - type: 3} - smallSceneryPrefab: {fileID: 4881190563108725493, guid: e5123beefdc062f42b5e3fb98e104cef, - type: 3} - entrancePrefab: {fileID: 67614980614369834, guid: b3a4fb9191c251d44b6aadea9354fba3, - type: 3} - wallPrefab: {fileID: 6613264330481197744, guid: 3c5d91e604076ff43b5c7556fe1c89e5, - type: 3} - largeSceneryPrefab: {fileID: 8665094481412155395, guid: ab17a95a8234f8e42b1bcde029bf4720, - type: 3} - bannerPrefab: {fileID: 1690927267108533612, guid: 3ffc06cfa16e4e24a9c7526f41ba500f, - type: 3} - generatePath: 1 - generateTrack: 1 - generateSmallScenery: 1 - generateEntrance: 0 - generateWall: 1 - generateLargeScenery: 0 - generateBanner: 0 - surfaceShader: {fileID: -6465566751694194690, guid: c5119169087bdc14bb9a8a4b72cab9e7, - type: 3} - surfaceTextureField: Surface - edgeShader: {fileID: -6465566751694194690, guid: 5be9d4f19d70f504d90b782f27c81015, - type: 3} - edgeTextureField: Edge - waterShader: {fileID: -6465566751694194690, guid: f2b2dbc11d613b9478c958f95f47ef17, - type: 3} - waterTextureField: Water - waterRefractionField: WaterRefraction + generationFlags: 125 + surfaceGenerator: + id: 0 + pathGenerator: + id: 1 + trackGenerator: + id: 2 + smallSceneryGenerator: + id: 3 + entranceGenerator: + id: 4 + wallGenerator: + id: 5 + largeSceneryGenerator: + id: 6 + bannerGenerator: + id: 7 + references: + version: 1 + 00000000: + type: {class: SurfaceGenerator, ns: Generation.Retro, asm: Assembly-CSharp} + data: + surfaceShader: {fileID: -6465566751694194690, guid: c5119169087bdc14bb9a8a4b72cab9e7, + type: 3} + surfaceTextureField: Surface + edgeShader: {fileID: -6465566751694194690, guid: 5be9d4f19d70f504d90b782f27c81015, + type: 3} + edgeTextureField: Edge + waterShader: {fileID: -6465566751694194690, guid: f2b2dbc11d613b9478c958f95f47ef17, + type: 3} + waterTextureField: Water + waterRefractionField: WaterRefraction + 00000001: + type: {class: PrefabGenerator, ns: Generation, asm: Assembly-CSharp} + data: + prefab: {fileID: 6681454114598486694, guid: d5e4b199bf0e87b47b14b43c86d8c12f, + type: 3} + 00000002: + type: {class: PrefabGenerator, ns: Generation, asm: Assembly-CSharp} + data: + prefab: {fileID: 3460111253241373034, guid: ac7c5b20c9776c2458a7c5f077e645f0, + type: 3} + 00000003: + type: {class: SmallSceneryGenerator, ns: Generation.Retro, asm: Assembly-CSharp} + data: + crossShape: {fileID: 4881190563108725493, guid: e5123beefdc062f42b5e3fb98e104cef, + type: 3} + 00000004: + type: {class: PrefabGenerator, ns: Generation, asm: Assembly-CSharp} + data: + prefab: {fileID: 67614980614369834, guid: b3a4fb9191c251d44b6aadea9354fba3, + type: 3} + 00000005: + type: {class: WallGenerator, ns: Generation.Retro, asm: Assembly-CSharp} + data: + prefab: {fileID: 6613264330481197744, guid: 3c5d91e604076ff43b5c7556fe1c89e5, + type: 3} + textureField: Wall + 00000006: + type: {class: PrefabGenerator, ns: Generation, asm: Assembly-CSharp} + data: + prefab: {fileID: 8665094481412155395, guid: ab17a95a8234f8e42b1bcde029bf4720, + type: 3} + 00000007: + type: {class: PrefabGenerator, ns: Generation, asm: Assembly-CSharp} + data: + prefab: {fileID: 1690927267108533612, guid: 3ffc06cfa16e4e24a9c7526f41ba500f, + type: 3} --- !u!4 &1491562770 Transform: m_ObjectHideFlags: 0 diff --git a/src/openrct2-unity/Assets/Scripts/Generation.meta b/src/openrct2-unity/Assets/Scripts/Generation.meta new file mode 100644 index 0000000000..4b3e8dc483 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b02a7a3993994bc438ff2aae967a46de +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs b/src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs new file mode 100644 index 0000000000..67223b9cb9 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs @@ -0,0 +1,28 @@ +using OpenRCT; + +namespace Generation +{ + /// + /// A generator that creates the tile elements. + /// + public interface IElementGenerator + { + /// + /// Creates a tile element at the specified position. + /// + void CreateElement(int x, int y, ref TileElement tile); + + + /// + /// Initialises the generator for the specified map, before new elements + /// are created. + /// + void StartGenerator(Map map); + + + /// + /// Finalizes the created elements and finishes the generator. + /// + void FinishGenerator(); + } +} diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Materials.cs.meta b/src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs.meta similarity index 83% rename from src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Materials.cs.meta rename to src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs.meta index 7d14d1f48d..152b5a1d34 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Materials.cs.meta +++ b/src/openrct2-unity/Assets/Scripts/Generation/IElementGenerator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 208e55b7f2c341549806949cefabc5a2 +guid: d4f42a2eb53ba834699e03e64789137c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous.meta b/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous.meta new file mode 100644 index 0000000000..fe1b9d8460 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 36b553d098048e14a9b38ca185a1895a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs b/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs new file mode 100644 index 0000000000..272f6d63df --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs @@ -0,0 +1,40 @@ +using OpenRCT; +using UnityEngine; + +namespace Generation +{ + /// + /// A simple generator that spawns the specified prefab for the given tile element. + /// + public class PrefabGenerator : IElementGenerator + { + [SerializeField] GameObject prefab; + + + Map map; + + + /// + public void StartGenerator(Map map) + { + this.map = map; + } + + + /// + public void FinishGenerator() + { + map = null; + } + + + /// + public void CreateElement(int x, int y, ref TileElement tile) + { + Vector3 position = Map.TileCoordsToUnity(x, tile.baseHeight, y); + Quaternion rotation = Quaternion.Euler(0, 90 * tile.Rotation + 90, 0); + + GameObject.Instantiate(prefab, position, rotation, map.transform); + } + } +} diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Surface.cs.meta b/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs.meta similarity index 83% rename from src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Surface.cs.meta rename to src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs.meta index 63d66eaa59..3a66fed5a7 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Surface.cs.meta +++ b/src/openrct2-unity/Assets/Scripts/Generation/Miscellaneous/PrefabGenerator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fb5b2ad3f981c4b4983569596d3e5cb0 +guid: 74099863aa18bdc4f9b805afc6f8d7ed MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro.meta b/src/openrct2-unity/Assets/Scripts/Generation/Retro.meta new file mode 100644 index 0000000000..93f07ee835 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 502c2cce8f36f2244b516fb69a1a282b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs new file mode 100644 index 0000000000..1b1f6eab33 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs @@ -0,0 +1,92 @@ +using OpenRCT; +using UnityEngine; + +namespace Generation.Retro +{ + /// + /// A generator for small scenery tile elements. + /// + public class SmallSceneryGenerator : IElementGenerator + { + [Header("Meshes")] + [SerializeField] GameObject crossShape; + + Map map; + + + /// + public void StartGenerator(Map map) + { + this.map = map; + } + + + /// + public void FinishGenerator() + { + map = null; + } + + + /// + public void CreateElement(int x, int y, ref TileElement tile) + { + float pos_x = x; + float pos_y = tile.baseHeight; + float pos_z = y; + + SmallSceneryElement smallScenery = tile.AsSmallScenery(); + + SmallSceneryEntry entry = OpenRCT2.GetSmallSceneryEntry(smallScenery.EntryIndex); + SmallSceneryFlags flags = entry.Flags; + + // If not a full tile, move small scenery to the correct quadrant. + if ((flags & SmallSceneryFlags.FullTile) == 0) + { + const float distanceToQuadrant = (Map.TileCoordsToVector3Multiplier / 4); + byte quadrant = smallScenery.Quadrant; + + switch (quadrant) + { + case 0: pos_x -= distanceToQuadrant; pos_z -= distanceToQuadrant; break; + case 1: pos_x -= distanceToQuadrant; pos_z += distanceToQuadrant; break; + case 2: pos_x += distanceToQuadrant; pos_z += distanceToQuadrant; break; + case 3: pos_x += distanceToQuadrant; pos_z -= distanceToQuadrant; break; + } + } + + // Instantiate the element. + GameObject obj = InstantiateElement(crossShape, pos_x, pos_y, pos_z, (90 * tile.Rotation + 90)); + ApplySprite(obj, ref tile); + } + + + /// + /// Instantiates the prefab in the place of a tile element. + /// + GameObject InstantiateElement(GameObject prefab, float x, float y, float z, float rotation) + { + Vector3 position = Map.TileCoordsToUnity(x, y, z); + Quaternion quatRot = Quaternion.Euler(0, rotation, 0); + + return GameObject.Instantiate(prefab, position, quatRot, map.transform); + } + + + /// + /// Gets the sprite of the tile element and applies it to the gameobject. + /// + static void ApplySprite(GameObject obj, ref TileElement tile) + { + uint imageIndex = OpenRCT2.GetSmallSceneryImageIndex(tile, 0); + Texture2D texture = GraphicsFactory.ForImageIndex(imageIndex).ToTexture2D(TextureWrapMode.Clamp); + + MeshRenderer renderer = obj.GetComponentInChildren(); + renderer.material.SetTexture("_BaseMap", texture); + + // Set the visual scale of the model. + float width = (texture.width * Map.PixelPerUnitMultiplier); + obj.transform.localScale = new Vector3(width, texture.height * Map.PixelPerUnitMultiplier, width); + } + } +} diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs.meta b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs.meta new file mode 100644 index 0000000000..e6f8e669e3 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SmallSceneryGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 28af2eb3d2845f444837f44047f843eb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Materials.cs b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs similarity index 89% rename from src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Materials.cs rename to src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs index ba661d0481..9585899683 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Materials.cs +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs @@ -1,17 +1,18 @@ using System.Collections.Generic; +using OpenRCT; using UnityEngine; -namespace OpenRCT2.Unity +namespace Generation.Retro { - public partial class Map + public partial class SurfaceGenerator { [SerializeField] Shader surfaceShader; - [SerializeField] string surfaceTextureField; + [SerializeField] string surfaceTextureField = "Surface"; [SerializeField] Shader edgeShader; - [SerializeField] string edgeTextureField; + [SerializeField] string edgeTextureField = "Edge"; [SerializeField] Shader waterShader; - [SerializeField] string waterTextureField; - [SerializeField] string waterRefractionField; + [SerializeField] string waterTextureField = "Water"; + [SerializeField] string waterRefractionField = "WaterRefraction"; const byte TypeSurface = 1; @@ -19,7 +20,7 @@ namespace OpenRCT2.Unity const byte TypeWater = 3; - readonly List images = new List(); + List images; /// diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs.meta b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs.meta new file mode 100644 index 0000000000..3dc8607986 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.Textures.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a733e2964083f9c418ebee1921b299ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Surface.cs b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs similarity index 74% rename from src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Surface.cs rename to src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs index 66bf6cc82c..6d84b976af 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Surface.cs +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs @@ -1,9 +1,15 @@ +using System; +using System.Collections.Generic; using MeshBuilding; +using OpenRCT; using UnityEngine; -namespace OpenRCT2.Unity +namespace Generation.Retro { - public partial class Map + /// + /// A generator that generates the surface of a map. + /// + public partial class SurfaceGenerator : IElementGenerator { // For now we only use these two water sprites. static readonly uint WaterImageIndex = OpenRCT2.GetWaterImageIndex(); @@ -11,52 +17,52 @@ namespace OpenRCT2.Unity const byte NoWater = 0; - + Map map; MeshBuilder surfaceMeshBuilder; - /// - /// Initializes the required components for building the surface. - /// - void SetupSurfaceMesh() + /// + public void StartGenerator(Map map) { + this.map = map; surfaceMeshBuilder = new MeshBuilder(); + images = new List(); } - /// - /// Finishes surface building and returns the mesh. - /// - Mesh FinalizeSurfaceMesh() + /// + public void FinishGenerator() { Mesh mesh = surfaceMeshBuilder.ToMesh(); + mesh.name = "Map"; mesh.RecalculateNormals(); + map.Mesh = mesh; + map.Materials = GenerateSurfaceMaterials(); + surfaceMeshBuilder = null; - return mesh; + images = null; } - /// - /// Generates a surface tile along with the edges. - /// - void GenerateSurface(ref TileElement tile, int x, int y) + /// + public void CreateElement(int x, int y, ref TileElement tile) { /* Surface coords to Unity: - * - * ^ W N - * | S E - * y - * x --> - */ + * + * ^ W N + * | S E + * y + * x --> + */ SurfaceElement surface = tile.AsSurface(); SurfaceSlope slope = surface.Slope; int baseHeight = tile.baseHeight; Vertex north = GetSurfaceCorner(x + 1, y + 1, baseHeight, slope, SurfaceSlope.NorthUp); - Vertex east = GetSurfaceCorner(x + 1, y, baseHeight, slope, SurfaceSlope.EastUp); - Vertex south = GetSurfaceCorner(x, y, baseHeight, slope, SurfaceSlope.SouthUp); - Vertex west = GetSurfaceCorner(x, y + 1, baseHeight, slope, SurfaceSlope.WestUp); + Vertex east = GetSurfaceCorner(x + 1, y, baseHeight, slope, SurfaceSlope.EastUp); + Vertex south = GetSurfaceCorner(x, y, baseHeight, slope, SurfaceSlope.SouthUp); + Vertex west = GetSurfaceCorner(x, y + 1, baseHeight, slope, SurfaceSlope.WestUp); uint surfaceImage = OpenRCT2.GetSurfaceImageIndex(tile, x, y, 0); int surfaceSubmesh = PushImageIndex(surfaceImage, TypeSurface); @@ -72,22 +78,22 @@ namespace OpenRCT2.Unity { surfaceMeshBuilder.AddQuad(north, east, south, west, surfaceSubmesh); } - + // Water int waterHeight = surface.WaterHeight; if (waterHeight != NoWater) { - float waterVertexHeight = (waterHeight * TileHeightMultiplier * TileHeightStep); + float waterVertexHeight = (waterHeight * Map.TileHeightMultiplier * Map.TileHeightStep); Vertex waterNorth = new Vertex(north.position.x, waterVertexHeight, north.position.z, Vector3.up, north.uv); - Vertex waterEast = new Vertex(east.position.x, waterVertexHeight, east.position.z, Vector3.up, east.uv); + Vertex waterEast = new Vertex(east.position.x, waterVertexHeight, east.position.z, Vector3.up, east.uv); Vertex waterSouth = new Vertex(south.position.x, waterVertexHeight, south.position.z, Vector3.up, south.uv); - Vertex waterWest = new Vertex(west.position.x, waterVertexHeight, west.position.z, Vector3.up, west.uv); + Vertex waterWest = new Vertex(west.position.x, waterVertexHeight, west.position.z, Vector3.up, west.uv); int waterSubmesh = PushImageIndex(WaterImageIndex, TypeWater); surfaceMeshBuilder.AddQuad(waterNorth, waterEast, waterSouth, waterWest, waterSubmesh); } - + // Edges uint edgeImage = OpenRCT2.GetSurfaceEdgeImageIndex(tile); int edgeSubmesh = PushImageIndex(edgeImage, TypeEdge); @@ -104,20 +110,20 @@ namespace OpenRCT2.Unity /// void TryAddSurfaceEdge(MeshBuilder builder, Vertex leftTop, Vertex rightTop, int x, int y, int offsetX, int offsetY, int waterHeight, SurfaceSlope leftOtherCorner, SurfaceSlope rightOtherCorner, int submesh) { - SurfaceElement other = tiles[x + offsetX, y + offsetY].Surface; + SurfaceElement other = map.Tiles[x + offsetX, y + offsetY].Surface; int baseHeight = other.BaseHeight; SurfaceSlope otherSlope = other.Slope; if (waterHeight != NoWater && other.WaterHeight != waterHeight) { // Render water edge at different height - float waterY = (waterHeight * TileHeightMultiplier * TileHeightStep); + float waterY = (waterHeight * Map.TileHeightMultiplier * Map.TileHeightStep); leftTop.position.y = waterY; rightTop.position.y = waterY; } - float leftBottomY = GetSurfaceCornerHeight(baseHeight, otherSlope, leftOtherCorner) * TileHeightMultiplier; - float rightBottomY = GetSurfaceCornerHeight(baseHeight, otherSlope, rightOtherCorner) * TileHeightMultiplier; + float leftBottomY = GetSurfaceCornerHeight(baseHeight, otherSlope, leftOtherCorner) * Map.TileHeightMultiplier; + float rightBottomY = GetSurfaceCornerHeight(baseHeight, otherSlope, rightOtherCorner) * Map.TileHeightMultiplier; if (leftTop.position.y > leftBottomY || rightTop.position.y > rightBottomY) { @@ -145,9 +151,9 @@ namespace OpenRCT2.Unity int height = GetSurfaceCornerHeight(startHeight, surfaceSlope, surfaceCorner); Vector3 position = new Vector3( - x * TileCoordsToVector3Multiplier, - height * TileHeightMultiplier, - y * TileCoordsToVector3Multiplier + x * Map.TileCoordsToVector3Multiplier, + height * Map.TileHeightMultiplier, + y * Map.TileCoordsToVector3Multiplier ); return new Vertex(position, Vector3.zero, new Vector2(x, y)); @@ -164,7 +170,7 @@ namespace OpenRCT2.Unity // Lift corner vertex up if ((slope & corner) != 0) - height += TileHeightStep; + height += Map.TileHeightStep; if ((slope & (int)SurfaceSlope.DoubleHeight) != 0) { @@ -175,9 +181,10 @@ namespace OpenRCT2.Unity // Check if all corners except opposite are raised. if (corners == (allcornersup & ~opposite)) - height += TileHeightStep; + height += Map.TileHeightStep; } return height; } + } } diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs.meta b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs.meta new file mode 100644 index 0000000000..6589fda882 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/SurfaceGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb755727c9ed637499a59fb3df9d04f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs b/src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs new file mode 100644 index 0000000000..69ce68c097 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs @@ -0,0 +1,51 @@ +using OpenRCT; +using UnityEngine; + +namespace Generation.Retro +{ + /// + /// A generator for wall elements. + /// + public class WallGenerator : IElementGenerator + { + [SerializeField] GameObject prefab; + [SerializeField] string textureField = "Wall"; + + + Map map; + + + /// + public void StartGenerator(Map map) + { + this.map = map; + } + + + /// + public void FinishGenerator() + { + map = null; + } + + + /// + public void CreateElement(int x, int y, ref TileElement tile) + { + Vector3 position = Map.TileCoordsToUnity(x, tile.baseHeight, y); + Quaternion rotation = Quaternion.Euler(0, (90 * tile.Rotation + 90), 0); + + GameObject obj = GameObject.Instantiate(prefab, position, rotation, map.transform); + + // Apply the wall sprite + uint imageIndex = OpenRCT2.GetWallImageIndex(tile, 0); + Texture2D texture = GraphicsFactory.ForImageIndex(imageIndex).ToTexture2D(TextureWrapMode.Repeat); + + MeshRenderer renderer = obj.GetComponentInChildren(); + renderer.material.SetTexture(textureField, texture); + + // Set the visual scale of the model. + obj.transform.localScale = new Vector3(1, (tile.clearanceHeight - tile.baseHeight), 1); + } + } +} diff --git a/src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs.meta b/src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs.meta new file mode 100644 index 0000000000..9154e695a7 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/Generation/Retro/WallGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f4ba4537bc24da48af64bfcbdd42462 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/Maths.cs.meta b/src/openrct2-unity/Assets/Scripts/Maths.cs.meta index 3e22e47492..ecbd1cef40 100644 --- a/src/openrct2-unity/Assets/Scripts/Maths.cs.meta +++ b/src/openrct2-unity/Assets/Scripts/Maths.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cc0a1a7abd6241847b5f5de53b3a98f5 +guid: 55200e5041359b948a5d542b6d81106f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Configuration.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Configuration.cs index d5e7e99ee7..0f39374ad7 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Configuration.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Configuration.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Static class to access OpenRCT2-Unity configuration. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Editor/OpenRCT2Editor.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Editor/OpenRCT2Editor.cs index 5b494bfd48..3ed37d44d0 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Editor/OpenRCT2Editor.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Editor/OpenRCT2Editor.cs @@ -4,7 +4,7 @@ using System.Linq; using UnityEditor; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// An editor that helps configuring OpenRCT2 settings in Unity, for example diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/Ownership.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/Ownership.cs index 79f839cb33..99b105a05b 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/Ownership.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/Ownership.cs @@ -1,6 +1,6 @@ using System; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Flags of ownership of a specific tile. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepAction.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepAction.cs index 7730a2bb9e..a62384b937 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepAction.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepAction.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum PeepAction : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepActionSprite.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepActionSprite.cs index f877982ad0..220d8eb09e 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepActionSprite.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepActionSprite.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum PeepActionSprite : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSpriteType.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSpriteType.cs index 8f92f0c27e..5a60505b62 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSpriteType.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSpriteType.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum PeepSpriteType : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepState.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepState.cs index e899dda1f6..e922b09226 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepState.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepState.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum PeepState : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSubState.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSubState.cs index 7e353db1d3..e92423e40c 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSubState.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepSubState.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum PeepSubState : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepType.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepType.cs index 0180bca0a7..0918bbaed1 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepType.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/PeepType.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum PeepType : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SmallSceneryFlags.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SmallSceneryFlags.cs index 418333dd5d..526024e0d4 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SmallSceneryFlags.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SmallSceneryFlags.cs @@ -1,6 +1,6 @@ using System; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Flags that can be set on a small scenery. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SpriteType.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SpriteType.cs index 11e09ec5a4..b202c579ba 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SpriteType.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SpriteType.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum SpriteType { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SurfaceSlope.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SurfaceSlope.cs index 8711cbc524..01a9616cde 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SurfaceSlope.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/SurfaceSlope.cs @@ -1,6 +1,6 @@ using System; -namespace OpenRCT2.Unity +namespace OpenRCT { [Flags] public enum SurfaceSlope : byte diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainEdgeStyle.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainEdgeStyle.cs index e79f12a922..70e31e74ad 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainEdgeStyle.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainEdgeStyle.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum TerrainEdgeStyle : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainSurfaceStyle.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainSurfaceStyle.cs index 501ee9297f..d3920d33ee 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainSurfaceStyle.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TerrainSurfaceStyle.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { public enum TerrainSurfaceStyle : byte { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TileElementType.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TileElementType.cs index fdd488b738..4097789876 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TileElementType.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Enums/TileElementType.cs @@ -1,6 +1,6 @@ using System; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// The type of element. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/Graphic.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/Graphic.cs index 28556ef600..8db8a123b9 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/Graphic.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/Graphic.cs @@ -1,6 +1,6 @@ using System; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// A small struct that contains RCT graphic information. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicExtensions.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicExtensions.cs index 7761408cef..995de49447 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicExtensions.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicExtensions.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Extensions for the Graphic struct. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicsFactory.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicsFactory.cs index 13b1a0c34c..36b0c7a7e4 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicsFactory.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/GraphicsFactory.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Factory for graphics related things in OpenRCT2. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/PaletteEntry.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/PaletteEntry.cs index dc9a9f5da0..63001a0039 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/PaletteEntry.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Graphics/PaletteEntry.cs @@ -1,7 +1,7 @@ using System.Runtime.InteropServices; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { [StructLayout(LayoutKind.Sequential, Size = 4)] public struct PaletteEntry diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Game.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Game.cs index 05af609891..fffcf2a5a4 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Game.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Game.cs @@ -3,7 +3,7 @@ using System.Runtime.InteropServices; #pragma warning disable CA2101 // Specify marshaling for P/Invoke string arguments -> this is deliberate -namespace OpenRCT2.Unity +namespace OpenRCT { public partial class OpenRCT2 { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Graphics.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Graphics.cs index 98af854dbe..9620241aca 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Graphics.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Graphics.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace OpenRCT2.Unity +namespace OpenRCT { public partial class OpenRCT2 { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Map.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Map.cs index d899dfcea0..637f09cec3 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Map.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Map.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace OpenRCT2.Unity +namespace OpenRCT { public partial class OpenRCT2 { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Sprites.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Sprites.cs index 12999aa110..67a14b9562 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Sprites.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.Sprites.cs @@ -1,7 +1,7 @@ using System.Runtime.InteropServices; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { public partial class OpenRCT2 { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.cs index e9beb033f6..981c1c1e8f 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/OpenRCT2.cs @@ -1,7 +1,7 @@ using System.IO; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { public partial class OpenRCT2 : MonoBehaviour { diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/Ptr.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/Ptr.cs index f15057a280..72f6398fa1 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/Ptr.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Imports/Ptr.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Static helper class for pointer information. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Generation.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Generation.cs index 580b9f0cb9..3befea178b 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Generation.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Generation.cs @@ -1,194 +1,135 @@ +using System; +using Generation; +using Generation.Retro; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { public partial class Map { - [SerializeField] GameObject pathPrefab; - [SerializeField] GameObject trackPrefab; - [SerializeField] GameObject smallSceneryPrefab; - [SerializeField] GameObject entrancePrefab; - [SerializeField] GameObject wallPrefab; - [SerializeField] GameObject largeSceneryPrefab; - [SerializeField] GameObject bannerPrefab; + /// + /// Flags to select which elements to generate and which to ignore. + /// + [Flags] + enum TileElementFlags + { + None = 0, + Path = (1 << 0), + Track = (1 << 1), + SmallScenery = (1 << 2), + Entrance = (1 << 3), + Wall = (1 << 4), + LargeScenery = (1 << 5), + Banner = (1 << 6), + All = ~0 + }; - [SerializeField] bool generatePath = true; - [SerializeField] bool generateTrack = true; - [SerializeField] bool generateSmallScenery = true; - [SerializeField] bool generateEntrance = true; - [SerializeField] bool generateWall = true; - [SerializeField] bool generateLargeScenery = true; - [SerializeField] bool generateBanner = true; + [SerializeField] TileElementFlags generationFlags = TileElementFlags.All; - - const int TileCoordsToCoords = 32; - const float TileCoordsToVector3Multiplier = 1f; - const float CoordsToVector3Multiplier = TileCoordsToVector3Multiplier / TileCoordsToCoords; - - const float TileHeightMultiplier = 0.25f; - const int TileHeightStep = 2; - - const float PixelPerUnitMultiplier = 0.022f; + [Header("Generators")] + [SerializeReference] IElementGenerator surfaceGenerator = new SurfaceGenerator(); + [SerializeReference] IElementGenerator pathGenerator = new PrefabGenerator(); + [SerializeReference] IElementGenerator trackGenerator = new PrefabGenerator(); + [SerializeReference] IElementGenerator smallSceneryGenerator = new SmallSceneryGenerator(); + [SerializeReference] IElementGenerator entranceGenerator = new PrefabGenerator(); + [SerializeReference] IElementGenerator wallGenerator = new WallGenerator(); + [SerializeReference] IElementGenerator largeSceneryGenerator = new PrefabGenerator(); + [SerializeReference] IElementGenerator bannerGenerator = new PrefabGenerator(); /// - /// Generates the surface of the map. + /// Returns all generators currently selected. /// - Mesh GenerateSurfaceMesh() - { - ResetImages(); - SetupSurfaceMesh(); + IElementGenerator[] GetGenerators() + { + return new IElementGenerator[] + { + surfaceGenerator, + pathGenerator, + trackGenerator, + smallSceneryGenerator, + entranceGenerator, + wallGenerator, + largeSceneryGenerator, + bannerGenerator + }; + } - int end = mapSize - 1; + + /// + /// Generates the surface of the map.public + /// + void GenerateMap() + { + IElementGenerator[] generators = GetGenerators(); + + foreach (var generator in generators) + generator.StartGenerator(this); + + int end = (Size - 1); for (int x = 1; x < end; x++) { for (int y = 1; y < end; y++) { - Tile tile = tiles[x, y]; + Tile tile = Tiles[x, y]; for (int e = 0; e < tile.Count; e++) { - GenerateTileElement(ref tile.Elements[e], x, y); + GenerateTileElement(x, y, ref tile.Elements[e]); } } } - return FinalizeSurfaceMesh(); + foreach (var generator in generators) + generator.FinishGenerator(); } /// /// Generates a tile element based on the type of the given tile. /// - void GenerateTileElement(ref TileElement tile, int x, int y) + void GenerateTileElement(int x, int y, ref TileElement tile) { switch (tile.Type) { case TileElementType.Surface: - GenerateSurface(ref tile, x, y); + surfaceGenerator.CreateElement(x, y, ref tile); break; case TileElementType.Path: - if (generatePath) - { - InstantiateElement(ref tile, pathPrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.Path) != 0) + pathGenerator.CreateElement(x, y, ref tile); break; case TileElementType.Track: - if (generateTrack) - { - InstantiateElement(ref tile, trackPrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.Track) != 0) + trackGenerator.CreateElement(x, y, ref tile); break; case TileElementType.SmallScenery: - if (generateSmallScenery) - { - InstantiateSmallScenery(ref tile, smallSceneryPrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.SmallScenery) != 0) + smallSceneryGenerator.CreateElement(x, y, ref tile); break; case TileElementType.Entrance: - if (generateEntrance) - { - InstantiateElement(ref tile, entrancePrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.Entrance) != 0) + entranceGenerator.CreateElement(x, y, ref tile); break; case TileElementType.Wall: - if (generateWall) - { - InstantiateWall(ref tile, wallPrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.Wall) != 0) + wallGenerator.CreateElement(x, y, ref tile); break; case TileElementType.LargeScenery: - if (generateLargeScenery) - { - InstantiateElement(ref tile, largeSceneryPrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.LargeScenery) != 0) + largeSceneryGenerator.CreateElement(x, y, ref tile); break; case TileElementType.Banner: - if (generateBanner) - { - InstantiateElement(ref tile, bannerPrefab, x, tile.baseHeight, y); - } + if ((generationFlags & TileElementFlags.Banner) != 0) + bannerGenerator.CreateElement(x, y, ref tile); break; } } - - - /// - /// Instantiates a prefab in the place of a tile element. - /// - GameObject InstantiateElement(ref TileElement tile, GameObject prefab, float x, float y, float z) - { - Vector3 position = TileCoordsToUnity(x, y, z); - Quaternion rotation = Quaternion.Euler(0, 90 * tile.Rotation + 90, 0); - - return Instantiate(prefab, position, rotation, transform); - } - - - /// - /// Instantiates a small scenery prefab in the place of a tile element. - /// - GameObject InstantiateSmallScenery(ref TileElement tile, GameObject prefab, float x, float y, float z) - { - SmallSceneryElement smallScenery = tile.AsSmallScenery(); - - SmallSceneryEntry entry = OpenRCT2.GetSmallSceneryEntry(smallScenery.EntryIndex); - SmallSceneryFlags flags = entry.Flags; - - // If not a full tile, move small scenery to the correct quadrant. - if ((flags & SmallSceneryFlags.FullTile) == 0) - { - const float distanceToQuadrant = (TileCoordsToVector3Multiplier / 4); - byte quadrant = smallScenery.Quadrant; - - switch (quadrant) - { - case 0: x -= distanceToQuadrant; z -= distanceToQuadrant; break; - case 1: x -= distanceToQuadrant; z += distanceToQuadrant; break; - case 2: x += distanceToQuadrant; z += distanceToQuadrant; break; - case 3: x += distanceToQuadrant; z -= distanceToQuadrant; break; - } - } - - // Instantiate the element. - GameObject obj = InstantiateElement(ref tile, prefab, x, y, z); - - uint imageIndex = OpenRCT2.GetSmallSceneryImageIndex(tile, 0); - Texture2D texture = GraphicsFactory.ForImageIndex(imageIndex).ToTexture2D(TextureWrapMode.Clamp); - - MeshRenderer renderer = obj.GetComponentInChildren(); - renderer.material.SetTexture("_BaseMap", texture); - - // Set the visual scale of the model. - float width = (texture.width * PixelPerUnitMultiplier); - obj.transform.localScale = new Vector3(width, texture.height * PixelPerUnitMultiplier, width); - return obj; - } - - - /// - /// Instantiates a wall prefab in the place of a tile element. - /// - GameObject InstantiateWall(ref TileElement tile, GameObject prefab, float x, float y, float z) - { - // Instantiate the element. - GameObject obj = InstantiateElement(ref tile, prefab, x, y, z); - - uint imageIndex = OpenRCT2.GetWallImageIndex(tile, 0); - Texture2D texture = GraphicsFactory.ForImageIndex(imageIndex).ToTexture2D(TextureWrapMode.Repeat); - - MeshRenderer renderer = obj.GetComponentInChildren(); - renderer.material.SetTexture("Wall", texture); - - // Set the visual scale of the model. - obj.transform.localScale = new Vector3(1, (tile.clearanceHeight - tile.baseHeight), 1); - return obj; - } } } diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs new file mode 100644 index 0000000000..e652412006 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs @@ -0,0 +1,55 @@ +using System; +using UnityEngine; + +namespace OpenRCT +{ + /// + /// The map of the park. + /// + public partial class Map + { + public const int TileCoordsToCoords = 32; + public const float TileCoordsToVector3Multiplier = 1f; + public const float CoordsToVector3Multiplier = TileCoordsToVector3Multiplier / TileCoordsToCoords; + + public const float TileHeightMultiplier = 0.25f; + public const int TileHeightStep = 2; + + public const float PixelPerUnitMultiplier = 0.022f; + + + /// + /// Transforms a OpenRCT2 TileCoords to the Unity coordination system. + /// + public static Vector3 TileCoordsToUnity(float x, float y, float z) + { + float halftile = TileCoordsToVector3Multiplier / 2f; + + return new Vector3( + (x * TileCoordsToVector3Multiplier) + halftile, + y * TileHeightMultiplier, + (z * TileCoordsToVector3Multiplier) + halftile + ); + } + + + /// + /// Transforms a OpenRCT2 Coords to the Unity coordination system. + /// + public static Vector3 CoordsToVector3(float x, float y, float z) + { + return new Vector3( + (x * CoordsToVector3Multiplier), + y * CoordsToVector3Multiplier, + (z * CoordsToVector3Multiplier) + ); + } + + + /// + /// Transforms a OpenRCT2 Coords to the Unity coordination system. + /// + public static Vector3 CoordsToVector3(Vector3 position) + => CoordsToVector3(position.x, position.y, position.z); + } +} diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs.meta b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs.meta new file mode 100644 index 0000000000..792e0e911c --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.Helpers.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea863c9039be81d4190ff5888a22caac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.cs index 26af1589a5..91760af400 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/Map.cs @@ -1,24 +1,55 @@ using System; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// The map of the park. /// + [RequireComponent(typeof(MeshFilter))] + [RequireComponent(typeof(MeshRenderer))] public partial class Map : MonoBehaviour { - MeshFilter meshFilter; - MeshRenderer meshRenderer; + /// + /// Gets the size of one side of the map in tiles. + /// + public int Size { get; private set; } + + + /// + /// Gets all tiles of the map as a 2-dimensional array. + /// + public Tile[,] Tiles { get; private set; } + + + /// + /// Gets or sets the map's mesh. + /// + public Mesh Mesh + { + get => meshFilter.sharedMesh; + set => meshFilter.sharedMesh = value; + } + + + /// + /// Gets or sets the map's materials. + /// + public Material[] Materials + { + get => meshRenderer.sharedMaterials; + set => meshRenderer.sharedMaterials = value; + } const int MaxElementsPerTile = 128; - int mapSize; - Tile[,] tiles; + + MeshFilter meshFilter; + MeshRenderer meshRenderer; - void Awake() + void Awake() { meshFilter = gameObject.GetComponent(); meshRenderer = gameObject.GetComponent(); @@ -28,6 +59,7 @@ namespace OpenRCT2.Unity void Start() { LoadMap(); + GenerateMap(); Debug.Log($"Map load complete!"); } @@ -43,103 +75,20 @@ namespace OpenRCT2.Unity Destroy(child.gameObject); // Load the map - mapSize = OpenRCT2.GetMapSize(); - tiles = new Tile[mapSize, mapSize]; + Size = OpenRCT2.GetMapSize(); + Tiles = new Tile[Size, Size]; TileElement[] buffer = new TileElement[MaxElementsPerTile]; - for (int x = 0; x < mapSize; x++) + for (int x = 0; x < Size; x++) { - for (int y = 0; y < mapSize; y++) + for (int y = 0; y < Size; y++) { int amount = OpenRCT2.GetMapElementsAt(x, y, buffer); - tiles[x, y] = new Tile(buffer, amount); + Tiles[x, y] = new Tile(buffer, amount); } } - - // Generate the surface mesh - Mesh mesh = GenerateSurfaceMesh(); - mesh.name = "Map"; - meshFilter.sharedMesh = mesh; - meshRenderer.sharedMaterials = GenerateSurfaceMaterials(); - } - - - /// - /// A tile struct containing multiple elements. - /// - readonly struct Tile - { - /// - /// All the elements on this tile. - /// - public TileElement[] Elements { get; } - - - // The index at which the surface tile element is located. - readonly int surfaceIndex; - - - /// - /// Creates a new tile from the specified buffer. - /// - public Tile(TileElement[] buffer, int size) - { - Elements = new TileElement[size]; - Array.Copy(buffer, Elements, size); - - surfaceIndex = Array.FindIndex(Elements, t => t.Type == TileElementType.Surface); - } - - - /// - /// Returns the amount of tile elements on this tile. - /// - public int Count - => Elements.Length; - - - /// - /// Returns the surface element on this tile. - /// - public SurfaceElement Surface - => ((surfaceIndex != -1) ? Elements[surfaceIndex].AsSurface() : default); - } - - - /// - /// Transforms a OpenRCT2 TileCoords to the Unity coordination system. - /// - public static Vector3 TileCoordsToUnity(float x, float y, float z) - { - float halftile = TileCoordsToVector3Multiplier / 2f; - - return new Vector3( - (x * TileCoordsToVector3Multiplier) + halftile, - y * TileHeightMultiplier, - (z * TileCoordsToVector3Multiplier) + halftile - ); - } - - - /// - /// Transforms a OpenRCT2 Coords to the Unity coordination system. - /// - public static Vector3 CoordsToVector3(float x, float y, float z) - { - return new Vector3( - (x * CoordsToVector3Multiplier), - y * CoordsToVector3Multiplier, - (z * CoordsToVector3Multiplier) - ); - } - - - /// - /// Transforms a OpenRCT2 Coords to the Unity coordination system. - /// - public static Vector3 CoordsToVector3(Vector3 position) - => CoordsToVector3(position.x, position.y, position.z); + } } } diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs new file mode 100644 index 0000000000..e47bb63f57 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs @@ -0,0 +1,79 @@ +using System; + +namespace OpenRCT +{ + /// + /// A tile struct containing multiple elements. + /// + public readonly struct Tile : IEquatable + { + /// + /// All the elements on this tile. + /// + public TileElement[] Elements { get; } + + + // The index at which the surface tile element is located. + readonly int surfaceIndex; + + + /// + /// Creates a new tile from the specified buffer. + /// + public Tile(TileElement[] buffer, int size) + { + Elements = new TileElement[size]; + Array.Copy(buffer, Elements, size); + + surfaceIndex = Array.FindIndex(Elements, t => t.Type == TileElementType.Surface); + } + + + /// + /// Returns the amount of tile elements on this tile. + /// + public int Count + => Elements.Length; + + + /// + /// Returns the surface element on this tile. + /// + public SurfaceElement Surface + => ((surfaceIndex != -1) ? Elements[surfaceIndex].AsSurface() : default); + + + #region Equals override + + public static bool Equals(Tile left, Tile right) + => (left.Count == right.Count) + && (left.Elements == right.Elements); + + + /// + public override bool Equals(object obj) + => (obj is Tile tile && Equals(this, tile)); + + + /// + public bool Equals(Tile other) + => (Equals(this, other)); + + + /// + public override int GetHashCode() + => (Elements.GetHashCode()); + + + /// + public static bool operator ==(Tile left, Tile right) + => (Equals(left, right)); + + + /// + public static bool operator !=(Tile left, Tile right) + => (!Equals(left, right)); + + #endregion + } +} diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs.meta b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs.meta new file mode 100644 index 0000000000..1823463ce5 --- /dev/null +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/MapTile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f2b904c2ae3d3404e9bd31414109768b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/PeepController.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/PeepController.cs index 88f6208112..4dce1dc8e1 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/PeepController.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/PeepController.cs @@ -1,7 +1,7 @@ using System.Linq; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Controller which moves and updates all the peeps in the park. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/SpriteController.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/SpriteController.cs index 3c2c49150c..f4d5859595 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/SpriteController.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/SpriteController.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Abstract base class for shared code in moving sprites around. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/VehicleController.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/VehicleController.cs index 914a163c88..c1e26e6708 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/VehicleController.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Map/VehicleController.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Controller which moves and updates all ride vehicles in the park. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/ISprite.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/ISprite.cs index 5aa9ee8bbd..c2f267233d 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/ISprite.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/ISprite.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Generic sprite information. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Peep.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Peep.cs index 93bb07ff29..997b61467e 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Peep.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Peep.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// The struct of a peep, which can be either a guest or a staff member. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteBase.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteBase.cs index 7c073f9a01..d4f3570b75 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteBase.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteBase.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace OpenRCT2.Unity +namespace OpenRCT { [StructLayout(LayoutKind.Sequential, Size = 31)] public struct SpriteBase diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteSize.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteSize.cs index badc03e2e7..5c5e25ad69 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteSize.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/SpriteSize.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace OpenRCT2.Unity +namespace OpenRCT { [StructLayout(LayoutKind.Sequential, Size = 4)] public struct SpriteSize diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Vehicle.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Vehicle.cs index 782dee61e1..67a535db90 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Vehicle.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/Sprites/Vehicle.cs @@ -1,7 +1,7 @@ using System.Runtime.InteropServices; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// The struct of a ride vehicle. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/Entries/SmallSceneryEntry.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/Entries/SmallSceneryEntry.cs index 5fa5d07e12..5085244ce7 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/Entries/SmallSceneryEntry.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/Entries/SmallSceneryEntry.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// A small scenery entry struct. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/PathElement.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/PathElement.cs index cbd2afb09d..56bcf84935 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/PathElement.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/PathElement.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// An element representing a piece of path. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SmallSceneryElement.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SmallSceneryElement.cs index 839465d2e2..e0da983ef0 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SmallSceneryElement.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SmallSceneryElement.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// An element representing a small scenery piece. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SurfaceElement.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SurfaceElement.cs index 443e963262..31f01f3cdd 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SurfaceElement.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/SurfaceElement.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// An element representing the surface of the map. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElement.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElement.cs index 43f9d517db..45f3175b01 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElement.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElement.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace OpenRCT2.Unity +namespace OpenRCT { [StructLayout(LayoutKind.Sequential, Size = 16)] public struct TileElement diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElementExtensions.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElementExtensions.cs index 2da6d79cdd..d74e7972c8 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElementExtensions.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TileElementExtensions.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// Extensions for a tile element struct. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TrackElement.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TrackElement.cs index e86b496c1f..5aa919e5ec 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TrackElement.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/TrackElement.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// An element representing a trackpiece of a ride, or a stall. diff --git a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/WallElement.cs b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/WallElement.cs index 91b213465c..78812a2079 100644 --- a/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/WallElement.cs +++ b/src/openrct2-unity/Assets/Scripts/OpenRCT2/TileElements/WallElement.cs @@ -1,4 +1,4 @@ -namespace OpenRCT2.Unity +namespace OpenRCT { /// /// An element representing a piece of wall. diff --git a/src/openrct2-unity/Assets/Scripts/Tools/SelectionTool.cs b/src/openrct2-unity/Assets/Scripts/Tools/SelectionTool.cs index 903e28814e..6f8fd73b26 100644 --- a/src/openrct2-unity/Assets/Scripts/Tools/SelectionTool.cs +++ b/src/openrct2-unity/Assets/Scripts/Tools/SelectionTool.cs @@ -1,44 +1,41 @@ -using System.Collections; -using System.Collections.Generic; +using OpenRCT; +using UI; using UnityEngine; -using UnityEngine.EventSystems; -using OpenRCT2.Unity; -public class SelectionTool : MonoBehaviour + +namespace Tools { - - [SerializeField] WindowManager canvasManager; - [SerializeField] PeepController peepController; - - - void Start() + public class SelectionTool : MonoBehaviour { - } + [SerializeField] WindowManager canvasManager; + [SerializeField] PeepController peepController; - // Update is called once per frame - void Update() - { - if (Input.GetMouseButtonDown(0)) + + // Update is called once per frame + void Update() { - var ray = Camera.main.ScreenPointToRay(Input.mousePosition); - RaycastHit hit; - if (Physics.Raycast(ray, out hit)) + if (Input.GetMouseButtonDown(0)) { - CheckHit(hit.collider.gameObject); + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + + if (Physics.Raycast(ray, out RaycastHit hit)) + { + CheckHit(hit.collider.gameObject); + } + } + } + + + void CheckHit(GameObject obj) + { + switch (obj.tag) + { + case "Peep": + canvasManager.CreatePeepWindow(peepController.FindPeepIdForGameObject(obj)); + break; + default: + break; } } } - - void CheckHit(GameObject obj) - { - switch (obj.tag) - { - case "Peep": - canvasManager.CreatePeepWindow(peepController.FindPeepIdForGameObject(obj)); - break; - default: - break; - } - } - } diff --git a/src/openrct2-unity/Assets/Scripts/UI/PeepWindow.cs b/src/openrct2-unity/Assets/Scripts/UI/PeepWindow.cs index c54c59ee95..a0806d7866 100644 --- a/src/openrct2-unity/Assets/Scripts/UI/PeepWindow.cs +++ b/src/openrct2-unity/Assets/Scripts/UI/PeepWindow.cs @@ -1,49 +1,56 @@ -using System.Collections; -using System.Collections.Generic; +using OpenRCT; using UnityEngine; using UnityEngine.UI; -using OpenRCT2.Unity; -public class PeepWindow : MonoBehaviour +namespace UI { - [SerializeField] Text title; - [SerializeField] Slider happinessBar; - [SerializeField] Slider energyBar; - [SerializeField] Slider hungerBar; - [SerializeField] Slider thirstBar; - [SerializeField] Slider nauseaBar; - [SerializeField] Slider toiletBar; - ushort peepId; - PeepController peepControllerScript; - - public void LoadPeepController(PeepController peepController, ushort id) + public class PeepWindow : MonoBehaviour { - peepId = id; - peepControllerScript = peepController; - title.text = $"Guest {peepId}"; - InvokeRepeating("UpdateData", 0f, 5f); - } + [SerializeField] Text title; + [SerializeField] Slider happinessBar; + [SerializeField] Slider energyBar; + [SerializeField] Slider hungerBar; + [SerializeField] Slider thirstBar; + [SerializeField] Slider nauseaBar; + [SerializeField] Slider toiletBar; - void UpdateData() - { - Peep? peep = peepControllerScript.GetPeepById(peepId); - if (peep == null) + PeepController peepController; + ushort peepId; + + + public void LoadPeepController(PeepController peepController, ushort peepId) { - Destroy(gameObject); + this.peepId = peepId; + this.peepController = peepController; + + title.text = $"Guest {this.peepId}"; + InvokeRepeating(nameof(UpdateData), 0f, 5f); } - var value = peep.Value; - happinessBar.value = value.happiness; - energyBar.value = value.energy; - hungerBar.value = value.hunger; - thirstBar.value = value.thirst; - nauseaBar.value = value.nausea; - toiletBar.value = value.toilet; - /* - var intensityBinary = System.Convert.ToString(peep.intensity, 2); - var maxIntensityString = System.Convert.ToString(peep.intensity >> 4); - var minIntensityString = System.Convert.ToString(peep.intensity & 0b1111); - */ + void UpdateData() + { + Peep? peep = peepController.GetPeepById(peepId); + if (peep == null) + { + Destroy(gameObject); + return; + } + + Peep value = peep.Value; + + happinessBar.value = value.happiness; + energyBar.value = value.energy; + hungerBar.value = value.hunger; + thirstBar.value = value.thirst; + nauseaBar.value = value.nausea; + toiletBar.value = value.toilet; + + /* + var intensityBinary = System.Convert.ToString(peep.intensity, 2); + var maxIntensityString = System.Convert.ToString(peep.intensity >> 4); + var minIntensityString = System.Convert.ToString(peep.intensity & 0b1111); + */ + } } } diff --git a/src/openrct2-unity/Assets/Scripts/UI/WindowManager.cs b/src/openrct2-unity/Assets/Scripts/UI/WindowManager.cs index d2f34a0a4b..f4d3b1d28d 100644 --- a/src/openrct2-unity/Assets/Scripts/UI/WindowManager.cs +++ b/src/openrct2-unity/Assets/Scripts/UI/WindowManager.cs @@ -1,19 +1,21 @@ -using System.Collections; -using System.Collections.Generic; +using OpenRCT; using UnityEngine; -using OpenRCT2.Unity; -public class WindowManager : MonoBehaviour + +namespace UI { - - [SerializeField] GameObject peepBox; - [SerializeField] GameObject peepCanvas; - [SerializeField] PeepController peepController; - - public void CreatePeepWindow(ushort id) + public class WindowManager : MonoBehaviour { - GameObject obj = Instantiate(peepBox, peepCanvas.transform); - obj.name = $"PeepBox: {id}"; - obj.GetComponent().LoadPeepController(peepController, id); + + [SerializeField] GameObject peepBox; + [SerializeField] GameObject peepCanvas; + [SerializeField] PeepController peepController; + + public void CreatePeepWindow(ushort id) + { + GameObject obj = Instantiate(peepBox, peepCanvas.transform); + obj.name = $"PeepBox: {id}"; + obj.GetComponent().LoadPeepController(peepController, id); + } } } diff --git a/src/openrct2-unity/Assets/csc.rsp b/src/openrct2-unity/Assets/csc.rsp index 5d85f266dc..9784145f94 100644 --- a/src/openrct2-unity/Assets/csc.rsp +++ b/src/openrct2-unity/Assets/csc.rsp @@ -1 +1 @@ --nowarn:649,1401 +-nowarn:649,1401,2235 diff --git a/src/openrct2-unity/ProjectSettings/QualitySettings.asset b/src/openrct2-unity/ProjectSettings/QualitySettings.asset index a45c679e5d..cab35ccc42 100644 --- a/src/openrct2-unity/ProjectSettings/QualitySettings.asset +++ b/src/openrct2-unity/ProjectSettings/QualitySettings.asset @@ -95,7 +95,7 @@ QualitySettings: skinWeights: 2 textureQuality: 0 anisotropicTextures: 1 - antiAliasing: 2 + antiAliasing: 0 softParticles: 0 softVegetation: 1 realtimeReflectionProbes: 1