public override void OnInspectorGUI() { serializedObject.Update(); // Targeted Size PixelPerfectCamera.Dimension dimensionType = (PixelPerfectCamera.Dimension)Enum.GetValues(typeof(PixelPerfectCamera.Dimension)).GetValue(targetDimension.enumValueIndex); targetDimension.enumValueIndex = (int)(PixelPerfectCamera.Dimension)EditorGUILayout.EnumPopup("Target size", dimensionType); if (targetDimension.enumValueIndex == (int)PixelPerfectCamera.Dimension.Width) { EditorGUILayout.PropertyField(targetCameraHalfWidth, new GUIContent("Width", "The targetted half width of the camera.")); } else { EditorGUILayout.PropertyField(targetCameraHalfHeight, new GUIContent("Height", "The targetted half height of the camera.")); } EditorGUILayout.BeginHorizontal(); maxCameraHalfWidthEnabled.boolValue = EditorGUILayout.Toggle(maxCameraHalfWidthEnabled.boolValue, GUILayout.Width(12)); EditorGUI.BeginDisabledGroup(!maxCameraHalfWidthEnabled.boolValue); EditorGUILayout.PropertyField(maxCameraHalfWidth, new GUIContent("Max Width", "The maximum allowed half width of the camera.")); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); maxCameraHalfHeightEnabled.boolValue = EditorGUILayout.Toggle(maxCameraHalfHeightEnabled.boolValue, GUILayout.Width(12)); EditorGUI.BeginDisabledGroup(!maxCameraHalfHeightEnabled.boolValue); EditorGUILayout.PropertyField(maxCameraHalfHeight, new GUIContent("Max Height", "The maximum allowed half height of the camera.")); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); // Pixels Per Unit EditorGUILayout.PropertyField(assetsPixelsPerUnit); // Pixel Perfect toggle pixelPerfect.boolValue = EditorGUILayout.Toggle(new GUIContent("Pixel Perfect", "Makes the camera's pixels per unit to be a multiple of the assets' pixels per unit."), pixelPerfect.boolValue); // RetroSnap toggle retroSnap.boolValue = EditorGUILayout.Toggle(new GUIContent("Retro Snap", "Makes the objects using the PixelSnap script snap to the asset's pixel grid"), retroSnap.boolValue); // Show HUD toggle EditorGUILayout.PropertyField(showHUD); serializedObject.ApplyModifiedProperties(); // Show results if (!((PixelPerfectCamera)target).isInitialized) { return; } GUILayout.BeginVertical(); GUILayout.Space(5); DrawSizeStats(); GUILayout.EndVertical(); }
public override void OnInspectorGUI() { // Using serialized objects requires a bit more work, but enables multi-object editing, undo, and Prefab overrides. // https://docs.unity3d.com/ScriptReference/Editor.html // https://stackoverflow.com/questions/55027410/editor-target-vs-editor-serializedobject serializedObject.Update(); // Targeted Size PixelPerfectCamera.Dimension dimensionType = (PixelPerfectCamera.Dimension)Enum.GetValues(typeof(PixelPerfectCamera.Dimension)).GetValue(targetDimension.enumValueIndex); targetDimension.enumValueIndex = (int)(PixelPerfectCamera.Dimension)EditorGUILayout.EnumPopup("Target size", dimensionType); if (targetDimension.enumValueIndex == (int)PixelPerfectCamera.Dimension.Width) { EditorGUILayout.PropertyField(targetCameraWidth, new GUIContent("Width", "The target width of the camera in pixels.")); } else { EditorGUILayout.PropertyField(targetCameraHeight, new GUIContent("Height", "The target height of the camera in pixels.")); } EditorGUILayout.BeginHorizontal(); maxCameraWidthEnabled.boolValue = EditorGUILayout.Toggle(maxCameraWidthEnabled.boolValue, GUILayout.Width(12)); EditorGUI.BeginDisabledGroup(!maxCameraWidthEnabled.boolValue); EditorGUILayout.PropertyField(maxCameraWidth, new GUIContent("Max Width", "The maximum allowed width of the camera in pixels.")); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); maxCameraHeightEnabled.boolValue = EditorGUILayout.Toggle(maxCameraHeightEnabled.boolValue, GUILayout.Width(12)); EditorGUI.BeginDisabledGroup(!maxCameraHeightEnabled.boolValue); EditorGUILayout.PropertyField(maxCameraHeight, new GUIContent("Max Height", "The maximum allowed height of the camera in pixels.")); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); // Pixels Per Unit EditorGUILayout.PropertyField(assetsPixelsPerUnit); // Pixel Perfect toggle pixelPerfect.boolValue = EditorGUILayout.Toggle(new GUIContent("Pixel Perfect", "Makes the camera's pixels per unit to be a multiple of the assets' pixels per unit."), pixelPerfect.boolValue); // PixelSnap menu PixelPerfectCamera.PixelSnapMode pixelSnapModeSelected = (PixelPerfectCamera.PixelSnapMode)Enum.GetValues(typeof(PixelPerfectCamera.PixelSnapMode)).GetValue(pixelSnapMode.enumValueIndex); pixelSnapMode.enumValueIndex = (int)(PixelPerfectCamera.PixelSnapMode)EditorGUILayout.EnumPopup(new GUIContent("Pixel Snap mode", "Off: disables Pixel Snap \n" + "RetroSnap: Makes the objects snap to the asset's pixel grid \n" + "PixelSnap: Makes the objects snap to the screen's pixel grid \n\n" + "This option affects only objects that use the PixelSnap script."), pixelSnapModeSelected); // Show HUD toggle EditorGUILayout.PropertyField(showHUD); serializedObject.ApplyModifiedProperties(); // Show results if (!((PixelPerfectCamera)target).isInitialized) { return; } GUILayout.BeginVertical(); GUILayout.Space(5); DrawSizeStats(); GUILayout.EndVertical(); }