diff --git a/VisualPinball.Engine/Game/Engines/GamelogicEngineCoil.cs b/VisualPinball.Engine/Game/Engines/GamelogicEngineCoil.cs index ee1c4b768..eab4939e2 100644 --- a/VisualPinball.Engine/Game/Engines/GamelogicEngineCoil.cs +++ b/VisualPinball.Engine/Game/Engines/GamelogicEngineCoil.cs @@ -16,7 +16,7 @@ namespace VisualPinball.Engine.Game.Engines { - public struct GamelogicEngineCoil + public class GamelogicEngineCoil { public string Id; public string Description; diff --git a/VisualPinball.Engine/Game/Engines/GamelogicEngineSwitch.cs b/VisualPinball.Engine/Game/Engines/GamelogicEngineSwitch.cs index 5153a197e..47527a54f 100644 --- a/VisualPinball.Engine/Game/Engines/GamelogicEngineSwitch.cs +++ b/VisualPinball.Engine/Game/Engines/GamelogicEngineSwitch.cs @@ -16,7 +16,7 @@ namespace VisualPinball.Engine.Game.Engines { - public struct GamelogicEngineSwitch + public class GamelogicEngineSwitch { public string Id; public string Description; diff --git a/VisualPinball.Engine/VPT/Mappings/Mappings.cs b/VisualPinball.Engine/VPT/Mappings/Mappings.cs index 132523cff..da7d7a0b6 100644 --- a/VisualPinball.Engine/VPT/Mappings/Mappings.cs +++ b/VisualPinball.Engine/VPT/Mappings/Mappings.cs @@ -72,7 +72,7 @@ public void PopulateSwitches(GamelogicEngineSwitch[] engineSwitches, IEnumerable var source = GuessSwitchSource(engineSwitch); var playfieldItem = source == SwitchSource.Playfield ? GuessPlayfieldSwitch(switches, engineSwitch) : null; var device = source == SwitchSource.Device ? GuessDevice(switchDevices, engineSwitch) : null; - var deviceItem = source == SwitchSource.Device && device != null ? GuessDeviceSwitch(engineSwitch, device) : default; + var deviceItem = source == SwitchSource.Device && device != null ? GuessDeviceSwitch(engineSwitch, device) : null; var inputActionMap = source == SwitchSource.InputSystem ? string.IsNullOrEmpty(engineSwitch.InputMapHint) ? InputConstants.MapCabinetSwitches : engineSwitch.InputMapHint : string.Empty; @@ -88,7 +88,7 @@ public void PopulateSwitches(GamelogicEngineSwitch[] engineSwitches, IEnumerable InputActionMap = inputActionMap, InputAction = inputAction, Device = device != null ? device.Name : string.Empty, - DeviceItem = deviceItem.Id + DeviceItem = deviceItem != null ? deviceItem.Id : string.Empty }); } } @@ -175,7 +175,7 @@ private static GamelogicEngineSwitch GuessDeviceSwitch(GamelogicEngineSwitch eng } } } - return default; + return null; } #endregion @@ -215,7 +215,7 @@ public void PopulateCoils(GamelogicEngineCoil[] engineCoils, IEnumerable diff --git a/VisualPinball.Engine/Math/ProgMesh.meta b/VisualPinball.Unity/Assets.meta similarity index 77% rename from VisualPinball.Engine/Math/ProgMesh.meta rename to VisualPinball.Unity/Assets.meta index c318d2a89..50813cf40 100644 --- a/VisualPinball.Engine/Math/ProgMesh.meta +++ b/VisualPinball.Unity/Assets.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 99e7165debbf74a40b62bad26304c77d +guid: 1f1097b31ca91c947ab0e48ce64e1fde folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/VisualPinball.Engine/VPT/Ball.meta b/VisualPinball.Unity/Assets/Materials.meta similarity index 77% rename from VisualPinball.Engine/VPT/Ball.meta rename to VisualPinball.Unity/Assets/Materials.meta index 80221ce16..8197bb791 100644 --- a/VisualPinball.Engine/VPT/Ball.meta +++ b/VisualPinball.Unity/Assets/Materials.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f152d85d99f8d0045b82006e41ab152c +guid: ba8cdac2dd565ca4da1812678a43d513 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/VisualPinball.Unity/Assets/Materials/DefaultBall.mat b/VisualPinball.Unity/Assets/Materials/DefaultBall.mat new file mode 100644 index 000000000..2297349f0 --- /dev/null +++ b/VisualPinball.Unity/Assets/Materials/DefaultBall.mat @@ -0,0 +1,78 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: DefaultBall + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: f9cf0be10d18f504382975efa980b1b6, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0.5 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/VisualPinball.Unity/Assets/Materials/DefaultBall.mat.meta b/VisualPinball.Unity/Assets/Materials/DefaultBall.mat.meta new file mode 100644 index 000000000..a4d03ab05 --- /dev/null +++ b/VisualPinball.Unity/Assets/Materials/DefaultBall.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6eb0d5d325d217242a1ec1ecd5aae780 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Engine/Resources.meta b/VisualPinball.Unity/Assets/Resources.meta similarity index 77% rename from VisualPinball.Engine/Resources.meta rename to VisualPinball.Unity/Assets/Resources.meta index c37489c0c..4bd043366 100644 --- a/VisualPinball.Engine/Resources.meta +++ b/VisualPinball.Unity/Assets/Resources.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3ae7037aad5f2ef4b83851555066820b +guid: 6f8d3f1771e52244899b1a292612f19c folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/Managers/Switches.meta b/VisualPinball.Unity/Assets/Resources/Prefabs.meta similarity index 77% rename from VisualPinball.Unity/VisualPinball.Unity.Editor/Managers/Switches.meta rename to VisualPinball.Unity/Assets/Resources/Prefabs.meta index cb5c259bf..42fd7f858 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/Managers/Switches.meta +++ b/VisualPinball.Unity/Assets/Resources/Prefabs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 53fdb2d40e5e4ad4586e0ce3129fdc6f +guid: f3600da168d88334ba3354c0653cd27f folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/VisualPinball.Unity/Assets/Resources/Prefabs/DefaultBall.prefab b/VisualPinball.Unity/Assets/Resources/Prefabs/DefaultBall.prefab new file mode 100644 index 000000000..f6106a510 --- /dev/null +++ b/VisualPinball.Unity/Assets/Resources/Prefabs/DefaultBall.prefab @@ -0,0 +1,83 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &8289283333368007096 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3881672604355561253} + - component: {fileID: 6075728238804368159} + - component: {fileID: 5180081487853661404} + m_Layer: 0 + m_Name: DefaultBall + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3881672604355561253 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8289283333368007096} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.05, y: 0.05, z: 0.05} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &6075728238804368159 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8289283333368007096} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &5180081487853661404 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8289283333368007096} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 6eb0d5d325d217242a1ec1ecd5aae780, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} diff --git a/VisualPinball.Unity/Assets/Resources/Prefabs/DefaultBall.prefab.meta b/VisualPinball.Unity/Assets/Resources/Prefabs/DefaultBall.prefab.meta new file mode 100644 index 000000000..6f9bd3209 --- /dev/null +++ b/VisualPinball.Unity/Assets/Resources/Prefabs/DefaultBall.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 408769e6e653d18449e33b50500e437b +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipeline.meta b/VisualPinball.Unity/Assets/Textures.meta similarity index 77% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipeline.meta rename to VisualPinball.Unity/Assets/Textures.meta index cfee99429..80cfd4f77 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipeline.meta +++ b/VisualPinball.Unity/Assets/Textures.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 77a4bb08abed3554192b47625f387bd2 +guid: 8110cb114f58a8e49bce9df18b28b916 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/VisualPinball.Unity/Assets/Textures/BallDebug.png b/VisualPinball.Unity/Assets/Textures/BallDebug.png new file mode 100644 index 000000000..d06ef8d3d Binary files /dev/null and b/VisualPinball.Unity/Assets/Textures/BallDebug.png differ diff --git a/VisualPinball.Unity/Assets/Textures/BallDebug.png.meta b/VisualPinball.Unity/Assets/Textures/BallDebug.png.meta new file mode 100644 index 000000000..cf8d19b4b --- /dev/null +++ b/VisualPinball.Unity/Assets/Textures/BallDebug.png.meta @@ -0,0 +1,92 @@ +fileFormatVersion: 2 +guid: f9cf0be10d18f504382975efa980b1b6 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + 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: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/explorer-vpe-root.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/explorer-vpe-root.png index 84b55a0f6..823dbf165 100644 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/explorer-vpe-root.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/explorer-vpe-root.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md b/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md index b7c71fd66..1ba8cc15a 100644 --- a/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md +++ b/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md @@ -45,30 +45,36 @@ If you create an HDRP project, Unity provides you with a sample scene: ![HDRP Sample Scene](unity-hdrp-default-scene.png) -It's best to start by removing the unneeded objects. In the hierarchy, select: +The sample scene is awesome but huge, so we're going to discard it and create a new one. Click on *File -> New Scene* and select the *Basic Indoors (HDRP)* template. Save it in your *Assets/Scenes* folder as `TestTable.unity`. -Sky and Fog Volume, Light Probe Group, Example Assets +In this scene there's a plane that will [Z-fight](https://en.wikipedia.org/wiki/Z-fighting) with our imported table later. Select it in the *Hierarchy* and move it down a little by setting the *Y Position* under *Transform* in the *Inspector* to `-0.1`. Your scene should now look like this: -and press `delete`. +![TestTable Scene](unity-hdrp-test-scene.png) -Similarly, to clean up the project, get rid of the extra assets in the project view: - -ExampleAssets, TutorialInfo +Hit *Ctrl+S* to save your scene. ## VPE Source Code -Now you have your project and scene set up, let's bring VPE into the project. Go to the GitHub page and [download the source code](https://github.com/freezy/VisualPinball.Engine). You can do that by clicking on the green *Code* button, and choosing *Downlaod ZIP*. +Now you have your project and scene set up, let's bring VPE into the project. Go to the GitHub page and [download the source code](https://github.com/freezy/VisualPinball.Engine). You can do that by clicking on the green *Code* button, and choosing *Download ZIP*. + +As mentioned above, we recommend extracting this into the `VPE\VisualPinball.Engine` folder. Now, since we're using the High Definition Render Pipeline, we need to download another package which contains the rendering code. This package is part of VPE but lives in a different repository. Like before, [download](https://github.com/freezy/VisualPinball.Unity.Hdrp) and extract it to your VPE folder. -As mentioned above, we recommend extracting this into the `%userprofile%\VPE\VisualPinball.Engine` folder: +Your structure should now look something like this: ![File Structure](explorer-vpe-root.png) In Unity, go to *Window -> Package Manager*. Click on the "plus" icon on the top left corner of the window, and choose *Add package from disk*. Choose `package.json` in the root folder of the extracted VPE source code. -Package Manager +

Package Manager

This will take a moment as Unity downloads and compiles all of VPE's dependencies. If during this time, you see the following warning: -![Unity Input System Warning](unity-input-system-warning.png) +

Unity Input System Warning

Click *Yes*. When complete, you should now have a *Visual Pinball* menu in the editor. + +Now do the same for the HDRP package. If everything went okay, you should now have these two packages showing up in the Package Manager: + +![Package Manager after installation](unity-packages-after-installation.png) + +So let's [import a table](running-vpe.md)! \ No newline at end of file diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md b/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md index 51b89dc24..2df2e2bf7 100644 --- a/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md +++ b/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md @@ -9,17 +9,22 @@ You should now see Visual Pinball's blank table in the Editor's scene view: ![Imported blank table](unity-imported-table.png) -Now, we don't see much of our table. That's because the scene view's camera doesn't really point on it. Using the right mouse button and the `A` `W` `S` `D` keys while keeping right mouse button pressed, fly somewhere you have a better view of the table. +Now, we don't see much of our table. That's because the scene view's camera doesn't really point on it. Using the right mouse button in the *Scene View* and the `A` `W` `S` `D` keys while keeping right mouse button pressed, fly somewhere you have a better view of the table. > [!TIP] > Check Unity's documentation on [Scene view navigation](https://docs.unity3d.com/Manual/SceneViewNavigation.html) for a more complete list of ways to move the camera around the scene. -Now that you have the camera of the scene view somewhat aligned. +Now that we have the camera of the scene view somewhat aligned, we still can't see much! + +![Imported blank table](unity-imported-table-ugly-gizmos.png) + +These orange artifacts are what Unity calls [Gizmo Icons](https://docs.unity3d.com/Manual/GizmosMenu.html). They are enabled by default, and since VPE uses icons for its playfield elements, they are all over the place. In order to get rid of them, click on the *Gizmos* dropdown and de-select them by clicking on the icon next to the check box. Sorry, we're looking into a way of deactivating them automatically. + +Since a pinball table is a relatively small object, the icons are huge when working on a table, so use the top slider to shrink them down a bit. ![Scene view camera on table](unity-imported-table-aligned.png) -> [!TIP] -> A pinball table is a relatively small object, so Unity's "gizmo" icons marking scene objects are huge. You can make them smaller with the [Gizmos menu](https://docs.unity3d.com/Manual/GizmosMenu.html) by using the *3D Icons* slider. +Now that's better! The view in the scene tab is not the camera used in game. The *Scene View* really allows you to fly anywhere, zoom in on things you're working on, switch from orthagonal view to perspective, and so on. It's where you get work done. @@ -30,11 +35,19 @@ This camera can be moved [using Unity's gizmos](https://docs.unity3d.com/Manual/ > [!TIP] > A quick way to fix the game camera is to align it with the scene view camera. To do that, select the camera in the hierarchy, then click on the *GameObject* menu and select *Align with view*. -Now, click on the play button. This will run your scene. Test that the shift keys move the flippers. Press `B` to add a new ball. If it's not already choppy, it will get after a dozen or so balls, because VPE currently doesn't destroy them. +One last thing we need to do before playing is enable version 2 of the [Hybrid Renderer](https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.10/manual/index.html) we're using. Go to *Edit -> Project Settings*, select *Player* on the left, scroll down a bit on the right and add `ENABLE_HYBRID_RENDERER_V2` under *Script Define Symbols*. -The choppiness is also due to running the game inside the editor, fetching data during gameplay, and the code not being optimized. +![Enable hybrid renderer](unity-settings-hybridv2.png) -This should all go away if you choose *Build and Run* under the *File* menu. Running it as "build" should give you significantly smoother gameplay. +Then click on *Apply* and close the window. + +Let's start the game by clicking on the play button. This will run your scene. Test that the shift keys move the flippers. `ENTER` will launch a ball. If you expand *Table1* in the hierarchy and select the *Trough*, you can watch its status in the inspector in real time. Cool! + +You can also right-click on the scene view tab and select *Maximize*. + +![Play Mode](unity-first-play.png) > [!TIP] > If you want to enter play mode more quickly, you can check the experimental play mode option described [here](https://blogs.unity3d.com/2019/11/05/enter-play-mode-faster-in-unity-2019-3/). + +One last thing: The game view is pretty static now. You can change that by dropping an [orbit script](https://gist.github.com/freezy/cd6a2371c90a84a7af850cab3b07b1ed) on the camera that lets you rotate and zoom in. If you're a Unity beginner, that would be your first exercise! \ No newline at end of file diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-create-new-project.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-create-new-project.png index 8bffac045..43a686931 100644 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-create-new-project.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-create-new-project.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-first-play.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-first-play.png new file mode 100644 index 000000000..3b05d0b03 Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-first-play.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-default-scene.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-default-scene.png index febb6f83b..6a705fa89 100644 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-default-scene.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-default-scene.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-test-scene.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-test-scene.png new file mode 100644 index 000000000..cd980c808 Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-test-scene.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-to-delete-assets.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-to-delete-assets.png deleted file mode 100644 index 6f3f2eda6..000000000 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-to-delete-assets.png and /dev/null differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-to-delete.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-to-delete.png deleted file mode 100644 index 9262aea89..000000000 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-to-delete.png and /dev/null differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-aligned.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-aligned.png index acf54302c..5bf7d630e 100644 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-aligned.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-aligned.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-ugly-gizmos.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-ugly-gizmos.png new file mode 100644 index 000000000..9600b7766 Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-ugly-gizmos.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table.png index 79f6e4ebc..c4ce271f7 100644 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-input-system-warning.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-input-system-warning.png index a2349091a..d1021d6c6 100644 Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-input-system-warning.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-input-system-warning.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-packages-after-installation.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-packages-after-installation.png new file mode 100644 index 000000000..fc5a0b307 Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-packages-after-installation.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-settings-hybridv2.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-settings-hybridv2.png new file mode 100644 index 000000000..f46e31c26 Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-settings-hybridv2.png differ diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/updating-vpe.md b/VisualPinball.Unity/Documentation~/creators-guide/setup/updating-vpe.md index 22396e827..7ca849848 100644 --- a/VisualPinball.Unity/Documentation~/creators-guide/setup/updating-vpe.md +++ b/VisualPinball.Unity/Documentation~/creators-guide/setup/updating-vpe.md @@ -18,13 +18,16 @@ Following the recommended file structure, you would type: ```cmd cd %userprofile%\VPE git clone https://github.com/freezy/VisualPinball.Engine.git +git clone https://github.com/freezy/VisualPinball.Unity.Hdrp.git ``` -This downloads the latest version of VPE into `%userprofile%\VPE\VisualPinball.Engine` and keeps a link to GitHub. In the future, if you want to update VPE, it's simply a matter of going into the folder and "pull" the changes: +This downloads the latest version of VPE into `VisualPinball.Engine` and `VisualPinball.Unity.Hdrp` respectively and keeps a link to GitHub. In the future, if you want to update VPE, it's simply a matter of going into the folder and "pull" the changes: ```cmd cd %userprofile%\VPE\VisualPinball.Engine git pull +cd ..\VisualPinball.Unity.Hdrp +git pull ``` However, you might have experimented in the VPE folder to test out stuff, and git complains it can't update. Here is a way to discard all local changes and pull in what's on GitHub: diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/Layers/LayerEditor.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/Layers/LayerEditor.cs index 5e88c48e4..de6df9091 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/Layers/LayerEditor.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/Layers/LayerEditor.cs @@ -19,10 +19,8 @@ using System.Collections.Generic; using System.Linq; using UnityEditor; -using UnityEditor.IMGUI.Controls; using UnityEngine; using VisualPinball.Unity.Editor.Utils.Dialogs; -using VisualPinball.Unity.Editor.Utils; namespace VisualPinball.Unity.Editor { diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/Toolbox/ToolboxEditor.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/Toolbox/ToolboxEditor.cs index 98b20e168..a4d595d62 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/Toolbox/ToolboxEditor.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/Toolbox/ToolboxEditor.cs @@ -17,7 +17,6 @@ using System; using UnityEditor; using UnityEngine; -using VisualPinball.Engine.Game; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Bumper; using VisualPinball.Engine.VPT.Flipper; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/Icons.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/Icons.cs index a47654575..e1fc6214c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/Icons.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/Icons.cs @@ -6,7 +6,6 @@ using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; -using VisualPinball.Engine.VPT; using VisualPinball.Unity.Playfield; using Object = UnityEngine.Object; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs index 692e1a8e3..a69731ef6 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs @@ -411,6 +411,10 @@ protected virtual void FinishEdit(string label, bool dirtyMesh = true) EditorUtility.SetDirty(target); } Undo.RecordObject(UndoTarget, undoLabel); + + if (target is IItemMainRenderableAuthoring item) { + item.ItemDataChanged(); + } } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerColliderInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerColliderInspector.cs index 7f8ccab75..8ce22964d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerColliderInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerColliderInspector.cs @@ -17,7 +17,6 @@ // ReSharper disable AssignmentInConditionalExpression using UnityEditor; -using VisualPinball.Engine.VPT.Kicker; using VisualPinball.Engine.VPT.Plunger; namespace VisualPinball.Unity.Editor diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampColliderInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampColliderInspector.cs index 222ea5289..6f894c889 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampColliderInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampColliderInspector.cs @@ -17,7 +17,6 @@ // ReSharper disable AssignmentInConditionalExpression using UnityEditor; -using VisualPinball.Engine.VPT.Kicker; using VisualPinball.Engine.VPT.Ramp; namespace VisualPinball.Unity.Editor diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberMeshInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberMeshInspector.cs index 419f21f7b..c71a7a8c2 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberMeshInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberMeshInspector.cs @@ -17,7 +17,6 @@ // ReSharper disable AssignmentInConditionalExpression using UnityEditor; -using VisualPinball.Engine.VPT.Kicker; using VisualPinball.Engine.VPT.Rubber; namespace VisualPinball.Unity.Editor diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs index a0782e96a..3465058ff 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs @@ -17,7 +17,6 @@ // ReSharper disable AssignmentInConditionalExpression using UnityEditor; -using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Trigger; namespace VisualPinball.Unity.Editor diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Item/RenderPipelineAttribute.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Item/RenderPipelineAttribute.cs index 6eaea0d00..ec383fb03 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Item/RenderPipelineAttribute.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Item/RenderPipelineAttribute.cs @@ -33,7 +33,7 @@ public RenderPipelineAttribute(RenderPipelineType type) public override bool Matches(Engine.VPT.Table.Table table, IRenderable item, GameObject obj) { - return RenderPipeline.Current == _type; + return RenderPipeline.Current.Type == _type; } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/RenderPipeline.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/RenderPipeline.cs deleted file mode 100644 index e5060edfb..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/RenderPipeline.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2020 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System; -using VisualPinball.Unity.Patcher.RenderPipelinePatcher; - -namespace VisualPinball.Unity.Patcher.Matcher -{ - public enum RenderPipelineType - { - BuiltIn, - Hdrp, - Urp - } - - public static class RenderPipeline - { - public static RenderPipelineType Current - { - get { if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null) { - - if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset.GetType().Name.Contains("UniversalRenderPipelineAsset")) { - return RenderPipelineType.Urp; - } - - if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset.GetType().Name.Contains("HDRenderPipelineAsset")) { - return RenderPipelineType.Hdrp; - } - } - return RenderPipelineType.BuiltIn; - } - } - - /// - /// Patcher instance for the current graphics pipeline - /// - public static IRenderPipelinePatcher Patcher => CreateRenderPipelinePatcher(); - - /// - /// Create a render pipeline patcher depending on the graphics pipeline - /// - /// - private static IRenderPipelinePatcher CreateRenderPipelinePatcher() - { - switch (RenderPipeline.Current) - { - case RenderPipelineType.BuiltIn: - return new BuiltInPatcher(); - case RenderPipelineType.Hdrp: - return new HdrpPatcher(); - case RenderPipelineType.Urp: - return new UrpPatcher(); - default: - throw new ArgumentOutOfRangeException(); - } - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Table/RenderPipelineAttribute.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Table/RenderPipelineAttribute.cs index 247fa238a..46aeed620 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Table/RenderPipelineAttribute.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/Table/RenderPipelineAttribute.cs @@ -30,7 +30,7 @@ public RenderPipelineAttribute(RenderPipelineType type) public override bool Matches(Engine.VPT.Table.Table table, string fileName) { - return RenderPipeline.Current == _type; + return RenderPipeline.Current.Type == _type; } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Common/PatcherUtil.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Common/PatcherUtil.cs index 3f9aae22d..eb3870e4e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Common/PatcherUtil.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Common/PatcherUtil.cs @@ -1,4 +1,20 @@ -using NLog; +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using NLog; using UnityEngine; using Logger = NLog.Logger; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Patcher.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Patcher.cs index a3aa2be70..f869ca5d4 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Patcher.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Patcher.cs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// ReSharper disable UnusedType.Global + using System; using System.Collections.Generic; using System.Linq; @@ -27,14 +29,14 @@ namespace VisualPinball.Unity.Patcher { - public class Patcher + public class Patcher : IPatcher { private readonly List _patchers = new List(); - private readonly Table _table; + private Table _table; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public Patcher(Table table, string fileName) + public void SetTable(Table table, string fileName) { _table = table; var types = typeof(Patcher).Assembly.GetTypes(); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher.meta b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher.meta deleted file mode 100644 index 3f66a4914..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d61219d2aaa40cd41bdfd31a01e28038 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/BuiltInPatcher.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/BuiltInPatcher.cs deleted file mode 100644 index 60ad8da0b..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/BuiltInPatcher.cs +++ /dev/null @@ -1,46 +0,0 @@ -using NLog; -using UnityEngine; -using Logger = NLog.Logger; - -namespace VisualPinball.Unity.Patcher.RenderPipelinePatcher -{ - public class BuiltInPatcher : IRenderPipelinePatcher - { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public void SetOpaque(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetOpaque"); - } - - public void SetDoubleSided(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetDoubleSided"); - } - - public void SetTransparentDepthPrepassEnabled(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetTransparentDepthPrepassEnabled"); - } - - public void SetAlphaCutOff(GameObject gameObject, float value) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetAlphaCutOff"); - } - - public void SetAlphaCutOffEnabled(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetAlphaCutOffEnabled"); - } - - public void SetNormalMapDisabled(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetNormalMapDisabled"); - } - - public void SetMetallic(GameObject gameObject, float value) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetMetallic"); - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/HdrpPatcher.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/HdrpPatcher.cs deleted file mode 100644 index 3880b8785..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/HdrpPatcher.cs +++ /dev/null @@ -1,88 +0,0 @@ -using NLog; -using UnityEngine; - -namespace VisualPinball.Unity.Patcher.RenderPipelinePatcher -{ - public class HdrpPatcher : IRenderPipelinePatcher - { - private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger(); - - public void SetOpaque(GameObject gameObject) - { - var material = gameObject.GetComponent().sharedMaterial; - - material.SetFloat("_SurfaceType", 0); - - material.SetFloat("_DstBlend", 0); - material.SetFloat("_ZWrite", 1); - - material.DisableKeyword("_ALPHATEST_ON"); - material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT"); - material.DisableKeyword("_BLENDMODE_PRE_MULTIPLY"); - material.DisableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); - } - - public void SetDoubleSided(GameObject gameObject) - { - - var material = gameObject.GetComponent().sharedMaterial; - - material.EnableKeyword("_DOUBLESIDED_ON"); - material.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); - - material.SetInt("_DoubleSidedEnable", 1); - material.SetInt("_DoubleSidedNormalMode", 1); - - material.SetInt("_CullMode", 0); - material.SetInt("_CullModeForward", 0); - } - - public void SetTransparentDepthPrepassEnabled(GameObject gameObject) - { - var material = gameObject.GetComponent().sharedMaterial; - - material.EnableKeyword("_DISABLE_SSR_TRANSPARENT"); - - material.SetInt("_TransparentDepthPrepassEnable", 1); - material.SetInt("_AlphaDstBlend", 10); - material.SetInt("_ZTestModeDistortion", 4); - - material.SetShaderPassEnabled("TransparentDepthPrepass", true); - material.SetShaderPassEnabled("RayTracingPrepass", true); - - } - - public void SetAlphaCutOff(GameObject gameObject, float value) - { - var material = gameObject.GetComponent().sharedMaterial; - - // enable the property - SetAlphaCutOffEnabled(gameObject); - - // set the cut-off value - material.SetFloat("_AlphaCutoff", value); - } - - public void SetAlphaCutOffEnabled(GameObject gameObject) - { - var material = gameObject.GetComponent().sharedMaterial; - - material.EnableKeyword("_ALPHATEST_ON"); - material.SetInt("_AlphaCutoffEnable", 1); - } - - public void SetNormalMapDisabled(GameObject gameObject) - { - var material = gameObject.GetComponent().sharedMaterial; - - material.SetTexture("_NormalMap", null); - material.DisableKeyword("_NORMALMAP"); - } - - public void SetMetallic(GameObject gameObject, float value) - { - var material = gameObject.GetComponent().sharedMaterial; - material.SetFloat("_Metallic", value); - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/JurassicPark.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/JurassicPark.cs index b975f7d42..1213f892b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/JurassicPark.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/JurassicPark.cs @@ -15,15 +15,38 @@ // along with this program. If not, see . // ReSharper disable StringLiteralTypo +// ReSharper disable UnusedType.Global +// ReSharper disable UnusedMember.Global using UnityEngine; -using VisualPinball.Unity.Patcher.Matcher; +using UnityEngine.Rendering; namespace VisualPinball.Unity.Patcher { [MetaMatch(TableName = "Jurassic Park (Data East)", AuthorName = "Dark & Friends")] public class JurassicPark { + #region Shader Properties + + private static readonly int DistortionSrcBlend = Shader.PropertyToID("_DistortionSrcBlend"); + private static readonly int DistortionDstBlend = Shader.PropertyToID("_DistortionDstBlend"); + private static readonly int DistortionBlurSrcBlend = Shader.PropertyToID("_DistortionBlurSrcBlend"); + private static readonly int DistortionBlurDstBlend = Shader.PropertyToID("_DistortionBlurDstBlend"); + private static readonly int StencilWriteMask = Shader.PropertyToID("_StencilWriteMask"); + private static readonly int StencilWriteMaskGBuffer = Shader.PropertyToID("_StencilWriteMaskGBuffer"); + private static readonly int StencilWriteMaskMv = Shader.PropertyToID("_StencilWriteMaskMV"); + private static readonly int AlphaCutoffEnable = Shader.PropertyToID("_AlphaCutoffEnable"); + private static readonly int TransparentDepthPrepassEnable = Shader.PropertyToID("_TransparentDepthPrepassEnable"); + private static readonly int SurfaceType = Shader.PropertyToID("_SurfaceType"); + private static readonly int BlendMode = Shader.PropertyToID("_BlendMode"); + private static readonly int DstBlend = Shader.PropertyToID("_DstBlend"); + private static readonly int AlphaDstBlend = Shader.PropertyToID("_AlphaDstBlend"); + private static readonly int ZWrite = Shader.PropertyToID("_ZWrite"); + private static readonly int ZTestDepthEqualForOpaque = Shader.PropertyToID("_ZTestDepthEqualForOpaque"); + private static readonly int ZTestGBuffer = Shader.PropertyToID("_ZTestGBuffer"); + + #endregion + /// /// Removing the normal map. /// The normal map of the TRex Head is bad and contains invalid data. @@ -33,10 +56,9 @@ public class JurassicPark [NameMatch("TrexMain")] public void FixBrokenNormalMap(GameObject gameObject) { - RenderPipeline.Patcher.SetNormalMapDisabled(gameObject); + RenderPipeline.Current.MaterialAdapter.SetNormalMapDisabled(gameObject); } - [NameMatch("LFLogo", Ref="Flippers/LeftFlipper")] [NameMatch("RFLogo", Ref="Flippers/RightFlipper")] [NameMatch("RFLogo1", Ref="Flippers/UpperRightFlipper")] @@ -50,13 +72,13 @@ public void ReparentFlippers(GameObject gameObject, ref GameObject parent) [NameMatch("PRightFlipper1")] public void SetAlphaCutOffEnabled(GameObject gameObject) { - RenderPipeline.Patcher.SetAlphaCutOffEnabled(gameObject); + RenderPipeline.Current.MaterialAdapter.SetAlphaCutOffEnabled(gameObject); } [NameMatch("Primitive_Plastics")] public void SetOpaque(GameObject gameObject) { - RenderPipeline.Patcher.SetOpaque(gameObject); + RenderPipeline.Current.MaterialAdapter.SetOpaque(gameObject); } [NameMatch("leftrail")] @@ -65,7 +87,7 @@ public void SetOpaque(GameObject gameObject) [NameMatch("sidewalls")] public void SetDoubleSided(GameObject gameObject) { - RenderPipeline.Patcher.SetDoubleSided(gameObject); + RenderPipeline.Current.MaterialAdapter.SetDoubleSided(gameObject); } [NameMatch("Primitive_SideWallReflect")] @@ -95,29 +117,28 @@ public void ApplyRampSettings(GameObject gameObject) material.EnableKeyword("_DISABLE_SSR_TRANSPARENT"); material.DisableKeyword("_ALPHATEST_ON"); - material.SetInt("_DistortionSrcBlend", 1); - material.SetInt("_DistortionDstBlend", 1); - material.SetInt("_DistortionBlurSrcBlend", 1); - material.SetInt("_DistortionBlurDstBlend", 1); - material.SetInt("_StencilWriteMask", 6); - material.SetInt("_StencilWriteMaskGBuffer", 14); - material.SetInt("_StencilWriteMaskMV", 40); - - material.SetInt("_AlphaCutoffEnable", 0); - material.SetInt("_TransparentDepthPrepassEnable", 1); - material.SetInt("_SurfaceType", 1); - material.SetInt("_BlendMode", 4); - material.SetInt("_DstBlend", 10); - material.SetInt("_AlphaDstBlend", 10); - material.SetInt("_ZWrite", 0); - material.SetInt("_ZTestDepthEqualForOpaque", 4); - material.SetInt("_ZTestGBuffer", 4); + material.SetInt(DistortionSrcBlend, 1); + material.SetInt(DistortionDstBlend, 1); + material.SetInt(DistortionBlurSrcBlend, 1); + material.SetInt(DistortionBlurDstBlend, 1); + material.SetInt(StencilWriteMask, 6); + material.SetInt(StencilWriteMaskGBuffer, 14); + material.SetInt(StencilWriteMaskMv, 40); + + material.SetInt(AlphaCutoffEnable, 0); + material.SetInt(TransparentDepthPrepassEnable, 1); + material.SetInt(SurfaceType, 1); + material.SetInt(BlendMode, 4); + material.SetInt(DstBlend, 10); + material.SetInt(AlphaDstBlend, 10); + material.SetInt(ZWrite, 0); + material.SetInt(ZTestDepthEqualForOpaque, 4); + material.SetInt(ZTestGBuffer, 4); material.SetShaderPassEnabled("TransparentDepthPrepass", true); material.SetShaderPassEnabled("RayTracingPrepass", false); - material.renderQueue = (int) UnityEngine.Rendering.RenderQueue.Transparent; - + material.renderQueue = (int) RenderQueue.Transparent; } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Mississippi.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Mississippi.cs index 452c54ac1..0b4a6b6f1 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Mississippi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Mississippi.cs @@ -15,9 +15,10 @@ // along with this program. If not, see . // ReSharper disable StringLiteralTypo +// ReSharper disable UnusedType.Global +// ReSharper disable UnusedMember.Global using UnityEngine; -using VisualPinball.Unity.Patcher.Matcher; namespace VisualPinball.Unity.Patcher { @@ -29,7 +30,7 @@ public class Mississippi public void SetDoubleSided(GameObject gameObject, ref GameObject child) { if (gameObject == child) - RenderPipeline.Patcher.SetDoubleSided(gameObject); + RenderPipeline.Current.MaterialAdapter.SetDoubleSided(gameObject); } /// @@ -50,7 +51,7 @@ public void SetTransparentDepthPrepassEnabled(GameObject gameObject, ref GameObj { if (gameObject == child) { - RenderPipeline.Patcher.SetTransparentDepthPrepassEnabled(gameObject); + RenderPipeline.Current.MaterialAdapter.SetTransparentDepthPrepassEnabled(gameObject); } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/TomAndJerry.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/TomAndJerry.cs index 0280f85f2..0f9bedab5 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/TomAndJerry.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/TomAndJerry.cs @@ -15,9 +15,10 @@ // along with this program. If not, see . // ReSharper disable StringLiteralTypo +// ReSharper disable UnusedType.Global +// ReSharper disable UnusedMember.Global using UnityEngine; -using VisualPinball.Unity.Patcher.Matcher; using VisualPinball.Unity.Patcher.Matcher.Table; namespace VisualPinball.Unity.Patcher @@ -51,7 +52,7 @@ public void HideGameObject(GameObject gameObject) [NameMatch("BumperCap3")] // Tom Bumper public void SetOpaque(GameObject gameObject) { - RenderPipeline.Patcher.SetOpaque(gameObject); + RenderPipeline.Current.MaterialAdapter.SetOpaque(gameObject); } /// @@ -63,7 +64,7 @@ public void SetOpaque(GameObject gameObject) [NameMatch("MusclesKnife")] public void SetAlphaClip(GameObject gameObject) { - RenderPipeline.Patcher.SetAlphaCutOff(gameObject, 0.05f); + RenderPipeline.Current.MaterialAdapter.SetAlphaCutOff(gameObject, 0.05f); } /// @@ -80,7 +81,7 @@ public void SetAlphaClip(GameObject gameObject) [NameMatch("Primitive66")] // jerry at plunger public void SetDoubleSided(GameObject gameObject) { - RenderPipeline.Patcher.SetDoubleSided(gameObject); + RenderPipeline.Current.MaterialAdapter.SetDoubleSided(gameObject); } [NameMatch("Ramp5")] @@ -90,7 +91,7 @@ public void SetDoubleSided(GameObject gameObject) [NameMatch("Ramp20")] public void SetMetallic(GameObject gameObject) { - RenderPipeline.Patcher.SetMetallic(gameObject, 1.0f); + RenderPipeline.Current.MaterialAdapter.SetMetallic(gameObject, 1.0f); } [NameMatch("Lflip", Ref = "Flippers/LeftFlipper")] diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/WipeOut.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/WipeOut.cs index 75fd0c79c..22d46c01e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/WipeOut.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/WipeOut.cs @@ -15,6 +15,8 @@ // along with this program. If not, see . // ReSharper disable StringLiteralTypo +// ReSharper disable UnusedType.Global +// ReSharper disable UnusedMember.Global using UnityEngine; using VisualPinball.Engine.VPT.Primitive; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.asmdef b/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.asmdef index e0fe9fb0b..cc3599747 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.asmdef +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.asmdef @@ -1,9 +1,10 @@ { - "name": "VisualPinball.Unity.Patcher", - "references": [ - "VisualPinball.Engine" - ], - "includePlatforms": [], - "excludePlatforms": [], - "allowUnsafeCode": false + "name": "VisualPinball.Unity.Patcher", + "references": [ + "VisualPinball.Engine", + "VisualPinball.Unity" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.csproj b/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.csproj index 128386d5e..549cfaa35 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.csproj +++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/VisualPinball.Unity.Patcher.csproj @@ -20,5 +20,6 @@ + diff --git a/VisualPinball.Unity/VisualPinball.Unity/Extensions/MaterialExtensions.cs b/VisualPinball.Unity/VisualPinball.Unity/Extensions/MaterialExtensions.cs index 7ed5cf914..157b69e1a 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Extensions/MaterialExtensions.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Extensions/MaterialExtensions.cs @@ -18,44 +18,14 @@ using System; using System.Text; -using NLog; using VisualPinball.Engine.VPT; -using VisualPinball.Unity.Patcher.Matcher; -using Logger = NLog.Logger; using Material = UnityEngine.Material; namespace VisualPinball.Unity { public static class MaterialExtensions { - - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - /// - /// Material Converter instance for the current graphics pipeline - /// - public static IMaterialConverter MaterialConverter => CreateMaterialConverter(); - - /// - /// Create a material converter depending on the graphics pipeline - /// - /// - private static IMaterialConverter CreateMaterialConverter() - { - switch (RenderPipeline.Current) - { - case RenderPipelineType.BuiltIn: - return new StandardMaterialConverter(); - case RenderPipelineType.Hdrp: - return new HdrpMaterialConverter(); - case RenderPipelineType.Urp: - return new UrpMaterialConverter(); - default: - throw new ArgumentOutOfRangeException(); - } - } - - public static Material ToUnityMaterial(this PbrMaterial vpxMaterial, TableAuthoring table, StringBuilder debug = null) + public static Material ToUnityMaterial(this PbrMaterial vpxMaterial, TableAuthoring table, Type objectType, StringBuilder debug = null) { if (table != null) { @@ -66,7 +36,7 @@ public static Material ToUnityMaterial(this PbrMaterial vpxMaterial, TableAuthor } } - var unityMaterial = MaterialConverter.CreateMaterial(vpxMaterial, table, debug); + var unityMaterial = RenderPipeline.Current.MaterialConverter.CreateMaterial(vpxMaterial, table, objectType, debug); if (table != null) { diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material.meta deleted file mode 100644 index 2ca691eec..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: df39e0ac4ab2f884c86a2c4e9e407870 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpBallMaterial.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpBallMaterial.cs deleted file mode 100644 index a789d977f..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpBallMaterial.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2020 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using UnityEngine; -using VisualPinball.Resources; - -namespace VisualPinball.Unity -{ - public class HdrpBallMaterial : IBallMaterial - { - #region Shader Properties - - private static readonly int BaseColorMap = Shader.PropertyToID("_BaseColorMap"); - private static readonly int BaseColor = Shader.PropertyToID("_BaseColor"); - private static readonly int Metallic = Shader.PropertyToID("_Metallic"); - private static readonly int Smoothness = Shader.PropertyToID("_Smoothness"); - - #endregion - - public Shader GetShader() - { - return Shader.Find("HDRP/Lit"); - } - - public Material CreateMaterial() - { - var material = new Material(GetShader()); - var texture = new Texture2D(512, 512, TextureFormat.RGBA32, true) { name = "BallDebugTexture" }; - texture.LoadImage(Resource.BallDebug.Data); - material.SetTexture(BaseColorMap, texture); - material.SetColor(BaseColor, Color.white); - material.SetFloat(Metallic, 0.85f); - material.SetFloat(Smoothness, 0.75f); - return material; - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpBallMaterial.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpBallMaterial.cs.meta deleted file mode 100644 index 452b3c308..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpBallMaterial.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 89baf5023dfbae44aa65d86b94870457 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpMaterialConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpMaterialConverter.cs deleted file mode 100644 index 19d346f27..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpMaterialConverter.cs +++ /dev/null @@ -1,238 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2020 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System; -using System.Text; -using UnityEngine; -using VisualPinball.Engine.VPT; - -namespace VisualPinball.Unity -{ - public class HdrpMaterialConverter : IMaterialConverter - { - #region Shader Properties - - private static readonly int BaseColor = Shader.PropertyToID("_BaseColor"); - private static readonly int Metallic = Shader.PropertyToID("_Metallic"); - private static readonly int Smoothness = Shader.PropertyToID("_Smoothness"); - private static readonly int BaseColorMap = Shader.PropertyToID("_BaseColorMap"); - private static readonly int NormalMapSpace = Shader.PropertyToID("_NormalMapSpace"); - private static readonly int NormalScale = Shader.PropertyToID("_NormalScale"); - private static readonly int NormalMap = Shader.PropertyToID("_NormalMap"); - private static readonly int SrcBlend = Shader.PropertyToID("_SrcBlend"); - private static readonly int DstBlend = Shader.PropertyToID("_DstBlend"); - private static readonly int ZWrite = Shader.PropertyToID("_ZWrite"); - private static readonly int SurfaceType = Shader.PropertyToID("_SurfaceType"); - private static readonly int AlphaCutoffEnable = Shader.PropertyToID("_AlphaCutoffEnable"); - private static readonly int ZTestDepthEqualForOpaque = Shader.PropertyToID("_ZTestDepthEqualForOpaque"); - private static readonly int ZTestModeDistortion = Shader.PropertyToID("_ZTestModeDistortion"); - private static readonly int ZTestGBuffer = Shader.PropertyToID("_ZTestGBuffer"); - private static readonly int BlendMode = Shader.PropertyToID("_BlendMode"); - private static readonly int TransparentSortPriority = Shader.PropertyToID("_TransparentSortPriority"); - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int Color = Shader.PropertyToID("_Color"); - private static readonly int AlphaCutoff = Shader.PropertyToID("_AlphaCutoff"); - private static readonly int Cutoff = Shader.PropertyToID("_Cutoff"); - - #endregion - - public Shader GetShader() - { - return Shader.Find("HDRP/Lit"); - } - - public UnityEngine.Material CreateMaterial(PbrMaterial vpxMaterial, TableAuthoring table, StringBuilder debug = null) - { - var unityMaterial = new UnityEngine.Material(GetShader()) - { - name = vpxMaterial.Id - }; - - // apply some basic manipulations to the color. this just makes very - // very white colors be clipped to 0.8204 aka 204/255 is 0.8 - // this is to give room to lighting values. so there is more modulation - // of brighter colors when being lit without blow outs too soon. - var col = vpxMaterial.Color.ToUnityColor(); - if (vpxMaterial.Color.IsGray() && col.grayscale > 0.8) - { - debug?.AppendLine("Color manipulation performed, brightness reduced."); - col.r = col.g = col.b = 0.8f; - } - - // alpha for color depending on blend mode - ApplyBlendMode(unityMaterial, vpxMaterial.MapBlendMode); - if (vpxMaterial.MapBlendMode == Engine.VPT.BlendMode.Translucent) - { - col.a = Mathf.Min(1, Mathf.Max(0, vpxMaterial.Opacity)); - } - unityMaterial.SetColor(BaseColor, col); - - // validate IsMetal. if true, set the metallic value. - // found VPX authors setting metallic as well as translucent at the - // same time, which does not render correctly in unity so we have - // to check if this value is true and also if opacity <= 1. - if (vpxMaterial.IsMetal && (!vpxMaterial.IsOpacityActive || vpxMaterial.Opacity >= 1)) - { - unityMaterial.SetFloat(Metallic, 1f); - debug?.AppendLine("Metallic set to 1."); - } - - // roughness / glossiness - unityMaterial.SetFloat(Smoothness, vpxMaterial.Roughness); - - // map - if (table != null && vpxMaterial.HasMap) - { - unityMaterial.SetTexture(BaseColorMap,table.GetTexture(vpxMaterial.Map.Name)); - } - - // normal map - if (table != null && vpxMaterial.HasNormalMap) - { - unityMaterial.EnableKeyword("_NORMALMAP"); - unityMaterial.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); - - unityMaterial.SetInt(NormalMapSpace, 0); // 0 = TangentSpace, 1 = ObjectSpace - unityMaterial.SetFloat(NormalScale, 0f); // TODO FIXME: setting the scale to 0 for now. anything above 0 makes the entire unity editor window become black which is more likely a unity bug - - unityMaterial.SetTexture( NormalMap, table.GetTexture(vpxMaterial.NormalMap.Name)); - } - - // GI hack. This is a necessary step, see respective code in BaseUnlitGUI.cs of the HDRP source - SetupMainTexForAlphaTestGI(unityMaterial, "_BaseColorMap", "_BaseColor"); - - return unityMaterial; - } - - private static void ApplyBlendMode(UnityEngine.Material unityMaterial, BlendMode blendMode) - { - // disable shader passes - unityMaterial.SetShaderPassEnabled("DistortionVectors", false); - unityMaterial.SetShaderPassEnabled("MOTIONVECTORS", false); - unityMaterial.SetShaderPassEnabled("TransparentDepthPrepass", false); - unityMaterial.SetShaderPassEnabled("TransparentDepthPostpass", false); - unityMaterial.SetShaderPassEnabled("TransparentBackface", false); - - // reset existing blend modes, will be enabled explicitly - unityMaterial.DisableKeyword("_BLENDMODE_ALPHA"); - unityMaterial.DisableKeyword("_BLENDMODE_ADD"); - unityMaterial.DisableKeyword("_BLENDMODE_PRE_MULTIPLY"); - - switch (blendMode) - { - case Engine.VPT.BlendMode.Opaque: - - // required for the blend mode - unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One); - unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero); - unityMaterial.SetInt(ZWrite, 1); - - // properties - unityMaterial.SetFloat(SurfaceType, 0); // 0 = Opaque; 1 = Transparent - unityMaterial.SetFloat(AlphaCutoffEnable, 0); - - // render queue - unityMaterial.renderQueue = -1; - - break; - - case Engine.VPT.BlendMode.Cutout: - - // set render type - unityMaterial.SetOverrideTag("RenderType", "TransparentCutout"); - - // keywords - unityMaterial.EnableKeyword("_ALPHATEST_ON"); - unityMaterial.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); - - // required for the blend mode - unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One); - unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero); - unityMaterial.SetInt(ZWrite, 1); - - // properties - unityMaterial.SetFloat(SurfaceType, 0); // 0 = Opaque; 1 = Transparent - unityMaterial.SetFloat(AlphaCutoffEnable, 1); - - unityMaterial.SetFloat(ZTestDepthEqualForOpaque, 3); - unityMaterial.SetFloat(ZTestModeDistortion, 4); - unityMaterial.SetFloat(ZTestGBuffer, 3); - - // render queue - unityMaterial.renderQueue = 2450; - - break; - - case Engine.VPT.BlendMode.Translucent: - - // set render type - unityMaterial.SetOverrideTag("RenderType", "Transparent"); - - // keywords - //unityMaterial.EnableKeyword("_ALPHATEST_ON"); // required for _AlphaCutoffEnable - unityMaterial.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); - unityMaterial.EnableKeyword("_BLENDMODE_PRE_MULTIPLY"); - unityMaterial.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - unityMaterial.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); - unityMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); - - // required for the blend mode - unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One); - unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); - unityMaterial.SetInt(ZWrite, 0); - - // properties - unityMaterial.SetFloat(SurfaceType, 1); // 0 = Opaque; 1 = Transparent - //unityMaterial.SetFloat("_AlphaCutoffEnable", 1); // enable keyword _ALPHATEST_ON if this is required - unityMaterial.SetFloat(BlendMode, 4); // 0 = Alpha, 1 = Additive, 4 = PreMultiply - - // render queue - const int transparentRenderQueueBase = 3000; - const int transparentSortingPriority = 0; - unityMaterial.SetInt(TransparentSortPriority, transparentSortingPriority); - unityMaterial.renderQueue = transparentRenderQueueBase + transparentSortingPriority; - - break; - - default: - throw new ArgumentOutOfRangeException(); - } - } - - // This is a hack for GI. PVR looks in the shader for a texture named "_MainTex" to extract the opacity of the material for baking. In the same manner, "_Cutoff" and "_Color" are also necessary. - // Since we don't have those parameters in our shaders we need to provide a "fake" useless version of them with the right values for the GI to work. - private static void SetupMainTexForAlphaTestGI(UnityEngine.Material unityMaterial, string colorMapPropertyName, string colorPropertyName) - { - if (unityMaterial.HasProperty(colorMapPropertyName)) - { - var mainTex = unityMaterial.GetTexture(colorMapPropertyName); - unityMaterial.SetTexture(MainTex, mainTex); - } - - if (unityMaterial.HasProperty(colorPropertyName)) - { - var color = unityMaterial.GetColor(colorPropertyName); - unityMaterial.SetColor(Color, color); - } - - if (unityMaterial.HasProperty("_AlphaCutoff")) - { - var cutoff = unityMaterial.GetFloat(AlphaCutoff); - unityMaterial.SetFloat(Cutoff, cutoff); - } - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpMaterialConverter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpMaterialConverter.cs.meta deleted file mode 100644 index 66f68a193..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/HdrpMaterialConverter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c20f5cfc2020f18428a0c368bbbaafd9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IBallMaterial.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IBallMaterial.cs.meta deleted file mode 100644 index 71ed63339..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IBallMaterial.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 62bcbb8022eedb341868da60780b5c27 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardBallMaterial.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardBallMaterial.cs deleted file mode 100644 index a6426699b..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardBallMaterial.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2020 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using UnityEngine; -using VisualPinball.Resources; - -namespace VisualPinball.Unity -{ - public class StandardBallMaterial : IBallMaterial - { - #region Shader Properties - - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int Metallic = Shader.PropertyToID("_Metallic"); - private static readonly int Glossiness = Shader.PropertyToID("_Glossiness"); - - #endregion - - public Shader GetShader() - { - return Shader.Find("Standard"); - } - - public Material CreateMaterial() - { - var material = new Material(GetShader()); - var texture = new Texture2D(512, 512, TextureFormat.RGBA32, true) { name = "BallDebugTexture" }; - texture.LoadImage(Resource.BallDebug.Data); - material.SetTexture(MainTex, texture); - material.SetFloat(Metallic, 1f); - material.SetFloat(Glossiness, 1f); - return material; - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardBallMaterial.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardBallMaterial.cs.meta deleted file mode 100644 index 034aafc43..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardBallMaterial.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bb3925f4976c2b64c863c64f4f4a9487 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpBallMaterial.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpBallMaterial.cs deleted file mode 100644 index e5a9945b0..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpBallMaterial.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2020 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using UnityEngine; -using VisualPinball.Resources; - -namespace VisualPinball.Unity -{ - public class UrpBallMaterial : IBallMaterial - { - #region Shader Properties - - private static readonly int BaseMap = Shader.PropertyToID("_BaseMap"); - private static readonly int BaseColor = Shader.PropertyToID("_BaseColor"); - private static readonly int Metallic = Shader.PropertyToID("_Metallic"); - private static readonly int Smoothness = Shader.PropertyToID("_Smoothness"); - - #endregion - - public Shader GetShader() - { - return Shader.Find("Universal Render Pipeline/Lit"); - } - - public Material CreateMaterial() - { - var material = new Material(GetShader()); - var texture = new Texture2D(512, 512, TextureFormat.RGBA32, true) { name = "BallDebugTexture" }; - texture.LoadImage(Resource.BallDebug.Data); - material.SetTexture(BaseMap, texture); - material.SetColor(BaseColor, Color.white); - material.SetFloat(Metallic, 0.85f); - material.SetFloat(Smoothness, 0.75f); - return material; - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpBallMaterial.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpBallMaterial.cs.meta deleted file mode 100644 index e4bd48cd3..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpBallMaterial.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cdb4ac41f2e95fc4d9907df6209d2390 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpMaterialConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpMaterialConverter.cs deleted file mode 100644 index 215a786da..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpMaterialConverter.cs +++ /dev/null @@ -1,185 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2020 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System; -using System.Text; -using UnityEngine; -using VisualPinball.Engine.VPT; - -namespace VisualPinball.Unity -{ - public class UrpMaterialConverter : IMaterialConverter - { - #region Shader Properties - - private static readonly int BaseColor = Shader.PropertyToID("_BaseColor"); - private static readonly int Metallic = Shader.PropertyToID("_Metallic"); - private static readonly int Smoothness = Shader.PropertyToID("_Smoothness"); - private static readonly int BaseMap = Shader.PropertyToID("_BaseMap"); - private static readonly int BumpMap = Shader.PropertyToID("_BumpMap"); - private static readonly int SrcBlend = Shader.PropertyToID("_SrcBlend"); - private static readonly int DstBlend = Shader.PropertyToID("_DstBlend"); - private static readonly int ZWrite = Shader.PropertyToID("_ZWrite"); - private static readonly int Surface = Shader.PropertyToID("_Surface"); - private static readonly int AlphaClip = Shader.PropertyToID("_AlphaClip"); - private static readonly int Blend = Shader.PropertyToID("_Blend"); - private static readonly int QueueOffset = Shader.PropertyToID("_QueueOffset"); - - #endregion - - public Shader GetShader() - { - return Shader.Find("Universal Render Pipeline/Lit"); - } - - public UnityEngine.Material CreateMaterial(PbrMaterial vpxMaterial, TableAuthoring table, StringBuilder debug = null) - { - var unityMaterial = new UnityEngine.Material(GetShader()) - { - name = vpxMaterial.Id - }; - - // apply some basic manipulations to the color. this just makes very - // very white colors be clipped to 0.8204 aka 204/255 is 0.8 - // this is to give room to lighting values. so there is more modulation - // of brighter colors when being lit without blow outs too soon. - var col = vpxMaterial.Color.ToUnityColor(); - if (vpxMaterial.Color.IsGray() && col.grayscale > 0.8) - { - debug?.AppendLine("Color manipulation performed, brightness reduced."); - col.r = col.g = col.b = 0.8f; - } - - // alpha for color depending on blend mode - ApplyBlendMode(unityMaterial, vpxMaterial.MapBlendMode); - if (vpxMaterial.MapBlendMode == BlendMode.Translucent) - { - col.a = Mathf.Min(1, Mathf.Max(0, vpxMaterial.Opacity)); - } - - unityMaterial.SetColor(BaseColor, col); - - // validate IsMetal. if true, set the metallic value. - // found VPX authors setting metallic as well as translucent at the - // same time, which does not render correctly in unity so we have - // to check if this value is true and also if opacity <= 1. - if (vpxMaterial.IsMetal && (!vpxMaterial.IsOpacityActive || vpxMaterial.Opacity >= 1)) - { - unityMaterial.SetFloat(Metallic, 1f); - debug?.AppendLine("Metallic set to 1."); - } - - // roughness / glossiness - unityMaterial.SetFloat(Smoothness, vpxMaterial.Roughness); - - - // map - if (table != null && vpxMaterial.HasMap) - { - unityMaterial.SetTexture( BaseMap, table.GetTexture(vpxMaterial.Map.Name)); - } - - // normal map - if (table != null && vpxMaterial.HasNormalMap) - { - unityMaterial.EnableKeyword("_NORMALMAP"); - - unityMaterial.SetTexture( BumpMap, table.GetTexture(vpxMaterial.NormalMap.Name) - ); - } - - return unityMaterial; - } - - private void ApplyBlendMode(UnityEngine.Material unityMaterial, BlendMode blendMode) - { - - switch (blendMode) - { - case BlendMode.Opaque: - - // set render type - unityMaterial.SetOverrideTag("RenderType", "Opaque"); - - // required for the blend mode - unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One); - unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero); - unityMaterial.SetInt(ZWrite, 1); - - // properties - unityMaterial.SetFloat(Surface, 0); // 0 = Opaque; 1 = Transparent - - // render queue - unityMaterial.renderQueue = -1; - - break; - - case BlendMode.Cutout: - - // set render type - unityMaterial.SetOverrideTag("RenderType", "TransparentCutout"); - - // keywords - unityMaterial.EnableKeyword("_ALPHATEST_ON"); - - // required for blend mode - unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One); - unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero); - unityMaterial.SetInt(ZWrite, 1); - - // properties - unityMaterial.SetFloat(Surface, 0); // 0 = Opaque; 1 = Transparent - unityMaterial.SetInt(AlphaClip, 1); - - // render queue - unityMaterial.renderQueue = 2450; - - break; - - case BlendMode.Translucent: - - // disable shader passes - unityMaterial.SetShaderPassEnabled("SHADOWCASTER", false); - - // set render type - unityMaterial.SetOverrideTag("RenderType", "Transparent"); - - // keywords - unityMaterial.EnableKeyword("_ALPHAPREMULTIPLY_ON"); - - // required for blend mode - unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One); - unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); - unityMaterial.SetInt(ZWrite, 0); - - // properties - unityMaterial.SetFloat(Surface, 1); // 0 = Opaque; 1 = Transparent - unityMaterial.SetFloat(Blend, 1); // 0 = Alpha, 1 = Premultiply, 2 = Additive, 3 = Multiply - - // render queue - const int transparentRenderQueueBase = 3000; - const int transparentSortingPriority = 0; - unityMaterial.SetInt(QueueOffset, transparentSortingPriority); - unityMaterial.renderQueue = transparentRenderQueueBase + transparentSortingPriority; - - break; - - default: - throw new ArgumentOutOfRangeException(); - } - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpMaterialConverter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpMaterialConverter.cs.meta deleted file mode 100644 index 766a7ab87..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/UrpMaterialConverter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 40ececa771b11ce429fa7a8bb0673e1d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/PatcherManager.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/PatcherManager.cs new file mode 100644 index 000000000..996e16929 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Import/PatcherManager.cs @@ -0,0 +1,30 @@ +using System; +using System.Linq; +using UnityEngine; +using VisualPinball.Engine.Game; +using VisualPinball.Engine.VPT.Table; + +namespace VisualPinball.Unity +{ + public interface IPatcher + { + void SetTable(Table table, string filename); + void ApplyPrePatches(IRenderable item); + void ApplyPatches(IRenderable item, GameObject gameObject, GameObject tableGameObject); + } + + public static class PatcherManager + { + public static IPatcher GetPatcher() { + var t = typeof(IPatcher); + var patchers = AppDomain.CurrentDomain.GetAssemblies() + .Where(x => x.FullName.StartsWith("VisualPinball.")) + .SelectMany(x => x.GetTypes()) + .Where(x => x.IsClass && t.IsAssignableFrom(x)) + .Select(x => (IPatcher) Activator.CreateInstance(x)) + .ToArray(); + + return patchers.First(); + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/BuiltInPatcher.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Import/PatcherManager.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/BuiltInPatcher.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Import/PatcherManager.cs.meta index ff59e2c03..12879983c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/BuiltInPatcher.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Import/PatcherManager.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8448f1905bef2954c9988a16951a8c25 +guid: 8d4f9ead7336a664f9a4c6432aae5547 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/VpxConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Import/VpxConverter.cs index 993b8b51b..fe020af9f 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/VpxConverter.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Import/VpxConverter.cs @@ -63,6 +63,7 @@ public class VpxConverter : MonoBehaviour private Table _table; private TableAuthoring _tableAuthoring; private bool _applyPatch = true; + private IPatcher _patcher; public void Convert(string fileName, Table table, bool applyPatch = true, string tableName = null) { @@ -86,7 +87,8 @@ public void Convert(string fileName, Table table, bool applyPatch = true, string .Replace("%INFONAME%", _table.InfoName); } - _tableAuthoring.Patcher = new Patcher.Patcher(_table, fileName); + _patcher = PatcherManager.GetPatcher(); + _patcher?.SetTable(_table, fileName); // import ConvertGameItems(go); @@ -126,7 +128,7 @@ orderby renderable.SubComponent foreach (var renderable in renderables) { - _tableAuthoring.Patcher.ApplyPrePatches(renderable); + _patcher?.ApplyPrePatches(renderable); var lookupName = renderable.Name.ToLower(); renderableLookup[lookupName] = renderable; @@ -182,7 +184,7 @@ orderby renderable.SubComponent // now we have all renderables imported, patch them. foreach (var lookupName in convertedItems.Keys) { foreach (var meshMb in convertedItems[lookupName].MeshAuthoring) { - _tableAuthoring.Patcher.ApplyPatches(renderableLookup[lookupName], meshMb.gameObject, tableGameObject); + _patcher?.ApplyPatches(renderableLookup[lookupName], meshMb.gameObject, tableGameObject); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/DefaultPhysicsEngine.cs b/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/DefaultPhysicsEngine.cs index 51d705651..d0e903d95 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/DefaultPhysicsEngine.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/DefaultPhysicsEngine.cs @@ -61,11 +61,11 @@ public void Init(TableAuthoring tableAuthoring, BallManager ballManager) _worldToLocal = transform.worldToLocalMatrix; } - public void BallCreate(Mesh mesh, Material material, in float3 worldPos, in float3 localPos, + public void BallCreate(in float3 worldPos, in float3 localPos, in float3 localVel, in float scale, in float mass, in float radius, in Entity kickerRef) { - _ballManager.CreateEntity(mesh, material, in worldPos, in localPos, in localVel, - scale * radius * 2, in mass, in radius, in kickerRef); + _ballManager.CreateEntity(in worldPos, in localPos, in localVel,scale * radius * 2, + in mass, in radius, in kickerRef); } public void BallManualRoll(in Entity entity, in float3 targetWorldPosition) diff --git a/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/IPhysicsEngine.cs b/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/IPhysicsEngine.cs index 5ac61f2b4..8f4e77db6 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/IPhysicsEngine.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Physics/Engine/IPhysicsEngine.cs @@ -16,7 +16,6 @@ using Unity.Entities; using Unity.Mathematics; -using UnityEngine; using VisualPinball.Engine.Common; namespace VisualPinball.Unity @@ -40,8 +39,6 @@ public interface IPhysicsEngine : IEngine /// /// Create a new ball and returns its entity. /// - /// Ball mesh - /// Material to use with the mesh /// Position in world space /// Position in local space /// Velocity in local space @@ -49,7 +46,7 @@ public interface IPhysicsEngine : IEngine /// Physics mass /// Radius in local space /// If created within a kicker, this is the kicker entity - void BallCreate(Mesh mesh, Material material, in float3 worldPos, in float3 localPos, in float3 localVel, + void BallCreate(in float3 worldPos, in float3 localPos, in float3 localVel, in float scale, in float mass, in float radius, in Entity kickerRef); /// diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering.meta new file mode 100644 index 000000000..42e27ced9 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: df41a046588ec2945af6656bab83a61b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IBallMaterial.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IBallConverter.cs similarity index 61% rename from VisualPinball.Unity/VisualPinball.Unity/Import/Material/IBallMaterial.cs rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/IBallConverter.cs index ce6118073..47a5deded 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IBallMaterial.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IBallConverter.cs @@ -19,23 +19,13 @@ namespace VisualPinball.Unity { /// - /// Common interface for ball material for the various render pipelines + /// Common interface creating (in the future different types of) balls. /// - public interface IBallMaterial + public interface IBallConverter { /// - /// Get the shader for the currently detected graphics pipeline. + /// Create a material for the currently detected graphics pipeline. /// - /// - Shader GetShader(); - - /// - /// Create a ball material for the currently detected graphics pipeline. - /// - /// - /// - /// - /// - Material CreateMaterial(); + GameObject CreateDefaultBall(); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/HdrpPatcher.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IBallConverter.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/HdrpPatcher.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/IBallConverter.cs.meta index 744f29e7d..4e9c6b7ad 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/HdrpPatcher.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IBallConverter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3683b9aafd1e525489289968164d2d16 +guid: cd9b38e1f6447a94b8362ec6d8f0569c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/ILightConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/ILightConverter.cs new file mode 100644 index 000000000..6d5c83e72 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/ILightConverter.cs @@ -0,0 +1,34 @@ +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using VisualPinball.Engine.VPT.Light; +using Light = UnityEngine.Light; + +namespace VisualPinball.Unity +{ + /// + /// Common interface for light conversion with the various render pipelines + /// + public interface ILightConverter + { + /// + /// Updates a Unity light based on VPX's light data. + /// + /// Which light to update + /// VPX light data + void UpdateLight(Light light, LightData data); + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/IRenderPipelinePatcher.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/ILightConverter.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/IRenderPipelinePatcher.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/ILightConverter.cs.meta index ac744d0c7..4bdd9ecc4 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/IRenderPipelinePatcher.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/ILightConverter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: acf27b3fa20f4dd459f25ff4ab9b9a28 +guid: 61561c7ce906b2b4f94e264025edf5c1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/IRenderPipelinePatcher.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialAdapter.cs similarity index 57% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/IRenderPipelinePatcher.cs rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialAdapter.cs index 76ff807b8..f5db35427 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/IRenderPipelinePatcher.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialAdapter.cs @@ -1,11 +1,28 @@ -using UnityEngine; +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . -namespace VisualPinball.Unity.Patcher.RenderPipelinePatcher +using UnityEngine; + +namespace VisualPinball.Unity { - public interface IRenderPipelinePatcher + public interface IMaterialAdapter { /// /// Set the material of the gameobject to opaque. + /// /// /// void SetOpaque(GameObject gameObject); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/UrpPatcher.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialAdapter.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/UrpPatcher.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialAdapter.cs.meta index a6adf2993..1a1e15a20 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/UrpPatcher.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialAdapter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8f0e7c18dabb26a42a4428846f7b8b7a +guid: 767889165ccd30e4ea5ff0a1a98bafc1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IMaterialConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialConverter.cs similarity index 76% rename from VisualPinball.Unity/VisualPinball.Unity/Import/Material/IMaterialConverter.cs rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialConverter.cs index b3c095cdd..ba3e750a8 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IMaterialConverter.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialConverter.cs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +using System; using System.Text; -using UnityEngine; using VisualPinball.Engine.VPT; +using VisualPinball.Engine.VPT.Flipper; +using Material = UnityEngine.Material; namespace VisualPinball.Unity { @@ -25,20 +27,15 @@ namespace VisualPinball.Unity /// public interface IMaterialConverter { - /// - /// Get the shader for the currently detected graphics pipeline. - /// - /// - Shader GetShader(); - /// /// Create a material for the currently detected graphics pipeline. /// /// /// + /// Type of the item to which the material is applied (e.g. ) /// /// - UnityEngine.Material CreateMaterial(PbrMaterial vpxMaterial, TableAuthoring table, StringBuilder debug = null); + Material CreateMaterial(PbrMaterial vpxMaterial, TableAuthoring table, Type objectType, StringBuilder debug = null); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IMaterialConverter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialConverter.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity/Import/Material/IMaterialConverter.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialConverter.cs.meta index c9ba684b1..0468886b8 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/IMaterialConverter.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/IMaterialConverter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9c2a9fffcb431d241be6e0fb62d7ffc9 +guid: c560b36666fc71849af25d2085179baa MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/RenderPipeline.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/RenderPipeline.cs new file mode 100644 index 000000000..01960d864 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/RenderPipeline.cs @@ -0,0 +1,115 @@ +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Linq; +using NLog; + +namespace VisualPinball.Unity +{ + /// + /// A common interface for all render pipelines that covers material + /// creation, lighting setup and ball creation. + /// + public interface IRenderPipeline + { + /// + /// Name of the render pipeline + /// + string Name { get; } + + /// + /// Type of the render pipeline. + /// + RenderPipelineType Type { get; } + + + /// + /// Converts a material from Visual Pinball to the active renderer. + /// + IMaterialConverter MaterialConverter { get; } + + /// + /// Provides a bunch of helper methods for setting common attributes + /// in materials. + /// + IMaterialAdapter MaterialAdapter { get; } + + /// + /// Converts a light from Visual Pinball to the active renderer. + /// + ILightConverter LightConverter { get; } + + /// + /// Creates a new ball. + /// + IBallConverter BallConverter { get; } + } + + public enum RenderPipelineType + { + /// + /// The built-in renderer. + /// + Standard, + + /// + /// The Universal Render Pipeline. + /// + Urp, + + /// + /// The High Definition Render Pipeline. + /// + Hdrp, + } + + /// + /// A global static class that checks which render pipeline implementations + /// are available and instantiates an SRP if available or the included + /// built-in instance otherwise. + /// + public static class RenderPipeline + { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + private static IRenderPipeline _current; + + /// + /// Returns the currently instantiated render pipeline. + /// + public static IRenderPipeline Current { + get { + if (_current == null) { + var t = typeof(IRenderPipeline); + var pipelines = AppDomain.CurrentDomain.GetAssemblies() + .Where(x => x.FullName.StartsWith("VisualPinball.")) + .SelectMany(x => x.GetTypes()) + .Where(x => x.IsClass && t.IsAssignableFrom(x)) + .Select(x => (IRenderPipeline) Activator.CreateInstance(x)) + .ToArray(); + + _current = pipelines.Length == 1 + ? pipelines.First() + : pipelines.First(p => p.Type != RenderPipelineType.Standard); + + Logger.Info($"Instantiated ${_current.Name}."); + } + return _current; + } + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/RenderPipeline.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/RenderPipeline.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/RenderPipeline.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/RenderPipeline.cs.meta index f32eaa9ac..3148c1d84 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/RenderPipeline.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/RenderPipeline.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a3c9cce3a51fb264590e2801ea69b977 +guid: 72a7be43d14c0b64da79f0d24d29d3a8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard.meta new file mode 100644 index 000000000..1d79c587e --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d7dac8976787ddd44a0f1d88f825b92e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardBallConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardBallConverter.cs new file mode 100644 index 000000000..2ccd51a21 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardBallConverter.cs @@ -0,0 +1,31 @@ +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global +// ReSharper disable CheckNamespace + +using UnityEngine; + +namespace VisualPinball.Unity +{ + public class StandardBallConverter : IBallConverter + { + public GameObject CreateDefaultBall() + { + return UnityEngine.Resources.Load("Prefabs/DefaultBall"); + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardBallConverter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardBallConverter.cs.meta new file mode 100644 index 000000000..b0485ec48 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardBallConverter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 269496db9b495cf49bbc81062c2267f4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardLightConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardLightConverter.cs new file mode 100644 index 000000000..18ea18fe9 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardLightConverter.cs @@ -0,0 +1,43 @@ +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global +// ReSharper disable CheckNamespace + +using UnityEngine; +using VisualPinball.Engine.VPT.Light; +using Light = UnityEngine.Light; + +namespace VisualPinball.Unity +{ + public class StandardLightConverter : ILightConverter + { + public void UpdateLight(Light light, LightData data) + { + // Set color and position + light.color = data.Color2.ToUnityColor(); + light.intensity = data.Intensity / 2f; + light.range = data.Falloff * 0.001f; + // TODO: vpe specific data for height + light.transform.localPosition = new Vector3(0f, 0f, 25f); + + // TODO: vpe specific shadow settings + light.shadows = LightShadows.Hard; + light.shadowBias = 0f; + light.shadowNearPlane = 0f; + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardLightConverter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardLightConverter.cs.meta new file mode 100644 index 000000000..5f005b57e --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardLightConverter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f0efa10759e0d94c89adae2834fed4b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/UrpPatcher.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialAdapter.cs similarity index 58% rename from VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/UrpPatcher.cs rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialAdapter.cs index bdc035af3..fc0bca914 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/RenderPipelinePatcher/UrpPatcher.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialAdapter.cs @@ -1,47 +1,62 @@ -using NLog; -using UnityEngine; -using Logger = NLog.Logger; - -namespace VisualPinball.Unity.Patcher.RenderPipelinePatcher -{ - public class UrpPatcher : IRenderPipelinePatcher - { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public void SetOpaque(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetOpaque"); - } - - public void SetDoubleSided(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetDoubleSided"); - } - - public void SetTransparentDepthPrepassEnabled(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetTransparentDepthPrepassEnabled"); - } - - - public void SetAlphaCutOff(GameObject gameObject, float value) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetAlphaCutOff"); - } - - public void SetAlphaCutOffEnabled(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetAlphaCutOffEnabled"); - } - - public void SetNormalMapDisabled(GameObject gameObject) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetNormalMapDisabled"); - } - - public void SetMetallic(GameObject gameObject, float value) - { - Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetMetallic"); - } - } -} +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using NLog; +using UnityEngine; +using Logger = NLog.Logger; + +namespace VisualPinball.Unity +{ + public class StandardMaterialAdapter : IMaterialAdapter + { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + public void SetOpaque(GameObject gameObject) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetOpaque"); + } + + public void SetDoubleSided(GameObject gameObject) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetDoubleSided"); + } + + public void SetTransparentDepthPrepassEnabled(GameObject gameObject) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetTransparentDepthPrepassEnabled"); + } + + public void SetAlphaCutOff(GameObject gameObject, float value) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetAlphaCutOff"); + } + + public void SetAlphaCutOffEnabled(GameObject gameObject) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetAlphaCutOffEnabled"); + } + + public void SetNormalMapDisabled(GameObject gameObject) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetNormalMapDisabled"); + } + + public void SetMetallic(GameObject gameObject, float value) + { + Logger.Info("Not implemented for {0}: {1}", gameObject.name, "SetMetallic"); + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialAdapter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialAdapter.cs.meta new file mode 100644 index 000000000..0ca4c638b --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialAdapter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb82dd9795de759439ee6a3c6ef05b2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardMaterialConverter.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialConverter.cs similarity index 95% rename from VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardMaterialConverter.cs rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialConverter.cs index 3b15617c8..4ee6fa544 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardMaterialConverter.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialConverter.cs @@ -42,7 +42,7 @@ public Shader GetShader() return Shader.Find("Standard"); } - public UnityEngine.Material CreateMaterial(PbrMaterial vpxMaterial, TableAuthoring table, StringBuilder debug = null) + public UnityEngine.Material CreateMaterial(PbrMaterial vpxMaterial, TableAuthoring table, Type objectType, StringBuilder debug = null) { var unityMaterial = new UnityEngine.Material(GetShader()) { diff --git a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardMaterialConverter.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialConverter.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardMaterialConverter.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialConverter.cs.meta index 004895a22..eeaf47ec5 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Import/Material/StandardMaterialConverter.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardMaterialConverter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b16c5d7a8d561c94b93076582a4709b7 +guid: 168eda1d8a9ed0543b87b657cb85d650 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardRenderPipeline.cs b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardRenderPipeline.cs new file mode 100644 index 000000000..aedcdbaee --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardRenderPipeline.cs @@ -0,0 +1,31 @@ +// Visual Pinball Engine +// Copyright (C) 2020 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +namespace VisualPinball.Unity +{ + public class StandardRenderPipeline : IRenderPipeline + { + public string Name { get; } = "Built-in Render Pipeline"; + + public RenderPipelineType Type { get; } = RenderPipelineType.Standard; + public IMaterialConverter MaterialConverter { get; } = new StandardMaterialConverter(); + public IMaterialAdapter MaterialAdapter { get; } = new StandardMaterialAdapter(); + public ILightConverter LightConverter { get; } = new StandardLightConverter(); + public IBallConverter BallConverter { get; } = new StandardBallConverter(); + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardRenderPipeline.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardRenderPipeline.cs.meta new file mode 100644 index 000000000..97fcb77f7 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/Rendering/Standard/StandardRenderPipeline.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 082720aa6c8bccb40bac37a0d4f0cd69 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallManager.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallManager.cs index 5dfad7898..62f504f44 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallManager.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallManager.cs @@ -17,10 +17,8 @@ using System; using Unity.Entities; using Unity.Mathematics; -using Unity.Rendering; using Unity.Transforms; using UnityEngine; -using UnityEngine.Rendering; using VisualPinball.Engine.Common; using VisualPinball.Engine.Game; using VisualPinball.Engine.VPT.Table; @@ -68,56 +66,43 @@ public void CreateBall(IBallCreationPosition ballCreator, float radius, float ma _ltw.GetColumn(2).magnitude ); var scale = (scale3.x + scale3.y + scale3.z) / 3.0f; // scale is only scale (without radiusfloat now, not vector. - var material = BallMaterial.CreateMaterial(); - var mesh = GetSphereMesh(); // create ball entity EngineProvider .Get() - .BallCreate(mesh, material, worldPos, localPos, localVel, scale, mass, radius, in kickerRef); + .BallCreate(worldPos, localPos, localVel, scale, mass, radius, in kickerRef); } - public void CreateEntity(Mesh mesh, Material material, in float3 worldPos, in float3 localPos, - in float3 localVel, in float scale, in float mass, in float radius, in Entity kickerEntity) + public void CreateEntity(in float3 worldPos, in float3 localPos, in float3 localVel, in float scale, + in float mass, in float radius, in Entity kickerEntity) { - var world = World.DefaultGameObjectInjectionWorld; - var ecbs = world.GetOrCreateSystem(); - var ecb = ecbs.CreateCommandBuffer(); + var ballPrefab = RenderPipeline.Current.BallConverter.CreateDefaultBall(); - var archetype = EntityManager.CreateArchetype( - typeof(Translation), - typeof(Scale), - typeof(Rotation), - typeof(RenderMesh), - typeof(LocalToWorld), - typeof(RenderBounds), - typeof(BallData), - typeof(CollisionEventData), - typeof(OverlappingStaticColliderBufferElement), - typeof(OverlappingDynamicBufferElement), - typeof(BallInsideOfBufferElement), - typeof(BallLastPositionsBufferElement) - ); - var entity = ecb.CreateEntity(archetype); + // Create entity prefab from the game object hierarchy once + var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null); + var prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings); - ecb.SetSharedComponent(entity, new RenderMesh { - mesh = mesh, - material = material - }); + // Efficiently instantiate a bunch of entities from the already converted entity prefab + var entity = EntityManager.Instantiate(prefab); - ecb.SetComponent(entity, new RenderBounds { - Value = mesh.bounds.ToAABB() - }); + var world = World.DefaultGameObjectInjectionWorld; + var ecbs = world.GetOrCreateSystem(); + var ecb = ecbs.CreateCommandBuffer(); - ecb.SetComponent(entity, new Translation { + ecb.AddComponent(entity, new Translation { Value = worldPos }); - ecb.SetComponent(entity, new Scale { + ecb.AddComponent(entity, new Scale { Value = scale }); - ecb.SetComponent(entity, new BallData { + ecb.AddBuffer(entity); + ecb.AddBuffer(entity); + ecb.AddBuffer(entity); + ecb.AddBuffer(entity); + + ecb.AddComponent(entity, new BallData { Id = NumBallsCreated++, IsFrozen = false, Position = localPos, @@ -129,7 +114,7 @@ public void CreateEntity(Mesh mesh, Material material, in float3 worldPos, in fl AngularMomentum = float3.zero }); - ecb.SetComponent(entity, new CollisionEventData { + ecb.AddComponent(entity, new CollisionEventData { HitTime = -1, HitDistance = 0, HitFlag = false, @@ -189,30 +174,6 @@ private static Mesh GetSphereMesh() #region Material - /// - /// Ball material creator instance for the current graphics pipeline - /// - public static IBallMaterial BallMaterial => CreateBallMaterial(); - - /// - /// Create a material converter depending on the graphics pipeline - /// - /// - private static IBallMaterial CreateBallMaterial() - { - if (GraphicsSettings.renderPipelineAsset != null) { - if (GraphicsSettings.renderPipelineAsset.GetType().Name.Contains("UniversalRenderPipelineAsset")) { - return new UrpBallMaterial(); - } - - if (GraphicsSettings.renderPipelineAsset.GetType().Name.Contains("HDRenderPipelineAsset")) { - return new HdrpBallMaterial(); - } - } - - return new StandardBallMaterial(); - } - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs index 125bee1f7..38cbd2d75 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs @@ -15,7 +15,6 @@ // along with this program. If not, see . using System; -using System.Transactions; using Unity.Entities; using VisualPinball.Engine.VPT.Bumper; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemAuthoring.cs index b05e3faba..3a73222b7 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemAuthoring.cs @@ -12,5 +12,7 @@ public interface IItemAuthoring IItem IItem { get; } ItemData ItemData { get; } + + void ItemDataChanged(); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemMainRenderableAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemMainRenderableAuthoring.cs index 4b9fb0a57..830d7f83f 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemMainRenderableAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/IItemMainRenderableAuthoring.cs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -using System; -using System.Collections.Generic; using UnityEngine; namespace VisualPinball.Unity diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemAuthoring.cs index 086db8296..c8b8e867c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemAuthoring.cs @@ -17,7 +17,6 @@ // ReSharper disable InconsistentNaming using UnityEngine; -using VisualPinball.Engine.Game; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Table; @@ -28,7 +27,8 @@ namespace VisualPinball.Unity /// /// /// - public abstract class ItemAuthoring : MonoBehaviour + public abstract class ItemAuthoring : MonoBehaviour, + IItemAuthoring where TData : ItemData where TItem : Item { @@ -72,7 +72,7 @@ public abstract class ItemAuthoring : MonoBehaviour protected Table Table => _table ?? (_table = GetComponentInParent()?.Item); - protected virtual void ItemDataChanged() + public virtual void ItemDataChanged() { } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMainAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMainAuthoring.cs index 8f330b459..3b388e5c7 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMainAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMainAuthoring.cs @@ -71,7 +71,7 @@ public abstract class ItemMainAuthoring : ItemAuthoring [NonSerialized] - protected TItem _item; + private TItem _item; public IItemMainAuthoring SetItem(TItem item, string gameObjectName = null) { diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMeshAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMeshAuthoring.cs index f8d1d9797..df0f1905b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMeshAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/ItemMeshAuthoring.cs @@ -110,12 +110,12 @@ private void CreateMesh() // apply material if (ro.Mesh.AnimationFrames.Count > 0) { var smr = gameObject.AddComponent(); - smr.sharedMaterial = ro.Material.ToUnityMaterial(ta); + smr.sharedMaterial = ro.Material.ToUnityMaterial(ta, MainAuthoring.Item.GetType()); smr.sharedMesh = mesh; smr.enabled = ro.IsVisible; } else { var mr = gameObject.AddComponent(); - mr.sharedMaterial = ro.Material.ToUnityMaterial(ta); + mr.sharedMaterial = ro.Material.ToUnityMaterial(ta, MainAuthoring.Item.GetType()); mr.enabled = ro.IsVisible; } } @@ -142,7 +142,7 @@ private void UpdateMesh() if (mr != null) { if (ta != null) { - mr.sharedMaterial = ro.Material.ToUnityMaterial(ta); + mr.sharedMaterial = ro.Material.ToUnityMaterial(ta, MainAuthoring.Item.GetType()); } mr.enabled = true; } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightAuthoring.cs index 2157d0555..759ca6a0f 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightAuthoring.cs @@ -83,34 +83,22 @@ public void OnBulbEnabled(bool bulbEnabledBefore, bool bulbEnabledAfter) } } - protected override void ItemDataChanged() + public override void ItemDataChanged() { base.ItemDataChanged(); if (_unityLight == null) { _unityLight = GetComponentInChildren(includeInactive: true); if (_unityLight == null) { - var lightObj = new GameObject("Light (Unity)"); - lightObj.layer = VpxConverter.ChildObjectsLayer; + var lightObj = new GameObject("Light (Unity)") { + layer = VpxConverter.ChildObjectsLayer + }; lightObj.transform.parent = transform; lightObj.transform.localPosition = Vector3.zero; _unityLight = lightObj.AddComponent(); } } - - if (_unityLight != null) { - // Set color and position - _unityLight.color = Data.Color2.ToUnityColor(); - _unityLight.intensity = Data.Intensity / 2f; - _unityLight.range = Data.Falloff * 0.001f; - // TODO: vpe specific data for height - _unityLight.transform.localPosition = new Vector3(0f, 0f, 25f); - - // TODO: vpe specific shadow settings - _unityLight.shadows = LightShadows.Hard; - _unityLight.shadowBias = 0f; - _unityLight.shadowNearPlane = 0f; - } + RenderPipeline.Current.LightConverter.UpdateLight(_unityLight, Data); } public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableAuthoring.cs index 5c32abf99..62d4ffef3 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableAuthoring.cs @@ -23,11 +23,9 @@ using NLog; using UnityEngine; using VisualPinball.Engine.Common; -using VisualPinball.Engine.Game; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Bumper; using VisualPinball.Engine.VPT.Collection; -using VisualPinball.Engine.VPT.Mappings; using VisualPinball.Engine.VPT.Decal; using VisualPinball.Engine.VPT.DispReel; using VisualPinball.Engine.VPT.Flasher; @@ -37,18 +35,21 @@ using VisualPinball.Engine.VPT.Kicker; using VisualPinball.Engine.VPT.Light; using VisualPinball.Engine.VPT.LightSeq; +using VisualPinball.Engine.VPT.Mappings; using VisualPinball.Engine.VPT.Plunger; using VisualPinball.Engine.VPT.Primitive; using VisualPinball.Engine.VPT.Ramp; using VisualPinball.Engine.VPT.Rubber; using VisualPinball.Engine.VPT.Spinner; +using VisualPinball.Engine.VPT.Surface; using VisualPinball.Engine.VPT.Table; using VisualPinball.Engine.VPT.TextBox; using VisualPinball.Engine.VPT.Timer; using VisualPinball.Engine.VPT.Trigger; using VisualPinball.Engine.VPT.Trough; +using Light = VisualPinball.Engine.VPT.Light.Light; using Logger = NLog.Logger; -using SurfaceData = VisualPinball.Engine.VPT.Surface.SurfaceData; +using Material = UnityEngine.Material; using Texture = VisualPinball.Engine.VPT.Texture; namespace VisualPinball.Unity @@ -67,7 +68,7 @@ public class TableAuthoring : ItemMainRenderableAuthoring public TableSerializedSoundContainer Sounds => _sidecar?.sounds; public List Collections => _sidecar?.collections; public MappingsData Mappings => _sidecar?.mappings; - public Patcher.Patcher Patcher { get; internal set; } + //public PatcherManager.Patcher Patcher { get; internal set; } [HideInInspector] [SerializeField] public string physicsEngineId = "VisualPinball.Unity.DefaultPhysicsEngine"; [HideInInspector] [SerializeField] public string debugUiId; @@ -75,7 +76,7 @@ public class TableAuthoring : ItemMainRenderableAuthoring private readonly Dictionary _unityTextures = new Dictionary(); // note: this cache needs to be keyed on the engine material itself so that when its recreated due to property changes the unity material // will cache miss and get recreated as well - private readonly Dictionary _unityMaterials = new Dictionary(); + private readonly Dictionary _unityMaterials = new Dictionary(); /// /// Keeps a list of serializables names that need recreation, serialized and /// lazy so when undo happens they'll be considered dirty again @@ -176,9 +177,9 @@ public Texture2D GetTexture(string name) return null; } - public void AddMaterial(PbrMaterial vpxMat, UnityEngine.Material material) + public void AddMaterial(PbrMaterial vpxMat, Material material) { - UnityEngine.Material oldMaterial = null; + Material oldMaterial = null; _unityMaterials.TryGetValue(vpxMat, out oldMaterial); _unityMaterials[vpxMat] = material; @@ -187,7 +188,7 @@ public void AddMaterial(PbrMaterial vpxMat, UnityEngine.Material material) } } - public UnityEngine.Material GetMaterial(PbrMaterial vpxMat) + public Material GetMaterial(PbrMaterial vpxMat) { if (_unityMaterials.ContainsKey(vpxMat)) { return _unityMaterials[vpxMat]; @@ -236,13 +237,13 @@ public Table CreateTable(TableData data) Restore(table); Restore(table); Restore(table); - Restore(table); + Restore(table); Restore(table); Restore(table); Restore(table); Restore(table); Restore(table); - Restore(table); + Restore(table); Restore(table); Restore(table); diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughApi.cs index 4acf3fff1..32cf72105 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughApi.cs @@ -609,6 +609,9 @@ private static void RefreshUI() /// IApiSwitch IApiSwitchDevice.Switch(string switchId) { + if (switchId == null) { + throw new ArgumentException("Must provide a non-null switch ID!"); + } return _switchLookup.ContainsKey(switchId) ? _switchLookup[switchId] : null; } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughAuthoring.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughAuthoring.cs index 143d826fd..b35eecca3 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughAuthoring.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughAuthoring.cs @@ -22,10 +22,7 @@ using System; using System.Collections.Generic; -using Unity.Mathematics; -using Unity.Transforms; using UnityEngine; -using UnityEngine.Networking.PlayerConnection; using VisualPinball.Engine.Game.Engines; using VisualPinball.Engine.VPT.Kicker; using VisualPinball.Engine.VPT.Trigger; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughExtensions.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughExtensions.cs index 6bcb488d5..16c18f124 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughExtensions.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trough/TroughExtensions.cs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -using Unity.Entities; using UnityEngine; -using VisualPinball.Engine.Game; namespace VisualPinball.Unity { diff --git a/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.asmdef b/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.asmdef index e5cee54f5..10ec8ede2 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.asmdef +++ b/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.asmdef @@ -14,8 +14,7 @@ "Unity.Transforms", "Unity.InputSystem", "VisualPinball.Engine", - "VisualPinball.Resources", - "VisualPinball.Unity.Patcher" + "VisualPinball.Resources" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.csproj b/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.csproj index 01f10ba63..c67225e77 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.csproj +++ b/VisualPinball.Unity/VisualPinball.Unity/VisualPinball.Unity.csproj @@ -17,7 +17,6 @@ - @@ -66,4 +65,7 @@ + + +