コード例 #1
0
        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();
            }
        }