public void PreviewSettings() { bool hasR = false, hasG = false, hasB = false; // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop foreach (Object texture in targets) { bool _hasR, _hasG, _hasB; switch (texture) { case Texture3D texture3D: NTexturePreview.CheckRGBFormats(texture3D.format, out _hasR, out _hasG, out _hasB); break; case RenderTexture renderTexture: NTexturePreview.CheckRGBFormats(renderTexture.format, out _hasR, out _hasG, out _hasB); break; default: continue; } hasR = hasR || _hasR; hasB = hasB || _hasB; hasG = hasG || _hasG; } if (ImplementAxisSliders() && (materialOverride == null || materialOverride.ImplementAxisSliders())) { int width, height, depth; switch (target) { case Texture3D texture3D: width = texture3D.width; height = texture3D.height; depth = texture3D.depth; break; case RenderTexture renderTexture: width = renderTexture.width; height = renderTexture.height; depth = renderTexture.volumeDepth; break; default: return; } using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope()) { Vector3 size = new Vector3(width, height, depth); Vector3 sizeCurrent = new Vector3(x * (size.x - 1) + 1, y * (size.y - 1) + 1, z * (size.z - 1) + 1); #if UNITY_2019_3_OR_NEWER axis = (Axis)EditorGUILayout.EnumPopup(axis, s_Styles.previewDropDown, GUILayout.Width(30)); #else axis = (Axis)EditorGUILayout.EnumPopup(axis, s_Styles.previewDropDown, GUILayout.Width(25)); #endif switch (axis) { case Axis.X: x = Mathf.RoundToInt(GUILayout.HorizontalSlider((int)sizeCurrent.x, 1, (int)size.x, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.Width(200)) - 1) / Mathf.Max(1, size.x - 1); EditorGUILayout.LabelField(sizeCurrent.x.ToString(), s_Styles.previewLabel, GUILayout.Width(35)); break; case Axis.Y: y = Mathf.RoundToInt(GUILayout.HorizontalSlider((int)sizeCurrent.y, 1, (int)size.y, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.Width(200)) - 1) / Mathf.Max(1, size.y - 1); EditorGUILayout.LabelField(sizeCurrent.y.ToString(), s_Styles.previewLabel, GUILayout.Width(35)); break; case Axis.Z: z = Mathf.RoundToInt(GUILayout.HorizontalSlider((int)sizeCurrent.z, 1, (int)size.z, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.Width(200)) - 1) / Mathf.Max(1, size.z - 1); EditorGUILayout.LabelField(sizeCurrent.z.ToString(), s_Styles.previewLabel, GUILayout.Width(35)); break; } if (changeCheckScope.changed) { SetXYZFloats(); } } } continuousRepaint = GUILayout.Toggle(continuousRepaint, s_Styles.playIcon, s_Styles.previewButtonScale); if (GUILayout.Button(s_Styles.scaleIcon, s_Styles.previewButtonScale)) { zoom = 3; Repaint(); } DrawRGBToggles(hasR, hasB, hasG); }
public override void OnPreviewSettings() { defaultEditor.OnPreviewSettings(); bool hasR = false, hasG = false, hasB = false; // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop foreach (Texture3D texture3D in targets) { if (texture3D == null) // texture might have disappeared while we're showing this in a preview popup { continue; } bool _hasR, _hasG, _hasB; NTexturePreview.CheckRGBFormats(texture3D.format, out _hasR, out _hasG, out _hasB); hasR = hasR || _hasR; hasB = hasB || _hasB; hasG = hasG || _hasG; } if (ImplementAxisSliders() && (materialOverride == null || materialOverride.ImplementAxisSliders())) { Texture3D defaultTex3D = target as Texture3D; if (defaultTex3D != null) { using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope()) { Vector3 size = new Vector3(defaultTex3D.width, defaultTex3D.height, defaultTex3D.depth); Vector3 sizeCurrent = new Vector3(x * (size.x - 1) + 1, y * (size.y - 1) + 1, z * (size.z - 1) + 1); axis = (Axis)EditorGUILayout.EnumPopup(axis, s_Styles.previewDropDown, GUILayout.Width(25)); switch (axis) { case Axis.X: x = Mathf.RoundToInt(GUILayout.HorizontalSlider((int)sizeCurrent.x, 1, (int)size.x, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.Width(200)) - 1) / (size.x - 1); EditorGUILayout.LabelField(sizeCurrent.x.ToString(), s_Styles.previewLabel, GUILayout.Width(25)); break; case Axis.Y: y = Mathf.RoundToInt(GUILayout.HorizontalSlider((int)sizeCurrent.y, 1, (int)size.y, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.Width(200)) - 1) / (size.y - 1); EditorGUILayout.LabelField(sizeCurrent.y.ToString(), s_Styles.previewLabel, GUILayout.Width(25)); break; case Axis.Z: z = Mathf.RoundToInt(GUILayout.HorizontalSlider((int)sizeCurrent.z, 1, (int)size.z, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.Width(200)) - 1) / (size.z - 1); EditorGUILayout.LabelField(sizeCurrent.z.ToString(), s_Styles.previewLabel, GUILayout.Width(25)); break; } if (changeCheckScope.changed) { SetXYZFloats(); } } } } if (GUILayout.Button(s_Styles.scaleIcon, s_Styles.previewButton)) { zoom = 3; Repaint(); } DrawRGBToggles(hasR, hasB, hasG); }