Skip to content

Commit 9fb296e

Browse files
committed
Added missing delayed-friendly dragging for lens clip planes
1 parent 9016fee commit 9fb296e

File tree

1 file changed

+43
-45
lines changed

1 file changed

+43
-45
lines changed

com.unity.cinemachine/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class LensSettingsHideModeOverridePropertyDrawer : LensSettingsPropertyDrawer
1616
[CustomPropertyDrawer(typeof(LensSettings))]
1717
class LensSettingsPropertyDrawer : PropertyDrawer
1818
{
19-
static LensSettings s_Def = new (); // to access name strings
20-
2119
static bool IsOrtho(SerializedProperty property) => AccessProperty<bool>(
2220
typeof(LensSettings), SerializedPropertyHelper.GetPropertyValue(property), "Orthographic");
2321

@@ -96,9 +94,8 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
9694
// Populate the foldout
9795
var innerFovControl = foldout.AddChild(new FovPropertyControl(property, false));
9896

99-
var nearClip = property.FindPropertyRelative(() => s_Def.NearClipPlane);
100-
var nearClipField = foldout.AddChild(new PropertyField(nearClip));
101-
nearClipField.OnInitialGeometry(() => nearClipField.SafeSetIsDelayed());
97+
var nearClip = property.FindPropertyRelative(nameof(LensSettings.NearClipPlane));
98+
foldout.AddChild(InspectorUtility.PropertyRow(nearClip, out var nearClipField)); // for friendly drag
10299
nearClipField.RegisterValueChangeCallback((evt) =>
103100
{
104101
if (!IsOrtho(property) && nearClip.floatValue < 0.01f)
@@ -107,17 +104,18 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
107104
property.serializedObject.ApplyModifiedPropertiesWithoutUndo();
108105
}
109106
});
110-
var farClipField = foldout.AddChild(new PropertyField(property.FindPropertyRelative(() => s_Def.FarClipPlane)));
107+
foldout.AddChild(InspectorUtility.PropertyRow(
108+
property.FindPropertyRelative(nameof(LensSettings.FarClipPlane)), out var farClipField)); // for friendly drag
111109
farClipField.OnInitialGeometry(() => farClipField.SafeSetIsDelayed());
112-
foldout.Add(new PropertyField(property.FindPropertyRelative(() => s_Def.Dutch)));
110+
foldout.Add(new PropertyField(property.FindPropertyRelative(nameof(LensSettings.Dutch))));
113111

114-
var physical = foldout.AddChild(new PropertyField(property.FindPropertyRelative(() => s_Def.PhysicalProperties)));
112+
var physical = foldout.AddChild(new PropertyField(property.FindPropertyRelative(nameof(LensSettings.PhysicalProperties))));
115113

116114
SerializedProperty modeOverrideProperty = null;
117115
VisualElement modeHelp = null;
118116
if (!HideModeOverride)
119117
{
120-
modeOverrideProperty = property.FindPropertyRelative(() => s_Def.ModeOverride);
118+
modeOverrideProperty = property.FindPropertyRelative(nameof(LensSettings.ModeOverride));
121119
modeHelp = foldout.AddChild(
122120
new HelpBox("Lens Mode Override must be enabled in the Cinemachine Brain for Mode Override to take effect",
123121
HelpBoxMessageType.Warning));
@@ -185,8 +183,8 @@ public FovPropertyControl(SerializedProperty property, bool hideLabel) : base(hi
185183
style.flexGrow = 1;
186184

187185
m_LensProperty = property;
188-
var physicalProp = property.FindPropertyRelative(() => s_Def.PhysicalProperties);
189-
m_SensorSizeProperty = physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.SensorSize);
186+
var physicalProp = property.FindPropertyRelative(nameof(LensSettings.PhysicalProperties));
187+
m_SensorSizeProperty = physicalProp.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.SensorSize));
190188

191189
m_Control = Contents.AddChild(new FloatField("") { style = { flexBasis = 20, flexGrow = 2, marginLeft = 2 }});
192190
m_Control.RegisterValueChangedCallback(OnControlValueChanged);
@@ -213,7 +211,7 @@ void OnControlValueChanged(ChangeEvent<float> evt)
213211
{
214212
case Modes.Ortho:
215213
{
216-
var orthoProp = m_LensProperty.FindPropertyRelative(() => s_Def.OrthographicSize);
214+
var orthoProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.OrthographicSize));
217215
orthoProp.floatValue = evt.newValue;
218216
orthoProp.serializedObject.ApplyModifiedProperties();
219217
break;
@@ -226,7 +224,7 @@ void OnControlValueChanged(ChangeEvent<float> evt)
226224
m_Control.SetValueWithoutNotify(FovToFocalLength(vfov));
227225

228226
// Push to property
229-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
227+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
230228
fovProp.floatValue = vfov;
231229
fovProp.serializedObject.ApplyModifiedProperties();
232230
break;
@@ -242,7 +240,7 @@ void OnControlValueChanged(ChangeEvent<float> evt)
242240
newValue = Camera.HorizontalToVerticalFieldOfView(newValue, Aspect(m_LensProperty));
243241

244242
// Push to property
245-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
243+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
246244
fovProp.floatValue = newValue;
247245
fovProp.serializedObject.ApplyModifiedProperties();
248246
break;
@@ -257,14 +255,14 @@ void OnLensPropertyChanged(SerializedProperty p)
257255
{
258256
case Modes.Ortho:
259257
{
260-
var orthoProp = m_LensProperty.FindPropertyRelative(() => s_Def.OrthographicSize);
258+
var orthoProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.OrthographicSize));
261259
m_Control.SetValueWithoutNotify(orthoProp.floatValue);
262260
break;
263261
}
264262
case Modes.Physical:
265263
{
266264
// Convert to display FolcalLength units
267-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
265+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
268266
var v = FovToFocalLength(fovProp.floatValue);
269267
m_Control.SetValueWithoutNotify(v);
270268

@@ -282,7 +280,7 @@ void OnLensPropertyChanged(SerializedProperty p)
282280
case Modes.HFOV:
283281
{
284282
// Convert to display FOV units
285-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
283+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
286284
var v = fovProp.floatValue;
287285
if (mode == Modes.HFOV)
288286
v = Camera.VerticalToHorizontalFieldOfView(v, Aspect(m_LensProperty));
@@ -307,7 +305,7 @@ public void TimedUpdate(bool aspectChanged)
307305
var text = "O";
308306
if (ShortLabel.text != text)
309307
{
310-
var orthoProp = m_LensProperty.FindPropertyRelative(() => s_Def.OrthographicSize);
308+
var orthoProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.OrthographicSize));
311309
ShortLabel.text = text;
312310
Label.text = orthoProp.displayName;
313311
Label.tooltip = m_Control.tooltip = ShortLabel.tooltip = orthoProp.tooltip;
@@ -320,7 +318,7 @@ public void TimedUpdate(bool aspectChanged)
320318
var text = "F";
321319
if (ShortLabel.text != text)
322320
{
323-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
321+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
324322
ShortLabel.text = text;
325323
Label.text = ShortLabel.tooltip = "Focal Length";
326324
Label.tooltip = m_Control.tooltip = fovProp.tooltip;
@@ -334,7 +332,7 @@ public void TimedUpdate(bool aspectChanged)
334332
var text = "H";
335333
if (ShortLabel.text != text)
336334
{
337-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
335+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
338336
ShortLabel.text = text;
339337
Label.text = ShortLabel.tooltip = "Horizontal FOV";
340338
Label.tooltip = m_Control.tooltip = fovProp.tooltip;
@@ -351,7 +349,7 @@ public void TimedUpdate(bool aspectChanged)
351349
var text = "V";
352350
if (ShortLabel.text != text)
353351
{
354-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
352+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
355353
ShortLabel.text = text;
356354
Label.text = ShortLabel.tooltip = "Vertical FOV";
357355
Label.tooltip = m_Control.tooltip = fovProp.tooltip;
@@ -395,7 +393,7 @@ void OnPresetValueChanged(ChangeEvent<string> evt)
395393
if (index >= 0)
396394
{
397395
var v = palette.Presets[index];
398-
m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView).floatValue = FocalLengthToFov(v.FocalLength);
396+
m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView)).floatValue = FocalLengthToFov(v.FocalLength);
399397
WritePhysicalSettings(v.PhysicalProperties);
400398
m_LensProperty.serializedObject.ApplyModifiedProperties();
401399
return;
@@ -409,7 +407,7 @@ void OnPresetValueChanged(ChangeEvent<string> evt)
409407
var palette = CinemachineLensPalette.Instance;
410408
if (palette != null)
411409
{
412-
var fovProp = m_LensProperty.FindPropertyRelative(() => s_Def.FieldOfView);
410+
var fovProp = m_LensProperty.FindPropertyRelative(nameof(LensSettings.FieldOfView));
413411

414412
// Edit the presets assets if desired
415413
if (evt.newValue == k_EditPresetsLabel)
@@ -439,35 +437,35 @@ void OnPresetValueChanged(ChangeEvent<string> evt)
439437

440438
LensSettings.PhysicalSettings ReadPhysicalSettings()
441439
{
442-
var p = m_LensProperty.FindPropertyRelative(() => s_Def.PhysicalProperties);
440+
var p = m_LensProperty.FindPropertyRelative(nameof(LensSettings.PhysicalProperties));
443441
return new ()
444442
{
445-
GateFit = (Camera.GateFitMode)p.FindPropertyRelative(() => s_Def.PhysicalProperties.GateFit).intValue,
446-
SensorSize = p.FindPropertyRelative(() => s_Def.PhysicalProperties.SensorSize).vector2Value,
447-
LensShift = p.FindPropertyRelative(() => s_Def.PhysicalProperties.LensShift).vector2Value,
448-
Iso = p.FindPropertyRelative(() => s_Def.PhysicalProperties.Iso).intValue,
449-
ShutterSpeed = p.FindPropertyRelative(() => s_Def.PhysicalProperties.ShutterSpeed).floatValue,
450-
Aperture = p.FindPropertyRelative(() => s_Def.PhysicalProperties.Aperture).floatValue,
451-
BladeCount = p.FindPropertyRelative(() => s_Def.PhysicalProperties.BladeCount).intValue,
452-
Curvature = p.FindPropertyRelative(() => s_Def.PhysicalProperties.Curvature).vector2Value,
453-
BarrelClipping = p.FindPropertyRelative(() => s_Def.PhysicalProperties.BarrelClipping).floatValue,
454-
Anamorphism =p.FindPropertyRelative(() => s_Def.PhysicalProperties.Anamorphism).floatValue
443+
GateFit = (Camera.GateFitMode)p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.GateFit)).intValue,
444+
SensorSize = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.SensorSize)).vector2Value,
445+
LensShift = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.LensShift)).vector2Value,
446+
Iso = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Iso)).intValue,
447+
ShutterSpeed = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.ShutterSpeed)).floatValue,
448+
Aperture = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Aperture)).floatValue,
449+
BladeCount = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.BladeCount)).intValue,
450+
Curvature = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Curvature)).vector2Value,
451+
BarrelClipping = p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.BarrelClipping)).floatValue,
452+
Anamorphism =p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Anamorphism)).floatValue
455453
};
456454
}
457455

458456
void WritePhysicalSettings(in LensSettings.PhysicalSettings s)
459457
{
460-
var p = m_LensProperty.FindPropertyRelative(() => s_Def.PhysicalProperties);
461-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.GateFit).intValue = (int)s.GateFit;
462-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.SensorSize).vector2Value = s.SensorSize;
463-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.LensShift).vector2Value = s.LensShift;
464-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.Iso).intValue = s.Iso;
465-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.ShutterSpeed).floatValue = s.ShutterSpeed;
466-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.Aperture).floatValue = s.Aperture;
467-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.BladeCount).intValue = s.BladeCount;
468-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.Curvature).vector2Value = s.Curvature;
469-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.BarrelClipping).floatValue = s.BarrelClipping;
470-
p.FindPropertyRelative(() => s_Def.PhysicalProperties.Anamorphism).floatValue = s.Anamorphism;
458+
var p = m_LensProperty.FindPropertyRelative(nameof(LensSettings.PhysicalProperties));
459+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.GateFit)).intValue = (int)s.GateFit;
460+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.SensorSize)).vector2Value = s.SensorSize;
461+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.LensShift)).vector2Value = s.LensShift;
462+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Iso)).intValue = s.Iso;
463+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.ShutterSpeed)).floatValue = s.ShutterSpeed;
464+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Aperture)).floatValue = s.Aperture;
465+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.BladeCount)).intValue = s.BladeCount;
466+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Curvature)).vector2Value = s.Curvature;
467+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.BarrelClipping)).floatValue = s.BarrelClipping;
468+
p.FindPropertyRelative(nameof(LensSettings.PhysicalProperties.Anamorphism)).floatValue = s.Anamorphism;
471469
}
472470
}
473471
}

0 commit comments

Comments
 (0)