diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf4d75a47..5093920c6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ Built with Unity 2021.2.
- Native trough component ([#229](https://github.com/freezy/VisualPinball.Engine/pull/229), [#248](https://github.com/freezy/VisualPinball.Engine/pull/248), [#256](https://github.com/freezy/VisualPinball.Engine/pull/256), [Documentation](https://docs.visualpinball.org/creators-guide/manual/mechanisms/troughs.html)).
### Changed
+- Decouple light components from transformation override ([#350](https://github.com/freezy/VisualPinball.Engine/pull/350)).
- Refactored drag points. They are nicely separated and typed now.
- Collider debug view is now much faster and intuitive. It's also activated per default when there is no visible mesh.
- Drop and hit targets are now different components.
diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md b/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md
index 8d235b6bc..2e65db55e 100644
--- a/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md
+++ b/VisualPinball.Unity/Documentation~/creators-guide/setup/installing-vpe.md
@@ -12,35 +12,31 @@ In order to start creating or modifying tables with VPE, the first thing you'll
Unity uses an application called *Unity Hub* to update itself and provide quick access to your projects. The install process is straight-forward and documented [here](https://docs.unity3d.com/Manual/GettingStartedInstallingHub.html) if you run into troubles.
-When installing Unity, use the latest **2020.3** version. You can leave all the other options unchecked.
+When installing Unity, use the latest **2021.2** version. You can leave all the other options unchecked.
-Once Unity is downloaded and installed, you're ready to create a new VPE project. Unity has multiple render pipelines, and you'll be asked which render pipeline to use:
+Once Unity is downloaded and installed, you're ready to create a new VPE project. Click on *New Project*, be sure to have selected the 2021.2 version at the top, and you'll see the following choices:

-You'll have the choice between:
+The relevant options for VPE are:
-- **2D** - For 2D games. VPE doesn't support this renderer.
- **3D** - Unity's original built-in renderer.
-- **High Definition RP** - Unity's new [HDRP](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@0.0.0/manual/index.html), used for high-end platforms.
-- **Universal Render Pipeline** - Unity's new [URP](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@8.2/manual/index.html) is aimed at mobile and low-end platforms.
+- **3D (URP)** - Unity's [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@8.2/manual/index.html) is aimed at mobile and low-end platforms.
+- **3D (HDRP)** - Unity's [High Definition Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@0.0.0/manual/index.html) used for high-end platforms.
-We recommend using HDRP. It's not as mature as the built-in renderer, but it's able to achieve better visuals, and it's what Unity will be focusing on in the future.
-
-> [!NOTE]
-> If you're just creating a throw-away project for testing out gameplay, the built-in renderer is more mature and faster to set up. We also support the URP, but it's not as well tested as the other two pipelines.
+We recommend using HDRP. It's what we're using when developing and should be the most stable pipeline. Alternatively if you're on a laptop don't have a beefy GPU, use the URP. The built-in renderer is legacy not recommended.
Next, enter a project name and a location for your project. We recommend putting the render pipeline into the name, because in the future you might want to test out other pipelines in their own projects.
-Clicking *Create* launches the Unity editor, pulls in all the dependencies for the new project, and compiles them. This will take a few minutes.
+Clicking *Create project* launches the Unity editor, pulls in all the dependencies for the new project, and compiles them. This will take a few minutes.
### HDRP Setup
-If you create an HDRP project, Unity provides you with a sample scene:
+Once the editor has opened you can click away the HDRP Wizard that opens. You should now see an empty scene:
-
+
-The sample scene is impressive but contains lots of content we don't need, 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`.
+Click on *File -> New Scene* and select the *Basic Indoors (HDRP)* template. Save it in your *Assets/Scenes* folder as `TestTable.unity`.
In this base 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:
@@ -58,22 +54,27 @@ To do that, go to *Edit -> Project Settings*, and select the *Package Manager* p
- URL: `https://registry.visualpinball.org/`
- Scope(s): `org.visualpinball`
-Your settings page should now look like this:
+Also check *Enable Pre-release Packages* (and confirm), as well as *Show dependencies*. Your settings page should now look like this:
-
+
Hit *Save* and close the window. Now you'll add VPE's HDRP package, which will automatically pull in the core package and the assets package.
-Open the package manager by clicking on *Window -> Package Manager*. Then click on the "plus" icon on the top left corner of the window, and choose *Add package from git URL*.
+Open the package manager by clicking on *Window -> Package Manager*. Then click on the "plus" icon on the top left corner of the window, and choose *Add package by name..*.
-

+
-There, enter `org.visualpinball.engine.unity.hdrp` and click *Add*. This will take a moment as Unity downloads and compiles all of VPE's dependencies. If during this time, you see the following warning about the input system:
+There, enter `org.visualpinball.engine.unity.hdrp` and click *Add*. This will take a moment as Unity downloads and compiles all of VPE's dependencies and parses all the assets that we ship in our library. If during this time, you see the following warning about the input system:

-Click *Yes*. When complete, you should now have a *Visual Pinball* menu in the editor, and you should see the following new packages in the package manager (version numbers may vary):
+Click *Yes*.
+
+> [!WARNING]
+> Our patcher, which is currently part of the main package, depends on the PinMAME package. Until we move the patcher into a separate package, you will have to install the PinMAME package as well. To do that, click on the plus button again and enter `org.visualpinball.engine.pinmame`, then click on *Add*.
+
+When complete, you should now have a *Visual Pinball* menu in the editor, and you should see the following new packages in the package manager (version numbers will vary):
-
+
Now that VPE is installed let's [import a table](xref:setup_running_vpe)!
diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md b/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md
index 48f929ce8..73b34054a 100644
--- a/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md
+++ b/VisualPinball.Unity/Documentation~/creators-guide/setup/running-vpe.md
@@ -4,7 +4,7 @@ description: How to run VPE
---
# Running VPE
-Now we can get begin with some simple game play. Open Visual Pinball, create a new "blank" table, and save it somewhere. In Unity, go to *Visual Pinball -> Import VPX* and choose the new `.vpx` file.
+Now we can get begin with some simple game play. Open [Visual Pinball](https://github.com/vpinball/vpinball), create a new "blank" table, and save it somewhere. In Unity, go to *Visual Pinball -> Import VPX* and choose the `.vpx` file you've just created.
You should now see Visual Pinball's blank table in the Editor's scene view:
@@ -19,11 +19,11 @@ Now that we have the camera of the scene view somewhat aligned, we still can't s

-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 hide them, click on *Visual Pinball -> Editor -> Disable Gizmo Icons*.
+
-Since a pinball table is a relatively small object, the remaining icons are huge when working on a table, so click on the *Gizmos* dropdown in the scene view and use the top slider to shrink them down a bit.
+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. Unity's default gizmo size is adapted for rather large scenes and we're dealing with a pinball table, let's make them smaller by clicking on the gizmo icon in the *Scene* view, and pull the size *3D Icons* slider down until you're happy. You can additionally hide the VPE icons by clicking on *Visual Pinball -> Editor -> Disable Gizmo Icons*.
-And while we're at it, choose *Visual Pinball -> Editor -> Setup Layouts* to populate a bunch of pre-made editor layouts that give you easy access to the tooling we've added to the editor.
+And while we're at it, choose *Visual Pinball -> Editor -> Setup Layouts* to populate a bunch of pre-made editor layouts that give you easy access to the tooling we've added to the editor. Then, click on the top right drop down in the editor where it says *Default*, and choose *3) VPE Simple*.

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 43a686931..903d16eea 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-gizmo-size.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-gizmo-size.png
new file mode 100644
index 000000000..94bf00588
Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-gizmo-size.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
deleted file mode 100644
index c0e49b826..000000000
Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-default-scene.png and /dev/null differ
diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-empty-scene.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-empty-scene.png
new file mode 100644
index 000000000..e20815bef
Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-empty-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
index cd980c808..1a1066cb2 100644
Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-test-scene.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-hdrp-test-scene.png 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 5bf7d630e..1bb1ef8e1 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
index 9600b7766..dcc302bec 100644
Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-imported-table-ugly-gizmos.png 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 c4ce271f7..673b7f57a 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-package-manager.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-package-manager.png
index 243ef4b64..7c30f44ce 100644
Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-package-manager.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-package-manager.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
index 0a9d200a6..c6861470d 100644
Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-packages-after-installation.png and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-packages-after-installation.png differ
diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-scoped-registry.jpg b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-scoped-registry.jpg
deleted file mode 100644
index 579192ea0..000000000
Binary files a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-scoped-registry.jpg and /dev/null differ
diff --git a/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-scoped-registry.png b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-scoped-registry.png
new file mode 100644
index 000000000..c523bb7ec
Binary files /dev/null and b/VisualPinball.Unity/Documentation~/creators-guide/setup/unity-scoped-registry.png differ
diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs
index 04b2c6ba0..12b2dbb28 100644
--- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs
@@ -78,7 +78,7 @@ private void OnSceneGUI()
#region Dragpoint Tooling
public DragPointData[] DragPoints { get => MeshComponent.DragPoints; set => MeshComponent.DragPoints = value; }
- public Vector3 EditableOffset => new Vector3(-MeshComponent.MainComponent.Position.x, -MeshComponent.MainComponent.Position.y, MeshComponent.PositionZ);
+ public Vector3 EditableOffset => new Vector3(-MeshComponent.MainComponent.transform.localPosition.x, -MeshComponent.MainComponent.transform.localPosition.y, MeshComponent.PositionZ);
public Vector3 GetDragPointOffset(float ratio) => Vector3.zero;
public bool PointsAreLooping => true;
public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.Texture };
diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs
index b546a100a..9cc993f77 100644
--- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs
@@ -34,7 +34,7 @@ public class LightInspector : MainInspector
private static readonly string[] LightStateLabels = { "Off", "On", "Blinking" };
private static readonly int[] LightStateValues = { LightStatus.LightStateOff, LightStatus.LightStateOn, LightStatus.LightStateBlinking };
- private SerializedProperty _positionProperty;
+ //private SerializedProperty _positionProperty;
private SerializedProperty _surfaceProperty;
private SerializedProperty _bulbSizeProperty;
private SerializedProperty _stateProperty;
@@ -47,7 +47,7 @@ protected override void OnEnable()
{
base.OnEnable();
- _positionProperty = serializedObject.FindProperty(nameof(LightComponent.Position));
+ //_positionProperty = serializedObject.FindProperty(nameof(LightComponent.Position));
_surfaceProperty = serializedObject.FindProperty(nameof(LightComponent._surface));
_bulbSizeProperty = serializedObject.FindProperty(nameof(LightComponent.BulbSize));
@@ -68,7 +68,7 @@ public override void OnInspectorGUI()
OnPreInspectorGUI();
- PropertyField(_positionProperty, updateTransforms: true);
+ //PropertyField(_positionProperty, updateTransforms: true);
PropertyField(_surfaceProperty, updateTransforms: true);
PropertyField(_bulbSizeProperty, "Bulb Mesh Size", updateTransforms: true);
diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs
index 6548edc05..f32ac540d 100644
--- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs
@@ -69,13 +69,14 @@ protected virtual void OnEnable()
continue;
}
-
var item = itemTransform.GetComponent();
+ var isRenderableItem = item != null;
+ var overrideTransform = isRenderableItem && item.OverrideTransform;
_itemSelected = itemTransform.GetComponent() != null;
- useDefault = useDefault && !_itemSelected && itemTransform.GetComponent() == null;
+ useDefault = useDefault && (!_itemSelected || !overrideTransform) && itemTransform.GetComponent() == null;
// must be main but not the table itself
- if (item != null && !(item is TableComponent)) {
+ if (isRenderableItem && item is not TableComponent) {
if (_primaryItem == null) {
_primaryItem = item;
diff --git a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Rock.cs b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Rock.cs
index c663e3fe7..8894f4bb8 100644
--- a/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Rock.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Rock.cs
@@ -61,7 +61,7 @@ public override void PostPatch(GameObject tableGo)
private static void SetupLamps(GameObject tableGo, GameObject playfieldGo)
{
var displayRegEx = new Regex("^[a-c][0-9a-f][0-9a-f]$");
-
+
foreach (var child in playfieldGo.transform.Find("Lights").gameObject.transform.Cast().ToList()) {
var go = child.gameObject;
@@ -83,7 +83,7 @@ private static void SetupLamps(GameObject tableGo, GameObject playfieldGo)
var lampGroups = CreateEmptyGameObject(playfieldGo, "Lamp Groups");
var lampGroup1 = CreateEmptyGameObject(lampGroups, "LampGroup1");
-
+
AddLightGroup(tableGo, lampGroup1,
"gi2", "gi4", "gi6", "gi7", "gi9",
"gi10", "gi11", "gi12", "gi13", "gi14", "gi15", "gi16", "gi17", "gi18", "gi19",
@@ -91,7 +91,7 @@ private static void SetupLamps(GameObject tableGo, GameObject playfieldGo)
"gi30", "gi31");
var lampGroup12 = CreateEmptyGameObject(lampGroups, "LampGroup12");
-
+
AddLightGroup(tableGo, lampGroup12,
"gi22", "gi24", "gi27");
@@ -367,7 +367,7 @@ public void DisableLamps(GameObject go)
[NameMatch("gi14")]
public void FixGI14(GameObject go)
{
- go.GetComponent().Position = new Vector3(894.29f, 178.4f);
+ go.GetComponent().transform.localPosition = new Vector3(894.29f, 178.4f);
}
[NameMatch("gi2")]
diff --git a/VisualPinball.Unity/VisualPinball.Unity/Game/DisplayPlayer.cs b/VisualPinball.Unity/VisualPinball.Unity/Game/DisplayPlayer.cs
index ac114f3e5..f9cfe3e5f 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/Game/DisplayPlayer.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/Game/DisplayPlayer.cs
@@ -50,7 +50,7 @@ private void HandleDisplayAvailable(object sender, AvailableDisplays availableDi
_displayGameObjects[display.Id].Clear();
} else {
- Logger.Error($"Cannot find DMD game object for display \"{display.Id}\"");
+ Logger.Warn($"Cannot find DMD game object for display \"{display.Id}\"");
}
}
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs
index 3c5af4751..098fc60df 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs
@@ -23,8 +23,17 @@ public interface IMainRenderableComponent : IMainComponent
{
bool IsLocked { get; set; }
+ ///
+ /// If true, no transformation gizmos are displayed
+ ///
bool CanBeTransformed { get; }
+ ///
+ /// If true, we override the transformation gizmos to be able to sync transformation
+ /// with the component data. Otherwise, Unity's transformation is used.
+ ///
+ bool OverrideTransform { get; }
+
string ItemName { get; }
///
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs
index 692a558b3..800714ebc 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs
@@ -40,8 +40,6 @@ public class LightComponent : MainRenderableComponent, ILampDeviceCom
{
#region Data
- public Vector3 Position;
-
public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; }
[SerializeField]
[TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)]
@@ -77,6 +75,8 @@ public class LightComponent : MainRenderableComponent, ILampDeviceCom
public override LightData InstantiateData() => new LightData();
+ public override bool OverrideTransform => false;
+
protected override Type MeshComponentType { get; } = typeof(MeshComponent);
protected override Type ColliderComponentType { get; } = null;
@@ -84,6 +84,8 @@ public class LightComponent : MainRenderableComponent, ILampDeviceCom
private const string BulbMeshName = "Light (Bulb)";
private const string SocketMeshName = "Light (Socket)";
+ private static readonly int EmissiveColorProperty = Shader.PropertyToID("_EmissiveColor");
+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
#endregion
@@ -111,43 +113,46 @@ public class LightComponent : MainRenderableComponent, ILampDeviceCom
#region Transformation
- public override void UpdateTransforms()
- {
- base.UpdateTransforms();
-
- // position
- transform.localPosition = Surface != null
- ? new Vector3(Position.x, Position.y, Surface.Height(Position) + Position.z)
- : new Vector3(Position.x, Position.y, PlayfieldHeight + Position.z);
-
- // bulb size
- foreach (var mf in GetComponentsInChildren(true)) {
- if (!mf.sharedMesh) {
- continue;
- }
- switch (mf.sharedMesh.name) {
- case BulbMeshName:
- case SocketMeshName:
- mf.gameObject.transform.localScale = new Vector3(BulbSize, BulbSize, BulbSize);
- break;
- }
- }
-
- // insert mesh position
- var insertMeshComponent = GetComponentInChildren();
- if (insertMeshComponent) {
- var t = insertMeshComponent.transform;
- var pos = t.localPosition;
- t.localPosition = new Vector3(-Position.x, -Position.y, insertMeshComponent.PositionZ);
- }
- }
+ // public override void UpdateTransforms()
+ // {
+ // base.UpdateTransforms();
+ //
+ // // position
+ // transform.localPosition = Surface != null
+ // ? new Vector3(Position.x, Position.y, Surface.Height(Position) + Position.z)
+ // : new Vector3(Position.x, Position.y, PlayfieldHeight + Position.z);
+ //
+ // // bulb size
+ // foreach (var mf in GetComponentsInChildren(true)) {
+ // if (!mf.sharedMesh) {
+ // continue;
+ // }
+ // switch (mf.sharedMesh.name) {
+ // case BulbMeshName:
+ // case SocketMeshName:
+ // mf.gameObject.transform.localScale = new Vector3(BulbSize, BulbSize, BulbSize);
+ // break;
+ // }
+ // }
+ //
+ // // insert mesh position
+ // var insertMeshComponent = GetComponentInChildren();
+ // if (insertMeshComponent) {
+ // var t = insertMeshComponent.transform;
+ // var pos = t.localPosition;
+ // t.localPosition = new Vector3(-Position.x, -Position.y, insertMeshComponent.PositionZ);
+ // }
+ // }
#endregion
#region Runtime
+ private bool _hasLights;
private UnityEngine.Light[] _unityLights;
+ private readonly List<(Renderer, Color, float)> _fullEmissions = new List<(Renderer, Color, float)>();
private float _fullIntensity;
+ private MaterialPropertyBlock _propBlock;
public bool Enabled {
set {
@@ -177,9 +182,10 @@ private void Awake()
player.RegisterLamp(this);
_unityLights = GetComponentsInChildren();
+ _hasLights = _unityLights.Length > 0;
// remember intensity
- if (_unityLights.Length > 0) {
+ if (_hasLights) {
_fullIntensity = _unityLights[0].intensity;
}
// enable at 0
@@ -192,10 +198,22 @@ private void Awake()
unityLight.enabled = false;
}
}
+
+ // emissive materials
+ _propBlock = new MaterialPropertyBlock();
+ foreach (var mr in GetComponentsInChildren()) {
+ var emissiveColor = mr.sharedMaterial.GetColor(EmissiveColorProperty);
+ if (emissiveColor.a > 10f) {
+ _fullEmissions.Add((mr, emissiveColor, 0));
+ }
+ }
}
public void FadeTo(float value)
{
+ if (!_hasLights) {
+ return;
+ }
if (FadeEnabled) {
StopAllCoroutines();
StartCoroutine(nameof(Fade), value);
@@ -210,11 +228,16 @@ public void FadeTo(float value)
unityLight.enabled = false;
}
}
+
+ SetEmissions(value);
}
}
public void StartBlinking()
{
+ if (!_hasLights) {
+ return;
+ }
StopAllCoroutines();
StartCoroutine(nameof(Blink));
}
@@ -252,18 +275,48 @@ private IEnumerator Fade(float value)
foreach (var unityLight in _unityLights) {
unityLight.intensity = b;
}
+ SetEmissions(value);
} else {
while (counter <= duration) {
counter += Time.deltaTime;
+ var position = counter / duration;
foreach (var unityLight in _unityLights) {
- unityLight.intensity = Mathf.Lerp(a, b, counter / duration);
+ unityLight.intensity = Mathf.Lerp(a, b, position);
}
- yield return null;
+ yield return FadeEmissions(value, position);
}
}
}
+ ///
+ /// Sets the material emissions as a LERP between the current emission and
+ /// a value for a given position.
+ ///
+ /// Value, between 0 and 1. End position of LERP is this value times full emission.
+ /// LERP position
+ private IEnumerator FadeEmissions(float value, float position)
+ {
+ for (var i = 0; i < _fullEmissions.Count; i++) {
+ var (mr, color, lastValue) = _fullEmissions[i];
+ mr.GetPropertyBlock(_propBlock);
+ var emission = Mathf.Lerp(lastValue, value, position);
+ _propBlock.SetColor(EmissiveColorProperty, emission * color * 0.05f);
+ _fullEmissions[i] = (mr, color, emission);
+ mr.SetPropertyBlock(_propBlock);
+ }
+ yield return null;
+ }
+
+ private void SetEmissions(float value)
+ {
+ foreach (var (mr, color, lastValue) in _fullEmissions) {
+ mr.GetPropertyBlock(_propBlock);
+ _propBlock.SetColor(EmissiveColorProperty, value * color * 0.05f);
+ mr.SetPropertyBlock(_propBlock);
+ }
+ }
+
#endregion
#region Conversion
@@ -273,7 +326,7 @@ public override IEnumerable SetData(LightData data)
var updatedComponents = new List { this };
// transforms
- Position = new Vector3(data.Center.X, data.Center.Y, 0);
+ //Position = new Vector3(data.Center.X, data.Center.Y, 0);
BulbSize = data.MeshRadius;
// logical params
@@ -335,7 +388,7 @@ public override LightData CopyDataTo(LightData data, string[] materialNames, str
{
// name and position
data.Name = name;
- data.Center = Position.ToVertex2Dxy();
+ //data.Center = Position.ToVertex2Dxy();
data.Surface = Surface != null ? Surface.name : string.Empty;
data.MeshRadius = BulbSize;
@@ -371,17 +424,5 @@ public override LightData CopyDataTo(LightData data, string[] materialNames, str
}
#endregion
-
- #region Editor Tooling
-
- public override ItemDataTransformType EditorPositionType => ItemDataTransformType.ThreeD;
- public override Vector3 GetEditorPosition() => Position;
- public override void SetEditorPosition(Vector3 pos) => Position = pos;
-
- public override ItemDataTransformType EditorScaleType => ItemDataTransformType.OneD;
- public override Vector3 GetEditorScale() => new Vector3(BulbSize, BulbSize, BulbSize);
- public override void SetEditorScale(Vector3 scale) => BulbSize = scale.x;
-
- #endregion
}
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs
index 7df39f3ab..47ebd4950 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs
@@ -30,6 +30,8 @@ public abstract class MainRenderableComponent : MainComponent,
{
public virtual bool CanBeTransformed => true;
+ public virtual bool OverrideTransform => true;
+
///
/// Component type of the child class.
///
@@ -124,7 +126,7 @@ protected float ClampDegrees(float deg)
private static void CopyMaterialName(MeshRenderer mr, string[] materialNames, string[] textureNames,
ref string materialName, ref string mapName, ref string normalMapName, ref string envMapName)
{
- if (!mr || materialNames == null || textureNames == null) {
+ if (!mr || materialNames == null || textureNames == null || mr.sharedMaterial == null) {
return;
}
var result = PbrMaterial.ParseId(mr.sharedMaterial.name, materialNames, textureNames);
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveColliderComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveColliderComponent.cs
index aa3e0beb8..72b5205ad 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveColliderComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveColliderComponent.cs
@@ -64,7 +64,8 @@ public class PrimitiveColliderComponent : ColliderComponent ValidParents => ValidParentTypes;
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs
index d2c9856f6..a06b8068b 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs
@@ -54,6 +54,7 @@ public class PrimitiveMeshComponent : MeshComponent ValidParents => ValidParentTypes;
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs
index c3063a2f4..f2f782ffb 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs
@@ -214,6 +214,7 @@ private Mesh GetMesh()
public bool IsLocked { get => _isLocked; set => _isLocked = value; }
public bool CanBeTransformed => false;
+ public bool OverrideTransform => false;
public string ItemName => "Slingshot";
public Entity Entity { get; set; }
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderComponent.cs
index ff3c0ef0e..f19f3eb70 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderComponent.cs
@@ -70,7 +70,8 @@ public class SurfaceColliderComponent : ColliderComponent ValidParents => ValidParentTypes;