From cb9708f54690e86ae3fc99dd732f2b7595e927dd Mon Sep 17 00:00:00 2001 From: freezy Date: Tue, 14 Sep 2021 00:05:43 +0200 Subject: [PATCH 1/7] lights: Add light insert generator. --- VisualPinball.Engine/VPT/Light/LightData.cs | 15 ++++ .../VPT/Surface/ISurfaceData.cs | 29 ++++++++ .../VPT/Surface/ISurfaceData.cs.meta | 11 +++ VisualPinball.Engine/VPT/Surface/Surface.cs | 6 +- .../VPT/Surface/SurfaceData.cs | 8 +-- .../VPT/Surface/SurfaceMeshGenerator.cs | 40 +++++------ .../VPT/Light/LightComponent.cs | 49 +++++++++++-- .../VPT/Light/LightInsertMeshComponent.cs | 69 +++++++++++++++++++ .../Light/LightInsertMeshComponent.cs.meta | 11 +++ .../VPT/Surface/SurfaceSideMeshComponent.cs | 2 +- .../VPT/Surface/SurfaceTopMeshComponent.cs | 2 +- 11 files changed, 204 insertions(+), 38 deletions(-) create mode 100644 VisualPinball.Engine/VPT/Surface/ISurfaceData.cs create mode 100644 VisualPinball.Engine/VPT/Surface/ISurfaceData.cs.meta create mode 100644 VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs create mode 100644 VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs.meta diff --git a/VisualPinball.Engine/VPT/Light/LightData.cs b/VisualPinball.Engine/VPT/Light/LightData.cs index 91d12aa55..adfcbd8ea 100644 --- a/VisualPinball.Engine/VPT/Light/LightData.cs +++ b/VisualPinball.Engine/VPT/Light/LightData.cs @@ -26,6 +26,7 @@ using System.IO; using VisualPinball.Engine.IO; using VisualPinball.Engine.Math; +using VisualPinball.Engine.VPT.Surface; using VisualPinball.Engine.VPT.Table; namespace VisualPinball.Engine.VPT.Light @@ -157,4 +158,18 @@ public override void Write(BinaryWriter writer, HashWriter hashWriter) #endregion } + + public class LightInsertData : ISurfaceData + { + public float HeightBottom { get; } + public float HeightTop { get; } + public DragPointData[] DragPoints { get; } + + public LightInsertData(DragPointData[] dragPoints, float height) + { + HeightBottom = -height; + HeightTop = 0f; + DragPoints = dragPoints; + } + } } diff --git a/VisualPinball.Engine/VPT/Surface/ISurfaceData.cs b/VisualPinball.Engine/VPT/Surface/ISurfaceData.cs new file mode 100644 index 000000000..68a8303ff --- /dev/null +++ b/VisualPinball.Engine/VPT/Surface/ISurfaceData.cs @@ -0,0 +1,29 @@ +// Visual Pinball Engine +// Copyright (C) 2021 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using VisualPinball.Engine.Math; + +namespace VisualPinball.Engine.VPT.Surface +{ + public interface ISurfaceData + { + float HeightBottom { get; } + + float HeightTop { get; } + + DragPointData[] DragPoints { get; } + } +} diff --git a/VisualPinball.Engine/VPT/Surface/ISurfaceData.cs.meta b/VisualPinball.Engine/VPT/Surface/ISurfaceData.cs.meta new file mode 100644 index 000000000..24c857d32 --- /dev/null +++ b/VisualPinball.Engine/VPT/Surface/ISurfaceData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 773f46c53f6f1304e8d96cbb1bd0a5e2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Engine/VPT/Surface/Surface.cs b/VisualPinball.Engine/VPT/Surface/Surface.cs index 7efb91282..519357c91 100644 --- a/VisualPinball.Engine/VPT/Surface/Surface.cs +++ b/VisualPinball.Engine/VPT/Surface/Surface.cs @@ -53,14 +53,10 @@ public static Surface GetDefault(Table.Table table) Matrix3D IRenderable.TransformationMatrix(Table.Table table, Origin origin) => Matrix3D.Identity; - public RenderObject GetRenderObject(Table.Table table, string id = null, Origin origin = Origin.Global, bool asRightHanded = true) - { - return _meshGenerator.GetRenderObject(table, id, table.TableHeight, asRightHanded); - } public RenderObjectGroup GetRenderObjects(Table.Table table, Origin origin = Origin.Global, bool asRightHanded = true) { - return _meshGenerator.GetRenderObjects(table, asRightHanded); + return _meshGenerator.GetRenderObjects(table, Data, asRightHanded); } #endregion diff --git a/VisualPinball.Engine/VPT/Surface/SurfaceData.cs b/VisualPinball.Engine/VPT/Surface/SurfaceData.cs index 4bd2bbacf..0da64cdee 100644 --- a/VisualPinball.Engine/VPT/Surface/SurfaceData.cs +++ b/VisualPinball.Engine/VPT/Surface/SurfaceData.cs @@ -31,7 +31,7 @@ namespace VisualPinball.Engine.VPT.Surface { [Serializable] - public class SurfaceData : ItemData + public class SurfaceData : ItemData, ISurfaceData { public override string GetName() => Name; public override void SetName(string name) { Name = name; } @@ -76,10 +76,10 @@ public class SurfaceData : ItemData public string SlingShotMaterial = string.Empty; [BiffFloat("HTBT", Pos = 14)] - public float HeightBottom = 0f; + public float HeightBottom { get; set; } [BiffFloat("HTTP", Pos = 15)] - public float HeightTop = 50f; + public float HeightTop { get; set; } = 50f; [BiffBool("INNR", SkipWrite = true)] public bool Inner = true; @@ -127,7 +127,7 @@ public class SurfaceData : ItemData public bool IsReflectionEnabled = true; [BiffDragPoint("DPNT", TagAll = true, Pos = 2000)] - public DragPointData[] DragPoints; + public DragPointData[] DragPoints { get; set; } [BiffBool("TMON", Pos = 6)] public bool IsTimerEnabled; diff --git a/VisualPinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs b/VisualPinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs index dfde129de..262f62762 100644 --- a/VisualPinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs +++ b/VisualPinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs @@ -27,14 +27,14 @@ public class SurfaceMeshGenerator public const string Side = "Side"; public const string Top = "Top"; - private readonly SurfaceData _data; + private readonly ISurfaceData _data; - public SurfaceMeshGenerator(SurfaceData data) + public SurfaceMeshGenerator(ISurfaceData data) { _data = data; } - public RenderObject GetRenderObject(Table.Table table, string id, float playfieldHeight, bool asRightHanded, Mesh preGeneratedMesh = null) + public RenderObject GetRenderObject(Table.Table table, SurfaceData data, string id, float playfieldHeight, bool asRightHanded, Mesh preGeneratedMesh = null) { var mesh = preGeneratedMesh ?? GenerateMesh(table.Width, table.Height, playfieldHeight, id); switch (id) { @@ -42,15 +42,15 @@ public RenderObject GetRenderObject(Table.Table table, string id, float playfiel return new RenderObject( id, asRightHanded ? mesh.Transform(Matrix3D.RightHanded) : mesh, - new PbrMaterial(table.GetMaterial(_data.SideMaterial), table.GetTexture(_data.SideImage)), - _data.IsSideVisible + new PbrMaterial(table.GetMaterial(data.SideMaterial), table.GetTexture(data.SideImage)), + data.IsSideVisible ); case Top: return new RenderObject( id, asRightHanded ? mesh.Transform(Matrix3D.RightHanded) : mesh, - new PbrMaterial(table.GetMaterial(_data.TopMaterial), table.GetTexture(_data.Image)), - _data.IsTopBottomVisible + new PbrMaterial(table.GetMaterial(data.TopMaterial), table.GetTexture(data.Image)), + data.IsTopBottomVisible ); default: throw new ArgumentException($"Unknown mesh ID \"{id}\"."); @@ -62,19 +62,19 @@ public Mesh GetMesh(float tableWidth, float tableHeight, float playfieldHeight, return GenerateMesh(tableWidth, tableHeight, playfieldHeight, id); } - public RenderObjectGroup GetRenderObjects(Table.Table table, bool asRightHanded = true) + public RenderObjectGroup GetRenderObjects(Table.Table table, SurfaceData data, bool asRightHanded = true) { var renderObjects = new List(); var sideMesh = GenerateSideMesh(table.TableHeight); var topMesh = GenerateTopMesh(table.Width, table.Height, table.TableHeight); if (sideMesh != null) { - renderObjects.Add(GetRenderObject(table, Side, table.TableHeight, asRightHanded, sideMesh)); + renderObjects.Add(GetRenderObject(table, data, Side, table.TableHeight, asRightHanded, sideMesh)); } if (topMesh != null) { - renderObjects.Add(GetRenderObject(table, Top, table.TableHeight, asRightHanded, topMesh)); + renderObjects.Add(GetRenderObject(table, data, Top, table.TableHeight, asRightHanded, topMesh)); } - return new RenderObjectGroup(_data.Name, "Surfaces", Matrix3D.Identity, renderObjects.ToArray()); + return new RenderObjectGroup(data.Name, "Surfaces", Matrix3D.Identity, renderObjects.ToArray()); } private Mesh GenerateMesh(float tableWidth, float tableHeight, float zHeight, string id) @@ -250,19 +250,17 @@ private Mesh GenerateSideMesh(float playfieldHeight) { sideMesh.Vertices[offset + 3].Y = pv2.Y; sideMesh.Vertices[offset + 3].Z = bottom; - if (_data.SideImage != null) { - sideMesh.Vertices[offset].Tu = rgTexCoord[i]; - sideMesh.Vertices[offset].Tv = 1.0f; + sideMesh.Vertices[offset].Tu = rgTexCoord[i]; + sideMesh.Vertices[offset].Tv = 1.0f; - sideMesh.Vertices[offset + 1].Tu = rgTexCoord[i]; - sideMesh.Vertices[offset + 1].Tv = 0f; + sideMesh.Vertices[offset + 1].Tu = rgTexCoord[i]; + sideMesh.Vertices[offset + 1].Tv = 0f; - sideMesh.Vertices[offset + 2].Tu = rgTexCoord[c]; - sideMesh.Vertices[offset + 2].Tv = 0f; + sideMesh.Vertices[offset + 2].Tu = rgTexCoord[c]; + sideMesh.Vertices[offset + 2].Tv = 0f; - sideMesh.Vertices[offset + 3].Tu = rgTexCoord[c]; - sideMesh.Vertices[offset + 3].Tv = 1.0f; - } + sideMesh.Vertices[offset + 3].Tu = rgTexCoord[c]; + sideMesh.Vertices[offset + 3].Tv = 1.0f; sideMesh.Vertices[offset].Nx = vNormal[0].X; sideMesh.Vertices[offset].Ny = -vNormal[0].Y; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs index 9fb6582e4..365600df1 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs @@ -106,6 +106,9 @@ public override void UpdateTransforms() // bulb size foreach (var mf in GetComponentsInChildren(true)) { + if (!mf.sharedMesh) { + continue; + } switch (mf.sharedMesh.name) { case BulbMeshName: case SocketMeshName: @@ -113,6 +116,14 @@ public override void UpdateTransforms() break; } } + + // insert mesh position + var insertMeshComponent = GetComponentInChildren(); + if (insertMeshComponent) { + var t = insertMeshComponent.transform; + var pos = t.localPosition; + t.localPosition = new Vector3(-Position.x, -Position.y, insertMeshComponent.PositionZ); + } } #endregion @@ -220,9 +231,26 @@ public override IEnumerable SetData(LightData data) RenderPipeline.Current.LightConverter.UpdateLight(unityLight, data); } + // insert mesh + var insertMeshComponent = GetComponentInChildren(); + if (insertMeshComponent) { + insertMeshComponent.DragPoints = data.DragPoints; + } + + return updatedComponents; + } + + + 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()) { + if (!mf.sharedMesh) { + continue; + } switch (mf.sharedMesh.name) { case BulbMeshName: case SocketMeshName: @@ -232,13 +260,16 @@ public override IEnumerable SetData(LightData data) } } - return updatedComponents; - } - + // insert mesh + var insertMeshComponent = GetComponentInChildren(); + if (insertMeshComponent) { + if (!data.ShowBulbMesh && data.OffImage == table.Data.Image) { + insertMeshComponent.CreateMesh(data, table, textureProvider, materialProvider); + } else { + insertMeshComponent.gameObject.SetActive(false); + } + } - public override IEnumerable SetReferencedData(LightData data, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider, Dictionary components) - { - Surface = FindComponent(components, data.Surface); return Array.Empty(); } @@ -257,6 +288,12 @@ public override LightData CopyDataTo(LightData data, string[] materialNames, str data.FadeSpeedUp = FadeSpeedUp; data.FadeSpeedDown = FadeSpeedDown; + // insert mesh + var insertMeshComponent = GetComponentInChildren(); + if (insertMeshComponent) { + data.DragPoints = insertMeshComponent.DragPoints; + } + // visibility data.ShowBulbMesh = false; foreach (var mf in GetComponentsInChildren(true)) { diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs new file mode 100644 index 000000000..f4f5a0214 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs @@ -0,0 +1,69 @@ +// Visual Pinball Engine +// Copyright (C) 2021 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 InconsistentNaming + +using System; +using System.Collections.Generic; +using UnityEngine; +using VisualPinball.Engine.Game; +using VisualPinball.Engine.Math; +using VisualPinball.Engine.VPT; +using VisualPinball.Engine.VPT.Light; +using VisualPinball.Engine.VPT.Surface; +using VisualPinball.Engine.VPT.Table; +using Mesh = VisualPinball.Engine.VPT.Mesh; + +namespace VisualPinball.Unity +{ + public class LightInsertMeshComponent : MeshComponent + { + #region Data + + public float InsertHeight = 20f; + + public float PositionZ; + + [SerializeField] + private DragPointData[] _dragPoints; + public DragPointData[] DragPoints { get => _dragPoints; set => _dragPoints = value; } + + #endregion + + public const string InsertObjectName = "Insert"; + + public override IEnumerable ValidParents => Type.EmptyTypes; + + protected override RenderObject GetRenderObject(LightData data, Table table) + { + return new RenderObject( + InsertObjectName, + GetMesh(data), + new PbrMaterial(table.GetMaterial(table.Data.PlayfieldMaterial), table.GetTexture(table.Data.Image)), + false + ); + } + + protected override Mesh GetMesh(LightData data) + { + var playfieldComponent = GetComponentInParent(); + var meshGen = new SurfaceMeshGenerator(new LightInsertData(_dragPoints, InsertHeight)); + var topMesh = meshGen.GetMesh(playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, SurfaceMeshGenerator.Top); + var sideMesh = meshGen.GetMesh(playfieldComponent.Width, playfieldComponent.Height, playfieldComponent.PlayfieldHeight, SurfaceMeshGenerator.Side); + return topMesh.Merge(sideMesh); + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs.meta new file mode 100644 index 000000000..e474107e9 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e2a11a120b7da4b4db6fd330516311db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs index 732eb5b1c..e747f627d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs @@ -34,7 +34,7 @@ public class SurfaceSideMeshComponent : MeshComponent Date: Tue, 14 Sep 2021 21:37:49 +0200 Subject: [PATCH 2/7] light: Add insert light inspector. --- .../VPT/Light/LightInsertMeshInspector.cs | 56 +++++++++++++++++++ .../Light/LightInsertMeshInspector.cs.meta | 11 ++++ .../VPT/Light/LightComponent.cs | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs create mode 100644 VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs.meta diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs new file mode 100644 index 000000000..0d53d54aa --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs @@ -0,0 +1,56 @@ +// Visual Pinball Engine +// Copyright (C) 2021 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 AssignmentInConditionalExpression + +using UnityEditor; +using VisualPinball.Engine.VPT.Light; + +namespace VisualPinball.Unity.Editor +{ + [CustomEditor(typeof(LightInsertMeshComponent)), CanEditMultipleObjects] + public class LightInsertMeshInspector : MeshInspector + { + private SerializedProperty _insertHeightProperty; + private SerializedProperty _positionZProperty; + + protected override void OnEnable() + { + base.OnEnable(); + + _insertHeightProperty = serializedObject.FindProperty(nameof(LightInsertMeshComponent.InsertHeight)); + _positionZProperty = serializedObject.FindProperty(nameof(LightInsertMeshComponent.PositionZ)); + } + + public override void OnInspectorGUI() + { + if (HasErrors()) { + return; + } + + BeginEditing(); + + OnPreInspectorGUI(); + + PropertyField(_insertHeightProperty, rebuildMesh: true); + PropertyField(_positionZProperty, updateTransforms: true); + + base.OnInspectorGUI(); + + EndEditing(); + } + } +} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs.meta b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs.meta new file mode 100644 index 000000000..ed94a7c81 --- /dev/null +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49b9e1f6ce5e90e4f876450638683c97 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs index 365600df1..a7c1d587c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightComponent.cs @@ -263,7 +263,7 @@ public override IEnumerable SetReferencedData(LightData data, Tab // insert mesh var insertMeshComponent = GetComponentInChildren(); if (insertMeshComponent) { - if (!data.ShowBulbMesh && data.OffImage == table.Data.Image) { + if (!data.ShowBulbMesh && string.Equals(data.OffImage, table.Data.Image, StringComparison.OrdinalIgnoreCase)) { insertMeshComponent.CreateMesh(data, table, textureProvider, materialProvider); } else { insertMeshComponent.gameObject.SetActive(false); From 259d1da73ce695ebdf346a9ef5b624666bcecd7a Mon Sep 17 00:00:00 2001 From: freezy Date: Tue, 14 Sep 2021 21:45:07 +0200 Subject: [PATCH 3/7] light: Add insert icon. --- .../Editor/Icons/small_blue/light_insert.png | Bin 0 -> 644 bytes .../Icons/small_blue/light_insert.png.meta | 108 ++++++++++++++++++ .../Editor/Icons/small_gray/light_insert.png | Bin 0 -> 647 bytes .../Icons/small_gray/light_insert.png.meta | 108 ++++++++++++++++++ .../Editor/Icons/small_green/light_insert.png | Bin 0 -> 647 bytes .../Icons/small_green/light_insert.png.meta | 108 ++++++++++++++++++ .../Icons/small_orange/light_insert.png | Bin 0 -> 650 bytes .../Icons/small_orange/light_insert.png.meta | 108 ++++++++++++++++++ .../Light/LightInsertMeshComponent.cs.meta | 2 +- 9 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_blue/light_insert.png create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_blue/light_insert.png.meta create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_gray/light_insert.png create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_gray/light_insert.png.meta create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_green/light_insert.png create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_green/light_insert.png.meta create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_orange/light_insert.png create mode 100644 VisualPinball.Unity/Assets/Editor/Icons/small_orange/light_insert.png.meta diff --git a/VisualPinball.Unity/Assets/Editor/Icons/small_blue/light_insert.png b/VisualPinball.Unity/Assets/Editor/Icons/small_blue/light_insert.png new file mode 100644 index 0000000000000000000000000000000000000000..93b550845f4958c924d169b9d73fd98277767c49 GIT binary patch literal 644 zcmV-~0(1ZrZkLE*L%7}4blF-=aJNk%gvpqrBwpmG`rgvY`9%+ z*>|^5s1=uBV?XJrLskmF2J>u6dQyk1id5Z4@;f`WW7<0&kMI}Nmu9rC7~znfR}_>0 z*EpnMr7fBPz=TF7IkC9w&!rovv<9L1tShDfFb05?(Q0!}2XM6nrOGnJPJPLYL4| zxzslBKzC%wEB_OjVkSr(z8-vJkL>{YFttcdLQD23nh3B;e>VUtt zigm>|MlyYDUATSTD9T@B48ZNtrn0WU1)poLC0Q#)k_jJkVam13fl_eXd2S6UnRk|y zMLG9g6(|RD9iWWcONqE&!lEfr-5GR17Fh?9`IgEicfd%2h(2Rofv2V?&#hDG?vq7A z6=y<~DKvS^?WI`vTUU&kk3qKSz-TqIuGj^t&cYeRs&!}DI+z-`y;P^@?-KR17VlgHG9 zU<<5`R`a%NC4p8OF{4$l?P8VrFk_S_`&mlE7u6dJ=~$<$(1lWLX00VGTMn36!N}S}*2&(dzB31X1{LYT;nD&mxBm4y^X+~QXLmblcih>g0 z3WqeTv_&%j7}LlkCl+`8xpV`SR^KF-@6B(C#CYfXL6aiG;ggIHLt41(qW@EGF-f_$%C^1kD(OtqXirb}q4 zTxuIQAV0M-=@!+>?8rJBx-=kg3CJu3k_Ba8Ll8NRz+?5Q6@&yX>g%wy@Vv1=6Y$qo zv1Rd%kxU=k6mFk4it^VG18{pZRkkc}!RN+nQPzr)WWvW>7<27%pcEW;j#~pt=A9*F zQO>`6ds!y%OtwTNWecV~}my*UHRnS!_L3XRVc4FaRmZ96_9O;i-$Np9^+})vHrw zq7RI*C~B{jY2BH&4yFXRSLzh~U7~*0;+>0thK_PBT?AD8XB$pkK%L#<8QwXmYt+vZ zw!lg&GjF?A6llE>)5`SPE>@clGe&i?pT#tcLDxIFMG4{lzNZn@inE}umR1OK-Ry2d zuwKyAzB@&}R-A(k{iGufS;+(I&9gD-NgT401J*B$de>MUCd1`nlKJjSkL6*Kb94UR h|B9STH&9Ulzz?ThTk=)~8At#C002ovPDHLkV1f~mB?ABe literal 0 HcmV?d00001 diff --git a/VisualPinball.Unity/Assets/Editor/Icons/small_green/light_insert.png.meta b/VisualPinball.Unity/Assets/Editor/Icons/small_green/light_insert.png.meta new file mode 100644 index 000000000..5eaccbcf3 --- /dev/null +++ b/VisualPinball.Unity/Assets/Editor/Icons/small_green/light_insert.png.meta @@ -0,0 +1,108 @@ +fileFormatVersion: 2 +guid: 981d6f1141a86b74ebbd6117c85083d5 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 2 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 64 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 64 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/VisualPinball.Unity/Assets/Editor/Icons/small_orange/light_insert.png b/VisualPinball.Unity/Assets/Editor/Icons/small_orange/light_insert.png new file mode 100644 index 0000000000000000000000000000000000000000..5c8e50a4da2d261535907d10d83fd757d5c735f2 GIT binary patch literal 650 zcmV;50(Jd~P)2!j>puRMt&C?MM>3Ky# z32===8dln(2>?uJB$5-0yS^*kK&3VC&1ds;1^{CKSSf8bT|(GAeV{$PQ`&sEp5ZKt zpf41`v4ODzfFu2Vh=jy-zG$tP?>P>%SZEjvtF%GT3;-Tuyg-oerAyv-yp^ex6DM>D zEtN@a0|(@%(x$#el{N>m&Xz6>30wj)sRPM^GO!_t3`gLxa@7h#0vGjVSXy{dS)dB| zYpd8i{l-Y9kF5%~&l^SgYls23Jz7^bPjSKL%4<>9ijic($6Oe5?Q)ER?*)k>gNsKxd>?JDCg2eK*fKy;nW7y*)4YP&RK1v zeo4-xX^1yoYY)pC*hb-iP^$VlkHTKKtXuq5$zWdT+zno^= kod5T~B3 Date: Tue, 14 Sep 2021 22:13:10 +0200 Subject: [PATCH 4/7] light: Move insert mesh up to avoid z-fighting. --- .../VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs index f4f5a0214..b13ecbb7c 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs @@ -35,7 +35,7 @@ public class LightInsertMeshComponent : MeshComponent public float InsertHeight = 20f; - public float PositionZ; + public float PositionZ = 0.1f; [SerializeField] private DragPointData[] _dragPoints; From b2a0808890658c72640cd57061d906e7ebfd581f Mon Sep 17 00:00:00 2001 From: freezy Date: Wed, 15 Sep 2021 00:23:15 +0200 Subject: [PATCH 5/7] dragpoints: Remove drag points logic from class hierarchy and use it as helper. --- .../DragPoint/ControlPoint.cs | 2 +- .../DragPoint/DragPointsHandler.cs | 59 +++---- ...pector.cs => DragPointsInspectorHelper.cs} | 165 ++++++++---------- ...meta => DragPointsInspectorHelper.cs.meta} | 2 +- .../DragPoint/DragPointsSceneViewHandler.cs | 8 +- .../VPT/ItemInspector.cs | 2 +- .../VPT/Light/LightInsertMeshInspector.cs | 36 +++- .../VPT/MainInspector.cs | 2 +- .../VPT/Ramp/RampInspector.cs | 34 +++- .../VPT/Rubber/RubberInspector.cs | 34 +++- .../VPT/Surface/SurfaceInspector.cs | 34 +++- .../VPT/Trigger/TriggerInspector.cs | 39 ++++- ...ntsEditable.cs => IDragPointsInspector.cs} | 15 +- ...e.cs.meta => IDragPointsInspector.cs.meta} | 2 +- .../VPT/Light/LightInsertMeshComponent.cs | 2 + .../VPT/Ramp/RampComponent.cs | 4 +- .../VPT/Rubber/RubberComponent.cs | 4 +- .../VPT/Surface/SurfaceComponent.cs | 4 +- .../VPT/Trigger/TriggerComponent.cs | 9 +- 19 files changed, 274 insertions(+), 183 deletions(-) rename VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/{DragPointsItemInspector.cs => DragPointsInspectorHelper.cs} (56%) rename VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/{DragPointsItemInspector.cs.meta => DragPointsInspectorHelper.cs.meta} (83%) rename VisualPinball.Unity/VisualPinball.Unity/VPT/{IDragPointsEditable.cs => IDragPointsInspector.cs} (88%) rename VisualPinball.Unity/VisualPinball.Unity/VPT/{IDragPointsEditable.cs.meta => IDragPointsInspector.cs.meta} (83%) diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/ControlPoint.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/ControlPoint.cs index 92a9b7b64..76ac7e70d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/ControlPoint.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/ControlPoint.cs @@ -75,7 +75,7 @@ public ControlPoint(DragPointData dp, int controlId, int idx, float indexRatio) IndexRatio = indexRatio; } - public void UpdateDragPoint(IDragPointsEditable editable, Transform transform) + public void UpdateDragPoint(IDragPointsInspector editable, Transform transform) { var dragpointPos = transform.worldToLocalMatrix.MultiplyPoint(WorldPos); dragpointPos -= editable.EditableOffset; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs index 944f3b52c..a36e084e5 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs @@ -31,12 +31,12 @@ public class DragPointsHandler /// /// Component /// - public IMainRenderableComponent Editable { get; private set; } + public IMainRenderableComponent MainComponent { get; private set; } /// /// Component item as IDragPointsEditable /// - public IDragPointsEditable DragPointEditable { get; private set; } + public IDragPointsInspector DragPointInspector { get; private set; } /// /// Transform component of the game object @@ -83,20 +83,15 @@ public class DragPointsHandler /// /// Every DragPointsInspector instantiates this to manage its curve handling. /// - /// - /// + /// The renderable main component, to retrieve IsLocked. + /// /// - public DragPointsHandler(Object target, IDragPointsEditable dragPointsEditable) + public DragPointsHandler(IMainRenderableComponent mainComponent, IDragPointsInspector dragPointsInspector) { - Editable = target as IMainRenderableComponent - ?? throw new ArgumentException("Target must extend `IItemMainRenderableComponent`."); + MainComponent = mainComponent; + DragPointInspector = dragPointsInspector; - DragPointEditable = dragPointsEditable; - - if (!(target is Behaviour)) { - throw new ArgumentException("Target must extend `Behavior`."); - } - Transform = (target as Behaviour).transform; + Transform = mainComponent.gameObject.transform; _sceneViewHandler = new DragPointsSceneViewHandler(this){ CurveWidth = 10.0f, @@ -114,13 +109,13 @@ public DragPointsHandler(Object target, IDragPointsEditable dragPointsEditable) public bool RemapControlPoints() { // if count differs, rebuild - if (ControlPoints.Count != DragPointEditable.DragPoints.Length) { + if (ControlPoints.Count != DragPointInspector.DragPoints.Length) { RebuildControlPoints(); return true; } - for (var i = 0; i < DragPointEditable.DragPoints.Length; ++i) { - ControlPoints[i].DragPoint = DragPointEditable.DragPoints[i]; + for (var i = 0; i < DragPointInspector.DragPoints.Length; ++i) { + ControlPoints[i].DragPoint = DragPointInspector.DragPoints[i]; } return false; @@ -140,23 +135,23 @@ public void AddDragPointOnTraveller() return; } - var dragPoint = new DragPointData(DragPointEditable.DragPoints[CurveTravellerControlPointIdx]) { + var dragPoint = new DragPointData(DragPointInspector.DragPoints[CurveTravellerControlPointIdx]) { IsLocked = false }; var newIdx = CurveTravellerControlPointIdx + 1; - float ratio = (float)newIdx / DragPointEditable.DragPoints.Length; + float ratio = (float)newIdx / DragPointInspector.DragPoints.Length; var dragPointPosition = Transform.worldToLocalMatrix.MultiplyPoint(CurveTravellerPosition); - dragPointPosition -= DragPointEditable.EditableOffset; - dragPointPosition -= DragPointEditable.GetDragPointOffset(ratio); + dragPointPosition -= DragPointInspector.EditableOffset; + dragPointPosition -= DragPointInspector.GetDragPointOffset(ratio); dragPoint.Center = dragPointPosition.ToVertex3D(); - var dragPoints = DragPointEditable.DragPoints.ToList(); + var dragPoints = DragPointInspector.DragPoints.ToList(); dragPoints.Insert(newIdx, dragPoint); - DragPointEditable.DragPoints = dragPoints.ToArray(); + DragPointInspector.DragPoints = dragPoints.ToArray(); ControlPoints.Insert(newIdx, new ControlPoint( - DragPointEditable.DragPoints[newIdx], + DragPointInspector.DragPoints[newIdx], GUIUtility.GetControlID(FocusType.Passive), newIdx, ratio @@ -181,9 +176,9 @@ public void RemoveDragPoint(int controlId) if (!removalOk) { return; } - var dragPoints = DragPointEditable.DragPoints.ToList(); + var dragPoints = DragPointInspector.DragPoints.ToList(); dragPoints.RemoveAt(idx); - DragPointEditable.DragPoints = dragPoints.ToArray(); + DragPointInspector.DragPoints = dragPoints.ToArray(); RebuildControlPoints(); } @@ -198,7 +193,7 @@ public void FlipDragPoints(FlipAxis flipAxis) ? _flipAxis.x : flipAxis == FlipAxis.Y ? _flipAxis.y : _flipAxis.z; - var offset = DragPointEditable.EditableOffset; + var offset = DragPointInspector.EditableOffset; var wlMat = Transform.worldToLocalMatrix; foreach (var controlPoint in ControlPoints) { @@ -222,7 +217,7 @@ public void FlipDragPoints(FlipAxis flipAxis) default: throw new ArgumentOutOfRangeException(nameof(flipAxis), flipAxis, null); } - controlPoint.UpdateDragPoint(DragPointEditable, Transform); + controlPoint.UpdateDragPoint(DragPointInspector, Transform); } } @@ -250,7 +245,7 @@ public bool UpdateDragPointsLock(bool itemLock) private void RebuildControlPoints() { ControlPoints.Clear(); - var dragPoints = DragPointEditable.DragPoints; + var dragPoints = DragPointInspector.DragPoints; for (var i = 0; i < dragPoints.Length; ++i) { var cp = new ControlPoint( dragPoints[i], @@ -309,13 +304,13 @@ public void OnSceneGUI(Event evt, OnDragPointPositionChange onChange = null) parentRot = Transform.parent.transform.rotation; } EditorGUI.BeginChangeCheck(); - var newHandlePos = HandlesUtils.HandlePosition(_positionHandlePosition, DragPointEditable.HandleType, parentRot); + var newHandlePos = HandlesUtils.HandlePosition(_positionHandlePosition, DragPointInspector.HandleType, parentRot); if (EditorGUI.EndChangeCheck()) { onChange?.Invoke(newHandlePos); var deltaPosition = newHandlePos - _positionHandlePosition; foreach (var controlPoint in SelectedControlPoints) { controlPoint.WorldPos += deltaPosition; - controlPoint.UpdateDragPoint(DragPointEditable, Transform); + controlPoint.UpdateDragPoint(DragPointInspector, Transform); } } } @@ -332,8 +327,8 @@ private void InitSceneGui() //Setup Screen positions & controlID for control points (in case of modification of drag points coordinates outside) foreach (var controlPoint in ControlPoints) { controlPoint.WorldPos = controlPoint.DragPoint.Center.ToUnityVector3(); - controlPoint.WorldPos += DragPointEditable.EditableOffset; - controlPoint.WorldPos += DragPointEditable.GetDragPointOffset(controlPoint.IndexRatio); + controlPoint.WorldPos += DragPointInspector.EditableOffset; + controlPoint.WorldPos += DragPointInspector.GetDragPointOffset(controlPoint.IndexRatio); controlPoint.WorldPos = Transform.localToWorldMatrix.MultiplyPoint(controlPoint.WorldPos); _flipAxis += controlPoint.WorldPos; controlPoint.LocalPos = Handles.matrix.MultiplyPoint(controlPoint.WorldPos); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsItemInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs similarity index 56% rename from VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsItemInspector.cs rename to VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs index 7e52703ff..80c87e340 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsItemInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs @@ -14,28 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -using System.Collections.Generic; +using System; +using System.Collections; using System.Linq; using UnityEditor; -using UnityEditor.SceneManagement; using UnityEngine; using VisualPinball.Engine.Math; -using VisualPinball.Engine.VPT; namespace VisualPinball.Unity.Editor { - public abstract class DragPointsInspector - : MainInspector, - IDragPointsItemInspector, IDragPointsEditable - where TData : ItemData - where TMainComponent : MainRenderableComponent + public class DragPointsInspectorHelper : IDragPointsItemInspector { /// /// Catmull Curve Handler /// public DragPointsHandler DragPointsHandler { get; private set; } - private bool EditingEnabled => _dragPointsComponent.DragPointsActive && Selection.count == 1 && target is MonoBehaviour mb && Selection.activeGameObject == mb.gameObject; + private bool EditingEnabled => _dragPointsInspector.DragPointsActive; /// /// If true, a list of the drag points is displayed in the inspector. @@ -51,27 +46,33 @@ public abstract class DragPointsInspector /// private static Vector3 _storedControlPoint = Vector3.zero; - private IMainRenderableComponent _renderable; - private IDragPointsComponent _dragPointsComponent; + private readonly MonoBehaviour _mb; + private readonly IMainRenderableComponent _mainComponent; + private readonly IDragPointsInspector _dragPointsInspector; + private readonly PlayfieldComponent _playfieldComponent; + + public DragPointsInspectorHelper(IMainRenderableComponent mainComponent, IDragPointsInspector dragPointsInspector) + { + _mb = mainComponent as MonoBehaviour; + _mainComponent = mainComponent; + _dragPointsInspector = dragPointsInspector; + _playfieldComponent = mainComponent.gameObject.GetComponentInParent();; + DragPointsHandler = new DragPointsHandler(mainComponent, _dragPointsInspector); + } public void RebuildMeshes() { - _renderable.RebuildMeshes(); - WalkChildren(PlayfieldComponent.transform, UpdateSurfaceReferences); + _mainComponent.RebuildMeshes(); + WalkChildren(_playfieldComponent.transform, UpdateSurfaceReferences); } - protected override void OnEnable() + public void OnEnable() { - base.OnEnable(); - _dragPointsComponent = MainComponent as IDragPointsComponent; - _renderable = target as IMainRenderableComponent; - DragPointsHandler = new DragPointsHandler(target, this); Undo.undoRedoPerformed += OnUndoRedoPerformed; } - protected override void OnDisable() + public void OnDisable() { - base.OnDisable(); DragPointsHandler = null; Undo.undoRedoPerformed -= OnUndoRedoPerformed; } @@ -117,7 +118,7 @@ public void PasteDragPoint(int controlId) /// True if game item is locked, false otherwise. public bool IsItemLocked() { - return !(target is IMainRenderableComponent editable) || editable.IsLocked; + return _mainComponent.IsLocked; } /// @@ -127,10 +128,7 @@ public bool IsItemLocked() /// True if exposed, false otherwise. public bool HasDragPointExposure(DragPointExposure exposure) { - if (!(target is IDragPointsEditable editable)) { - return false; - } - return editable.DragPointExposition.Contains(exposure); + return _dragPointsInspector.DragPointExposition.Contains(exposure); } /// @@ -139,11 +137,7 @@ public bool HasDragPointExposure(DragPointExposure exposure) /// Axis to flip on public void FlipDragPoints(FlipAxis flipAxis) { - if (!(target is IDragPointsEditable editable)) { - return; - } - - if (editable.HandleType != ItemDataTransformType.ThreeD && flipAxis == FlipAxis.Z) { + if (_dragPointsInspector.HandleType != ItemDataTransformType.ThreeD && flipAxis == FlipAxis.Z) { return; } @@ -189,63 +183,51 @@ public void RemoveDragPoint(int controlId) /// Message to appear in the UNDO menu public void PrepareUndo(string message) { - Undo.RecordObjects(new []{this, target}, message); + Undo.RecordObject(_mb, message); } - public override void OnInspectorGUI() + public void OnInspectorGUI(ItemInspector inspector) { - if (!(target is IMainRenderableComponent editable)) { - base.OnInspectorGUI(); + if (_mainComponent.IsLocked) { + EditorGUILayout.LabelField("Drag Points are Locked"); return; } - // var editButtonText = dragPointEditable.DragPointEditEnabled ? "Stop Editing Drag Points" : "Edit Drag Points"; - // if (GUILayout.Button(editButtonText)) { - // dragPointEditable.DragPointEditEnabled = !dragPointEditable.DragPointEditEnabled; - // SceneView.RepaintAll(); - // } - - if (editable.IsLocked) { - EditorGUILayout.LabelField("Drag Points are Locked"); - - } else { - _foldoutControlPoints = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutControlPoints, "Drag Points"); - if (_foldoutControlPoints) { + _foldoutControlPoints = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutControlPoints, "Drag Points"); + if (_foldoutControlPoints) { + EditorGUI.indentLevel++; + for (var i = 0; i < DragPointsHandler.ControlPoints.Count; ++i) { + var controlPoint = DragPointsHandler.ControlPoints[i]; + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField($"#{i} ({controlPoint.DragPoint.Center.X},{controlPoint.DragPoint.Center.Y},{controlPoint.DragPoint.Center.Z})"); + if (GUILayout.Button("Copy")) { + CopyDragPoint(controlPoint.ControlId); + } + else if (GUILayout.Button("Paste")) { + PasteDragPoint(controlPoint.ControlId); + } + EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; - for (var i = 0; i < DragPointsHandler.ControlPoints.Count; ++i) { - var controlPoint = DragPointsHandler.ControlPoints[i]; - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField($"#{i} ({controlPoint.DragPoint.Center.X},{controlPoint.DragPoint.Center.Y},{controlPoint.DragPoint.Center.Z})"); - if (GUILayout.Button("Copy")) { - CopyDragPoint(controlPoint.ControlId); - } - else if (GUILayout.Button("Paste")) { - PasteDragPoint(controlPoint.ControlId); - } - EditorGUILayout.EndHorizontal(); - EditorGUI.indentLevel++; - if (HasDragPointExposure(DragPointExposure.SlingShot)) { - ItemDataField("Slingshot", ref controlPoint.DragPoint.IsSlingshot); - } - if (HasDragPointExposure(DragPointExposure.Smooth)) { - ItemDataField("Smooth", ref controlPoint.DragPoint.IsSmooth); - } - if (HasDragPointExposure(DragPointExposure.Texture)) { - ItemDataField("Has AutoTexture", ref controlPoint.DragPoint.HasAutoTexture); - ItemDataSlider("Texture Coord", ref controlPoint.DragPoint.TextureCoord, 0.0f, 1.0f); - } - EditorGUI.indentLevel--; + if (HasDragPointExposure(DragPointExposure.SlingShot)) { + inspector.ItemDataField("Slingshot", ref controlPoint.DragPoint.IsSlingshot); + } + if (HasDragPointExposure(DragPointExposure.Smooth)) { + inspector.ItemDataField("Smooth", ref controlPoint.DragPoint.IsSmooth); + } + if (HasDragPointExposure(DragPointExposure.Texture)) { + inspector.ItemDataField("Has AutoTexture", ref controlPoint.DragPoint.HasAutoTexture); + inspector.ItemDataSlider("Texture Coord", ref controlPoint.DragPoint.TextureCoord, 0.0f, 1.0f); } EditorGUI.indentLevel--; } - EditorGUILayout.EndFoldoutHeaderGroup(); + EditorGUI.indentLevel--; } - base.OnInspectorGUI(); + EditorGUILayout.EndFoldoutHeaderGroup(); } private void UpdateDragPointsLock() { - if (target is IMainRenderableComponent editable && DragPointsHandler.UpdateDragPointsLock(editable.IsLocked)) { + if (DragPointsHandler.UpdateDragPointsLock(_mainComponent.IsLocked)) { HandleUtility.Repaint(); } } @@ -259,15 +241,12 @@ private void OnDragPointPositionChange(Vector3 newPos) private void OnUndoRedoPerformed() { RemapControlPoints(); - WalkChildren(PlayfieldComponent.transform, UpdateSurfaceReferences); + WalkChildren(_playfieldComponent.transform, UpdateSurfaceReferences); } - protected virtual void OnSceneGUI() + public void OnSceneGUI(ItemInspector inspector) { - var editable = target as IMainRenderableComponent; - var bh = target as Behaviour; - - if (editable == null || bh == null || !EditingEnabled) { + if (!EditingEnabled) { return; } @@ -281,30 +260,32 @@ protected virtual void OnSceneGUI() var nearestControlPoint = DragPointsHandler.ControlPoints.Find(cp => cp.ControlId == HandleUtility.nearestControl); if (nearestControlPoint != null) { - var command = new MenuCommand(this, nearestControlPoint.ControlId); + var command = new MenuCommand(inspector, nearestControlPoint.ControlId); EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), DragPointMenuItems.ControlPointsMenuPath, command); Event.current.Use(); } else if (DragPointsHandler.CurveTravellerVisible && HandleUtility.nearestControl == DragPointsHandler.CurveTravellerControlId) { - var command = new MenuCommand(this, 0); + var command = new MenuCommand(inspector, 0); EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), DragPointMenuItems.CurveTravellerMenuPath, command); Event.current.Use(); } } } - public DragPointData[] DragPoints { - get => _dragPointsComponent.DragPoints; - set { - _dragPointsComponent.DragPoints = value; - EditorUtility.SetDirty(MainComponent.gameObject); - PrefabUtility.RecordPrefabInstancePropertyModifications(MainComponent); - EditorSceneManager.MarkSceneDirty(MainComponent.gameObject.scene); + private static void WalkChildren(IEnumerable node, Action action) + { + foreach (Transform childTransform in node) { + action(childTransform); + WalkChildren(childTransform, action); } } - public abstract Vector3 EditableOffset { get; } - public abstract Vector3 GetDragPointOffset(float ratio); - public abstract bool PointsAreLooping { get; } - public abstract IEnumerable DragPointExposition { get; } - public abstract ItemDataTransformType HandleType { get; } + + 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/DragPointsItemInspector.cs.meta b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsItemInspector.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs.meta index be17b5482..f2b666b5f 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsItemInspector.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4411ffe564a0415498413d31bc69924d +guid: 8f2c609845b713246b88a786eaf768dc MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs index 84f54d929..3fa0fd818 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsSceneViewHandler.cs @@ -89,7 +89,7 @@ private void DisplayCurve() var accuracy = Mathf.Abs(vAccuracy.x * vAccuracy.y * vAccuracy.z); accuracy *= HandleUtility.GetHandleSize(_handler.CurveTravellerPosition) * ControlPoint.ScreenRadius; var vVertex = DragPoint.GetRgVertex( - transformedDPoints.ToArray(), _handler.DragPointEditable.PointsAreLooping, accuracy + transformedDPoints.ToArray(), _handler.DragPointInspector.PointsAreLooping, accuracy ); if (vVertex.Length > 0) { @@ -108,7 +108,7 @@ private void DisplayCurve() } // close loop if needed - if (_handler.DragPointEditable.PointsAreLooping) { + if (_handler.DragPointInspector.PointsAreLooping) { controlPointsSegments[_handler.ControlPoints.Count - 1].Add(controlPointsSegments[0][0]); } @@ -149,7 +149,7 @@ private void DisplayCurve() foreach (var controlPoint in _handler.ControlPoints) { var segments = controlPointsSegments[controlPoint.Index].ToArray(); if (segments.Length > 1) { - Handles.color = _handler.DragPointEditable.DragPointExposition.Contains(DragPointExposure.SlingShot) && controlPoint.DragPoint.IsSlingshot ? CurveSlingShotColor : CurveColor; + Handles.color = _handler.DragPointInspector.DragPointExposition.Contains(DragPointExposure.SlingShot) && controlPoint.DragPoint.IsSlingshot ? CurveSlingShotColor : CurveColor; Handles.DrawAAPolyLine(CurveWidth, segments); var closestToPath = HandleUtility.ClosestPointToPolyLine(segments); var dist = (closestToPath - _handler.CurveTravellerPosition).magnitude; @@ -195,7 +195,7 @@ private void DisplayControlPoints() distToCPoint = Mathf.Min(distToCPoint, dist); } - if (!_handler.Editable.IsLocked) { + if (!_handler.MainComponent.IsLocked) { // curve traveller is not overlapping a control point, we can draw it. if (distToCPoint > HandleUtility.GetHandleSize(_handler.CurveTravellerPosition) * ControlPoint.ScreenRadius) { Handles.color = Color.grey; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs index 826da254a..9418e99b6 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ItemInspector.cs @@ -260,7 +260,7 @@ public void ItemDataSlider(string label, ref float field, float leftVal, float r } } - protected void ItemDataField(string label, ref bool field, bool dirtyMesh = true, Action onChanged = null) + public void ItemDataField(string label, ref bool field, bool dirtyMesh = true, Action onChanged = null) { EditorGUI.BeginChangeCheck(); var val = EditorGUILayout.Toggle(label, field); diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs index 0d53d54aa..109ccf9bf 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs @@ -16,25 +16,41 @@ // ReSharper disable AssignmentInConditionalExpression +using System.Collections.Generic; using UnityEditor; +using UnityEngine; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT.Light; namespace VisualPinball.Unity.Editor { [CustomEditor(typeof(LightInsertMeshComponent)), CanEditMultipleObjects] - public class LightInsertMeshInspector : MeshInspector + public class LightInsertMeshInspector : MeshInspector, IDragPointsInspector { + private DragPointsInspectorHelper _dragPointsInspectorHelper; + private SerializedProperty _insertHeightProperty; private SerializedProperty _positionZProperty; + public bool DragPointsActive => true; + protected override void OnEnable() { base.OnEnable(); + _dragPointsInspectorHelper = new DragPointsInspectorHelper(MeshComponent.MainComponent, this); + _dragPointsInspectorHelper.OnEnable(); + _insertHeightProperty = serializedObject.FindProperty(nameof(LightInsertMeshComponent.InsertHeight)); _positionZProperty = serializedObject.FindProperty(nameof(LightInsertMeshComponent.PositionZ)); } + protected override void OnDisable() + { + base.OnDisable(); + _dragPointsInspectorHelper.OnDisable(); + } + public override void OnInspectorGUI() { if (HasErrors()) { @@ -48,9 +64,27 @@ public override void OnInspectorGUI() PropertyField(_insertHeightProperty, rebuildMesh: true); PropertyField(_positionZProperty, updateTransforms: true); + _dragPointsInspectorHelper.OnInspectorGUI(this); + base.OnInspectorGUI(); EndEditing(); } + + private void OnSceneGUI() + { + _dragPointsInspectorHelper.OnSceneGUI(this); + } + + #region Dragpoint Tooling + + public DragPointData[] DragPoints { get => MeshComponent.DragPoints; set => MeshComponent.DragPoints = value; } + public Vector3 EditableOffset => new Vector3(-MeshComponent.MainComponent.Position.x, -MeshComponent.MainComponent.Position.y, MeshComponent.PositionZ); + public Vector3 GetDragPointOffset(float ratio) => Vector3.zero; + public bool PointsAreLooping => true; + public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.Texture }; + public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + + #endregion } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs index 592ca0da9..96036e902 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/MainInspector.cs @@ -62,7 +62,7 @@ protected void InvalidParentError() protected void UpdateSurfaceReferences(Transform obj) { var surfaceComponent = obj.gameObject.GetComponent(); - if (surfaceComponent != null && surfaceComponent.Surface == MainComponent) { + if (surfaceComponent != null && (TMainComponent)surfaceComponent.Surface == MainComponent) { surfaceComponent.OnSurfaceUpdated(); } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs index 450c9e761..a63616247 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs @@ -19,13 +19,14 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT; using VisualPinball.Engine.VPT.Ramp; namespace VisualPinball.Unity.Editor { [CustomEditor(typeof(RampComponent)), CanEditMultipleObjects] - public class RampInspector : DragPointsInspector + public class RampInspector : MainInspector, IDragPointsInspector { private bool _foldoutGeometry = true; @@ -54,6 +55,8 @@ public class RampInspector : DragPointsInspector RampImageAlignment.ImageModeWrap, }; + private DragPointsInspectorHelper _dragPointsInspectorHelper; + private SerializedProperty _typeProperty; private SerializedProperty _heightTopProperty; private SerializedProperty _heightBottomProperty; @@ -66,10 +69,14 @@ public class RampInspector : DragPointsInspector private SerializedProperty _wireDistanceXProperty; private SerializedProperty _wireDistanceYProperty; + protected override void OnEnable() { base.OnEnable(); + _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); + _dragPointsInspectorHelper.OnEnable(); + _heightBottomProperty = serializedObject.FindProperty(nameof(RampComponent._heightBottom)); _heightTopProperty = serializedObject.FindProperty(nameof(RampComponent._heightTop)); _imageAlignmentProperty = serializedObject.FindProperty(nameof(RampComponent._imageAlignment)); @@ -83,6 +90,12 @@ protected override void OnEnable() _wireDistanceYProperty = serializedObject.FindProperty(nameof(RampComponent._wireDistanceY)); } + protected override void OnDisable() + { + base.OnDisable(); + _dragPointsInspectorHelper.OnDisable(); + } + public override void OnInspectorGUI() { if (HasErrors()) { @@ -124,18 +137,27 @@ public override void OnInspectorGUI() } EditorGUILayout.EndFoldoutHeaderGroup(); + _dragPointsInspectorHelper.OnInspectorGUI(this); + base.OnInspectorGUI(); EndEditing(); } + private void OnSceneGUI() + { + _dragPointsInspectorHelper.OnSceneGUI(this); + } + #region Dragpoint Tooling - public override Vector3 EditableOffset => new Vector3(0.0f, 0.0f, 0f); - public override Vector3 GetDragPointOffset(float ratio) => new Vector3(0.0f, 0.0f, (MainComponent.HeightTop - MainComponent.HeightBottom) * ratio); - public override bool PointsAreLooping => false; - public override IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; - public override ItemDataTransformType HandleType => ItemDataTransformType.ThreeD; + public bool DragPointsActive => true; + public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } + public Vector3 EditableOffset => new Vector3(0.0f, 0.0f, 0f); + public Vector3 GetDragPointOffset(float ratio) => new Vector3(0.0f, 0.0f, (MainComponent.HeightTop - MainComponent.HeightBottom) * ratio); + public bool PointsAreLooping => false; + public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; + public ItemDataTransformType HandleType => ItemDataTransformType.ThreeD; #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs index daacb9fc9..4cba7122b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs @@ -19,13 +19,16 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT.Rubber; namespace VisualPinball.Unity.Editor { [CustomEditor(typeof(RubberComponent)), CanEditMultipleObjects] - public class RubberInspector : DragPointsInspector + public class RubberInspector : MainInspector, IDragPointsInspector { + private DragPointsInspectorHelper _dragPointsInspectorHelper; + private SerializedProperty _heightProperty; private SerializedProperty _thicknessProperty; private SerializedProperty _rotationProperty; @@ -34,11 +37,21 @@ protected override void OnEnable() { base.OnEnable(); + + _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); + _dragPointsInspectorHelper.OnEnable(); + _heightProperty = serializedObject.FindProperty(nameof(RubberComponent._height)); _thicknessProperty = serializedObject.FindProperty(nameof(RubberComponent._thickness)); _rotationProperty = serializedObject.FindProperty(nameof(RubberComponent.Rotation)); } + protected override void OnDisable() + { + base.OnDisable(); + _dragPointsInspectorHelper.OnDisable(); + } + public override void OnInspectorGUI() { if (HasErrors()) { @@ -53,18 +66,27 @@ public override void OnInspectorGUI() PropertyField(_heightProperty, rebuildMesh: true); PropertyField(_thicknessProperty, rebuildMesh: true); + _dragPointsInspectorHelper.OnInspectorGUI(this); + base.OnInspectorGUI(); EndEditing(); } + private void OnSceneGUI() + { + _dragPointsInspectorHelper.OnSceneGUI(this); + } + #region Dragpoint Tooling - public override Vector3 EditableOffset => new Vector3(0.0f, 0.0f, MainComponent._height); - public override Vector3 GetDragPointOffset(float ratio) => Vector3.zero; - public override bool PointsAreLooping => true; - public override IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth }; - public override ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public bool DragPointsActive => true; + public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } + public Vector3 EditableOffset => new Vector3(0.0f, 0.0f, MainComponent._height); + public Vector3 GetDragPointOffset(float ratio) => Vector3.zero; + public bool PointsAreLooping => true; + public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth }; + public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs index 8ba2d77d0..81bbe2c3e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs @@ -19,24 +19,38 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT.Surface; namespace VisualPinball.Unity.Editor { [CustomEditor(typeof(SurfaceComponent)), CanEditMultipleObjects] - public class SurfaceInspector : DragPointsInspector + public class SurfaceInspector : MainInspector, IDragPointsInspector { + private DragPointsInspectorHelper _dragPointsInspectorHelper; + private SerializedProperty _heightTopProperty; private SerializedProperty _heightBottomProperty; + public bool DragPointsActive => true; + protected override void OnEnable() { base.OnEnable(); + _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); + _dragPointsInspectorHelper.OnEnable(); + _heightTopProperty = serializedObject.FindProperty(nameof(SurfaceComponent.HeightTop)); _heightBottomProperty = serializedObject.FindProperty(nameof(SurfaceComponent.HeightBottom)); } + protected override void OnDisable() + { + base.OnDisable(); + _dragPointsInspectorHelper.OnDisable(); + } + public override void OnInspectorGUI() { if (HasErrors()) { @@ -52,18 +66,26 @@ public override void OnInspectorGUI() }); PropertyField(_heightBottomProperty, "Bottom Height", true); + _dragPointsInspectorHelper.OnInspectorGUI(this); + base.OnInspectorGUI(); EndEditing(); } + private void OnSceneGUI() + { + _dragPointsInspectorHelper.OnSceneGUI(this); + } + #region Dragpoint Tooling - public override Vector3 EditableOffset => new Vector3(0.0f, 0.0f, MainComponent.HeightTop + MainComponent.PlayfieldHeight); - public override Vector3 GetDragPointOffset(float ratio) => Vector3.zero; - public override bool PointsAreLooping => true; - public override IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth , DragPointExposure.SlingShot , DragPointExposure.Texture }; - public override ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } + public Vector3 EditableOffset => new Vector3(0.0f, 0.0f, MainComponent.HeightTop + MainComponent.PlayfieldHeight); + public Vector3 GetDragPointOffset(float ratio) => Vector3.zero; + public bool PointsAreLooping => true; + public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot, DragPointExposure.Texture }; + public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs index bbddbfe7e..7e122ea96 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs @@ -19,13 +19,16 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; +using VisualPinball.Engine.Math; using VisualPinball.Engine.VPT.Trigger; namespace VisualPinball.Unity.Editor { [CustomEditor(typeof(TriggerComponent)), CanEditMultipleObjects] - public class TriggerInspector : DragPointsInspector + public class TriggerInspector : MainInspector, IDragPointsInspector { + private DragPointsInspectorHelper _dragPointsInspectorHelper; + private SerializedProperty _positionProperty; private SerializedProperty _rotationProperty; private SerializedProperty _surfaceProperty; @@ -34,11 +37,20 @@ protected override void OnEnable() { base.OnEnable(); + _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); + _dragPointsInspectorHelper.OnEnable(); + _positionProperty = serializedObject.FindProperty(nameof(TriggerComponent.Position)); _rotationProperty = serializedObject.FindProperty(nameof(TriggerComponent.Rotation)); _surfaceProperty = serializedObject.FindProperty(nameof(TriggerComponent._surface)); } + protected override void OnDisable() + { + base.OnDisable(); + _dragPointsInspectorHelper.OnDisable(); + } + public override void OnInspectorGUI() { if (HasErrors()) { @@ -53,18 +65,33 @@ public override void OnInspectorGUI() PropertyField(_rotationProperty, updateTransforms: true); PropertyField(_surfaceProperty, updateTransforms: true); + _dragPointsInspectorHelper.OnInspectorGUI(this); + base.OnInspectorGUI(); EndEditing(); } + private void OnSceneGUI() + { + _dragPointsInspectorHelper.OnSceneGUI(this); + } + #region Dragpoint Tooling - public override Vector3 EditableOffset => new Vector3(-MainComponent.Position.x, -MainComponent.Position.y, 0.0f); - public override Vector3 GetDragPointOffset(float ratio) => Vector3.zero; - public override bool PointsAreLooping => true; - public override IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; - public override ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public bool DragPointsActive { + get { + var meshComp = MainComponent.GetComponent(); + return !meshComp || !meshComp.IsCircle; + } + } + + public DragPointData[] DragPoints { get => MainComponent.DragPoints; set => MainComponent.DragPoints = value; } + public Vector3 EditableOffset => new Vector3(-MainComponent.Position.x, -MainComponent.Position.y, 0.0f); + public Vector3 GetDragPointOffset(float ratio) => Vector3.zero; + public bool PointsAreLooping => true; + public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; + public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsEditable.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs similarity index 88% rename from VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsEditable.cs rename to VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs index 8809cbe66..f568ee312 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsEditable.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs @@ -45,22 +45,21 @@ public enum DragPointExposure Texture } - public interface IDragPointsComponent - { - bool DragPointsActive { get; } - DragPointData[] DragPoints { get; set; } - } - /// - /// Abstraction for components that support drag points. + /// Abstraction inspectors that support drag points. /// - public interface IDragPointsEditable + public interface IDragPointsInspector { /// /// Access to the drag point data /// DragPointData[] DragPoints { get; set; } + /// + /// Whether to render drag points at all. Because sometimes we don't want to, like for trigger buttons. + /// + bool DragPointsActive { get; } + /// /// Returns the global offset applied on all drag points. /// diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsEditable.cs.meta b/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsEditable.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs.meta index 2421253f8..86787c7ed 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsEditable.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d59d7481d338f354a9290af78a1ff975 +guid: 2b279c1659601c74fbbe1653d71fbf7a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs index b13ecbb7c..5346c8c35 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Light/LightInsertMeshComponent.cs @@ -43,6 +43,8 @@ public class LightInsertMeshComponent : MeshComponent #endregion + public bool DragPointsActive => true; + public const string InsertObjectName = "Insert"; public override IEnumerable ValidParents => Type.EmptyTypes; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs index 571d1b482..31c9a3e61 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Ramp/RampComponent.cs @@ -36,7 +36,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Ramp")] public class RampComponent : MainRenderableComponent, - IRampData, ISurfaceComponent, IDragPointsComponent, IConvertGameObjectToEntity + IRampData, ISurfaceComponent, IConvertGameObjectToEntity { #region Data @@ -121,8 +121,6 @@ public class RampComponent : MainRenderableComponent, public override void OnPlayfieldHeightUpdated() => RebuildMeshes(); - public bool DragPointsActive => true; - #endregion #region Transformation diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs index d15b8ece1..04715d069 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Rubber/RubberComponent.cs @@ -35,7 +35,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Rubber")] public class RubberComponent : MainRenderableComponent, - IRubberData, IDragPointsComponent, IConvertGameObjectToEntity + IRubberData, IConvertGameObjectToEntity { #region Data @@ -79,8 +79,6 @@ public class RubberComponent : MainRenderableComponent, protected override Type MeshComponentType { get; } = typeof(MeshComponent); protected override Type ColliderComponentType { get; } = typeof(ColliderComponent); - public bool DragPointsActive => true; - #endregion #region Transformation diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs index 56ea47956..9066b1446 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceComponent.cs @@ -35,7 +35,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Surface")] public class SurfaceComponent : MainRenderableComponent, - IConvertGameObjectToEntity, ISurfaceComponent, IDragPointsComponent + IConvertGameObjectToEntity, ISurfaceComponent { #region Data @@ -67,8 +67,6 @@ public class SurfaceComponent : MainRenderableComponent, protected override Type MeshComponentType { get; } = typeof(MeshComponent); protected override Type ColliderComponentType { get; } = typeof(ColliderComponent); - public bool DragPointsActive => true; - #endregion #region Transformation diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs index 24b33822c..7798d3cf6 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs @@ -37,7 +37,7 @@ namespace VisualPinball.Unity { [AddComponentMenu("Visual Pinball/Game Item/Trigger")] public class TriggerComponent : MainRenderableComponent, - ITriggerComponent, IDragPointsComponent, IOnSurfaceComponent, IConvertGameObjectToEntity + ITriggerComponent, IOnSurfaceComponent, IConvertGameObjectToEntity { #region Data @@ -74,13 +74,6 @@ public class TriggerComponent : MainRenderableComponent, protected override Type MeshComponentType { get; } = typeof(MeshComponent); protected override Type ColliderComponentType { get; } = typeof(ColliderComponent); - public bool DragPointsActive { - get { - var meshComp = GetComponent(); - return !meshComp || !meshComp.IsCircle; - } - } - public const string SwitchItem = "trigger_switch"; #endregion From 101a0fe2822de1017ddf8799af09a21bf2e0745a Mon Sep 17 00:00:00 2001 From: freezy Date: Wed, 15 Sep 2021 00:25:38 +0200 Subject: [PATCH 6/7] doc: Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23dfd39a6..534089471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Built with Unity 2020.3. ### Added +- Create insert meshes ([#320](https://github.com/freezy/VisualPinball.Engine/pull/320)) - Full support for custom playfield meshes. - Remove Hybrid Renderer ([#316](https://github.com/freezy/VisualPinball.Engine/pull/316)). - Create and use Unity assets when importing ([#320](https://github.com/freezy/VisualPinball.Engine/pull/302)). From 35e994ee440ac7e8bbc63620ae1cb2c7dcbe03a9 Mon Sep 17 00:00:00 2001 From: freezy Date: Wed, 15 Sep 2021 19:52:06 +0200 Subject: [PATCH 7/7] dragpoints: Fix menu. --- .../DragPoint/DragPointMenuItems.cs | 58 ++++++------ .../DragPoint/DragPointsInspectorHelper.cs | 2 +- .../DragPoint}/IDragPointsInspector.cs | 3 + .../DragPoint}/IDragPointsInspector.cs.meta | 2 +- .../DragPoint/IDragPointsItemInspector.cs | 89 ------------------- .../IDragPointsItemInspector.cs.meta | 11 --- .../VPT/Light/LightInsertMeshInspector.cs | 12 +-- .../VPT/Ramp/RampInspector.cs | 13 ++- .../VPT/Rubber/RubberInspector.cs | 12 +-- .../VPT/Surface/SurfaceInspector.cs | 12 +-- .../VPT/Trigger/TriggerInspector.cs | 12 +-- 11 files changed, 64 insertions(+), 162 deletions(-) rename VisualPinball.Unity/{VisualPinball.Unity/VPT => VisualPinball.Unity.Editor/DragPoint}/IDragPointsInspector.cs (93%) rename VisualPinball.Unity/{VisualPinball.Unity/VPT => VisualPinball.Unity.Editor/DragPoint}/IDragPointsInspector.cs.meta (83%) delete mode 100644 VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs delete mode 100644 VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs.meta diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs index 68486e342..b6a3936dd 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs @@ -24,35 +24,35 @@ public static class DragPointMenuItems public const string ControlPointsMenuPath = "CONTEXT/DragPointsItemInspector/ControlPoint"; public const string CurveTravellerMenuPath = "CONTEXT/DragPointsItemInspector/CurveTraveller"; - private static DragPointData RetrieveDragPoint(IDragPointsItemInspector inspector, int controlId) + private static DragPointData RetrieveDragPoint(IDragPointsInspector inspector, int controlId) { - return inspector?.GetDragPoint(controlId); + return inspector?.DragPointsHelper.GetDragPoint(controlId); } // Drag Points [MenuItem(ControlPointsMenuPath + "/Is Slingshot", false, 1)] private static void SlingShot(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } var dragPoint = RetrieveDragPoint(inspector, command.userData); if (dragPoint != null) { - inspector.PrepareUndo("Toggle Drag Point Slingshot"); + inspector.DragPointsHelper.PrepareUndo("Toggle Drag Point Slingshot"); dragPoint.IsSlingshot = !dragPoint.IsSlingshot; - inspector.RebuildMeshes(); + inspector.DragPointsHelper.RebuildMeshes(); } } [MenuItem(ControlPointsMenuPath + "/Is Slingshot", true)] private static bool SlingshotValidate(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector) || inspector.IsItemLocked()) { + if (!(command.context is IDragPointsInspector inspector) || inspector.DragPointsHelper.IsItemLocked()) { return false; } - if (!inspector.HasDragPointExposure(DragPointExposure.SlingShot)) { + if (!inspector.DragPointsHelper.HasDragPointExposure(DragPointExposure.SlingShot)) { Menu.SetChecked($"{ControlPointsMenuPath}/IsSlingshot", false); return false; } @@ -68,27 +68,27 @@ private static bool SlingshotValidate(MenuCommand command) [MenuItem(ControlPointsMenuPath + "/Is Smooth", false, 1)] private static void Smooth(MenuCommand command) { - var inspector = command.context as IDragPointsItemInspector; + var inspector = command.context as IDragPointsInspector; if (inspector == null) { return; } var dragPoint = RetrieveDragPoint(inspector, command.userData); if (dragPoint != null) { - inspector.PrepareUndo("Toggle Drag Point Smooth"); + inspector.DragPointsHelper.PrepareUndo("Toggle Drag Point Smooth"); dragPoint.IsSmooth = !dragPoint.IsSmooth; - inspector.RebuildMeshes(); + inspector.DragPointsHelper.RebuildMeshes(); } } [MenuItem(ControlPointsMenuPath + "/Is Smooth", true)] private static bool SmoothValidate(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector) || inspector.IsItemLocked()) { + if (!(command.context is IDragPointsInspector inspector) || inspector.DragPointsHelper.IsItemLocked()) { return false; } - if (!inspector.HasDragPointExposure(DragPointExposure.Smooth)) { + if (!inspector.DragPointsHelper.HasDragPointExposure(DragPointExposure.Smooth)) { Menu.SetChecked($"{ControlPointsMenuPath}/IsSmooth", false); return false; } @@ -104,23 +104,23 @@ private static bool SmoothValidate(MenuCommand command) [MenuItem(ControlPointsMenuPath + "/Remove Point", false, 101)] private static void Remove(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } if (EditorUtility.DisplayDialog("Drag point removal", "Are you sure you want to remove this drag point?", "Yes", "No")) { - inspector.RemoveDragPoint(command.userData); + inspector.DragPointsHelper.RemoveDragPoint(command.userData); } } [MenuItem(ControlPointsMenuPath + "/Remove Point", true)] private static bool RemoveValidate(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector) || inspector.IsItemLocked()) { + if (!(command.context is IDragPointsInspector inspector) || inspector.DragPointsHelper.IsItemLocked()) { return false; } - if (inspector.DragPointsHandler?.ControlPoints.Count <= 2) { + if (inspector.DragPointsHelper.DragPointsHandler?.ControlPoints.Count <= 2) { Menu.SetChecked($"{ControlPointsMenuPath}/Remove Point", false); return false; } @@ -131,71 +131,71 @@ private static bool RemoveValidate(MenuCommand command) [MenuItem(ControlPointsMenuPath + "/Copy Point", false, 301)] private static void Copy(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } - inspector.CopyDragPoint(command.userData); + inspector.DragPointsHelper.CopyDragPoint(command.userData); } [MenuItem(ControlPointsMenuPath + "/Paste Point", false, 302)] private static void Paste(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } - inspector.PasteDragPoint(command.userData); + inspector.DragPointsHelper.PasteDragPoint(command.userData); } [MenuItem(ControlPointsMenuPath + "/Paste Point", true)] private static bool PasteValidate(MenuCommand command) { - return command.context is IDragPointsItemInspector inspector && !inspector.IsItemLocked(); + return command.context is IDragPointsInspector inspector && !inspector.DragPointsHelper.IsItemLocked(); } //Curve Traveller [MenuItem(CurveTravellerMenuPath + "/Add Point", false, 1)] private static void Add(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } - inspector.AddDragPointOnTraveller(); + inspector.DragPointsHelper.AddDragPointOnTraveller(); } [MenuItem(CurveTravellerMenuPath + "/Flip Drag Points/X", false, 101)] [MenuItem(ControlPointsMenuPath + "/Flip Drag Points/X", false, 201)] private static void FlipX(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } - inspector.FlipDragPoints(FlipAxis.X); + inspector.DragPointsHelper.FlipDragPoints(FlipAxis.X); } [MenuItem(CurveTravellerMenuPath + "/Flip Drag Points/Y", false, 102)] [MenuItem(ControlPointsMenuPath + "/Flip Drag Points/Y", false, 202)] private static void FlipY(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } - inspector.FlipDragPoints(FlipAxis.Y); + inspector.DragPointsHelper.FlipDragPoints(FlipAxis.Y); } [MenuItem(CurveTravellerMenuPath + "/Flip Drag Points/Z", false, 103)] [MenuItem(ControlPointsMenuPath + "/Flip Drag Points/Z", false, 203)] private static void FlipZ(MenuCommand command) { - if (!(command.context is IDragPointsItemInspector inspector)) { + if (!(command.context is IDragPointsInspector inspector)) { return; } - inspector.FlipDragPoints(FlipAxis.Z); + inspector.DragPointsHelper.FlipDragPoints(FlipAxis.Z); } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs index 80c87e340..e9ef81723 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs @@ -23,7 +23,7 @@ namespace VisualPinball.Unity.Editor { - public class DragPointsInspectorHelper : IDragPointsItemInspector + public class DragPointsInspectorHelper { /// /// Catmull Curve Handler diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs similarity index 93% rename from VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs rename to VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs index f568ee312..37d7811b2 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs @@ -17,6 +17,7 @@ using System.Collections.Generic; using UnityEngine; using VisualPinball.Engine.Math; +using VisualPinball.Unity.Editor; namespace VisualPinball.Unity { @@ -87,5 +88,7 @@ public interface IDragPointsInspector /// /// ItemDataTransformType HandleType { get; } + + DragPointsInspectorHelper DragPointsHelper { get; } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs.meta b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs.meta similarity index 83% rename from VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs.meta rename to VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs.meta index 86787c7ed..618c27c7e 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/IDragPointsInspector.cs.meta +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsInspector.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2b279c1659601c74fbbe1653d71fbf7a +guid: 6f0f2996dddc2e243b834359e370e51b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs deleted file mode 100644 index 8228f819d..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2021 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using VisualPinball.Engine.Math; - -namespace VisualPinball.Unity.Editor -{ - /// - /// A non-generic interface for DragPointsItemInspector we can use for all - /// types of items. - /// - public interface IDragPointsItemInspector - { - /// - /// Catmull Curve Handler - /// - DragPointsHandler DragPointsHandler { get; } - - /// - /// Returns a reference to the drag point data for a given control ID. - /// - /// Control ID of the drag point - /// Drag point data or null if no linked data. - DragPointData GetDragPoint(int controlId); - - /// - /// Sets an UNDO point before the next operation. - /// - /// Message to appear in the UNDO menu - void PrepareUndo(string message); - - /// - /// Returns true if the game item is locked. - /// - /// True if game item is locked, false otherwise. - bool IsItemLocked(); - - /// - /// Returns whether this game item has a given drag point exposure. - /// - /// Exposure to check - /// True if exposed, false otherwise. - bool HasDragPointExposure(DragPointExposure exposure); - - /// - /// Removes a drag point of a given control ID. - /// - /// Control ID of the drag point to remove. - void RemoveDragPoint(int controlId); - - /// - /// Copies the position of a drag point. - /// - /// Control ID of the drag point - void CopyDragPoint(int controlId); - - /// - /// Sets the position of a previously copied drag point to another drag point. - /// - /// Control ID of the drag point to which the new position is applied. - void PasteDragPoint(int controlId); - - /// - /// Adds a new drag point at the traveller's current position. - /// - void AddDragPointOnTraveller(); - - /// - /// Flips all drag points on a given axis. - /// - /// Axis to flip on - void FlipDragPoints(FlipAxis flipAxis); - - void RebuildMeshes(); - } -} diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs.meta b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs.meta deleted file mode 100644 index e0d27d079..000000000 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/IDragPointsItemInspector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 747d367bff8d4ce4e988bc6ba5503021 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs index 109ccf9bf..04b2c6ba0 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Light/LightInsertMeshInspector.cs @@ -27,7 +27,6 @@ namespace VisualPinball.Unity.Editor [CustomEditor(typeof(LightInsertMeshComponent)), CanEditMultipleObjects] public class LightInsertMeshInspector : MeshInspector, IDragPointsInspector { - private DragPointsInspectorHelper _dragPointsInspectorHelper; private SerializedProperty _insertHeightProperty; private SerializedProperty _positionZProperty; @@ -38,8 +37,8 @@ protected override void OnEnable() { base.OnEnable(); - _dragPointsInspectorHelper = new DragPointsInspectorHelper(MeshComponent.MainComponent, this); - _dragPointsInspectorHelper.OnEnable(); + DragPointsHelper = new DragPointsInspectorHelper(MeshComponent.MainComponent, this); + DragPointsHelper.OnEnable(); _insertHeightProperty = serializedObject.FindProperty(nameof(LightInsertMeshComponent.InsertHeight)); _positionZProperty = serializedObject.FindProperty(nameof(LightInsertMeshComponent.PositionZ)); @@ -48,7 +47,7 @@ protected override void OnEnable() protected override void OnDisable() { base.OnDisable(); - _dragPointsInspectorHelper.OnDisable(); + DragPointsHelper.OnDisable(); } public override void OnInspectorGUI() @@ -64,7 +63,7 @@ public override void OnInspectorGUI() PropertyField(_insertHeightProperty, rebuildMesh: true); PropertyField(_positionZProperty, updateTransforms: true); - _dragPointsInspectorHelper.OnInspectorGUI(this); + DragPointsHelper.OnInspectorGUI(this); base.OnInspectorGUI(); @@ -73,7 +72,7 @@ public override void OnInspectorGUI() private void OnSceneGUI() { - _dragPointsInspectorHelper.OnSceneGUI(this); + DragPointsHelper.OnSceneGUI(this); } #region Dragpoint Tooling @@ -84,6 +83,7 @@ private void OnSceneGUI() public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.Texture }; public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointsInspectorHelper DragPointsHelper { get; private set; } #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs index a63616247..46d5f0c72 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Ramp/RampInspector.cs @@ -55,8 +55,6 @@ public class RampInspector : MainInspector, IDragPoints RampImageAlignment.ImageModeWrap, }; - private DragPointsInspectorHelper _dragPointsInspectorHelper; - private SerializedProperty _typeProperty; private SerializedProperty _heightTopProperty; private SerializedProperty _heightBottomProperty; @@ -74,8 +72,8 @@ protected override void OnEnable() { base.OnEnable(); - _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); - _dragPointsInspectorHelper.OnEnable(); + DragPointsHelper = new DragPointsInspectorHelper(MainComponent, this); + DragPointsHelper.OnEnable(); _heightBottomProperty = serializedObject.FindProperty(nameof(RampComponent._heightBottom)); _heightTopProperty = serializedObject.FindProperty(nameof(RampComponent._heightTop)); @@ -93,7 +91,7 @@ protected override void OnEnable() protected override void OnDisable() { base.OnDisable(); - _dragPointsInspectorHelper.OnDisable(); + DragPointsHelper.OnDisable(); } public override void OnInspectorGUI() @@ -137,7 +135,7 @@ public override void OnInspectorGUI() } EditorGUILayout.EndFoldoutHeaderGroup(); - _dragPointsInspectorHelper.OnInspectorGUI(this); + DragPointsHelper.OnInspectorGUI(this); base.OnInspectorGUI(); @@ -146,7 +144,7 @@ public override void OnInspectorGUI() private void OnSceneGUI() { - _dragPointsInspectorHelper.OnSceneGUI(this); + DragPointsHelper.OnSceneGUI(this); } #region Dragpoint Tooling @@ -158,6 +156,7 @@ private void OnSceneGUI() public bool PointsAreLooping => false; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; public ItemDataTransformType HandleType => ItemDataTransformType.ThreeD; + public DragPointsInspectorHelper DragPointsHelper { get; private set; } #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs index 4cba7122b..5d1ceafd2 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Rubber/RubberInspector.cs @@ -27,7 +27,6 @@ namespace VisualPinball.Unity.Editor [CustomEditor(typeof(RubberComponent)), CanEditMultipleObjects] public class RubberInspector : MainInspector, IDragPointsInspector { - private DragPointsInspectorHelper _dragPointsInspectorHelper; private SerializedProperty _heightProperty; private SerializedProperty _thicknessProperty; @@ -38,8 +37,8 @@ protected override void OnEnable() base.OnEnable(); - _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); - _dragPointsInspectorHelper.OnEnable(); + DragPointsHelper = new DragPointsInspectorHelper(MainComponent, this); + DragPointsHelper.OnEnable(); _heightProperty = serializedObject.FindProperty(nameof(RubberComponent._height)); _thicknessProperty = serializedObject.FindProperty(nameof(RubberComponent._thickness)); @@ -49,7 +48,7 @@ protected override void OnEnable() protected override void OnDisable() { base.OnDisable(); - _dragPointsInspectorHelper.OnDisable(); + DragPointsHelper.OnDisable(); } public override void OnInspectorGUI() @@ -66,7 +65,7 @@ public override void OnInspectorGUI() PropertyField(_heightProperty, rebuildMesh: true); PropertyField(_thicknessProperty, rebuildMesh: true); - _dragPointsInspectorHelper.OnInspectorGUI(this); + DragPointsHelper.OnInspectorGUI(this); base.OnInspectorGUI(); @@ -75,7 +74,7 @@ public override void OnInspectorGUI() private void OnSceneGUI() { - _dragPointsInspectorHelper.OnSceneGUI(this); + DragPointsHelper.OnSceneGUI(this); } #region Dragpoint Tooling @@ -87,6 +86,7 @@ private void OnSceneGUI() public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth }; public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointsInspectorHelper DragPointsHelper { get; private set; } #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs index 81bbe2c3e..e3a9f2386 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SurfaceInspector.cs @@ -27,7 +27,6 @@ namespace VisualPinball.Unity.Editor [CustomEditor(typeof(SurfaceComponent)), CanEditMultipleObjects] public class SurfaceInspector : MainInspector, IDragPointsInspector { - private DragPointsInspectorHelper _dragPointsInspectorHelper; private SerializedProperty _heightTopProperty; private SerializedProperty _heightBottomProperty; @@ -38,8 +37,8 @@ protected override void OnEnable() { base.OnEnable(); - _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); - _dragPointsInspectorHelper.OnEnable(); + DragPointsHelper = new DragPointsInspectorHelper(MainComponent, this); + DragPointsHelper.OnEnable(); _heightTopProperty = serializedObject.FindProperty(nameof(SurfaceComponent.HeightTop)); _heightBottomProperty = serializedObject.FindProperty(nameof(SurfaceComponent.HeightBottom)); @@ -48,7 +47,7 @@ protected override void OnEnable() protected override void OnDisable() { base.OnDisable(); - _dragPointsInspectorHelper.OnDisable(); + DragPointsHelper.OnDisable(); } public override void OnInspectorGUI() @@ -66,7 +65,7 @@ public override void OnInspectorGUI() }); PropertyField(_heightBottomProperty, "Bottom Height", true); - _dragPointsInspectorHelper.OnInspectorGUI(this); + DragPointsHelper.OnInspectorGUI(this); base.OnInspectorGUI(); @@ -75,7 +74,7 @@ public override void OnInspectorGUI() private void OnSceneGUI() { - _dragPointsInspectorHelper.OnSceneGUI(this); + DragPointsHelper.OnSceneGUI(this); } #region Dragpoint Tooling @@ -86,6 +85,7 @@ private void OnSceneGUI() public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot, DragPointExposure.Texture }; public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointsInspectorHelper DragPointsHelper { get; private set; } #endregion } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs index 7e122ea96..7748e24ef 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Trigger/TriggerInspector.cs @@ -27,7 +27,6 @@ namespace VisualPinball.Unity.Editor [CustomEditor(typeof(TriggerComponent)), CanEditMultipleObjects] public class TriggerInspector : MainInspector, IDragPointsInspector { - private DragPointsInspectorHelper _dragPointsInspectorHelper; private SerializedProperty _positionProperty; private SerializedProperty _rotationProperty; @@ -37,8 +36,8 @@ protected override void OnEnable() { base.OnEnable(); - _dragPointsInspectorHelper = new DragPointsInspectorHelper(MainComponent, this); - _dragPointsInspectorHelper.OnEnable(); + DragPointsHelper = new DragPointsInspectorHelper(MainComponent, this); + DragPointsHelper.OnEnable(); _positionProperty = serializedObject.FindProperty(nameof(TriggerComponent.Position)); _rotationProperty = serializedObject.FindProperty(nameof(TriggerComponent.Rotation)); @@ -48,7 +47,7 @@ protected override void OnEnable() protected override void OnDisable() { base.OnDisable(); - _dragPointsInspectorHelper.OnDisable(); + DragPointsHelper.OnDisable(); } public override void OnInspectorGUI() @@ -65,7 +64,7 @@ public override void OnInspectorGUI() PropertyField(_rotationProperty, updateTransforms: true); PropertyField(_surfaceProperty, updateTransforms: true); - _dragPointsInspectorHelper.OnInspectorGUI(this); + DragPointsHelper.OnInspectorGUI(this); base.OnInspectorGUI(); @@ -74,7 +73,7 @@ public override void OnInspectorGUI() private void OnSceneGUI() { - _dragPointsInspectorHelper.OnSceneGUI(this); + DragPointsHelper.OnSceneGUI(this); } #region Dragpoint Tooling @@ -92,6 +91,7 @@ public bool DragPointsActive { public bool PointsAreLooping => true; public IEnumerable DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.SlingShot }; public ItemDataTransformType HandleType => ItemDataTransformType.TwoD; + public DragPointsInspectorHelper DragPointsHelper { get; private set; } #endregion }