void CacheABunchOfStuff(SerializedProperty property) { object lens = SerializedPropertyHelper.GetPropertyValue(property); IsOrtho = AccessProperty <bool>(typeof(LensSettings), lens, "Orthographic"); IsPhysical = AccessProperty <bool>(typeof(LensSettings), lens, "IsPhysicalCamera"); SensorSize = AccessProperty <Vector2>(typeof(LensSettings), lens, "SensorSize"); List <GUIContent> options = new List <GUIContent>(); CinemachineLensPresets presets = CinemachineLensPresets.InstanceIfExists; if (presets != null) { for (int i = 0; i < presets.m_Presets.Length; ++i) { options.Add(new GUIContent(presets.m_Presets[i].m_Name)); } } options.Add(new GUIContent("Edit Presets...")); m_PresetOptions = options.ToArray(); options.Clear(); if (presets != null) { for (int i = 0; i < presets.m_PhysicalPresets.Length; ++i) { options.Add(new GUIContent(presets.m_PhysicalPresets[i].m_Name)); } } options.Add(new GUIContent("Edit Presets...")); m_PhysicalPresetOptions = options.ToArray(); }
void DrawFOVControl(Rect rect, SerializedProperty property) { var FOVProperty = property.FindPropertyRelative(() => def.FieldOfView); float dropdownWidth = (rect.width - EditorGUIUtility.labelWidth) / 3; rect.width -= dropdownWidth; EditorGUI.PropertyField(rect, FOVProperty); rect.x += rect.width; rect.width = dropdownWidth; CinemachineLensPresets presets = CinemachineLensPresets.InstanceIfExists; int preset = (presets == null) ? -1 : presets.GetMatchingPreset(FOVProperty.floatValue); rect.x -= ExtraSpaceHackWTF(); rect.width += ExtraSpaceHackWTF(); int selection = EditorGUI.Popup(rect, GUIContent.none, preset, m_PresetOptions); if (selection == m_PresetOptions.Length - 1 && CinemachineLensPresets.Instance != null) { Selection.activeObject = presets = CinemachineLensPresets.Instance; } else if (selection >= 0 && selection < m_PresetOptions.Length - 1) { FOVProperty.floatValue = presets.m_Presets[selection].m_FieldOfView; property.serializedObject.ApplyModifiedProperties(); } }
void DrawFocalLengthControl(Rect rect, SerializedProperty property) { var FOVProperty = property.FindPropertyRelative(() => def.FieldOfView); float dropdownWidth = (rect.width - EditorGUIUtility.labelWidth) / 3; rect.width -= dropdownWidth; float f = VerticalFOVToFocalLength(FOVProperty.floatValue); f = EditorGUI.FloatField(rect, FocalLengthLabel, f); f = FocalLengthToVerticalFOV(f); if (!Mathf.Approximately(FOVProperty.floatValue, f)) { FOVProperty.floatValue = Mathf.Clamp(f, 1, 179); property.serializedObject.ApplyModifiedProperties(); } rect.x += rect.width; rect.width = dropdownWidth; CinemachineLensPresets presets = CinemachineLensPresets.Instance; int preset = presets.GetMatchingPhysicalPreset(VerticalFOVToFocalLength(FOVProperty.floatValue)); rect.x -= ExtraSpaceHackWTF(); rect.width += ExtraSpaceHackWTF(); int selection = EditorGUI.Popup(rect, GUIContent.none, preset, m_PhysicalPresetOptions); if (selection == m_PhysicalPresetOptions.Length - 1) { Selection.activeObject = presets; } else if (selection >= 0 && selection < m_PhysicalPresetOptions.Length - 1) { FOVProperty.floatValue = FocalLengthToVerticalFOV( presets.m_PhysicalPresets[selection].m_FocalLength); property.serializedObject.ApplyModifiedProperties(); } }
void DrawFOVControl(Rect rect, SerializedProperty property) { const float hSpace = 2; var label = UseHorizontalFOV ? HFOVLabel : VFOVLabel; var FOVProperty = property.FindPropertyRelative(() => m_LensSettingsDef.FieldOfView); float aspect = SensorSize.x / SensorSize.y; float dropdownWidth = (rect.width - EditorGUIUtility.labelWidth) / 4; rect.width -= dropdownWidth + hSpace; float f = FOVProperty.floatValue; if (UseHorizontalFOV) { f = CameraExtensions.VerticalToHorizontalFieldOfView(f, aspect); } EditorGUI.BeginProperty(rect, label, FOVProperty); f = EditorGUI.FloatField(rect, label, f); if (UseHorizontalFOV) { f = CameraExtensions.HorizontalToVerticalFieldOfView(Mathf.Clamp(f, 1, 179), aspect); } if (!Mathf.Approximately(FOVProperty.floatValue, f)) { FOVProperty.floatValue = Mathf.Clamp(f, 1, 179); } EditorGUI.EndProperty(); rect.x += rect.width + hSpace; rect.width = dropdownWidth; CinemachineLensPresets presets = CinemachineLensPresets.InstanceIfExists; int preset = (presets == null) ? -1 : presets.GetMatchingPreset(FOVProperty.floatValue); rect.x -= ExtraSpaceHackWTF(); rect.width += ExtraSpaceHackWTF(); int selection = EditorGUI.Popup(rect, GUIContent.none, preset, m_PresetOptions); if (selection == m_PresetOptions.Length - 1 && CinemachineLensPresets.Instance != null) { Selection.activeObject = presets = CinemachineLensPresets.Instance; } else if (selection >= 0 && selection < m_PresetOptions.Length - 1) { var vfov = presets.m_Presets[selection].m_FieldOfView; FOVProperty.floatValue = vfov; property.serializedObject.ApplyModifiedProperties(); } }
public LensSettingsInspectorHelper() { #if CINEMACHINE_HDRP PhysicalPropertiesLabel = new GUIContent("Physical Properties", "Physical properties of the lens"); #endif var options = new List <GUIContent>(); CinemachineLensPresets presets = CinemachineLensPresets.InstanceIfExists; for (int i = 0; presets != null && i < presets.m_Presets.Length; ++i) { options.Add(new GUIContent(presets.m_Presets[i].m_Name)); } options.Add(EditPresetsLabel); m_PresetOptions = options.ToArray(); options.Clear(); for (int i = 0; presets != null && i < presets.m_PhysicalPresets.Length; ++i) { options.Add(new GUIContent(presets.m_PhysicalPresets[i].m_Name)); } options.Add(EditPresetsLabel); m_PhysicalPresetOptions = options.ToArray(); }
void DrawFocalLengthControl(Rect rect, SerializedProperty property, GUIContent label) { const float hSpace = 2; var FOVProperty = property.FindPropertyRelative(() => m_LensSettingsDef.FieldOfView); float dropdownWidth = (rect.width - EditorGUIUtility.labelWidth) / 4; rect.width -= dropdownWidth + hSpace; float f = CameraExtensions.FieldOfViewToFocalLength(FOVProperty.floatValue, SensorSize.y); EditorGUI.BeginProperty(rect, label, FOVProperty); f = EditorGUI.FloatField(rect, label, f); f = CameraExtensions.FocalLengthToFieldOfView(Mathf.Max(f, 0.0001f), SensorSize.y); if (!Mathf.Approximately(FOVProperty.floatValue, f)) { FOVProperty.floatValue = Mathf.Clamp(f, 1, 179); } EditorGUI.EndProperty(); rect.x += rect.width + hSpace; rect.width = dropdownWidth; #if CINEMACHINE_HDRP CinemachineLensPresets presets = CinemachineLensPresets.InstanceIfExists; int preset = -1; if (presets != null) { var focalLength = CameraExtensions.FieldOfViewToFocalLength(FOVProperty.floatValue, SensorSize.y); var aperture = property.FindPropertyRelative(() => m_LensSettingsDef.Aperture).floatValue; var iso = property.FindPropertyRelative(() => m_LensSettingsDef.Iso).intValue; var shutterSpeed = property.FindPropertyRelative(() => m_LensSettingsDef.ShutterSpeed).floatValue; var bladeCount = property.FindPropertyRelative(() => m_LensSettingsDef.BladeCount).intValue; var curvature = property.FindPropertyRelative(() => m_LensSettingsDef.Curvature).vector2Value; var barrelClipping = property.FindPropertyRelative(() => m_LensSettingsDef.BarrelClipping).floatValue; var anamprphism = property.FindPropertyRelative(() => m_LensSettingsDef.Anamorphism).floatValue; var lensShift = property.FindPropertyRelative(() => m_LensSettingsDef.LensShift).vector2Value; preset = presets.GetMatchingPhysicalPreset( focalLength, iso, shutterSpeed, aperture, bladeCount, curvature, barrelClipping, anamprphism, lensShift); } rect.x -= ExtraSpaceHackWTF(); rect.width += ExtraSpaceHackWTF(); int selection = EditorGUI.Popup(rect, GUIContent.none, preset, m_PhysicalPresetOptions); if (selection == m_PhysicalPresetOptions.Length - 1 && CinemachineLensPresets.Instance != null) { Selection.activeObject = presets = CinemachineLensPresets.Instance; } else if (selection >= 0 && selection < m_PhysicalPresetOptions.Length - 1) { var v = presets.m_PhysicalPresets[selection]; FOVProperty.floatValue = CameraExtensions.FocalLengthToFieldOfView(v.m_FocalLength, SensorSize.y); property.FindPropertyRelative(() => m_LensSettingsDef.Aperture).floatValue = v.Aperture; property.FindPropertyRelative(() => m_LensSettingsDef.Iso).intValue = v.Iso; property.FindPropertyRelative(() => m_LensSettingsDef.ShutterSpeed).floatValue = v.ShutterSpeed; property.FindPropertyRelative(() => m_LensSettingsDef.BladeCount).intValue = v.BladeCount; property.FindPropertyRelative(() => m_LensSettingsDef.Curvature).vector2Value = v.Curvature; property.FindPropertyRelative(() => m_LensSettingsDef.BarrelClipping).floatValue = v.BarrelClipping; property.FindPropertyRelative(() => m_LensSettingsDef.Anamorphism).floatValue = v.Anamorphism; property.FindPropertyRelative(() => m_LensSettingsDef.LensShift).vector2Value = v.LensShift; property.serializedObject.ApplyModifiedProperties(); } #else CinemachineLensPresets presets = CinemachineLensPresets.InstanceIfExists; int preset = (presets == null) ? -1 : presets.GetMatchingPhysicalPreset( CameraExtensions.FieldOfViewToFocalLength(FOVProperty.floatValue, SensorSize.y)); rect.x -= ExtraSpaceHackWTF(); rect.width += ExtraSpaceHackWTF(); int selection = EditorGUI.Popup(rect, GUIContent.none, preset, m_PhysicalPresetOptions); if (selection == m_PhysicalPresetOptions.Length - 1 && CinemachineLensPresets.Instance != null) { Selection.activeObject = presets = CinemachineLensPresets.Instance; } else if (selection >= 0 && selection < m_PhysicalPresetOptions.Length - 1) { FOVProperty.floatValue = CameraExtensions.FocalLengthToFieldOfView( presets.m_PhysicalPresets[selection].m_FocalLength, SensorSize.y); property.serializedObject.ApplyModifiedProperties(); } #endif }