From 98a151abfeeee3da28cd4d6872127845a383704e Mon Sep 17 00:00:00 2001 From: freezy Date: Fri, 29 Nov 2024 22:08:19 +0100 Subject: [PATCH] cleanup: Remove editor transform overloads, surface props, table height, and merged z-pos into pos where possible. --- .../MetalWireGuideMeshGenerator.cs | 1 - .../AssetStructure/AssetDetails.cs | 4 +- .../DragPoint/DragPointMenuItems.cs | 2 +- .../DragPoint/DragPointsInspectorHelper.cs | 48 +- .../DragPoint/DragPointsSceneViewHandler.cs | 4 +- .../DragPoint/IDragPointsInspector.cs | 8 +- .../Utils/HandlesUtils.cs | 6 +- .../VPT/Bumper/BumperInspector.cs | 5 +- .../VPT/Flipper/FlipperInspector.cs | 3 - .../VPT/Gate/GateInspector.cs | 4 - .../VPT/ItemInspector.cs | 12 +- .../VPT/Kicker/KickerInspector.cs | 9 +- .../VPT/Light/LightInsertMeshInspector.cs | 2 +- .../VPT/Light/LightInspector.cs | 6 - .../VPT/MainInspector.cs | 14 - .../MetalWireGuide/MetalWireGuideInspector.cs | 2 +- .../VPT/Playfield/PlayfieldInspector.cs | 5 - .../VPT/Plunger/PlungerInspector.cs | 14 +- .../VPT/Ramp/RampInspector.cs | 2 +- .../VPT/Rubber/RubberInspector.cs | 2 +- .../VPT/Spinner/SpinnerInspector.cs | 8 +- .../VPT/Surface/SurfaceInspector.cs | 8 +- .../VPT/TransformInspector.cs | 371 ------------- .../VPT/TransformInspector.cs.meta | 11 - .../VPT/Trigger/TriggerInspector.cs | 10 +- .../Game/BallRollerComponent.cs | 7 +- .../Game/DebugBallCreator.cs | 4 +- .../Game/Engine/DefaultGamelogicEngine.cs | 2 +- .../VPT/Bumper/BumperApi.cs | 4 +- .../VPT/Bumper/BumperComponent.cs | 46 +- .../VPT/Bumper/BumperSkirtAnimationState.cs | 2 +- .../VPT/Flipper/FlipperApi.cs | 1 - .../VPT/Flipper/FlipperCollider.cs | 6 +- .../VPT/Flipper/FlipperComponent.cs | 39 +- .../VPT/Gate/GateComponent.cs | 39 +- .../VPT/HitTarget/TargetComponent.cs | 17 - .../VPT/IMainRenderableComponent.cs | 42 +- .../VPT/ISurfaceComponent.cs | 43 -- .../VPT/ISurfaceComponent.cs.meta | 11 - .../VPT/Kicker/KickerApi.cs | 8 +- .../VPT/Kicker/KickerComponent.cs | 58 +-- .../VPT/Light/LightComponent.cs | 15 - .../VPT/Light/LightInsertMeshComponent.cs | 4 +- .../VisualPinball.Unity/VPT/MainComponent.cs | 7 - .../VPT/MainRenderableComponent.cs | 26 +- .../VisualPinball.Unity/VPT/MeshComponent.cs | 9 - .../VPT/MetalWireGuide/MetalWireGuideApi.cs | 3 +- .../MetalWireGuide/MetalWireGuideComponent.cs | 489 ++++++++---------- .../MetalWireGuideMeshComponent.cs | 2 +- .../VPT/Playfield/PlayfieldApi.cs | 12 +- .../VPT/Playfield/PlayfieldComponent.cs | 17 +- .../VPT/Plunger/PlungerCollider.cs | 2 +- .../VPT/Plunger/PlungerComponent.cs | 57 +- .../VPT/Plunger/PlungerFlatMeshComponent.cs | 2 +- .../VPT/Plunger/PlungerRodMeshComponent.cs | 2 +- .../VPT/Plunger/PlungerSpringMeshComponent.cs | 2 +- .../VPT/Primitive/PrimitiveComponent.cs | 2 +- .../VPT/Primitive/PrimitiveMeshComponent.cs | 2 +- .../VisualPinball.Unity/VPT/Ramp/RampApi.cs | 4 +- .../VPT/Ramp/RampComponent.cs | 117 ++--- .../VPT/Ramp/RampFloorMeshComponent.cs | 2 +- .../VPT/Ramp/RampWallMeshComponent.cs | 2 +- .../VPT/Ramp/RampWireMeshComponent.cs | 2 +- .../VPT/Rubber/RubberApi.cs | 4 +- .../VPT/Rubber/RubberComponent.cs | 66 --- .../VPT/Rubber/RubberMeshComponent.cs | 2 +- .../VPT/Spinner/SpinnerComponent.cs | 81 +-- .../VPT/Surface/SlingshotComponent.cs | 33 +- .../VPT/Surface/SurfaceApi.cs | 4 +- .../VPT/Surface/SurfaceComponent.cs | 33 +- .../VPT/Surface/SurfaceSideMeshComponent.cs | 2 +- .../VPT/Surface/SurfaceTopMeshComponent.cs | 2 +- .../VPT/Table/TableComponent.cs | 2 +- .../VPT/Trigger/TriggerColliderGenerator.cs | 6 +- .../VPT/Trigger/TriggerComponent.cs | 55 +- .../VPT/Trigger/TriggerMeshComponent.cs | 3 +- 76 files changed, 406 insertions(+), 1557 deletions(-) delete mode 100644 VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs delete mode 100644 VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs.meta delete mode 100644 VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs delete mode 100644 VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs.meta diff --git a/VisualPinball.Engine/VPT/MetalWireGuide/MetalWireGuideMeshGenerator.cs b/VisualPinball.Engine/VPT/MetalWireGuide/MetalWireGuideMeshGenerator.cs index 4d0b54f20..a7c36f7ed 100644 --- a/VisualPinball.Engine/VPT/MetalWireGuide/MetalWireGuideMeshGenerator.cs +++ b/VisualPinball.Engine/VPT/MetalWireGuide/MetalWireGuideMeshGenerator.cs @@ -19,7 +19,6 @@ #nullable enable using VisualPinball.Engine.Common; -using VisualPinball.Engine.Game; using VisualPinball.Engine.Math; namespace VisualPinball.Engine.VPT.MetalWireGuide diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/AssetDetails.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/AssetDetails.cs index ded688c71..985003d9c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/AssetDetails.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/AssetDetails.cs @@ -274,11 +274,9 @@ private void OnAddSelected() var go = InstantiateAsset(parentTransform); // move to the middle of the playfield + go.transform.localPosition = new Vector3(Physics.ScaleToWorld(pf.Width / 2), 0, -Physics.ScaleToWorld(pf.Height / 2)); if (pf != null && go.GetComponent(typeof(IMainRenderableComponent)) is IMainRenderableComponent comp) { - comp.SetEditorPosition(new Vector3(pf.Width / 2, pf.Height / 2, 0)); comp.UpdateTransforms(); - } else if (pf != null) { - go.transform.localPosition = new Vector3(Physics.ScaleToWorld(pf.Width / 2), 0, -Physics.ScaleToWorld(pf.Height / 2)); } ApplyVariation(go); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs index 93d2a153c..d2c9b16b0 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs @@ -203,7 +203,7 @@ private static void FlipZ(MenuCommand command) private static bool FlipZValidate(MenuCommand command) { if (command.context is IDragPointsInspector inspector) { - return inspector.HandleType == ItemDataTransformType.ThreeD; + return inspector.HandleType == DragPointTransformType.ThreeD; } return false; } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs index c2904d95a..d7428b1fe 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.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; using System.Linq; using UnityEditor; using UnityEngine; @@ -65,11 +63,6 @@ public DragPointsInspectorHelper(IMainRenderableComponent mainComponent, IDragPo public void RebuildMeshes() { _mainComponent.RebuildMeshes(); - if (_playfieldComponent) { - WalkChildren(_playfieldComponent.transform, UpdateSurfaceReferences); - } else { - Debug.LogWarning($"{_mainComponent.name} doesn't seem to have a playfield parent."); - } } public void OnEnable() @@ -125,7 +118,8 @@ public void PasteDragPoint(int controlId) /// True if game item is locked, false otherwise. public bool IsItemLocked() { - return _mainComponent.IsLocked; + // todo delete or implement properly + return false; } /// @@ -144,7 +138,7 @@ public bool HasDragPointExposure(DragPointExposure exposure) /// Axis to flip on public void FlipDragPoints(FlipAxis flipAxis) { - if (_dragPointsInspector.HandleType != ItemDataTransformType.ThreeD && flipAxis == FlipAxis.Z) { + if (_dragPointsInspector.HandleType != DragPointTransformType.ThreeD && flipAxis == FlipAxis.Z) { return; } @@ -206,10 +200,11 @@ public void PrepareUndo(string message) public void OnInspectorGUI(ItemInspector inspector) { - if (_mainComponent.IsLocked) { - EditorGUILayout.LabelField("Drag Points are Locked"); - return; - } + // todo remove or implement properly + // if (_mainComponent.IsLocked) { + // EditorGUILayout.LabelField("Drag Points are Locked"); + // return; + // } GUILayout.Space(10); if (GUILayout.Button("Center Origin")) { @@ -232,7 +227,7 @@ public void OnInspectorGUI(ItemInspector inspector) EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); - if (_dragPointsInspector.HandleType == ItemDataTransformType.TwoD) { + if (_dragPointsInspector.HandleType == DragPointTransformType.TwoD) { var pos = EditorGUILayout.Vector2Field("Position", controlPoint.DragPoint.Center.ToUnityVector2()); if (EditorGUI.EndChangeCheck()) { controlPoint.DragPoint.Center.X = pos.x; @@ -266,9 +261,10 @@ public void OnInspectorGUI(ItemInspector inspector) private void UpdateDragPointsLock() { - if (DragPointsHandler.UpdateDragPointsLock(_mainComponent.IsLocked)) { - HandleUtility.Repaint(); - } + // todo remove or implement properly + // if (DragPointsHandler.UpdateDragPointsLock(_mainComponent.IsLocked)) { + // HandleUtility.Repaint(); + // } } private void OnDragPointPositionChange() @@ -280,7 +276,6 @@ private void OnDragPointPositionChange() private void OnUndoRedoPerformed() { RemapControlPoints(); - WalkChildren(_playfieldComponent.transform, UpdateSurfaceReferences); } public void OnSceneGUI(ItemInspector inspector) @@ -310,22 +305,5 @@ public void OnSceneGUI(ItemInspector inspector) } } } - - private static void WalkChildren(IEnumerable node, Action action) - { - foreach (Transform childTransform in node) { - action(childTransform); - WalkChildren(childTransform, action); - } - } - - private void UpdateSurfaceReferences(Transform obj) - { - var surfaceComponent = obj.gameObject.GetComponent(); - if (surfaceComponent != null && surfaceComponent.Surface == _mainComponent) { - surfaceComponent.OnSurfaceUpdated(); - } - } - } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs index 1e1f77794..a5138b96d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs @@ -241,7 +241,7 @@ private void DisplayControlPoints() } Handles.matrix = Matrix4x4.identity; - if (!_handler.MainComponent.IsLocked) { + // if (!_handler.MainComponent.IsLocked) { // curve traveller is not overlapping a control point, we can draw it. if (distToControlPoint > HandleUtility.GetHandleSize(_handler.CurveTravellerPosition) * ControlPoint.ScreenRadius) { Handles.color = Color.grey; @@ -257,7 +257,7 @@ private void DisplayControlPoints() HandleUtility.Repaint(); } } - } + // } Profiler.EndSample(); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs index 5cc92e471..959a7d0ef 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs @@ -46,6 +46,12 @@ public enum DragPointExposure Texture } + public enum DragPointTransformType + { + TwoD, + ThreeD, + } + /// /// Abstraction inspectors that support drag points. /// @@ -77,7 +83,7 @@ public interface IDragPointsInspector /// Returns the applied constrains to drag points position edition. /// /// - ItemDataTransformType HandleType { get; } + DragPointTransformType HandleType { get; } DragPointsInspectorHelper DragPointsHelper { get; } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/HandlesUtils.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/HandlesUtils.cs index 714266e7c..24f18f67e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/HandlesUtils.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/Utils/HandlesUtils.cs @@ -30,14 +30,14 @@ public static class HandlesUtils /// /// /// Moved position in VPX space. - public static Vector3 HandlePosition(Vector3 position, Matrix4x4 localToWorld, ItemDataTransformType type, float handleSize = 0.2f, float snap = 0.0f) + public static Vector3 HandlePosition(Vector3 position, Matrix4x4 localToWorld, DragPointTransformType type, float handleSize = 0.2f, float snap = 0.0f) { var pos = position.TranslateToWorld(); Handles.matrix = localToWorld; switch (type) { - case ItemDataTransformType.TwoD: { + case DragPointTransformType.TwoD: { var forward = Vector3.forward.TranslateToWorld().normalized; var right = Vector3.right.TranslateToWorld().normalized; @@ -61,7 +61,7 @@ public static Vector3 HandlePosition(Vector3 position, Matrix4x4 localToWorld, I break; } - case ItemDataTransformType.ThreeD: { + case DragPointTransformType.ThreeD: { pos = Handles.PositionHandle(pos, Quaternion.identity.RotateToWorld()); break; } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Bumper/BumperInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Bumper/BumperInspector.cs index 399af7ab5..8c8f672d9 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Bumper/BumperInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Bumper/BumperInspector.cs @@ -26,7 +26,6 @@ namespace VisualPinball.Unity.Editor public class BumperInspector : MainInspector { private SerializedProperty _radiusProperty; - private SerializedProperty _surfaceProperty; private SerializedProperty _isHardwiredProperty; protected override void OnEnable() @@ -34,7 +33,6 @@ protected override void OnEnable() base.OnEnable(); _radiusProperty = serializedObject.FindProperty(nameof(BumperComponent.Radius)); - _surfaceProperty = serializedObject.FindProperty(nameof(BumperComponent._surface)); _isHardwiredProperty = serializedObject.FindProperty(nameof(BumperComponent.IsHardwired)); } @@ -50,7 +48,7 @@ public override void OnInspectorGUI() // position EditorGUI.BeginChangeCheck(); - var newPos = EditorGUILayout.Vector2Field(new GUIContent("Position", "Position of the bumper on the playfield, relative to its parent."), MainComponent.Position); + var newPos = EditorGUILayout.Vector3Field(new GUIContent("Position", "Position of the bumper on the playfield, relative to its parent."), MainComponent.Position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(MainComponent.transform, "Change Bumper Position"); MainComponent.Position = newPos; @@ -74,7 +72,6 @@ public override void OnInspectorGUI() MainComponent.Orientation = newAngle; } - PropertyField(_surfaceProperty, updateTransforms: true); PropertyField(_isHardwiredProperty, updateTransforms: false); base.OnInspectorGUI(); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Flipper/FlipperInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Flipper/FlipperInspector.cs index b848528aa..a8c04f92e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Flipper/FlipperInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Flipper/FlipperInspector.cs @@ -29,7 +29,6 @@ public class FlipperInspector : MainInspector private bool _foldoutRubberGeometry = true; private SerializedProperty _endAngleProperty; - private SerializedProperty _surfaceProperty; private SerializedProperty _isEnabledProperty; private SerializedProperty _isDualWoundProperty; private SerializedProperty _heightProperty; @@ -46,7 +45,6 @@ protected override void OnEnable() base.OnEnable(); _endAngleProperty = serializedObject.FindProperty(nameof(FlipperComponent.EndAngle)); - _surfaceProperty = serializedObject.FindProperty(nameof(FlipperComponent._surface)); _isEnabledProperty = serializedObject.FindProperty(nameof(FlipperComponent.IsEnabled)); _isDualWoundProperty = serializedObject.FindProperty(nameof(FlipperComponent.IsDualWound)); _heightProperty = serializedObject.FindProperty(nameof(FlipperComponent._height)); @@ -86,7 +84,6 @@ public override void OnInspectorGUI() } PropertyField(_endAngleProperty); - PropertyField(_surfaceProperty); PropertyField(_isEnabledProperty); PropertyField(_isDualWoundProperty); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Gate/GateInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Gate/GateInspector.cs index db6281bb5..947f0e455 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Gate/GateInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Gate/GateInspector.cs @@ -36,7 +36,6 @@ public class GateInspector : MainInspector { "Wire W", GateType.GateWireW }, }; - private SerializedProperty _surfaceProperty; private SerializedProperty _meshProperty; private SerializedProperty _typeProperty; @@ -46,7 +45,6 @@ protected override void OnEnable() { base.OnEnable(); - _surfaceProperty = serializedObject.FindProperty(nameof(GateComponent._surface)); _meshProperty = serializedObject.FindProperty(nameof(GateComponent._meshName)); _typeProperty = serializedObject.FindProperty(nameof(GateComponent._type)); } @@ -85,8 +83,6 @@ public override void OnInspectorGUI() MainComponent.Length = newLength; } - PropertyField(_surfaceProperty); - var wire = MainComponent.transform.Find(GateComponent.WireObjectName); if (wire != null) { MeshDropdownPropertyFbx("Mesh", _meshProperty, MeshFbx, wire.gameObject, _typeProperty, WireTypeMap, "Wire."); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs index 69efc9b19..de1179aa4 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs @@ -64,12 +64,12 @@ private void OnUndoRedoPerformed() case IMeshComponent meshItem: meshItem.MainRenderableComponent.RebuildMeshes(); meshItem.MainRenderableComponent.UpdateTransforms(); - meshItem.MainRenderableComponent.UpdateVisibility(); + // meshItem.MainRenderableComponent.UpdateVisibility(); break; case IMainRenderableComponent mainItem: mainItem.RebuildMeshes(); mainItem.UpdateTransforms(); - mainItem.UpdateVisibility(); + // mainItem.UpdateVisibility(); break; } } @@ -106,7 +106,7 @@ protected void EndEditing() meshItem.MainRenderableComponent.UpdateTransforms(); } if (_visibilityDirty) { - meshItem.MainRenderableComponent.UpdateVisibility(); + // meshItem.MainRenderableComponent.UpdateVisibility(); } break; @@ -118,7 +118,7 @@ protected void EndEditing() mainItem.UpdateTransforms(); } if (_visibilityDirty) { - mainItem.UpdateVisibility(); + // mainItem.UpdateVisibility(); } break; @@ -227,7 +227,7 @@ protected void DropDownProperty(string label, SerializedProperty prop, string[] meshItem.MainRenderableComponent.RebuildMeshes(); } if (updateVisibility) { - meshItem.MainRenderableComponent.UpdateVisibility(); + // meshItem.MainRenderableComponent.UpdateVisibility(); } break; @@ -236,7 +236,7 @@ protected void DropDownProperty(string label, SerializedProperty prop, string[] mainItem.RebuildMeshes(); } if (updateVisibility) { - mainItem.UpdateVisibility(); + // mainItem.UpdateVisibility(); } break; } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Kicker/KickerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Kicker/KickerInspector.cs index 9c57258f2..5cc370c03 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Kicker/KickerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Kicker/KickerInspector.cs @@ -42,7 +42,6 @@ public class KickerInspector : MainInspector }; private SerializedProperty _orientationProperty; - private SerializedProperty _surfaceProperty; private SerializedProperty _kickerTypeProperty; private SerializedProperty _meshNameProperty; private SerializedProperty _coilsProperty; @@ -52,7 +51,6 @@ protected override void OnEnable() base.OnEnable(); _orientationProperty = serializedObject.FindProperty(nameof(KickerComponent.Orientation)); - _surfaceProperty = serializedObject.FindProperty(nameof(KickerComponent._surface)); _kickerTypeProperty = serializedObject.FindProperty(nameof(KickerComponent.KickerType)); _meshNameProperty = serializedObject.FindProperty(nameof(KickerComponent.MeshName)); _coilsProperty = serializedObject.FindProperty(nameof(KickerComponent.Coils)); @@ -70,7 +68,7 @@ public override void OnInspectorGUI() // position EditorGUI.BeginChangeCheck(); - var newPos = EditorGUILayout.Vector2Field(new GUIContent("Position", "Position of the kicker on the playfield, relative to its parent."), MainComponent.Position); + var newPos = EditorGUILayout.Vector3Field(new GUIContent("Position", "Position of the kicker on the playfield, relative to its parent."), MainComponent.Position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(MainComponent.transform, "Change Kicker Position"); MainComponent.Position = newPos; @@ -88,7 +86,6 @@ public override void OnInspectorGUI() MainComponent.KickerType == KickerType.KickerWilliams) { PropertyField(_orientationProperty, updateTransforms: true); } - PropertyField(_surfaceProperty, updateTransforms: true); MeshDropdownProperty("Mesh", _meshNameProperty, MeshFolder, MainComponent.gameObject, _kickerTypeProperty, TypeMap); @@ -108,9 +105,7 @@ private void OnSceneGUI() Handles.color = Color.cyan; Handles.matrix = Matrix4x4.identity; var transform = MainComponent.transform; - var localPos = MainComponent.GetEditorPosition(); - localPos.z = MainComponent.PositionZ; - + var localPos = MainComponent.Position; var worldPos = transform.parent == null ? localPos : localPos.TranslateToWorld(); foreach (var coil in MainComponent.Coils) { diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs index ba0a6f97b..23b1857af 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs @@ -82,7 +82,7 @@ private void OnSceneGUI() public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.Texture }; - public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointTransformType HandleType => DragPointTransformType.TwoD; public DragPointsInspectorHelper DragPointsHelper { get; private set; } public float ZOffset => MeshComponent.PositionZ; public float[] TopBottomZ => null; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs index 875569b74..f482893c6 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInspector.cs @@ -34,8 +34,6 @@ 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 _surfaceProperty; private SerializedProperty _bulbSizeProperty; private SerializedProperty _stateProperty; private SerializedProperty _blinkPatternProperty; @@ -47,8 +45,6 @@ protected override void OnEnable() { base.OnEnable(); - //_positionProperty = serializedObject.FindProperty(nameof(LightComponent.Position)); - _surfaceProperty = serializedObject.FindProperty(nameof(LightComponent._surface)); _bulbSizeProperty = serializedObject.FindProperty(nameof(LightComponent.BulbSize)); _stateProperty = serializedObject.FindProperty(nameof(LightComponent.State)); @@ -68,8 +64,6 @@ public override void OnInspectorGUI() OnPreInspectorGUI(); - //PropertyField(_positionProperty, updateTransforms: true); - PropertyField(_surfaceProperty, updateTransforms: true); PropertyField(_bulbSizeProperty, "Bulb Mesh Size", updateTransforms: true); if (_foldoutState = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutState, "State")) { diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs index fa542eea4..fd1693585 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs @@ -36,19 +36,5 @@ protected override void OnEnable() } protected bool HasErrors() => false; - - protected void UpdateSurfaceReferences(Transform obj) - { - var surfaceComponent = obj.gameObject.GetComponent(); - if (surfaceComponent != null && surfaceComponent.Surface == MainComponent) { - surfaceComponent.OnSurfaceUpdated(); - } - } - - protected void UpdateTableHeightReferences(Transform obj) - { - var onPlayfieldComponent = obj.gameObject.GetComponent(); - onPlayfieldComponent?.OnPlayfieldHeightUpdated(); - } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MetalWireGuide/MetalWireGuideInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MetalWireGuide/MetalWireGuideInspector.cs index 23631a40b..e565f534a 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MetalWireGuide/MetalWireGuideInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MetalWireGuide/MetalWireGuideInspector.cs @@ -91,7 +91,7 @@ private void OnSceneGUI() public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } public bool PointsAreLooping => false; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth }; - public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointTransformType HandleType => DragPointTransformType.TwoD; public DragPointsInspectorHelper DragPointsHelper { get; private set; } public float ZOffset => 0f; public float[] TopBottomZ => null; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Playfield/PlayfieldInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Playfield/PlayfieldInspector.cs index 1feac8464..ec4fa4f0b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Playfield/PlayfieldInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Playfield/PlayfieldInspector.cs @@ -25,7 +25,6 @@ public class PlayfieldInspector : MainInspector private SerializedProperty _rightProperty; private SerializedProperty _bottomProperty; private SerializedProperty _glassHeightProperty; - private SerializedProperty _tableHeightProperty; private SerializedProperty _angleTiltMinProperty; private SerializedProperty _angleTiltMaxProperty; private SerializedProperty _renderSlopeProperty; @@ -37,7 +36,6 @@ protected override void OnEnable() _rightProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.Right)); _bottomProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.Bottom)); _glassHeightProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.GlassHeight)); - _tableHeightProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.TableHeight)); _angleTiltMinProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.AngleTiltMin)); _angleTiltMaxProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.AngleTiltMax)); _renderSlopeProperty = serializedObject.FindProperty(nameof(PlayfieldComponent.RenderSlope)); @@ -56,9 +54,6 @@ public override void OnInspectorGUI() PropertyField(_rightProperty, "Table Width", true); PropertyField(_bottomProperty, "Table Height/Length", true); PropertyField(_glassHeightProperty, "Top Glass Height", true); - PropertyField(_tableHeightProperty, "Table Field Height", true, onChanged: () => { - WalkChildren(PlayfieldComponent.transform, UpdateTableHeightReferences); - }); PropertyField(_angleTiltMinProperty, "Slope for Min. Difficulty"); PropertyField(_angleTiltMaxProperty, "Slope for Max. Difficulty"); PropertyField(_renderSlopeProperty, "Rendered Playfield Angle"); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerInspector.cs index 2f5375c47..529f42169 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Plunger/PlungerInspector.cs @@ -27,7 +27,6 @@ public class PlungerInspector : MainInspector { private SerializedProperty _widthProperty; private SerializedProperty _heightProperty; - private SerializedProperty _surfaceProperty; protected override void OnEnable() { @@ -35,7 +34,6 @@ protected override void OnEnable() _widthProperty = serializedObject.FindProperty(nameof(PlungerComponent.Width)); _heightProperty = serializedObject.FindProperty(nameof(PlungerComponent.Height)); - _surfaceProperty = serializedObject.FindProperty(nameof(PlungerComponent._surface)); } public override void OnInspectorGUI() @@ -50,7 +48,7 @@ public override void OnInspectorGUI() // position EditorGUI.BeginChangeCheck(); - var newPos = EditorGUILayout.Vector2Field(new GUIContent("Position", "The position of the plunger on the playfield."), MainComponent.Position); + var newPos = EditorGUILayout.Vector3Field(new GUIContent("Position", "The position of the plunger on the playfield."), MainComponent.Position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(MainComponent.transform, "Change Plunger Position"); MainComponent.Position = newPos; @@ -59,16 +57,6 @@ public override void OnInspectorGUI() PropertyField(_widthProperty, rebuildMesh: true); PropertyField(_heightProperty, rebuildMesh: true); - // z-adjust - EditorGUI.BeginChangeCheck(); - var newZAdjust = EditorGUILayout.FloatField(new GUIContent("Z Adjustment", "The Z-Position of the plunger. VPX calls it like that."), MainComponent.ZAdjust); - if (EditorGUI.EndChangeCheck()) { - Undo.RecordObject(MainComponent.transform, "Change Plunger Z Adjustment"); - MainComponent.ZAdjust = newZAdjust; - } - - PropertyField(_surfaceProperty, rebuildMesh: true); - base.OnInspectorGUI(); EndEditing(); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs index 75bc1b7a1..fafa4313b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs @@ -155,7 +155,7 @@ private void OnSceneGUI() public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } public bool PointsAreLooping => false; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; - public ItemDataTransformType HandleType => ItemDataTransformType.ThreeD; + public DragPointTransformType HandleType => DragPointTransformType.ThreeD; public DragPointsInspectorHelper DragPointsHelper { get; private set; } public float ZOffset => 0f; public float[] TopBottomZ => new[] { MainComponent._heightBottom, MainComponent._heightTop }; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs index c75805695..1515a1127 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs @@ -84,7 +84,7 @@ private void OnSceneGUI() public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth }; - public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointTransformType HandleType => DragPointTransformType.TwoD; public DragPointsInspectorHelper DragPointsHelper { get; private set; } public float ZOffset => MainComponent.Height; public float[] TopBottomZ => null; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Spinner/SpinnerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Spinner/SpinnerInspector.cs index 5cb3650f7..8a3edd5e9 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Spinner/SpinnerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Spinner/SpinnerInspector.cs @@ -30,13 +30,11 @@ public class SpinnerInspector : MainInspector private SerializedProperty _dampingProperty; private SerializedProperty _angleMaxProperty; private SerializedProperty _angleMinProperty; - private SerializedProperty _surfaceProperty; protected override void OnEnable() { base.OnEnable(); - _surfaceProperty = serializedObject.FindProperty(nameof(SpinnerComponent._surface)); _dampingProperty = serializedObject.FindProperty(nameof(SpinnerComponent.Damping)); _angleMaxProperty = serializedObject.FindProperty(nameof(SpinnerComponent.AngleMax)); _angleMinProperty = serializedObject.FindProperty(nameof(SpinnerComponent.AngleMin)); @@ -61,10 +59,10 @@ public override void OnInspectorGUI() } EditorGUI.BeginChangeCheck(); - var newHeight = EditorGUILayout.FloatField(new GUIContent("Height", "Z-Position on the playfield, relative to its parent."), MainComponent.Height); + var newHeight = EditorGUILayout.FloatField(new GUIContent("Height", "Z-Position on the playfield, relative to its parent."), MainComponent.Position.z); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(MainComponent.transform, "Change Spinner Height"); - MainComponent.Height = newHeight; + MainComponent.Position = new Vector3(MainComponent.Position.x, MainComponent.Position.y, newHeight); } EditorGUI.BeginChangeCheck(); @@ -81,8 +79,6 @@ public override void OnInspectorGUI() MainComponent.Rotation = newRotation; } - PropertyField(_surfaceProperty, updateTransforms: true); - if (_foldoutPhysics = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutPhysics, "Physics")) { PropertyField(_dampingProperty); PropertyField(_angleMinProperty); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs index 16b6b3f62..81d0c4ae0 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs @@ -62,9 +62,7 @@ public override void OnInspectorGUI() OnPreInspectorGUI(); - PropertyField(_heightTopProperty, "Top Height", true, onChanged: () => { - WalkChildren(PlayfieldComponent.transform, UpdateSurfaceReferences); - }); + PropertyField(_heightTopProperty, "Top Height", true); PropertyField(_heightBottomProperty, "Bottom Height", true); DragPointsHelper.OnInspectorGUI(this); @@ -84,9 +82,9 @@ private void OnSceneGUI() public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot, DragPointExposure.Texture }; - public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointTransformType HandleType => DragPointTransformType.TwoD; public DragPointsInspectorHelper DragPointsHelper { get; private set; } - public float ZOffset => MainComponent.HeightTop + MainComponent.PlayfieldHeight; + public float ZOffset => MainComponent.HeightTop; public float[] TopBottomZ => null; public void SetDragPointPosition(DragPointData dragPoint, Vertex3D value, int numSelectedDragPoints, float[] topBottomZ) => dragPoint.Center = value; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs deleted file mode 100644 index 746c1efd2..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs +++ /dev/null @@ -1,371 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2023 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 SwitchStatementMissingSomeEnumCasesNoDefault - -using System; -using System.Collections.Generic; -using System.Reflection; -using UnityEditor; -using UnityEngine; - -namespace VisualPinball.Unity.Editor -{ - //[CustomEditor(typeof(Transform))] - [CanEditMultipleObjects] - public class TransformInspector : UnityEditor.Editor - { - private UnityEditor.Editor _defaultEditor; - private Transform _transform; - - /// - /// The first selected item - /// - private IMainRenderableComponent _primaryItem; - - /// - /// On multi-selection, these are the other selected items. - /// - private readonly List _secondaryItems = new List(); - - private ItemDataTransformType _positionType = ItemDataTransformType.ThreeD; - private ItemDataTransformType _rotationType = ItemDataTransformType.ThreeD; - private ItemDataTransformType _scaleType = ItemDataTransformType.ThreeD; - - // work around for scale handle weirdness - private float _scaleFactor = 1.0f; - - // control when to rotate each axis of your custom rotation handle - private Matrix4x4? _pauseAxisX; - private Matrix4x4? _pauseAxisY; - private Matrix4x4? _pauseAxisZ; - private bool _itemSelected; - - protected virtual void OnEnable() - { - _transform = target as Transform; - - // use default inspector. we do that when no vpe components are selected. - var useDefault = true; - - // loop through selected objects - foreach (var t in targets) { - - var itemTransform = t as Transform; - if (!itemTransform) { - continue; - } - - var item = itemTransform.GetComponent(); - var isRenderableItem = item != null; - var overrideTransform = isRenderableItem && item.OverrideTransform; - _itemSelected = itemTransform.GetComponent() != null; - useDefault = useDefault && (!_itemSelected || !overrideTransform) && itemTransform.GetComponent() == null; - - // must be main but not the table itself - if (isRenderableItem && item is not TableComponent) { - - if (_primaryItem == null) { - _primaryItem = item; - _positionType = item.EditorPositionType; - _rotationType = item.EditorRotationType; - _scaleType = item.EditorScaleType; - - } else { - // only transform on axes supported by all - if (item.EditorPositionType < _positionType) { - _positionType = item.EditorPositionType; - } - if (item.EditorRotationType < _rotationType) { - _rotationType = item.EditorRotationType; - } - if (item.EditorScaleType < _scaleType) { - _scaleType = item.EditorScaleType; - } - _secondaryItems.Add(new SecondaryItem { - Transform = t as Transform, - Item = item, - Offset = item.GetEditorPosition() - _primaryItem.GetEditorPosition(), - }); - } - } - } - if (useDefault) { - _defaultEditor = CreateEditor(targets, Type.GetType("UnityEditor.TransformInspector, UnityEditor")); - } - } - - protected virtual void OnDisable() - { - if (_defaultEditor != null) { - var defaultDisableMethod = _defaultEditor.GetType().GetMethod("OnDisable", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); - defaultDisableMethod?.Invoke(_defaultEditor, null); - DestroyImmediate(_defaultEditor); - _defaultEditor = null; - } - // restore tools - Tools.hidden = false; - } - - public override void OnInspectorGUI() - { - if (_defaultEditor != null) { - _defaultEditor.OnInspectorGUI(); - return; - } - - GUILayout.Label(_itemSelected - ? "Transforms are below. Don't collapse this component." - : "Cannot transform GameObjects on the playfield yet." - ); - } - - private void OnSceneGUI() - { - if (_defaultEditor != null) { - return; - } - - Tools.hidden = true; - - if (_transform == null || _primaryItem == null) { - return; - } - - if (!_primaryItem.CanBeTransformed) { - return; - } - - //var dragPointEditEnabled = (_primaryItem as IDragPointsEditable)?.DragPointEditEnabled ?? false; - - //if (!dragPointEditEnabled) { - if (_primaryItem.IsLocked) { - HandleLockedTool(); - - } else { - switch (Tools.current) { - case Tool.Rotate: - HandleRotationTool(); - break; - - case Tool.Move: - HandleMoveTool(); - break; - - case Tool.Scale: - HandleScaleTool(); - break; - } - } - //} - } - - private void HandleLockedTool() - { - Handles.matrix = Matrix4x4.identity; - var handlePos = _primaryItem.GetEditorPosition().TranslateToWorld(); - if (_transform.parent != null) { - handlePos = _transform.parent.TransformPoint(handlePos); - } - Handles.color = Color.red; - Handles.Button(handlePos, Quaternion.identity, HandleUtility.GetHandleSize(handlePos) * 0.25f, HandleUtility.GetHandleSize(handlePos) * 0.25f, Handles.SphereHandleCap); - Handles.Label(handlePos + Vector3.right * (HandleUtility.GetHandleSize(handlePos) * 0.3f), "LOCKED"); - } - - private void HandleRotationTool() - { - var e = Event.current; - if (e.type == EventType.MouseDown || e.type == EventType.MouseUp) { - _pauseAxisX = _pauseAxisY = _pauseAxisZ = null; - } - if (_secondaryItems.Count > 0) { - return; - } - var handlePos = _primaryItem.GetEditorPosition().TranslateToWorld(); - if (_transform.parent != null) { - handlePos = _transform.parent.TransformPoint(handlePos); - } - var handleSize = HandleUtility.GetHandleSize(handlePos); - var currentRot = _primaryItem.GetEditorRotation(); - switch (_primaryItem.EditorRotationType) { - case ItemDataTransformType.OneD: { - EditorGUI.BeginChangeCheck(); - if (_transform.parent != null) { - Handles.matrix = Matrix4x4.TRS(handlePos, _transform.parent.transform.rotation, Vector3.one); - } - Handles.color = Handles.zAxisColor; - var rot = Handles.Disc(Quaternion.AngleAxis(currentRot.x, Vector3.up), Vector3.zero, Vector3.up, handleSize, false, 10f); - if (EditorGUI.EndChangeCheck()) { - FinishRotate(new Vector3(rot.eulerAngles.y, 0f, 0f)); - } - break; - } - case ItemDataTransformType.ThreeD: { - EditorGUI.BeginChangeCheck(); - var baseMatrix = Handles.matrix; - if (_transform.parent != null) { - baseMatrix = Matrix4x4.TRS(handlePos, _transform.parent.transform.rotation, Vector3.one); - } - var currentRotTran = Matrix4x4.identity; - currentRotTran *= Matrix4x4.Rotate(Quaternion.Euler(currentRot.x, 0, 0)); - currentRotTran *= Matrix4x4.Rotate(Quaternion.Euler(0, currentRot.y, 0)); - - Handles.matrix = baseMatrix * /*(_pauseAxisX ?? currentRotTran) **/ Matrix4x4.Rotate(Quaternion.Euler(0, 0, -90)); - Handles.color = Handles.xAxisColor; - var rotX = Handles.Disc(Quaternion.AngleAxis(currentRot.x, Vector3.up), Vector3.zero, Vector3.up, handleSize, true, 10f); - - Handles.matrix = baseMatrix * (_pauseAxisY ?? currentRotTran) * Matrix4x4.Rotate(Quaternion.Euler(0, 0, 0)); - Handles.color = Handles.yAxisColor; - var rotY = Handles.Disc(Quaternion.AngleAxis(currentRot.y, Vector3.up), Vector3.zero, Vector3.up, handleSize, true, 10f); - - Handles.matrix = baseMatrix * (_pauseAxisZ ?? currentRotTran) * Matrix4x4.Rotate(Quaternion.Euler(90, 0, 0)); - Handles.color = Handles.zAxisColor; - var rotZ = Handles.Disc(Quaternion.AngleAxis(currentRot.z, Vector3.up), Vector3.zero, Vector3.up, handleSize, true, 10f); - - if (EditorGUI.EndChangeCheck()) { - // check which axis had the biggest change (they'll all change slightly due to float precision) - // and pause that axis' local rotation so the gizmo doesn't flip out - var xDiff = System.Math.Abs(rotX.eulerAngles.y - currentRot.x); - var yDiff = System.Math.Abs(rotY.eulerAngles.y - currentRot.y); - var zDiff = System.Math.Abs(rotZ.eulerAngles.y - currentRot.z); - if (_pauseAxisX == null && xDiff > yDiff && xDiff > zDiff) { - _pauseAxisX = currentRotTran; - } else if (_pauseAxisY == null && yDiff > xDiff && yDiff > zDiff) { - _pauseAxisY = currentRotTran; - } else if (_pauseAxisZ == null && zDiff > xDiff && zDiff > yDiff) { - _pauseAxisZ = currentRotTran; - } - - FinishRotate(new Vector3(rotX.eulerAngles.y, rotY.eulerAngles.y, rotZ.eulerAngles.y)); - } - break; - } - } - } - - private void HandleMoveTool() - { - // var handlePos = _primaryItem.GetEditorPosition(); - // EditorGUI.BeginChangeCheck(); - // handlePos = HandlesUtils.HandlePosition(_transform.GetComponentInParent(), handlePos, _primaryItem.EditorPositionType); - // if (EditorGUI.EndChangeCheck()) { - // FinishMove(handlePos); - // } - } - - private void HandleScaleTool() - { - var e = Event.current; - var startScaling = e.type == EventType.MouseDown; - var endScaling = e.type == EventType.MouseUp; - if (startScaling || endScaling) { - _scaleFactor = _primaryItem.GetEditorScale().x; - } - - if (_secondaryItems.Count > 0) { - return; - } - var handlePos = _primaryItem.GetEditorPosition().TranslateToWorld(); - if (_transform.parent != null) { - handlePos = _transform.parent.TransformPoint(handlePos); - } - var handleRot = _transform.rotation.RotateToWorld(); - var handleScale = HandleUtility.GetHandleSize(handlePos); - - if (startScaling) { - _primaryItem.EditorStartScaling(); - } - if (endScaling) { - _primaryItem.EditorEndScaling(); - } - Handles.matrix = Matrix4x4.identity; - - switch (_primaryItem.EditorScaleType) { - - case ItemDataTransformType.OneD: { - EditorGUI.BeginChangeCheck(); - var scale = Handles.ScaleSlider(_primaryItem.GetEditorScale().x, handlePos, _transform.right, handleRot, handleScale, 0f); - if (EditorGUI.EndChangeCheck()) { - FinishScale(new Vector3(scale, 0f, 0f)); - } - break; - } - - case ItemDataTransformType.ThreeD: { - EditorGUI.BeginChangeCheck(); - var oldScale = _primaryItem.GetEditorScale(); - var newScale = Handles.ScaleHandle(oldScale, handlePos, handleRot, handleScale); - if (Mathf.Abs(newScale.x - oldScale.x) > Mathf.Epsilon && Mathf.Abs(newScale.y - oldScale.y) > Mathf.Epsilon && Mathf.Abs(newScale.z - oldScale.z) > Mathf.Epsilon) { - // the center bit of the scale handle appears to be doing some extra multiplying, not totally sure what's going on, but experimentally - // it seems like its a factor of one of the axes too much, so (on click) we'll update a factor and adjust accordingly - if (_scaleFactor != 0) { - newScale /= _scaleFactor; - } else { - newScale = Vector3.zero; - } - } - if (EditorGUI.EndChangeCheck()) { - FinishScale(newScale); - } - break; - } - } - } - - /// - /// Applies the new translation to the item. - /// - /// New position in VPX space. - private void FinishMove(Vector3 newPosition) - { - var undoLabel = "Move " + _transform.gameObject.name; - Undo.RecordObjects(new[]{ _transform, _primaryItem as UnityEngine.Object }, undoLabel); - var finalPos = newPosition; - - _primaryItem.SetEditorPosition(finalPos); - _primaryItem.UpdateTransforms(); - - foreach (var secondary in _secondaryItems) { - secondary.Item.UpdateTransforms(); - Undo.RecordObjects(new[]{ secondary.Item as UnityEngine.Object, secondary.Transform }, undoLabel); - secondary.Item.SetEditorPosition(finalPos + secondary.Offset); - } - } - - private void FinishRotate(Vector3 newEuler) - { - var undoLabel = "Rotate " + _transform.gameObject.name; - Undo.RecordObjects(new [] {_primaryItem as UnityEngine.Object, _transform }, undoLabel); - _primaryItem.SetEditorRotation(newEuler); - _primaryItem.UpdateTransforms(); - } - - private void FinishScale(Vector3 newScale) - { - var undoLabel = "Scale " + _transform.gameObject.name; - Undo.RecordObjects(new [] {_primaryItem as UnityEngine.Object, _transform }, undoLabel); - _primaryItem.SetEditorScale(newScale); - _primaryItem.UpdateTransforms(); - } - - private class SecondaryItem - { - public Transform Transform; - public IMainRenderableComponent Item; - public Vector3 Offset; - } - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs.meta b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs.meta deleted file mode 100644 index b9da64ab0..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/TransformInspector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 37d98137d4c873e468cf564e34f71658 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs index 3c575b240..682a3545a 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs @@ -29,16 +29,12 @@ public class TriggerInspector : MainInspector, ID { public Transform Transform => MainComponent.transform; - private SerializedProperty _surfaceProperty; - protected override void OnEnable() { base.OnEnable(); DragPointsHelper = new DragPointsInspectorHelper(MainComponent, this); DragPointsHelper.OnEnable(); - - _surfaceProperty = serializedObject.FindProperty(nameof(TriggerComponent._surface)); } protected override void OnDisable() @@ -81,8 +77,6 @@ public override void OnInspectorGUI() MainComponent.Rotation = newRotation; } - PropertyField(_surfaceProperty, updateTransforms: true); - DragPointsHelper.OnInspectorGUI(this); base.OnInspectorGUI(); @@ -107,9 +101,9 @@ public bool DragPointsActive { public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; - public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointTransformType HandleType => DragPointTransformType.TwoD; public DragPointsInspectorHelper DragPointsHelper { get; private set; } - public float ZOffset => MainComponent.PositionZ; + public float ZOffset => MainComponent.Position.z; public float[] TopBottomZ => null; public void SetDragPointPosition(DragPointData dragPoint, Vertex3D value, int numSelectedDragPoints, float[] topBottomZ) => dragPoint.Center = value; diff --git a/VisualPinball.Unity/VisualPinball.Unity/Game/BallRollerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/Game/BallRollerComponent.cs index 2b450be6a..efc52019b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Game/BallRollerComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Game/BallRollerComponent.cs @@ -38,10 +38,9 @@ private void Awake() _ltw = Physics.VpxToWorld; _wtl = Physics.WorldToVpx; - var z = _playfield.PlayfieldHeight; - var p1 = _ltw.MultiplyPoint(new Vector3(-100f, 100f, z)); - var p2 = _ltw.MultiplyPoint(new Vector3(100f, 100f, z)); - var p3 = _ltw.MultiplyPoint(new Vector3(100f, -100f, z)); + var p1 = _ltw.MultiplyPoint(new Vector3(-100f, 100f, 0)); + var p2 = _ltw.MultiplyPoint(new Vector3(100f, 100f, 0)); + var p3 = _ltw.MultiplyPoint(new Vector3(100f, -100f, 0)); _playfieldPlane.Set3Points(p1, p2, p3); _physicsEngine = GetComponentInChildren(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/Game/DebugBallCreator.cs b/VisualPinball.Unity/VisualPinball.Unity/Game/DebugBallCreator.cs index 29778fc63..14b00bf67 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Game/DebugBallCreator.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Game/DebugBallCreator.cs @@ -29,11 +29,11 @@ public class DebugBallCreator : IBallCreationPosition private readonly float _kickAngle; private readonly float _kickForce; - public DebugBallCreator(float x, float y, float playfieldHeight) + public DebugBallCreator(float x, float y) { _x = x; _y = y; - _z = playfieldHeight; + _z = 0; _kickAngle = 0; _kickForce = 0; } diff --git a/VisualPinball.Unity/VisualPinball.Unity/Game/Engine/DefaultGamelogicEngine.cs b/VisualPinball.Unity/VisualPinball.Unity/Game/Engine/DefaultGamelogicEngine.cs index 48b75e01e..6ecb3fb9d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Game/Engine/DefaultGamelogicEngine.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Game/Engine/DefaultGamelogicEngine.cs @@ -271,7 +271,7 @@ public void Switch(string id, bool isClosed) case SwCreateBall: { if (isClosed) { - _ballManager.CreateBall(new DebugBallCreator(630, _playfieldComponent.Height / 2f, _playfieldComponent.TableHeight)); + _ballManager.CreateBall(new DebugBallCreator(630, _playfieldComponent.Height / 2f)); } break; } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs index 5f403ab9e..95ad45d4d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs @@ -77,7 +77,7 @@ void IApiCoil.OnCoil(bool enabled) continue; } ref var ballState = ref PhysicsEngine.BallState(ballId); - float3 bumperPos = new(MainComponent.Position.x, MainComponent.Position.y, MainComponent.PositionZ); + float3 bumperPos = MainComponent.Position; float3 ballPos = ballState.Position; var bumpDirection = ballPos - bumperPos; bumpDirection.z = 0f; @@ -114,7 +114,7 @@ protected override void CreateColliders(ref ColliderReference colliders, ref ColliderReference kinematicColliders, float4x4 translateWithinPlayfieldMatrix, float margin) { var matrix = MainComponent.transform.worldToLocalMatrix.WorldToLocalTranslateWithinPlayfield(Player.PlayfieldToWorldMatrix); - var height = MainComponent.PositionZ; + var height = MainComponent.Position.z; var switchCollider = new CircleCollider(new float2(0), MainComponent.Radius, height, height + 100f, GetColliderInfo(), ColliderType.Bumper); var rigidCollider = new CircleCollider(new float2(0), MainComponent.Radius * 0.5f, height, height + 100f, GetColliderInfo(), ColliderType.Circle); if (ColliderComponent._isKinematic) { diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperComponent.cs index e80a7c39d..5e0de1d18 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperComponent.cs @@ -27,6 +27,7 @@ using Unity.Mathematics; using UnityEngine; using VisualPinball.Engine.Game.Engines; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Bumper; using VisualPinball.Engine.VPT.Table; @@ -34,21 +35,15 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Bumper")] - public class BumperComponent : MainRenderableComponent, - ISwitchDeviceComponent, ICoilDeviceComponent, IOnSurfaceComponent + public class BumperComponent : MainRenderableComponent, ISwitchDeviceComponent, ICoilDeviceComponent { #region Data - private Vector3 _position { + public Vector3 Position { get => transform.localPosition.TranslateToVpx(); set => transform.localPosition = value.TranslateToWorld(); } - public Vector2 Position { - get => _position.XY(); - set => _position = new Vector3(value.x, value.y, _position.z); - } - [Range(20f, 250f)] [Tooltip("Radius of the bumper. Updates xy scaling. 50 = Original size.")] public float Radius = 45f; @@ -68,12 +63,6 @@ public float Orientation { [Tooltip("Should the bumper coil always activate when touched by a ball? Disable to give game logic engine full control")] public bool IsHardwired = true; - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this bumper is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; private IEnumerable _availableDeviceItems; #endregion @@ -165,8 +154,6 @@ private void Start() public void OnSurfaceUpdated() => UpdateTransforms(); - public float PositionZ => SurfaceHeight(Surface, Position); - public override void UpdateTransforms() { base.UpdateTransforms(); @@ -191,7 +178,7 @@ public override IEnumerable SetData(BumperData data) var updatedComponents = new List { this }; // transforms - Position = data.Center.ToUnityFloat2(); + Position = data.Center.ToUnityVector3(0); Radius = data.Radius; HeightScale = data.HeightScale; Orientation = data.Orientation; @@ -218,7 +205,6 @@ public override IEnumerable SetData(BumperData data) public override IEnumerable SetReferencedData(BumperData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); UpdateTransforms(); // children visibility @@ -262,14 +248,11 @@ public override BumperData CopyDataTo(BumperData data, string[] materialNames, s { // name and transforms data.Name = name; - data.Center = Position.ToVertex2D(); + data.Center = new Vertex2D(Position.x, Position.y); data.Radius = Radius; data.HeightScale = HeightScale; data.Orientation = Orientation; - // surface - data.Surface = Surface != null ? Surface.name : string.Empty; - // children visibility data.IsBaseVisible = false; data.IsCapVisible = false; @@ -329,7 +312,6 @@ public override void CopyFromObject(GameObject go) Radius = bumperComponent.Radius; HeightScale = bumperComponent.HeightScale; Orientation = bumperComponent.Orientation; - Surface = bumperComponent.Surface; } else { var scale = go.transform.localScale; @@ -398,23 +380,5 @@ internal BumperState CreateState() } #endregion - - #region Editor Tooling - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - public override Vector3 GetEditorPosition() => Surface != null - ? new Vector3(Position.x, Position.y, Surface.Height(Position)) - : new Vector3(Position.x, Position.y, 0); - public override void SetEditorPosition(Vector3 pos) => Position = ((float3)pos).xy; - - public override ItemDataTransformType EditorRotationType => ItemDataTransformType.OneD; - public override Vector3 GetEditorRotation() => new Vector3(Orientation, 0, 0); - public override void SetEditorRotation(Vector3 rot) => Orientation = ClampDegrees(rot.x); - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.OneD; - public override Vector3 GetEditorScale() => new Vector3(Radius * 2f, 0f, 0f); - public override void SetEditorScale(Vector3 scale) => Radius = scale.x / 2f; - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperSkirtAnimationState.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperSkirtAnimationState.cs index e9206f6ed..bdc209036 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperSkirtAnimationState.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperSkirtAnimationState.cs @@ -30,7 +30,7 @@ internal struct BumperSkirtAnimationState public float2 Rotation; // static - public float2 Center; + public float3 Center; public float Duration; } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs index 0707fba91..42d35f5d8 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs @@ -235,7 +235,6 @@ protected override void CreateColliders(ref ColliderReference colliders, // and add ColliderComponent.Overshoot to the endangle so that the bounding box is correctly calculated ColliderId = colliders.Add( new FlipperCollider( - MainComponent.PositionZ, MainComponent.Height, MainComponent.FlipperRadiusMax, MainComponent.BaseRadius, diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCollider.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCollider.cs index a29f9e8ce..573e8d590 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCollider.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCollider.cs @@ -44,15 +44,15 @@ public int Id #region Setup - public FlipperCollider(float posZ, float height, float flipperRadius, float startRadius, float endRadius, + public FlipperCollider(float height, float flipperRadius, float startRadius, float endRadius, float startAngle, float endAngle, ColliderInfo info) : this() { var baseRadius = math.max(startRadius, 0.01f); _hitCircleBase = new CircleCollider( float2.zero, // flipper collision is always done through the center and a matrix baseRadius, - posZ, - posZ + height, + 0, + height, info ); diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperComponent.cs index 0c7282847..e53d2e099 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperComponent.cs @@ -38,7 +38,7 @@ namespace VisualPinball.Unity [AddComponentMenu("Visual Pinball/Game Item/Flipper")] [HelpURL("https://docs.visualpinball.org/creators-guide/manual/mechanisms/flippers.html")] public class FlipperComponent : MainRenderableComponent, - IFlipperData, ISwitchDeviceComponent, ICoilDeviceComponent, IOnSurfaceComponent, + IFlipperData, ISwitchDeviceComponent, ICoilDeviceComponent, IRotatableComponent { #region Data @@ -71,12 +71,6 @@ public float StartAngle { [Tooltip("Angle of the flipper in end position (flipped)")] public float EndAngle = 70.0f; - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this flipper is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; - // todo implement [Tooltip("This does nothing yet!")] public bool IsEnabled = true; @@ -173,22 +167,6 @@ public float StartAngle { #region Transformation - public void OnSurfaceUpdated() => UpdateTransforms(); - - public float PositionZ => SurfaceHeight(Surface, Position); - - public override void UpdateTransforms() - { - base.UpdateTransforms(); - var t = transform; - - // position - //t.localPosition = Physics.TranslateToWorld(Position.x, Position.y, PositionZ); - - // rotation - //t.SetLocalYRotation(math.radians(StartAngle)); - } - /// /// Returns the local-to-world matrix of the flipper, but without the rotation around the Y-axis. /// @@ -270,7 +248,6 @@ public override IEnumerable SetData(FlipperData data) public override IEnumerable SetReferencedData(FlipperData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); UpdateTransforms(); // children mesh creation and visibility @@ -295,7 +272,6 @@ public override FlipperData CopyDataTo(FlipperData data, string[] materialNames, data.Name = name; data.Center = Position.ToVertex2D(); data.StartAngle = StartAngle; - data.Surface = Surface != null ? Surface.name : string.Empty; // geometry data.Height = _height; @@ -341,7 +317,6 @@ public override void CopyFromObject(GameObject go) Position = flipperComponent.Position; StartAngle = flipperComponent.StartAngle; EndAngle = flipperComponent.EndAngle; - Surface = flipperComponent.Surface; IsDualWound = flipperComponent.IsDualWound; _height = flipperComponent._height; _baseRadius = flipperComponent._baseRadius; @@ -363,18 +338,6 @@ public override void CopyFromObject(GameObject go) #region Editor Tooling - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - public override Vector3 GetEditorPosition() => Surface != null - ? new Vector3(Position.x, Position.y, Surface.Height(Position)) - : new Vector3(Position.x, Position.y, 0); - public override void SetEditorPosition(Vector3 pos) => Position = ((float3)pos).xy; - - public override ItemDataTransformType EditorRotationType => ItemDataTransformType.OneD; - public override Vector3 GetEditorRotation() => new Vector3(StartAngle, 0f, 0f); - public override void SetEditorRotation(Vector3 rot) => StartAngle = ClampDegrees(rot.x); - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.None; - #if UNITY_EDITOR protected void OnDrawGizmosSelected() diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Gate/GateComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Gate/GateComponent.cs index f60b1a334..7972d4786 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Gate/GateComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Gate/GateComponent.cs @@ -38,7 +38,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Gate")] public class GateComponent : MainRenderableComponent, - IGateData, ISwitchDeviceComponent, IOnSurfaceComponent, IRotatableAnimationComponent + IGateData, ISwitchDeviceComponent, IRotatableAnimationComponent { #region Data @@ -70,13 +70,6 @@ public float Length } } - - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this flipper is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; - public int _type; public string _meshName; @@ -168,13 +161,8 @@ private void Start() [NonSerialized] private float4x4 _playfieldToWorld; - public void OnSurfaceUpdated() => UpdateTransforms(); - - public float PositionZ => SurfaceHeight(Surface, Position); // todo handle surface - public float4x4 TransformationWithinPlayfield => transform.worldToLocalMatrix.WorldToLocalTranslateWithinPlayfield(_playfieldToWorld); - #endregion #region Conversion @@ -214,8 +202,6 @@ public override IEnumerable SetData(GateData data) public override IEnumerable SetReferencedData(GateData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); - // visibility foreach (var mf in GetComponentsInChildren()) { switch (mf.gameObject.name) { @@ -245,7 +231,6 @@ public override GateData CopyDataTo(GateData data, string[] materialNames, strin data.Rotation = Rotation; data.Height = Position.z; data.Length = Length; - data.Surface = Surface != null ? Surface.name : string.Empty; data.GateType = _type; @@ -288,7 +273,6 @@ public override void CopyFromObject(GameObject go) Position = gateComponent.Position; Rotation = gateComponent.Rotation; _length = gateComponent._length; - Surface = gateComponent.Surface; } else { @@ -337,27 +321,6 @@ internal GateState CreateState() #endregion - #region Editor Tooling - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.ThreeD; - public override void SetEditorPosition(Vector3 pos) => Position = Surface != null - ? pos - new Vector3(0, 0, Surface.Height(Position)) - : pos; - public override Vector3 GetEditorPosition() => Surface != null - ? new Vector3(Position.x, Position.y, Position.z + Surface.Height(Position)) - : new Vector3(Position.x, Position.y, Position.z); - - - public override ItemDataTransformType EditorRotationType => ItemDataTransformType.OneD; - public override Vector3 GetEditorRotation() => new Vector3(Rotation, 0f, 0f); - public override void SetEditorRotation(Vector3 rot) => Rotation = ClampDegrees(rot.x); - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.OneD; - public override Vector3 GetEditorScale() => new Vector3(Length, 0f, 0f); - public override void SetEditorScale(Vector3 scale) => _length = scale.x; - - #endregion - #region IRotatableAnimationComponent public void OnRotationUpdated(float angleRad) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/TargetComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/TargetComponent.cs index 8a607ff35..8ac084d25 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/TargetComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/TargetComponent.cs @@ -167,22 +167,5 @@ public override void CopyFromObject(GameObject go) } #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 EditorRotationType => ItemDataTransformType.OneD; - public override Vector3 GetEditorRotation() => new Vector3(Rotation, 0f, 0f); - public override void SetEditorRotation(Vector3 rot) => Rotation = ClampDegrees(rot.x); - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.ThreeD; - - public override Vector3 GetEditorScale() => Size; - public override void SetEditorScale(Vector3 scale) => Size = scale; - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs index 7eb40db1f..62f81fcec 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/IMainRenderableComponent.cs @@ -20,54 +20,14 @@ namespace VisualPinball.Unity { 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; } - /// /// Sets the mesh of all mesh sub components to dirty. /// void RebuildMeshes(); void UpdateTransforms(); - void UpdateVisibility(); - - // the following interfaces allow each item behavior to define which axes should - // be shown on the scene view gizmo, the gizmo itself will use the associated - // get and set methods, which are expected to update item data directly - ItemDataTransformType EditorPositionType { get; } - Vector3 GetEditorPosition(); - void SetEditorPosition(Vector3 pos); - - ItemDataTransformType EditorRotationType { get; } - Vector3 GetEditorRotation(); - void SetEditorRotation(Vector3 pos); - ItemDataTransformType EditorScaleType { get; } - Vector3 GetEditorScale(); - void SetEditorScale(Vector3 pos); - void EditorStartScaling(); - void EditorEndScaling(); - - //void SetTransform(Vector3 position, Vector3 scale, Quaternion rotation); void CopyFromObject(GameObject go); } - public enum ItemDataTransformType - { - None, - OneD, - TwoD, - ThreeD, - } + } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs deleted file mode 100644 index fcfbec986..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2023 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; - -namespace VisualPinball.Unity -{ - /// - /// Components implementing this interface can be referenced by - /// - public interface ISurfaceComponent : IIdentifiableItemComponent - { - float Height(Vector2 pos); - } - - /// - /// Components implementing this interface can be placed on . - /// - public interface IOnSurfaceComponent - { - ISurfaceComponent Surface { get; } - - void OnSurfaceUpdated(); - } - - public interface IOnPlayfieldComponent - { - void OnPlayfieldHeightUpdated(); - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs.meta deleted file mode 100644 index 64f5c5d37..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: be4a294401329574f9a8ae76aceccf6f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerApi.cs index 124321b31..7cee4435f 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerApi.cs @@ -47,7 +47,7 @@ public class KickerApi : CollidableApi public event EventHandler Switch; - internal float3 Position => new(MainComponent.Position.x, MainComponent.Position.y, MainComponent.PositionZ); + internal float3 Position => MainComponent.Position; public KickerDeviceCoil KickerCoil => _coils.Values.FirstOrDefault(); @@ -227,13 +227,11 @@ private void KickXYZ(float angle, float speed, float inclination, float x, float protected override void CreateColliders(ref ColliderReference colliders, ref ColliderReference kinematicColliders, float4x4 translateWithinPlayfieldMatrix, float margin) { - var height = MainComponent.PositionZ; - // reduce the hit circle radius because only the inner circle of the kicker should start a hit event var radius = MainComponent.Radius * (ColliderComponent.LegacyMode ? ColliderComponent.FallThrough ? 0.75f : 0.6f : 1f); - colliders.Add(new CircleCollider(float2.zero, radius, height, - height + ColliderComponent.HitHeight, GetColliderInfo(), ColliderType.KickerCircle), translateWithinPlayfieldMatrix); + colliders.Add(new CircleCollider(float2.zero, radius, MainComponent.Position.z, + MainComponent.Position.z + ColliderComponent.HitHeight, GetColliderInfo(), ColliderType.KickerCircle), translateWithinPlayfieldMatrix); } #endregion diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerComponent.cs index 98adc1c14..c94b7e9a4 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Kicker/KickerComponent.cs @@ -40,21 +40,16 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Kicker")] public class KickerComponent : MainRenderableComponent, - ICoilDeviceComponent, ITriggerComponent, IBallCreationPosition, IOnSurfaceComponent, + ICoilDeviceComponent, ITriggerComponent, IBallCreationPosition, IRotatableComponent, ISerializationCallbackReceiver { #region Data - private Vector3 _position { + public Vector3 Position { get => transform.localPosition.TranslateToVpx(); set => transform.localPosition = value.TranslateToWorld(); } - public Vector2 Position { - get => _position.XY(); - set => _position = new Vector3(value.x, value.y, _position.z); - } - public float Radius { get { var scale = transform.localScale; @@ -75,12 +70,6 @@ public float Radius { [Tooltip("R-Rotation of the kicker")] public float Orientation; - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface the kicker is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; - public List Coils = new() { new KickerCoil { Name = "Default Coil" } }; @@ -127,18 +116,12 @@ public float Radius { #region Transformation - public void OnSurfaceUpdated() => UpdateTransforms(); - public float PositionZ => SurfaceHeight(Surface, Position); - - public override void UpdateTransforms() { base.UpdateTransforms(); var t = transform; - // position - t.localPosition = Physics.TranslateToWorld(Position.x, Position.y, PositionZ); - + // todo move this to import if (KickerType == Engine.VPT.KickerType.KickerCup) { t.localPosition += Physics.TranslateToWorld(0, 0, -0.18f * Radius); } @@ -223,7 +206,6 @@ public override IEnumerable SetData(KickerData data) public override IEnumerable SetReferencedData(KickerData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); return Array.Empty(); } @@ -232,10 +214,9 @@ public override KickerData CopyDataTo(KickerData data, string[] materialNames, s { // name and transforms data.Name = name; - data.Center = Position.ToVertex2D(); + data.Center = new Vertex2D(Position.x, Position.y); data.Orientation = Orientation; data.Radius = Radius; - data.Surface = Surface != null ? Surface.name : string.Empty; data.KickerType = KickerType; @@ -264,7 +245,6 @@ public override void CopyFromObject(GameObject go) Position = kickerComponent.Position; Radius = kickerComponent.Radius; Orientation = kickerComponent.Orientation; - Surface = kickerComponent.Surface; } else { Position = go.transform.localPosition.TranslateToVpx(); @@ -285,19 +265,18 @@ internal KickerState CreateState() var colliderComponent = GetComponent(); var staticData = colliderComponent ? new KickerStaticState { - Center = Position, + Center = new float2(Position.x, Position.y), FallIn = colliderComponent.FallIn, FallThrough = colliderComponent.FallThrough, HitAccuracy = colliderComponent.HitAccuracy, Scatter = colliderComponent.Scatter, LegacyMode = colliderComponent.LegacyMode, - ZLow = Surface?.Height(Position) ?? PlayfieldHeight + ZLow = Position.z } : default; - var height = SurfaceHeight(Surface, Position); var meshData = colliderComponent.LegacyMode ? new ColliderMeshData(Array.Empty(), 0, float3.zero, Allocator.Persistent) - : new ColliderMeshData(KickerHitMesh.Vertices, Radius, new float3(Center.x, Center.y, height), Allocator.Persistent); + : new ColliderMeshData(KickerHitMesh.Vertices, Radius, Position, Allocator.Persistent); return new KickerState( staticData, @@ -363,32 +342,11 @@ private void Start() #region IBallCreationPosition - public Vertex3D GetBallCreationPosition() => new Vertex3D(Position.x, Position.y, PositionZ); + public Vertex3D GetBallCreationPosition() => new Vertex3D(Position.x, Position.y, 0); public Vertex3D GetBallCreationVelocity() => new Vertex3D(0.1f, 0, 0); #endregion - - #region Editor Tooling - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - - public override Vector3 GetEditorPosition() => Position; - - public override void SetEditorPosition(Vector3 pos) => Position = ((float3)pos).xy; - - public override ItemDataTransformType EditorRotationType => - KickerType == Engine.VPT.KickerType.KickerCup || KickerType == Engine.VPT.KickerType.KickerWilliams - ? ItemDataTransformType.OneD : ItemDataTransformType.None; - - public override Vector3 GetEditorRotation() => new Vector3(Orientation, 0f, 0f); - public override void SetEditorRotation(Vector3 rot) => Orientation = ClampDegrees(rot.x); - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.OneD; - public override void SetEditorScale(Vector3 rot) => Radius = rot.x; - public override Vector3 GetEditorScale() => new Vector3(Radius, 0f, 0f); - - #endregion } [Serializable] diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs index 52d705507..21e2b0d10 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs @@ -42,12 +42,6 @@ public class LightComponent : MainRenderableComponent, ILampDeviceCom { #region Data - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this light is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; - [Min(0)] [Tooltip("The radius of the bulb mesh")] public float BulbSize = 20f; @@ -124,11 +118,6 @@ public override void UpdateTransforms() var vpxPos = (float3)transform.localPosition.TranslateToVpx(); - // position - vpxPos.z = Surface != null - ? Surface.Height(vpxPos.xy) + vpxPos.z - : PlayfieldHeight + vpxPos.z; - transform.localPosition = vpxPos.TranslateToWorld(); // bulb size @@ -390,8 +379,6 @@ public override IEnumerable SetData(LightData data) public override IEnumerable SetReferencedData(LightData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); - // visibility if (!data.ShowBulbMesh) { foreach (var mf in GetComponentsInChildren()) { @@ -427,7 +414,6 @@ public override LightData CopyDataTo(LightData data, string[] materialNames, str // name and position data.Name = name; data.Center = pos.ToVertex2Dxy(); - data.Surface = Surface != null ? Surface.name : string.Empty; data.MeshRadius = BulbSize; // logical params @@ -467,7 +453,6 @@ public override void CopyFromObject(GameObject go) var lightComponent = go.GetComponent(); if (lightComponent != null) { - Surface = lightComponent.Surface; BulbSize = lightComponent.BulbSize; State = lightComponent.State; BlinkPattern = lightComponent.BlinkPattern; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs index ebd37aa2e..9f37a1d68 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs @@ -44,8 +44,8 @@ protected override Mesh GetMesh(LightData data) { var playfieldComponent = GetComponentInParent(); var meshGen = new SurfaceMeshGenerator(new LightInsertData(_dragPoints, InsertHeight)); - var topMesh = meshGen.GetMesh(SurfaceMeshGenerator.Top, playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, false); - var sideMesh = meshGen.GetMesh(SurfaceMeshGenerator.Side, playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, false); + var topMesh = meshGen.GetMesh(SurfaceMeshGenerator.Top, playfieldComponent.Width, playfieldComponent.Height, 0, false); + var sideMesh = meshGen.GetMesh(SurfaceMeshGenerator.Side, playfieldComponent.Width, playfieldComponent.Height, 0, false); return topMesh.Merge(sideMesh).TransformToWorld(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MainComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MainComponent.cs index 23b4fc75b..439bd0dd7 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MainComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MainComponent.cs @@ -32,13 +32,6 @@ public abstract class MainComponent : ItemComponent, [SerializeField] private bool _isLocked; - public float PlayfieldHeight { - get { - var playfieldComponent = GetComponentInParent(); - return playfieldComponent ? playfieldComponent.TableHeight : 0f; - } - } - public int PlayfieldDetailLevel { get { var playfieldComponent = GetComponentInParent(); diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs index bd64571bd..80e123930 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MainRenderableComponent.cs @@ -24,8 +24,7 @@ namespace VisualPinball.Unity { - public abstract class MainRenderableComponent : MainComponent, - IMainRenderableComponent, IOnPlayfieldComponent + public abstract class MainRenderableComponent : MainComponent, IMainRenderableComponent where TData : ItemData { public virtual bool CanBeTransformed => true; @@ -102,15 +101,6 @@ public virtual void UpdateTransforms() } } - public virtual void UpdateVisibility() - { - } - - protected float SurfaceHeight(ISurfaceComponent surface, Vector2 position) - { - return surface?.Height(position) ?? PlayfieldHeight; - } - protected static void CopyMaterialName(MeshRenderer mr, string[] materialNames, string[] textureNames, ref string materialName) { @@ -166,20 +156,6 @@ private static void CopyMaterialName(MeshRenderer mr, string[] materialNames, st #region Tools - public virtual ItemDataTransformType EditorPositionType => ItemDataTransformType.None; - public virtual Vector3 GetEditorPosition() => transform.localPosition; - public virtual void SetEditorPosition(Vector3 pos) { } - - public virtual ItemDataTransformType EditorRotationType => ItemDataTransformType.None; - public virtual Vector3 GetEditorRotation() => Vector3.zero; - public virtual void SetEditorRotation(Vector3 rot) { } - - public virtual ItemDataTransformType EditorScaleType => ItemDataTransformType.None; - public virtual Vector3 GetEditorScale() => Vector3.zero; - public virtual void SetEditorScale(Vector3 rot) { } - public virtual void EditorStartScaling() {} - public virtual void EditorEndScaling() {} - protected static void MoveDragPointsTo(DragPointData[] dragPoints, Vector3 destination) { var sum = Vertex3D.Zero; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs index 51f85fa21..e125fb66e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs @@ -186,15 +186,6 @@ public static bool ApplyChildrenTransformsValidate() var comps = UnityEditor.Selection.activeGameObject.GetComponentsInChildren(); return comps.Length != 0; } - - [UnityEditor.MenuItem("GameObject/Visual Pinball/Rebuild Meshes", false, 40)] - public static void ApplyChildrenTransforms() - { - var comps = UnityEditor.Selection.activeGameObject.GetComponentsInChildren(); - foreach (var comp in comps) { - comp.MainRenderableComponent.RebuildMeshes(); - } - } } #endif diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideApi.cs index 902931fb1..aafa74b9f 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideApi.cs @@ -15,7 +15,6 @@ // along with this program. If not, see . using System; -using System.Collections.Generic; using Unity.Mathematics; using UnityEngine; using VisualPinball.Engine.VPT.MetalWireGuide; @@ -48,7 +47,7 @@ protected override void CreateColliders(ref ColliderReference colliders, ref ColliderReference kinematicColliders, float4x4 translateWithinPlayfieldMatrix, float margin) { var colliderGenerator = new MetalWireGuideColliderGenerator(this, new MetalWireGuideMeshGenerator(MainComponent), translateWithinPlayfieldMatrix); - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ColliderComponent.HitHeight, MainComponent.Bendradius, MainComponent.PlayfieldDetailLevel, ref colliders, margin); + colliderGenerator.GenerateColliders(0, ColliderComponent.HitHeight, MainComponent.Bendradius, MainComponent.PlayfieldDetailLevel, ref colliders, margin); } #endregion diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideComponent.cs index 769b365bb..3dc6dfbfe 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideComponent.cs @@ -1,265 +1,224 @@ -// Visual Pinball Engine -// Copyright (C) 2023 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 . - -#region ReSharper -// ReSharper disable CompareOfFloatsByEqualityOperator -// ReSharper disable ClassNeverInstantiated.Global -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable InconsistentNaming -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; -using VisualPinball.Engine.Math; -using VisualPinball.Engine.VPT; -using VisualPinball.Engine.VPT.MetalWireGuide; -using VisualPinball.Engine.VPT.Table; - -namespace VisualPinball.Unity -{ - [AddComponentMenu("Visual Pinball/Game Item/Metal Wire Guide")] - public class MetalWireGuideComponent : MainRenderableComponent, - IMetalWireGuideData - { - #region Data - - [Tooltip("Height of the metal wire guide (z-axis).")] - public float _height = 25f; - - [Min(0)] - [Tooltip("How thick the metal wire guide band is rendered.")] - public float _thickness = 3; - - [Min(0)] - [Tooltip("How tall the metal wire ends are rendered.")] - public float _standheight = 30f; - - - [Tooltip("Rotation on the playfield")] - public Vector3 Rotation; - - [Tooltip("Radius of the bend")] - public float _bendradius = 8f; - - [SerializeField] - private DragPointData[] _dragPoints; - - #endregion - - #region IMetalWireGuideData - - public DragPointData[] DragPoints { get => _dragPoints; set => _dragPoints = value; } - public float Thickness => _thickness; - public float Standheight => _standheight; - public float Height => _height; - public float RotX => Rotation.x; - public float RotY => Rotation.y; - public float RotZ => Rotation.z; - public float Bendradius => _bendradius; - - #endregion - - #region Overrides - - public override ItemType ItemType => ItemType.MetalWireGuide; - public override string ItemName => "MetalWireGuide"; - - public override MetalWireGuideData InstantiateData() => new MetalWireGuideData(); - - public override bool HasProceduralMesh => true; - - protected override Type MeshComponentType { get; } = typeof(MeshComponent); - protected override Type ColliderComponentType { get; } = typeof(ColliderComponent); - - #endregion - - #region Runtime - - public MetalWireGuideApi MetalWireGuideApi { get; private set; } - - private void Awake() - { - var player = GetComponentInParent(); - var physicsEngine = GetComponentInParent(); - MetalWireGuideApi = new MetalWireGuideApi(gameObject, player, physicsEngine); - - player.Register(MetalWireGuideApi, this); - RegisterPhysics(physicsEngine); - } - - #endregion - - #region Transformation - - public override void OnPlayfieldHeightUpdated() => RebuildMeshes(); - - #endregion - - #region Conversion - - public override IEnumerable SetData(MetalWireGuideData data) - { - var updatedComponents = new List { this }; - - // geometry - _height = data.Height; - Rotation = new Vector3(data.RotX, data.RotY, data.RotZ); - _thickness = data.Thickness; - DragPoints = data.DragPoints; - _bendradius = data.Bendradius; - _standheight = data.Standheight; - - // collider data - var collComponent = GetComponent(); - if (collComponent) { - collComponent.enabled = data.IsCollidable; - - collComponent.HitEvent = data.HitEvent; - collComponent.HitHeight = data.HitHeight; - collComponent.OverwritePhysics = data.OverwritePhysics; - collComponent.Elasticity = data.Elasticity; - collComponent.ElasticityFalloff = data.ElasticityFalloff; - collComponent.Friction = data.Friction; - collComponent.Scatter = data.Scatter; - - updatedComponents.Add(collComponent); - } - - return updatedComponents; - } - - public override IEnumerable SetReferencedData(MetalWireGuideData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) - { - // mesh - var mesh = GetComponent(); - if (mesh) { - mesh.CreateMesh(data, table, textureProvider, materialProvider); - mesh.enabled = data.IsVisible; - SetEnabled(data.IsVisible); - } - - // collider data - var collComponent = GetComponentInChildren(); - if (collComponent) { - collComponent.PhysicsMaterial = materialProvider.GetPhysicsMaterial(data.PhysicsMaterial); - } - - return Array.Empty(); - } - - public override MetalWireGuideData CopyDataTo(MetalWireGuideData data, string[] materialNames, string[] textureNames, bool forExport) - { - // update the name - data.Name = name; - - // geometry - data.Height = _height; - data.RotX = Rotation.x; - data.RotY = Rotation.y; - data.RotZ = Rotation.z; - data.Thickness = _thickness; - data.Bendradius = _bendradius; - data.DragPoints = DragPoints; - - // visibility - data.IsVisible = GetEnabled(); - - // collision - var collComponent = GetComponentInChildren(); - if (collComponent) { - data.IsCollidable = collComponent.enabled; - - data.HitEvent = collComponent.HitEvent; - data.HitHeight = collComponent.HitHeight; - - data.PhysicsMaterial = collComponent.PhysicsMaterial ? collComponent.PhysicsMaterial.name : string.Empty; - data.OverwritePhysics = collComponent.OverwritePhysics; - data.Elasticity = collComponent.Elasticity; - data.ElasticityFalloff = collComponent.ElasticityFalloff; - data.Friction = collComponent.Friction; - data.Scatter = collComponent.Scatter; - - } else { - data.IsCollidable = false; - } - - return data; - } - - public override void CopyFromObject(GameObject go) - { - var mwgComponent = go.GetComponent(); - if (mwgComponent != null) { - _height = mwgComponent._height; - _thickness = mwgComponent._thickness; - _standheight = mwgComponent._standheight; - Rotation = mwgComponent.Rotation; - _bendradius = mwgComponent._bendradius; - _dragPoints = mwgComponent._dragPoints.Select(dp => dp.Clone()).ToArray(); - - } else { - MoveDragPointsTo(_dragPoints, go.transform.localPosition.TranslateToVpx()); - } - - UpdateTransforms(); - } - - #endregion - - #region Editor Tooling - - internal Vector3 DragPointCenter { - get { - var sum = Vertex3D.Zero; - foreach (var t in DragPoints) { - sum += t.Center; - } - var center = sum / DragPoints.Length; - return center.ToUnityVector3(); - } - } - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.ThreeD; - public override Vector3 GetEditorPosition() - { - var pos = DragPoints.Length == 0 ? Vector3.zero : DragPointCenter; - return new Vector3(pos.x, pos.y, _height); - } - public override void SetEditorPosition(Vector3 pos) { - if (DragPoints.Length == 0) { - return; - } - var diff = (pos - DragPointCenter).ToVertex3D(); - diff.Z = 0f; - foreach (var pt in DragPoints) { - pt.Center += diff; - } - _height = pos.z; - RebuildMeshes(); - } - - public override ItemDataTransformType EditorRotationType => ItemDataTransformType.ThreeD; - public override Vector3 GetEditorRotation() => Rotation; - public override void SetEditorRotation(Vector3 rot) { - Rotation = rot; - RebuildMeshes(); - } - - #endregion - } -} +// Visual Pinball Engine +// Copyright (C) 2023 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 . + +#region ReSharper +// ReSharper disable CompareOfFloatsByEqualityOperator +// ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable InconsistentNaming +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using VisualPinball.Engine.Math; +using VisualPinball.Engine.VPT; +using VisualPinball.Engine.VPT.MetalWireGuide; +using VisualPinball.Engine.VPT.Table; + +namespace VisualPinball.Unity +{ + [AddComponentMenu("Visual Pinball/Game Item/Metal Wire Guide")] + public class MetalWireGuideComponent : MainRenderableComponent, + IMetalWireGuideData + { + #region Data + + [Tooltip("Height of the metal wire guide (z-axis).")] + public float _height = 25f; + + [Min(0)] + [Tooltip("How thick the metal wire guide band is rendered.")] + public float _thickness = 3; + + [Min(0)] + [Tooltip("How tall the metal wire ends are rendered.")] + public float _standheight = 30f; + + + [Tooltip("Rotation on the playfield")] + public Vector3 Rotation; + + [Tooltip("Radius of the bend")] + public float _bendradius = 8f; + + [SerializeField] + private DragPointData[] _dragPoints; + + #endregion + + #region IMetalWireGuideData + + public DragPointData[] DragPoints { get => _dragPoints; set => _dragPoints = value; } + public float Thickness => _thickness; + public float Standheight => _standheight; + public float Height => _height; + public float RotX => Rotation.x; + public float RotY => Rotation.y; + public float RotZ => Rotation.z; + public float Bendradius => _bendradius; + + #endregion + + #region Overrides + + public override ItemType ItemType => ItemType.MetalWireGuide; + public override string ItemName => "MetalWireGuide"; + + public override MetalWireGuideData InstantiateData() => new MetalWireGuideData(); + + public override bool HasProceduralMesh => true; + + protected override Type MeshComponentType { get; } = typeof(MeshComponent); + protected override Type ColliderComponentType { get; } = typeof(ColliderComponent); + + #endregion + + #region Runtime + + public MetalWireGuideApi MetalWireGuideApi { get; private set; } + + private void Awake() + { + var player = GetComponentInParent(); + var physicsEngine = GetComponentInParent(); + MetalWireGuideApi = new MetalWireGuideApi(gameObject, player, physicsEngine); + + player.Register(MetalWireGuideApi, this); + RegisterPhysics(physicsEngine); + } + + #endregion + + #region Transformation + + public override void OnPlayfieldHeightUpdated() => RebuildMeshes(); + + #endregion + + #region Conversion + + public override IEnumerable SetData(MetalWireGuideData data) + { + var updatedComponents = new List { this }; + + // geometry + _height = data.Height; + Rotation = new Vector3(data.RotX, data.RotY, data.RotZ); + _thickness = data.Thickness; + DragPoints = data.DragPoints; + _bendradius = data.Bendradius; + _standheight = data.Standheight; + + // collider data + var collComponent = GetComponent(); + if (collComponent) { + collComponent.enabled = data.IsCollidable; + + collComponent.HitEvent = data.HitEvent; + collComponent.HitHeight = data.HitHeight; + collComponent.OverwritePhysics = data.OverwritePhysics; + collComponent.Elasticity = data.Elasticity; + collComponent.ElasticityFalloff = data.ElasticityFalloff; + collComponent.Friction = data.Friction; + collComponent.Scatter = data.Scatter; + + updatedComponents.Add(collComponent); + } + + return updatedComponents; + } + + public override IEnumerable SetReferencedData(MetalWireGuideData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) + { + // mesh + var mesh = GetComponent(); + if (mesh) { + mesh.CreateMesh(data, table, textureProvider, materialProvider); + mesh.enabled = data.IsVisible; + SetEnabled(data.IsVisible); + } + + // collider data + var collComponent = GetComponentInChildren(); + if (collComponent) { + collComponent.PhysicsMaterial = materialProvider.GetPhysicsMaterial(data.PhysicsMaterial); + } + + return Array.Empty(); + } + + public override MetalWireGuideData CopyDataTo(MetalWireGuideData data, string[] materialNames, string[] textureNames, bool forExport) + { + // update the name + data.Name = name; + + // geometry + data.Height = _height; + data.RotX = Rotation.x; + data.RotY = Rotation.y; + data.RotZ = Rotation.z; + data.Thickness = _thickness; + data.Bendradius = _bendradius; + data.DragPoints = DragPoints; + + // visibility + data.IsVisible = GetEnabled(); + + // collision + var collComponent = GetComponentInChildren(); + if (collComponent) { + data.IsCollidable = collComponent.enabled; + + data.HitEvent = collComponent.HitEvent; + data.HitHeight = collComponent.HitHeight; + + data.PhysicsMaterial = collComponent.PhysicsMaterial ? collComponent.PhysicsMaterial.name : string.Empty; + data.OverwritePhysics = collComponent.OverwritePhysics; + data.Elasticity = collComponent.Elasticity; + data.ElasticityFalloff = collComponent.ElasticityFalloff; + data.Friction = collComponent.Friction; + data.Scatter = collComponent.Scatter; + + } else { + data.IsCollidable = false; + } + + return data; + } + + public override void CopyFromObject(GameObject go) + { + var mwgComponent = go.GetComponent(); + if (mwgComponent != null) { + _height = mwgComponent._height; + _thickness = mwgComponent._thickness; + _standheight = mwgComponent._standheight; + Rotation = mwgComponent.Rotation; + _bendradius = mwgComponent._bendradius; + _dragPoints = mwgComponent._dragPoints.Select(dp => dp.Clone()).ToArray(); + + } else { + MoveDragPointsTo(_dragPoints, go.transform.localPosition.TranslateToVpx()); + } + + UpdateTransforms(); + } + + #endregion + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideMeshComponent.cs index 85bf57062..75c40f316 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideMeshComponent.cs @@ -28,7 +28,7 @@ public class MetalWireGuideMeshComponent : MeshComponent new MetalWireGuideMeshGenerator(MainComponent) - .GetTransformedMesh(MainComponent.PlayfieldHeight, MainComponent.Height, MainComponent.PlayfieldDetailLevel, MainComponent.Bendradius) + .GetTransformedMesh(0, MainComponent.Height, MainComponent.PlayfieldDetailLevel, MainComponent.Bendradius) .TransformToWorld(); protected override PbrMaterial GetMaterial(MetalWireGuideData data, Table table) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldApi.cs index c2268259c..5c477f4aa 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldApi.cs @@ -43,10 +43,10 @@ protected override void CreateColliders(ref ColliderReference colliders, } else { Debug.LogWarning($"Could not find mesh filter on playfield {GameObject.name}"); - colliders.Add(new PlaneCollider(new float3(0, 0, 1), MainComponent.TableHeight, info)); + colliders.Add(new PlaneCollider(new float3(0, 0, 1), 0, info)); } } else { - colliders.Add(new PlaneCollider(new float3(0, 0, 1), MainComponent.TableHeight, info)); + colliders.Add(new PlaneCollider(new float3(0, 0, 1), 0, info)); } // add playfield glass collider colliders.Add(new PlaneCollider(new float3(0, 0, -1), MainComponent.GlassHeight, info)); @@ -57,7 +57,7 @@ protected override void CreateColliders(ref ColliderReference colliders, colliders.Add(new LineCollider( new float2(MainComponent.Right, MainComponent.Top), new float2(MainComponent.Right, MainComponent.Bottom), - MainComponent.TableHeight, + 0, MainComponent.GlassHeight, info )); @@ -65,7 +65,7 @@ protected override void CreateColliders(ref ColliderReference colliders, colliders.Add(new LineCollider( new float2(MainComponent.Left, MainComponent.Bottom), new float2(MainComponent.Left, MainComponent.Top), - MainComponent.TableHeight, + 0, MainComponent.GlassHeight, info )); @@ -73,7 +73,7 @@ protected override void CreateColliders(ref ColliderReference colliders, colliders.Add(new LineCollider( new float2(MainComponent.Right, MainComponent.Bottom), new float2(MainComponent.Left, MainComponent.Bottom), - MainComponent.TableHeight, + 0, MainComponent.GlassHeight, info )); @@ -81,7 +81,7 @@ protected override void CreateColliders(ref ColliderReference colliders, colliders.Add(new LineCollider( new float2(MainComponent.Left, MainComponent.Top), new float2(MainComponent.Right, MainComponent.Top), - MainComponent.TableHeight, + 0, MainComponent.GlassHeight, info )); diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldComponent.cs index 800420ee1..0e7010e04 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldComponent.cs @@ -34,16 +34,8 @@ namespace VisualPinball.Unity [AddComponentMenu("Visual Pinball/Game Item/Playfield")] public class PlayfieldComponent : MainRenderableComponent { - //public static readonly Quaternion GlobalRotation = Quaternion.Euler(-90, 0, 0); - //public const float GlobalScale = 0.00053975f; // see: https://github.com/freezy/VisualPinball.Engine/issues/151 - //public static readonly Quaternion GlobalRotation = Quaternion.Euler(0, 0, 0); - //public const float GlobalScale = 1f; // see: https://github.com/freezy/VisualPinball.Engine/issues/151 - #region Data - [Tooltip("Height of the table. Translates all elements along the Z-axis.")] - public float TableHeight; - [Tooltip("Height of the glass above the playfield. Serves as outer collision bounds of the Z-axis.")] public float GlassHeight; @@ -88,8 +80,8 @@ public class PlayfieldComponent : MainRenderableComponent protected override Type MeshComponentType => typeof(PlayfieldMeshComponent); protected override Type ColliderComponentType => typeof(PlayfieldColliderComponent); - public Rect3D BoundingBox => new Rect3D(Left, Right, Top, Bottom, TableHeight, GlassHeight); - public Aabb Bounds => new Aabb(Left, Right, Top, Bottom, TableHeight, GlassHeight); + public Rect3D BoundingBox => new Rect3D(Left, Right, Top, Bottom, 0, GlassHeight); + public Aabb Bounds => new Aabb(Left, Right, Top, Bottom, 0, GlassHeight); public AABB2D Bounds2D => new AABB2D(new float2(Left, Top), new float2(Right, Bottom)); public float3 PlayfieldGravity(float strength) { @@ -117,7 +109,6 @@ public override IEnumerable SetData(TableData data) var updatedComponents = new List { this }; // position - TableHeight = data.TableHeight; GlassHeight = data.GlassHeight; Left = data.Left; Left = data.Left; @@ -172,7 +163,7 @@ public IEnumerable SetReferencedData(PrimitiveData primitiveData, var mg = new PrimitiveMeshGenerator(primitiveData); var mesh = mg .GetTransformedMesh(table?.TableHeight ?? 0f, primitiveData.Mesh, Origin.Original, false) - .Transform(mg.TransformationMatrix(PlayfieldHeight)) // apply transformation to mesh, because this is the playfield + .Transform(mg.TransformationMatrix(0)) // apply transformation to mesh, because this is the playfield .TransformToWorld(); // also, transform this to world space. var material = new PbrMaterial( table?.GetMaterial(_playfieldMaterial), @@ -191,7 +182,7 @@ public override TableData CopyDataTo(TableData data, string[] materialNames, str var physicsEngine = GetComponentInParent(); // position - data.TableHeight = TableHeight; + data.TableHeight = 0; data.GlassHeight = GlassHeight; data.Left = Left; data.Right = Right; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerCollider.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerCollider.cs index f8ccac042..dbfabf09a 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerCollider.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerCollider.cs @@ -50,7 +50,7 @@ public PlungerCollider(PlungerComponent comp, PlungerColliderComponent collComp, { Header.Init(info, ColliderType.Plunger); - var zHeight = comp.PositionZ; + var zHeight = comp.Position.z; var x = -comp.Width; var x2 = comp.Width; var y = comp.Height; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerComponent.cs index 72c536255..bd898a3ee 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerComponent.cs @@ -24,6 +24,7 @@ using UnityEngine; using UnityEngine.InputSystem; using VisualPinball.Engine.Game.Engines; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Plunger; using VisualPinball.Engine.VPT.Table; @@ -31,39 +32,17 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Plunger")] - public class PlungerComponent : MainRenderableComponent, - ICoilDeviceComponent, IOnSurfaceComponent + public class PlungerComponent : MainRenderableComponent, ICoilDeviceComponent { #region Data - private Vector3 _position { + public Vector3 Position { get => transform.localPosition.TranslateToVpx(); set => transform.localPosition = value.TranslateToWorld(); } - - public Vector2 Position { - get => _position.XY(); - set => _position = new Vector3(value.x, value.y, Height); - } - public float Width = 25f; - public float Height = 20f; - public float ZAdjust { - get => _position.z; - set { - var pos = _position; - _position = new Vector3(pos.x, pos.y, value); - } - } - - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this plunger is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; - #endregion public InputActionReference analogPlungerAction; @@ -126,12 +105,8 @@ public float4x4 TransformationWithinPlayfield [NonSerialized] private float4x4 _playfieldToWorld; - public void OnSurfaceUpdated() => RebuildMeshes(); - public override void OnPlayfieldHeightUpdated() => RebuildMeshes(); - public float PositionZ => SurfaceHeight(Surface, Position); - public override void UpdateTransforms() { base.UpdateTransforms(); @@ -154,10 +129,9 @@ public override IEnumerable SetData(PlungerData data) var updatedComponents = new List { this }; // geometry and position - Position = data.Center.ToUnityVector2(); + Position = new Vector3(data.Center.X, data.Center.Y, data.ZAdjust); Width = data.Width; Height = data.Height; - ZAdjust = data.ZAdjust; // collider data var collComponent = GetComponent(); @@ -209,8 +183,6 @@ public override IEnumerable SetData(PlungerData data) public override IEnumerable SetReferencedData(PlungerData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); - // rod mesh var rodMesh = GetComponentInChildren(true); if (rodMesh) { @@ -232,11 +204,10 @@ public override PlungerData CopyDataTo(PlungerData data, string[] materialNames, { // name, geometry and position data.Name = name; - data.Center = Position.ToVertex2D(); + data.Center = new Vertex2D(Position.x, Position.y); data.Width = Width; data.Height = Height; - data.ZAdjust = ZAdjust; - data.Surface = Surface != null ? Surface.name : string.Empty; + data.ZAdjust = Position.z; // collider data var collComponent = GetComponent(); @@ -287,8 +258,6 @@ public override void CopyFromObject(GameObject go) Position = plungerComponent.Position; Width = plungerComponent.Width; Height = plungerComponent.Height; - ZAdjust = plungerComponent.ZAdjust; - Surface = plungerComponent.Surface; } else { Position = go.transform.localPosition.TranslateToVpx(); @@ -309,7 +278,7 @@ internal PlungerState CreateState() return default; } - var zHeight = PositionZ; + var zHeight = Position.z; var x = -Width; var x2 = Width; var y = Height; @@ -381,17 +350,5 @@ public void UpdateParkPosition(float pos) skinnedMeshRenderer.SetBlendShapeWeight(0, pos); } } - - #region Editor Tooling - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - public override Vector3 GetEditorPosition() => Position; - public override void SetEditorPosition(Vector3 pos) - { - Position = ((float3)pos).xy; - RebuildMeshes(); - } - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerFlatMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerFlatMeshComponent.cs index 362f0c84f..f104ecaed 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerFlatMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerFlatMeshComponent.cs @@ -29,7 +29,7 @@ public class PlungerFlatMeshComponent : PlungerMeshComponent { protected override Mesh GetMesh(PlungerData data) => new PlungerMeshGenerator(data) - .GetMesh(MainComponent.PositionZ, PlungerMeshGenerator.Flat) + .GetMesh(MainComponent.Position.z, PlungerMeshGenerator.Flat) .TransformToWorld(); protected override PbrMaterial GetMaterial(PlungerData data, Table table) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerRodMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerRodMeshComponent.cs index 2390e6854..f0c25fed6 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerRodMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerRodMeshComponent.cs @@ -45,7 +45,7 @@ public class PlungerRodMeshComponent : PlungerMeshComponent protected override Mesh GetMesh(PlungerData data) => new PlungerMeshGenerator(data) - .GetMesh(MainComponent.PositionZ, PlungerMeshGenerator.Rod); + .GetMesh(MainComponent.Position.z, PlungerMeshGenerator.Rod); protected override PbrMaterial GetMaterial(PlungerData data, Table table) => new PlungerMeshGenerator(data).GetMaterial(table); diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerSpringMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerSpringMeshComponent.cs index d9bc04303..653432495 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerSpringMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Plunger/PlungerSpringMeshComponent.cs @@ -41,7 +41,7 @@ public class PlungerSpringMeshComponent : PlungerMeshComponent #endregion protected override Mesh GetMesh(PlungerData data) - => new PlungerMeshGenerator(data).GetMesh(MainComponent.PositionZ, PlungerMeshGenerator.Spring); + => new PlungerMeshGenerator(data).GetMesh(MainComponent.Position.z, PlungerMeshGenerator.Spring); protected override PbrMaterial GetMaterial(PlungerData data, Table table) => new PlungerMeshGenerator(data).GetMaterial(table); diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveComponent.cs index bc0235e34..92aeece1c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveComponent.cs @@ -79,7 +79,7 @@ public override IEnumerable SetData(PrimitiveData data) var objectRotation = new Vector3(data.RotAndTra[6], data.RotAndTra[7], data.RotAndTra[8]); var scaleMatrix = float4x4.Scale(size); - var transMatrix = float4x4.Translate(new float3(position.x, position.y, position.z + PlayfieldHeight)); + var transMatrix = float4x4.Translate(position); var rotTransMatrix = math.mul( float4x4.EulerZYX(math.radians(objectRotation)), math.mul( diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs index 4b209cf51..633ebc6a0 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Primitive/PrimitiveMeshComponent.cs @@ -45,7 +45,7 @@ public class PrimitiveMeshComponent : MeshComponent new PrimitiveMeshGenerator(data) - .GetMesh(MainComponent.PlayfieldHeight, data.Mesh, Origin.Original, false) + .GetMesh(0, data.Mesh, Origin.Original, false) .TransformToWorld(); protected override PbrMaterial GetMaterial(PrimitiveData data, Table table) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampApi.cs index 0c16d5aa5..f3e365616 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampApi.cs @@ -67,9 +67,9 @@ protected override void CreateColliders(ref ColliderReference colliders, { var colliderGenerator = new RampColliderGenerator(this, MainComponent, ColliderComponent, translateWithinPlayfieldMatrix); if (ColliderComponent._isKinematic) { - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ref kinematicColliders, margin); + colliderGenerator.GenerateColliders(0, ref kinematicColliders, margin); } else { - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ref colliders, margin); + colliderGenerator.GenerateColliders(0, ref colliders, margin); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs index 7b9d88170..7e7882e65 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs @@ -22,7 +22,6 @@ #endregion using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using Unity.Mathematics; @@ -37,8 +36,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Ramp")] - public class RampComponent : MainRenderableComponent, - IRampData, ISurfaceComponent + public class RampComponent : MainRenderableComponent, IRampData { #region Data @@ -177,39 +175,40 @@ public float Height(Vector2 pos) { var len = MathF.Sqrt(dx * dx + dy * dy); startLength += len; // Add the distance the object is between the two closest polyline segments. Matters mostly for straight edges. Z does not respect that yet! - var topHeight = _heightTop + PlayfieldHeight; - var bottomHeight = _heightBottom + PlayfieldHeight; + var topHeight = _heightTop; + var bottomHeight = _heightBottom; return vVertex[iSeg].Z + startLength / totalLength * (topHeight - bottomHeight) + bottomHeight; } - public override void UpdateVisibility() - { - // visibility - var wallComponent = GetComponentInChildren(true); - var floorComponent = GetComponentInChildren(true); - var wireComponent = GetComponentInChildren(true); - var isVisible = wireComponent && wireComponent.gameObject.activeInHierarchy || - floorComponent && floorComponent.gameObject.activeInHierarchy; - if (IsWireRamp) { - if (wireComponent) wireComponent.gameObject.SetActive(isVisible); - if (floorComponent) { - floorComponent.gameObject.SetActive(false); - floorComponent.ClearMeshVertices(); - } - if (wallComponent) { - wallComponent.gameObject.SetActive(false); - wallComponent.ClearMeshVertices(); - } - } else { - if (wireComponent) { - wireComponent.gameObject.SetActive(false); - wireComponent.ClearMeshVertices(); - } - if (floorComponent) floorComponent.gameObject.SetActive(isVisible); - if (wallComponent) wallComponent.gameObject.SetActive(isVisible && (_leftWallHeightVisible > 0 || _rightWallHeightVisible > 0)); - } - } + // todo revisit + // public override void UpdateVisibility() + // { + // // visibility + // var wallComponent = GetComponentInChildren(true); + // var floorComponent = GetComponentInChildren(true); + // var wireComponent = GetComponentInChildren(true); + // var isVisible = wireComponent && wireComponent.gameObject.activeInHierarchy || + // floorComponent && floorComponent.gameObject.activeInHierarchy; + // if (IsWireRamp) { + // if (wireComponent) wireComponent.gameObject.SetActive(isVisible); + // if (floorComponent) { + // floorComponent.gameObject.SetActive(false); + // floorComponent.ClearMeshVertices(); + // } + // if (wallComponent) { + // wallComponent.gameObject.SetActive(false); + // wallComponent.ClearMeshVertices(); + // } + // } else { + // if (wireComponent) { + // wireComponent.gameObject.SetActive(false); + // wireComponent.ClearMeshVertices(); + // } + // if (floorComponent) floorComponent.gameObject.SetActive(isVisible); + // if (wallComponent) wallComponent.gameObject.SetActive(isVisible && (_leftWallHeightVisible > 0 || _rightWallHeightVisible > 0)); + // } + // } public float4x4 TransformationWithinPlayfield => transform.worldToLocalMatrix.WorldToLocalTranslateWithinPlayfield(_playfieldToWorld); @@ -408,59 +407,5 @@ private void CenterPivot() #endregion - #region Editor Tooling - - private Vector3 DragPointCenter { - get { - var sum = Vertex3D.Zero; - foreach (var t in DragPoints) { - sum += t.Center; - } - var center = sum / DragPoints.Length; - return new Vector3(center.X, center.Y, _heightTop); - } - } - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - public override Vector3 GetEditorPosition() - { - return DragPoints.Length == 0 ? Vector3.zero : DragPointCenter; - } - - public override void SetEditorPosition(Vector3 pos) - { - if (DragPoints.Length == 0) { - return; - } - var diff = (pos - DragPointCenter).ToVertex3D(); - diff.Z = 0f; - foreach (var pt in DragPoints) { - pt.Center += diff; - } - RebuildMeshes(); - var playfieldComponent = GetComponentInParent(); - if (playfieldComponent) { - WalkChildren(playfieldComponent.transform, UpdateSurfaceReferences); - } - } - - protected static void WalkChildren(IEnumerable node, Action action) - { - foreach (Transform childTransform in node) { - action(childTransform); - WalkChildren(childTransform, action); - } - } - - protected void UpdateSurfaceReferences(Transform obj) - { - var surfaceComponent = obj.gameObject.GetComponent(); - if (surfaceComponent != null && ReferenceEquals(surfaceComponent.Surface, this)) - { - surfaceComponent.OnSurfaceUpdated(); - } - } - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampFloorMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampFloorMeshComponent.cs index dd8c180f3..244e86ed9 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampFloorMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampFloorMeshComponent.cs @@ -31,7 +31,7 @@ protected override Mesh GetMesh(RampData _) { var playfieldComponent = GetComponentInParent(); return new RampMeshGenerator(MainComponent) - .GetMesh(playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, RampMeshGenerator.Floor) + .GetMesh(playfieldComponent.Width, playfieldComponent.Height, 0, RampMeshGenerator.Floor) .TransformToWorld(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWallMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWallMeshComponent.cs index ab72368b2..3831b82db 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWallMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWallMeshComponent.cs @@ -31,7 +31,7 @@ protected override Mesh GetMesh(RampData data) { var playfieldComponent = GetComponentInParent(); return new RampMeshGenerator(MainComponent) - .GetMesh(playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, RampMeshGenerator.Wall) + .GetMesh(playfieldComponent.Width, playfieldComponent.Height, 0, RampMeshGenerator.Wall) .TransformToWorld(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWireMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWireMeshComponent.cs index 00286b2ff..57a83c7c7 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWireMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampWireMeshComponent.cs @@ -31,7 +31,7 @@ protected override Mesh GetMesh(RampData data) { var playfieldComponent = GetComponentInParent(); return new RampMeshGenerator(MainComponent) - .GetMesh(playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, RampMeshGenerator.Wires) + .GetMesh(playfieldComponent.Width, playfieldComponent.Height, 0, RampMeshGenerator.Wires) .TransformToWorld(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberApi.cs index 70eea1b4b..1fd393c86 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberApi.cs @@ -53,9 +53,9 @@ protected override void CreateColliders(ref ColliderReference colliders, translateWithinPlayfieldMatrix ); if (ColliderComponent._isKinematic) { - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ColliderComponent.HitHeight, MainComponent.PlayfieldDetailLevel, ref kinematicColliders, margin); + colliderGenerator.GenerateColliders(0, ColliderComponent.HitHeight, MainComponent.PlayfieldDetailLevel, ref kinematicColliders, margin); } else { - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ColliderComponent.HitHeight, MainComponent.PlayfieldDetailLevel, ref colliders, margin); + colliderGenerator.GenerateColliders(0, ColliderComponent.HitHeight, MainComponent.PlayfieldDetailLevel, ref colliders, margin); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs index d5986580a..1550d3d4d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs @@ -225,71 +225,5 @@ public override void CopyFromObject(GameObject go) } #endregion - - #region Editor Tooling - - private Vector3 DragPointCenter { - get { - var sum = Vertex3D.Zero; - foreach (var t in DragPoints) { - sum += t.Center; - } - var center = sum / DragPoints.Length; - return center.ToUnityVector3(); - } - } - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.ThreeD; - public override Vector3 GetEditorPosition() - { - var pos = DragPoints.Length == 0 ? Vector3.zero : DragPointCenter; - return new Vector3(pos.x, pos.y, _height); - } - public override void SetEditorPosition(Vector3 pos) { - if (DragPoints.Length == 0) { - return; - } - var diff = (pos - DragPointCenter).ToVertex3D(); - diff.Z = 0f; - foreach (var pt in DragPoints) { - pt.Center += diff; - } - _height = pos.z; - RebuildMeshes(); - } - - public override ItemDataTransformType EditorRotationType => ItemDataTransformType.ThreeD; - public override Vector3 GetEditorRotation() => Rotation; - public override void SetEditorRotation(Vector3 rot) { - Rotation = rot; - RebuildMeshes(); - } - - public override void EditorStartScaling() - { - _scalingDragPoints = _dragPoints.Select(dp => dp.Center).ToArray(); - _scale = 1f; - } - - public override void EditorEndScaling() - { - _scalingDragPoints = null; - } - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.OneD; - public override Vector3 GetEditorScale() => new(_scale, 1f, 1f); - public override void SetEditorScale(Vector3 vScale) - { - var scale = 1 + (vScale.x - 1) / 5f; - _scale = scale; - var center = DragPointCenter.ToVertex3D(); - for (var i = 0; i < _dragPoints.Length; i++) { - _dragPoints[i].Center = center + scale * (_scalingDragPoints[i] - center); - } - - RebuildMeshes(); - } - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberMeshComponent.cs index 575d8308e..590a54c40 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberMeshComponent.cs @@ -29,7 +29,7 @@ public class RubberMeshComponent : MeshComponent { protected override Mesh GetMesh(RubberData data) => new RubberMeshGenerator(MainComponent) - .GetTransformedMesh(MainComponent.PlayfieldHeight, MainComponent.Height, MainComponent.PlayfieldDetailLevel) + .GetTransformedMesh(0, MainComponent.Height, MainComponent.PlayfieldDetailLevel) .TransformToWorld(); protected override PbrMaterial GetMaterial(RubberData data, Table table) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Spinner/SpinnerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Spinner/SpinnerComponent.cs index 69d861939..6299ef1e8 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Spinner/SpinnerComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Spinner/SpinnerComponent.cs @@ -28,6 +28,7 @@ using UnityEngine; using VisualPinball.Engine.Common; using VisualPinball.Engine.Game.Engines; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Spinner; using VisualPinball.Engine.VPT.Table; @@ -36,28 +37,15 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Spinner")] public class SpinnerComponent : MainRenderableComponent, - ISwitchDeviceComponent, IOnSurfaceComponent, IRotatableAnimationComponent + ISwitchDeviceComponent, IRotatableAnimationComponent { #region Data - private Vector3 _position { + public Vector3 Position { get => transform.localPosition.TranslateToVpx(); set => transform.localPosition = value.TranslateToWorld(); } - public Vector2 Position { - get => _position.XY(); - set => _position = new Vector3(value.x, value.y, Height); - } - - public float Height { - get => _position.z; - set { - var pos = _position; - _position = new Vector3(pos.x, pos.y, value); - } - } - public float Rotation { get => transform.localEulerAngles.y > 180 ? transform.localEulerAngles.y - 360 : transform.localEulerAngles.y; set => transform.SetLocalYRotation(math.radians(value)); @@ -93,11 +81,18 @@ public float Length [Tooltip("Minimal angle. This allows the spinner to bounce back instead of executing a 360° rotation.")] public float AngleMin; - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this spinner is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; + public bool ShowBracket { + get { + foreach (var mf in GetComponentsInChildren()) { + // todo use a component instead of relying on mesh names + switch (mf.sharedMesh.name) { + case BracketMeshName: + return mf.gameObject.activeInHierarchy; + } + } + return false; + } + } #endregion @@ -106,7 +101,7 @@ public float Length public override ItemType ItemType => ItemType.Spinner; public override string ItemName => "Spinner"; - public override SpinnerData InstantiateData() => new SpinnerData(); + public override SpinnerData InstantiateData() => new(); public override bool HasProceduralMesh => false; @@ -164,11 +159,6 @@ private void Start() [NonSerialized] private float4x4 _playfieldToWorld; - public void OnSurfaceUpdated() => UpdateTransforms(); - public float PositionZ => SurfaceHeight(Surface, Position); - - public float HeightOnPlayfield => Height + PositionZ; // todo handle surface - public float4x4 TransformationWithinPlayfield => transform.worldToLocalMatrix.WorldToLocalTranslateWithinPlayfield(_playfieldToWorld); #endregion @@ -180,8 +170,7 @@ public override IEnumerable SetData(SpinnerData data) var updatedComponents = new List { this }; // transforms - Position = data.Center.ToUnityFloat2(); - Height = data.Height; + Position = new Vector3(data.Center.X, data.Center.Y, data.Height); Length = data.Length; Rotation = data.Rotation; @@ -214,7 +203,6 @@ public override IEnumerable SetData(SpinnerData data) public override IEnumerable SetReferencedData(SpinnerData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); return Array.Empty(); } @@ -222,11 +210,10 @@ public override SpinnerData CopyDataTo(SpinnerData data, string[] materialNames, { // name and transforms data.Name = name; - data.Center = Position.ToVertex2D(); - data.Height = Height; + data.Center = new Vertex2D(Position.x, Position.y); + data.Height = Position.z; data.Length = Length; data.Rotation = Rotation; - data.Surface = Surface != null ? Surface.name : string.Empty; // spinner props data.Damping = Damping; @@ -262,13 +249,11 @@ public override void CopyFromObject(GameObject go) var spinnerComponent = go.GetComponent(); if (spinnerComponent != null) { Position = spinnerComponent.Position; - Height = spinnerComponent.Height; Rotation = spinnerComponent.Rotation; Length = spinnerComponent.Length; Damping = spinnerComponent.Damping; AngleMax = spinnerComponent.AngleMax; AngleMin = spinnerComponent.AngleMin; - Surface = spinnerComponent.Surface; } else { Position = go.transform.localPosition.TranslateToVpx(); @@ -292,7 +277,7 @@ internal SpinnerState CreateState() AngleMin = math.radians(AngleMin), Damping = math.pow(Damping, (float)PhysicsConstants.PhysFactor), Elasticity = collComponent.Elasticity, - Height = Height + Height = Position.z } : default; // animation @@ -312,32 +297,6 @@ internal SpinnerState CreateState() #endregion - #region Editor Tooling - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.ThreeD; - public override Vector3 GetEditorPosition() - { - return new Vector3(Position.x, Position.y, Height); - } - public override void SetEditorPosition(Vector3 pos) - { - Position = pos; - Height = pos.z; - } - - public override ItemDataTransformType EditorRotationType => ItemDataTransformType.OneD; - public override Vector3 GetEditorRotation() => new Vector3(Rotation, 0f, 0f); - public override void SetEditorRotation(Vector3 rot) => Rotation = ClampDegrees(rot.x); - - public override ItemDataTransformType EditorScaleType => ItemDataTransformType.OneD; - - public bool ShowBracket => GetComponentsInChildren().Any(); - - public override Vector3 GetEditorScale() => new Vector3(Length, 0f, 0f); - public override void SetEditorScale(Vector3 scale) => Length = scale.x; - - #endregion - #region IRotatableAnimationComponent public void OnRotationUpdated(float angleRad) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs index 10ea2821d..878d85c4c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs @@ -164,9 +164,8 @@ private IEnumerator Animate() #endregion - #region IMeshComponent - public IMainRenderableComponent MainRenderableComponent => this; + public void UpdateTransforms() { } public void RebuildMeshes() { @@ -227,7 +226,7 @@ private Mesh GetMesh() Debug.Log($"Generating new mesh at {pos}"); var mesh = MeshGenerator - .GetTransformedMesh(pf.PlayfieldHeight, r0.Height, pf.PlayfieldDetailLevel) + .GetTransformedMesh(0, r0.Height, pf.PlayfieldDetailLevel) .TransformToWorld() .ToUnityMesh(); @@ -237,34 +236,6 @@ private Mesh GetMesh() return mesh; } - #endregion - - #region IMainRenderableComponent - - public bool IsLocked { get => _isLocked; set => _isLocked = value; } - public bool CanBeTransformed => false; - public bool OverrideTransform => false; - public string ItemName => "Slingshot"; - - public void UpdateTransforms() { } - public void UpdateVisibility() { } - - public ItemDataTransformType EditorPositionType => ItemDataTransformType.None; - public Vector3 GetEditorPosition() => Vector3.zero; - public void SetEditorPosition(Vector3 pos) { } - - public ItemDataTransformType EditorRotationType => ItemDataTransformType.None; - public Vector3 GetEditorRotation() => Vector3.zero; - public void SetEditorRotation(Vector3 pos) { } - - public ItemDataTransformType EditorScaleType => ItemDataTransformType.None; - public Vector3 GetEditorScale() => Vector3.one; - public void SetEditorScale(Vector3 pos) { } - public void EditorStartScaling() { } - public void EditorEndScaling() { } - - #endregion - public static GameObject LoadPrefab() => Resources.Load("Prefabs/Slingshot"); private DragPointData[] DragPointsAt(float pos) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs index 74a969ed6..cc0a9a695 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs @@ -56,10 +56,10 @@ protected override void CreateColliders(ref ColliderReference colliders, } var colliderGenerator = new SurfaceColliderGenerator(this, MainComponent, ColliderComponent, translateWithinPlayfieldMatrix); if (ColliderComponent._isKinematic) { - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ref kinematicColliders, margin); + colliderGenerator.GenerateColliders(0, ref kinematicColliders, margin); } else { - colliderGenerator.GenerateColliders(MainComponent.PlayfieldHeight, ref colliders, margin); + colliderGenerator.GenerateColliders(0, ref colliders, margin); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs index 885ff3bdc..9ea69f18d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs @@ -34,7 +34,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Surface")] - public class SurfaceComponent : MainRenderableComponent, ISurfaceComponent + public class SurfaceComponent : MainRenderableComponent { #region Data @@ -93,7 +93,7 @@ private void Start() [NonSerialized] private float4x4 _playfieldToWorld; - public float Height(Vector2 _) => HeightTop + PlayfieldHeight; + public float Height(Vector2 _) => HeightTop; public override void OnPlayfieldHeightUpdated() => RebuildMeshes(); @@ -259,34 +259,5 @@ internal SurfaceState CreateState() } #endregion - - #region Editor Tooling - - private Vector3 DragPointCenter { - get { - var sum = Vertex3D.Zero; - foreach (var t in DragPoints) { - sum += t.Center; - } - var center = sum / DragPoints.Length; - return new Vector3(center.X, center.Y, HeightTop); - } - } - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - public override Vector3 GetEditorPosition() => DragPoints.Length == 0 ? Vector3.zero : DragPointCenter; - public override void SetEditorPosition(Vector3 pos) { - if (DragPoints.Length == 0) { - return; - } - var diff = (pos - DragPointCenter).ToVertex3D(); - diff.Z = 0f; - foreach (var pt in DragPoints) { - pt.Center += diff; - } - RebuildMeshes(); - } - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs index 11d462e8c..4203d48af 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs @@ -31,7 +31,7 @@ protected override Mesh GetMesh(SurfaceData data) { var playfieldComponent = GetComponentInParent(); return new SurfaceMeshGenerator(data) - .GetMesh(SurfaceMeshGenerator.Side, playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, false) + .GetMesh(SurfaceMeshGenerator.Side, playfieldComponent.Width, playfieldComponent.Height, 0, false) .TransformToWorld(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs index 06ad3e7e0..e51abd3c1 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs @@ -30,7 +30,7 @@ protected override Mesh GetMesh(SurfaceData data) { var playfieldComponent = GetComponentInParent(); return new SurfaceMeshGenerator(data) - .GetMesh(SurfaceMeshGenerator.Top, playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, false) + .GetMesh(SurfaceMeshGenerator.Top, playfieldComponent.Width, playfieldComponent.Height, 0, false) .TransformToWorld(); } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableComponent.cs index 6c27281e6..d8c5fb7e4 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Table/TableComponent.cs @@ -107,7 +107,7 @@ public override IEnumerable SetReferencedData(TableData data, Tab public override TableData CopyDataTo(TableData data, string[] materialNames, string[] textureNames, bool forExport) { - data.TableHeight = PlayfieldHeight; + data.TableHeight = 0; data.GlobalDifficulty = GlobalDifficulty; data.OverridePhysics = OverridePhysics; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerColliderGenerator.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerColliderGenerator.cs index 53219c16c..70420e773 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerColliderGenerator.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerColliderGenerator.cs @@ -53,14 +53,14 @@ internal void GenerateColliders(ref ColliderReference colliders) private void GenerateRoundHitObjects(ref ColliderReference colliders) { - var height = _component.PositionZ; - colliders.Add(new CircleCollider(new float2(0), _colliderComponent.HitCircleRadius, height, height + _colliderComponent.HitHeight, + var height = _component.Position.z; + colliders.Add(new CircleCollider(new float2(0), _colliderComponent.HitCircleRadius, 0, height + _colliderComponent.HitHeight, _api.GetColliderInfo(), ColliderType.TriggerCircle), _matrix); } private void GenerateCurvedHitObjects(ref ColliderReference colliders) { - var height = _component.PositionZ; + var height = _component.Position.z; var vVertex = DragPoint.GetRgVertex(_component.DragPoints); var count = vVertex.Length; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs index 5c3f1d944..149614850 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs @@ -37,20 +37,15 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Trigger")] public class TriggerComponent : MainRenderableComponent, - ITriggerComponent, IOnSurfaceComponent + ITriggerComponent { #region Data - private Vector3 _position { + public Vector3 Position { get => transform.localPosition.TranslateToVpx(); set => transform.localPosition = value.TranslateToWorld(); } - public Vector2 Position { - get => _position.XY(); - set => _position = new Vector3(value.x, value.y, _position.z); - } - public float _scale = 1f; public float Scale { @@ -72,12 +67,6 @@ public float Rotation { set => transform.SetLocalYRotation(math.radians(value)); } - [SerializeField] - [TypeRestriction(typeof(ISurfaceComponent), PickerLabel = "Walls & Ramps", UpdateTransforms = true)] - [Tooltip("On which surface this surface is attached to. Updates Z-translation.")] - public MonoBehaviour _surface; - public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; } - [SerializeField] private DragPointData[] _dragPoints; public DragPointData[] DragPoints { get => _dragPoints; set => _dragPoints = value; } @@ -144,8 +133,6 @@ private void Start() public Vector2 Center => Position; // todo remove? public void OnSurfaceUpdated() => UpdateTransforms(); - public float PositionZ => SurfaceHeight(Surface, Position); - public float4x4 TransformationMatrix => transform.worldToLocalMatrix.WorldToLocalTranslateWithinPlayfield(_playfieldToWorld); #endregion @@ -191,8 +178,6 @@ public override IEnumerable SetData(TriggerData data) public override IEnumerable SetReferencedData(TriggerData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) { - Surface = FindComponent(components, data.Surface); - // mesh var meshComponent = GetComponent(); if (meshComponent) { @@ -208,9 +193,8 @@ public override TriggerData CopyDataTo(TriggerData data, string[] materialNames, { // name and transforms data.Name = name; - data.Center = Position.ToVertex2D(); + data.Center = new Vertex2D(Position.x, Position.y); data.Rotation = Rotation; - data.Surface = Surface != null ? Surface.name : string.Empty; // geometry data.DragPoints = DragPoints; @@ -251,7 +235,6 @@ public override void CopyFromObject(GameObject go) Position = triggerComponent.Position; Scale = triggerComponent.Scale; Rotation = triggerComponent.Rotation; - Surface = triggerComponent.Surface; _dragPoints = triggerComponent._dragPoints.Select(dp => dp.Clone()).ToArray(); } else { @@ -311,37 +294,5 @@ internal TriggerState CreateState() } #endregion - - #region Editor Tooling - - public override ItemDataTransformType EditorPositionType => ItemDataTransformType.TwoD; - - public override Vector3 GetEditorPosition() => Surface != null - ? new Vector3(Position.x, Position.y, Surface.Height(Position)) - : new Vector3(Position.x, Position.y, 0); // todo? plus table height? - - public override void SetEditorPosition(Vector3 pos) - { - var newPos = (Vector2)((float3)pos).xy; - if (DragPoints.Length > 0) { - var diff = newPos - Position; - foreach (var pt in DragPoints) { - pt.Center += new Vertex3D(diff.x, diff.y, 0f); - } - } - RebuildMeshes(); - Position = ((float3)pos).xy; - } - - public override ItemDataTransformType EditorRotationType{ - get { - var meshComp = GetComponent(); - return !meshComp || !meshComp.IsCircle ? ItemDataTransformType.None : ItemDataTransformType.OneD; - } - } - public override Vector3 GetEditorRotation() => new Vector3(Rotation, 0f, 0f); - public override void SetEditorRotation(Vector3 rot) => Rotation = ClampDegrees(rot.x); - - #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerMeshComponent.cs index f7641b23c..5c3b44597 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerMeshComponent.cs @@ -16,7 +16,6 @@ // ReSharper disable InconsistentNaming -using System; using UnityEngine; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Table; @@ -44,7 +43,7 @@ public class TriggerMeshComponent : MeshComponent protected override Mesh GetMesh(TriggerData data) => new TriggerMeshGenerator(data) - .GetMesh(MainComponent.PlayfieldHeight) + .GetMesh(0) .TransformToWorld(); protected override PbrMaterial GetMaterial(TriggerData data, Table table)