Skip to content

Commit

Permalink
cleanup: Remove editor transform overloads, surface props, table heig…
Browse files Browse the repository at this point in the history
…ht, and merged z-pos into pos where possible.
  • Loading branch information
freezy committed Nov 29, 2024
1 parent eb1b345 commit 98a151a
Show file tree
Hide file tree
Showing 76 changed files with 406 additions and 1,557 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#nullable enable

using VisualPinball.Engine.Common;
using VisualPinball.Engine.Game;
using VisualPinball.Engine.Math;

namespace VisualPinball.Engine.VPT.MetalWireGuide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,9 @@ private void OnAddSelected()
var go = InstantiateAsset(parentTransform);

// move to the middle of the playfield
go.transform.localPosition = new Vector3(Physics.ScaleToWorld(pf.Width / 2), 0, -Physics.ScaleToWorld(pf.Height / 2));
if (pf != null && go.GetComponent(typeof(IMainRenderableComponent)) is IMainRenderableComponent comp) {
comp.SetEditorPosition(new Vector3(pf.Width / 2, pf.Height / 2, 0));
comp.UpdateTransforms();
} else if (pf != null) {
go.transform.localPosition = new Vector3(Physics.ScaleToWorld(pf.Width / 2), 0, -Physics.ScaleToWorld(pf.Height / 2));
}

ApplyVariation(go);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static void FlipZ(MenuCommand command)
private static bool FlipZValidate(MenuCommand command)
{
if (command.context is IDragPointsInspector inspector) {
return inspector.HandleType == ItemDataTransformType.ThreeD;
return inspector.HandleType == DragPointTransformType.ThreeD;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Collections;
using System.Linq;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -65,11 +63,6 @@ public DragPointsInspectorHelper(IMainRenderableComponent mainComponent, IDragPo
public void RebuildMeshes()
{
_mainComponent.RebuildMeshes();
if (_playfieldComponent) {
WalkChildren(_playfieldComponent.transform, UpdateSurfaceReferences);
} else {
Debug.LogWarning($"{_mainComponent.name} doesn't seem to have a playfield parent.");
}
}

public void OnEnable()
Expand Down Expand Up @@ -125,7 +118,8 @@ public void PasteDragPoint(int controlId)
/// <returns>True if game item is locked, false otherwise.</returns>
public bool IsItemLocked()
{
return _mainComponent.IsLocked;
// todo delete or implement properly
return false;
}

/// <summary>
Expand All @@ -144,7 +138,7 @@ public bool HasDragPointExposure(DragPointExposure exposure)
/// <param name="flipAxis">Axis to flip on</param>
public void FlipDragPoints(FlipAxis flipAxis)
{
if (_dragPointsInspector.HandleType != ItemDataTransformType.ThreeD && flipAxis == FlipAxis.Z) {
if (_dragPointsInspector.HandleType != DragPointTransformType.ThreeD && flipAxis == FlipAxis.Z) {
return;
}

Expand Down Expand Up @@ -206,10 +200,11 @@ public void PrepareUndo(string message)

public void OnInspectorGUI(ItemInspector inspector)
{
if (_mainComponent.IsLocked) {
EditorGUILayout.LabelField("Drag Points are Locked");
return;
}
// todo remove or implement properly
// if (_mainComponent.IsLocked) {
// EditorGUILayout.LabelField("Drag Points are Locked");
// return;
// }

GUILayout.Space(10);
if (GUILayout.Button("Center Origin")) {
Expand All @@ -232,7 +227,7 @@ public void OnInspectorGUI(ItemInspector inspector)
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
if (_dragPointsInspector.HandleType == ItemDataTransformType.TwoD) {
if (_dragPointsInspector.HandleType == DragPointTransformType.TwoD) {
var pos = EditorGUILayout.Vector2Field("Position", controlPoint.DragPoint.Center.ToUnityVector2());
if (EditorGUI.EndChangeCheck()) {
controlPoint.DragPoint.Center.X = pos.x;
Expand Down Expand Up @@ -266,9 +261,10 @@ public void OnInspectorGUI(ItemInspector inspector)

private void UpdateDragPointsLock()
{
if (DragPointsHandler.UpdateDragPointsLock(_mainComponent.IsLocked)) {
HandleUtility.Repaint();
}
// todo remove or implement properly
// if (DragPointsHandler.UpdateDragPointsLock(_mainComponent.IsLocked)) {
// HandleUtility.Repaint();
// }
}

private void OnDragPointPositionChange()
Expand All @@ -280,7 +276,6 @@ private void OnDragPointPositionChange()
private void OnUndoRedoPerformed()
{
RemapControlPoints();
WalkChildren(_playfieldComponent.transform, UpdateSurfaceReferences);
}

public void OnSceneGUI(ItemInspector inspector)
Expand Down Expand Up @@ -310,22 +305,5 @@ public void OnSceneGUI(ItemInspector inspector)
}
}
}

private static void WalkChildren(IEnumerable node, Action<Transform> action)
{
foreach (Transform childTransform in node) {
action(childTransform);
WalkChildren(childTransform, action);
}
}

private void UpdateSurfaceReferences(Transform obj)
{
var surfaceComponent = obj.gameObject.GetComponent<IOnSurfaceComponent>();
if (surfaceComponent != null && surfaceComponent.Surface == _mainComponent) {
surfaceComponent.OnSurfaceUpdated();
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private void DisplayControlPoints()
}

Handles.matrix = Matrix4x4.identity;
if (!_handler.MainComponent.IsLocked) {
// if (!_handler.MainComponent.IsLocked) {
// curve traveller is not overlapping a control point, we can draw it.
if (distToControlPoint > HandleUtility.GetHandleSize(_handler.CurveTravellerPosition) * ControlPoint.ScreenRadius) {
Handles.color = Color.grey;
Expand All @@ -257,7 +257,7 @@ private void DisplayControlPoints()
HandleUtility.Repaint();
}
}
}
// }
Profiler.EndSample();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public enum DragPointExposure
Texture
}

public enum DragPointTransformType
{
TwoD,
ThreeD,
}

/// <summary>
/// Abstraction inspectors that support drag points.
/// </summary>
Expand Down Expand Up @@ -77,7 +83,7 @@ public interface IDragPointsInspector
/// Returns the applied constrains to drag points position edition.
/// </summary>
/// <returns></returns>
ItemDataTransformType HandleType { get; }
DragPointTransformType HandleType { get; }

DragPointsInspectorHelper DragPointsHelper { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public static class HandlesUtils
/// <param name="handleSize"></param>
/// <param name="snap"></param>
/// <returns>Moved position in VPX space.</returns>
public static Vector3 HandlePosition(Vector3 position, Matrix4x4 localToWorld, ItemDataTransformType type, float handleSize = 0.2f, float snap = 0.0f)
public static Vector3 HandlePosition(Vector3 position, Matrix4x4 localToWorld, DragPointTransformType type, float handleSize = 0.2f, float snap = 0.0f)
{

var pos = position.TranslateToWorld();
Handles.matrix = localToWorld;

switch (type) {
case ItemDataTransformType.TwoD: {
case DragPointTransformType.TwoD: {

var forward = Vector3.forward.TranslateToWorld().normalized;
var right = Vector3.right.TranslateToWorld().normalized;
Expand All @@ -61,7 +61,7 @@ public static Vector3 HandlePosition(Vector3 position, Matrix4x4 localToWorld, I
break;
}

case ItemDataTransformType.ThreeD: {
case DragPointTransformType.ThreeD: {
pos = Handles.PositionHandle(pos, Quaternion.identity.RotateToWorld());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ namespace VisualPinball.Unity.Editor
public class BumperInspector : MainInspector<BumperData, BumperComponent>
{
private SerializedProperty _radiusProperty;
private SerializedProperty _surfaceProperty;
private SerializedProperty _isHardwiredProperty;

protected override void OnEnable()
{
base.OnEnable();

_radiusProperty = serializedObject.FindProperty(nameof(BumperComponent.Radius));
_surfaceProperty = serializedObject.FindProperty(nameof(BumperComponent._surface));
_isHardwiredProperty = serializedObject.FindProperty(nameof(BumperComponent.IsHardwired));
}

Expand All @@ -50,7 +48,7 @@ public override void OnInspectorGUI()

// position
EditorGUI.BeginChangeCheck();
var newPos = EditorGUILayout.Vector2Field(new GUIContent("Position", "Position of the bumper on the playfield, relative to its parent."), MainComponent.Position);
var newPos = EditorGUILayout.Vector3Field(new GUIContent("Position", "Position of the bumper on the playfield, relative to its parent."), MainComponent.Position);
if (EditorGUI.EndChangeCheck()) {
Undo.RecordObject(MainComponent.transform, "Change Bumper Position");
MainComponent.Position = newPos;
Expand All @@ -74,7 +72,6 @@ public override void OnInspectorGUI()
MainComponent.Orientation = newAngle;
}

PropertyField(_surfaceProperty, updateTransforms: true);
PropertyField(_isHardwiredProperty, updateTransforms: false);

base.OnInspectorGUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class FlipperInspector : MainInspector<FlipperData, FlipperComponent>
private bool _foldoutRubberGeometry = true;

private SerializedProperty _endAngleProperty;
private SerializedProperty _surfaceProperty;
private SerializedProperty _isEnabledProperty;
private SerializedProperty _isDualWoundProperty;
private SerializedProperty _heightProperty;
Expand All @@ -46,7 +45,6 @@ protected override void OnEnable()
base.OnEnable();

_endAngleProperty = serializedObject.FindProperty(nameof(FlipperComponent.EndAngle));
_surfaceProperty = serializedObject.FindProperty(nameof(FlipperComponent._surface));
_isEnabledProperty = serializedObject.FindProperty(nameof(FlipperComponent.IsEnabled));
_isDualWoundProperty = serializedObject.FindProperty(nameof(FlipperComponent.IsDualWound));
_heightProperty = serializedObject.FindProperty(nameof(FlipperComponent._height));
Expand Down Expand Up @@ -86,7 +84,6 @@ public override void OnInspectorGUI()
}

PropertyField(_endAngleProperty);
PropertyField(_surfaceProperty);
PropertyField(_isEnabledProperty);
PropertyField(_isDualWoundProperty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class GateInspector : MainInspector<GateData, GateComponent>
{ "Wire W", GateType.GateWireW },
};

private SerializedProperty _surfaceProperty;
private SerializedProperty _meshProperty;
private SerializedProperty _typeProperty;

Expand All @@ -46,7 +45,6 @@ protected override void OnEnable()
{
base.OnEnable();

_surfaceProperty = serializedObject.FindProperty(nameof(GateComponent._surface));
_meshProperty = serializedObject.FindProperty(nameof(GateComponent._meshName));
_typeProperty = serializedObject.FindProperty(nameof(GateComponent._type));
}
Expand Down Expand Up @@ -85,8 +83,6 @@ public override void OnInspectorGUI()
MainComponent.Length = newLength;
}

PropertyField(_surfaceProperty);

var wire = MainComponent.transform.Find(GateComponent.WireObjectName);
if (wire != null) {
MeshDropdownPropertyFbx("Mesh", _meshProperty, MeshFbx, wire.gameObject, _typeProperty, WireTypeMap, "Wire.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ private void OnUndoRedoPerformed()
case IMeshComponent meshItem:
meshItem.MainRenderableComponent.RebuildMeshes();
meshItem.MainRenderableComponent.UpdateTransforms();
meshItem.MainRenderableComponent.UpdateVisibility();
// meshItem.MainRenderableComponent.UpdateVisibility();
break;
case IMainRenderableComponent mainItem:
mainItem.RebuildMeshes();
mainItem.UpdateTransforms();
mainItem.UpdateVisibility();
// mainItem.UpdateVisibility();
break;
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void EndEditing()
meshItem.MainRenderableComponent.UpdateTransforms();
}
if (_visibilityDirty) {
meshItem.MainRenderableComponent.UpdateVisibility();
// meshItem.MainRenderableComponent.UpdateVisibility();
}
break;

Expand All @@ -118,7 +118,7 @@ protected void EndEditing()
mainItem.UpdateTransforms();
}
if (_visibilityDirty) {
mainItem.UpdateVisibility();
// mainItem.UpdateVisibility();
}
break;

Expand Down Expand Up @@ -227,7 +227,7 @@ protected void DropDownProperty(string label, SerializedProperty prop, string[]
meshItem.MainRenderableComponent.RebuildMeshes();
}
if (updateVisibility) {
meshItem.MainRenderableComponent.UpdateVisibility();
// meshItem.MainRenderableComponent.UpdateVisibility();
}
break;

Expand All @@ -236,7 +236,7 @@ protected void DropDownProperty(string label, SerializedProperty prop, string[]
mainItem.RebuildMeshes();
}
if (updateVisibility) {
mainItem.UpdateVisibility();
// mainItem.UpdateVisibility();
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class KickerInspector : MainInspector<KickerData, KickerComponent>
};

private SerializedProperty _orientationProperty;
private SerializedProperty _surfaceProperty;
private SerializedProperty _kickerTypeProperty;
private SerializedProperty _meshNameProperty;
private SerializedProperty _coilsProperty;
Expand All @@ -52,7 +51,6 @@ protected override void OnEnable()
base.OnEnable();

_orientationProperty = serializedObject.FindProperty(nameof(KickerComponent.Orientation));
_surfaceProperty = serializedObject.FindProperty(nameof(KickerComponent._surface));
_kickerTypeProperty = serializedObject.FindProperty(nameof(KickerComponent.KickerType));
_meshNameProperty = serializedObject.FindProperty(nameof(KickerComponent.MeshName));
_coilsProperty = serializedObject.FindProperty(nameof(KickerComponent.Coils));
Expand All @@ -70,7 +68,7 @@ public override void OnInspectorGUI()

// position
EditorGUI.BeginChangeCheck();
var newPos = EditorGUILayout.Vector2Field(new GUIContent("Position", "Position of the kicker on the playfield, relative to its parent."), MainComponent.Position);
var newPos = EditorGUILayout.Vector3Field(new GUIContent("Position", "Position of the kicker on the playfield, relative to its parent."), MainComponent.Position);
if (EditorGUI.EndChangeCheck()) {
Undo.RecordObject(MainComponent.transform, "Change Kicker Position");
MainComponent.Position = newPos;
Expand All @@ -88,7 +86,6 @@ public override void OnInspectorGUI()
MainComponent.KickerType == KickerType.KickerWilliams) {
PropertyField(_orientationProperty, updateTransforms: true);
}
PropertyField(_surfaceProperty, updateTransforms: true);

MeshDropdownProperty("Mesh", _meshNameProperty, MeshFolder, MainComponent.gameObject, _kickerTypeProperty, TypeMap);

Expand All @@ -108,9 +105,7 @@ private void OnSceneGUI()
Handles.color = Color.cyan;
Handles.matrix = Matrix4x4.identity;
var transform = MainComponent.transform;
var localPos = MainComponent.GetEditorPosition();
localPos.z = MainComponent.PositionZ;

var localPos = MainComponent.Position;
var worldPos = transform.parent == null ? localPos : localPos.TranslateToWorld();

foreach (var coil in MainComponent.Coils) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void OnSceneGUI()

public bool PointsAreLooping => true;
public IEnumerable<DragPointExposure> DragPointExposition => new[] { DragPointExposure.Smooth, DragPointExposure.Texture };
public ItemDataTransformType HandleType => ItemDataTransformType.TwoD;
public DragPointTransformType HandleType => DragPointTransformType.TwoD;
public DragPointsInspectorHelper DragPointsHelper { get; private set; }
public float ZOffset => MeshComponent.PositionZ;
public float[] TopBottomZ => null;
Expand Down
Loading

0 comments on commit 98a151a

Please sign in to comment.