Add horizontal camera scaling for devices
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using AppleHillsCamera;
|
||||
|
||||
namespace Editor.CustomEditorsAndDrawers
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom editor for CameraScreenAdapter component.
|
||||
/// Shows scaling mode info and provides helper buttons.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(CameraScreenAdapter))]
|
||||
public class CameraScreenAdapterEditor : UnityEditor.Editor
|
||||
{
|
||||
private SerializedProperty _referenceMarkerProp;
|
||||
private SerializedProperty _adjustOnStartProp;
|
||||
private SerializedProperty _adjustOnScreenResizeProp;
|
||||
private SerializedProperty _debugLoggingProp;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_referenceMarkerProp = serializedObject.FindProperty("referenceMarker");
|
||||
_adjustOnStartProp = serializedObject.FindProperty("adjustOnStart");
|
||||
_adjustOnScreenResizeProp = serializedObject.FindProperty("adjustOnScreenResize");
|
||||
_debugLoggingProp = serializedObject.FindProperty("debugLogging");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
CameraScreenAdapter adapter = (CameraScreenAdapter)target;
|
||||
|
||||
// Reference Marker
|
||||
EditorGUILayout.PropertyField(_referenceMarkerProp);
|
||||
|
||||
// Show current scaling mode info if reference marker is assigned
|
||||
if (adapter.referenceMarker != null)
|
||||
{
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
ScreenReferenceMarker.ScalingMode mode = adapter.referenceMarker.scalingMode;
|
||||
string modeStr = mode == ScreenReferenceMarker.ScalingMode.Width ? "Width" : "Height";
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
$"Current Scaling Mode: {modeStr}\n" +
|
||||
(mode == ScreenReferenceMarker.ScalingMode.Width
|
||||
? $"Target Width: {adapter.referenceMarker.targetWidth:F2} units"
|
||||
: $"Target Height: {adapter.referenceMarker.targetHeight:F2} units"),
|
||||
MessageType.Info
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.Space(5);
|
||||
EditorGUILayout.HelpBox(
|
||||
"Assign a ScreenReferenceMarker to configure camera scaling.",
|
||||
MessageType.Warning
|
||||
);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
// Settings
|
||||
EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(_adjustOnStartProp);
|
||||
EditorGUILayout.PropertyField(_adjustOnScreenResizeProp);
|
||||
EditorGUILayout.PropertyField(_debugLoggingProp);
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
// Manual adjustment button
|
||||
GUI.enabled = adapter.referenceMarker != null;
|
||||
if (GUILayout.Button("Adjust Camera Now"))
|
||||
{
|
||||
adapter.AdjustCamera();
|
||||
SceneView.RepaintAll(); // Refresh scene view to show changes
|
||||
}
|
||||
GUI.enabled = true;
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 534f6a2da4584452b0df63f25d0d95df
|
||||
timeCreated: 1766065528
|
||||
@@ -0,0 +1,105 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using AppleHillsCamera;
|
||||
|
||||
namespace Editor.CustomEditorsAndDrawers
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom editor for ScreenReferenceMarker component.
|
||||
/// Shows only relevant fields based on the selected scaling mode.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(ScreenReferenceMarker))]
|
||||
public class ScreenReferenceMarkerEditor : UnityEditor.Editor
|
||||
{
|
||||
private SerializedProperty _scalingModeProp;
|
||||
private SerializedProperty _targetWidthProp;
|
||||
private SerializedProperty _targetHeightProp;
|
||||
private SerializedProperty _topMarginProp;
|
||||
private SerializedProperty _bottomMarginProp;
|
||||
private SerializedProperty _leftMarginProp;
|
||||
private SerializedProperty _rightMarginProp;
|
||||
private SerializedProperty _gizmoColorProp;
|
||||
private SerializedProperty _screenEdgeColorProp;
|
||||
private SerializedProperty _showVerticalMarginsProp;
|
||||
private SerializedProperty _showHorizontalMarginsProp;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_scalingModeProp = serializedObject.FindProperty("scalingMode");
|
||||
_targetWidthProp = serializedObject.FindProperty("targetWidth");
|
||||
_targetHeightProp = serializedObject.FindProperty("targetHeight");
|
||||
_topMarginProp = serializedObject.FindProperty("topMargin");
|
||||
_bottomMarginProp = serializedObject.FindProperty("bottomMargin");
|
||||
_leftMarginProp = serializedObject.FindProperty("leftMargin");
|
||||
_rightMarginProp = serializedObject.FindProperty("rightMargin");
|
||||
_gizmoColorProp = serializedObject.FindProperty("gizmoColor");
|
||||
_screenEdgeColorProp = serializedObject.FindProperty("screenEdgeColor");
|
||||
_showVerticalMarginsProp = serializedObject.FindProperty("showVerticalMargins");
|
||||
_showHorizontalMarginsProp = serializedObject.FindProperty("showHorizontalMargins");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
// Scaling Mode
|
||||
EditorGUILayout.PropertyField(_scalingModeProp);
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
// Reference Dimensions Header
|
||||
EditorGUILayout.LabelField("Reference Dimensions", EditorStyles.boldLabel);
|
||||
|
||||
// Show appropriate dimension field based on scaling mode
|
||||
ScreenReferenceMarker.ScalingMode mode = (ScreenReferenceMarker.ScalingMode)_scalingModeProp.enumValueIndex;
|
||||
|
||||
if (mode == ScreenReferenceMarker.ScalingMode.Width)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_targetWidthProp, new GUIContent(
|
||||
"Target Width",
|
||||
"The target width that should match the screen width"
|
||||
));
|
||||
|
||||
// Show info about height
|
||||
EditorGUILayout.HelpBox(
|
||||
"Height will automatically adjust based on screen aspect ratio.",
|
||||
MessageType.Info
|
||||
);
|
||||
}
|
||||
else // ScalingMode.Height
|
||||
{
|
||||
EditorGUILayout.PropertyField(_targetHeightProp, new GUIContent(
|
||||
"Target Height",
|
||||
"The target height that should match the screen height"
|
||||
));
|
||||
|
||||
// Show info about width
|
||||
EditorGUILayout.HelpBox(
|
||||
"Width will automatically adjust based on screen aspect ratio.",
|
||||
MessageType.Info
|
||||
);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
// Margins
|
||||
EditorGUILayout.LabelField("Margins", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(_topMarginProp);
|
||||
EditorGUILayout.PropertyField(_bottomMarginProp);
|
||||
EditorGUILayout.PropertyField(_leftMarginProp);
|
||||
EditorGUILayout.PropertyField(_rightMarginProp);
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
// Visualization
|
||||
EditorGUILayout.LabelField("Visualization", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(_gizmoColorProp);
|
||||
EditorGUILayout.PropertyField(_screenEdgeColorProp);
|
||||
EditorGUILayout.PropertyField(_showVerticalMarginsProp);
|
||||
EditorGUILayout.PropertyField(_showHorizontalMarginsProp);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9988ac8e5878470997a08ecb42697daf
|
||||
timeCreated: 1766065516
|
||||
Reference in New Issue
Block a user