// Disable 'obsolete' warnings #pragma warning disable 0618 using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEditor; using UnityEditor.IMGUI.Controls; #endif #if UNITY_EDITOR [CustomEditor(typeof(BakeryVolume))] [CanEditMultipleObjects] public class BakeryVolumeInspector : Editor { BoxBoundsHandle boundsHandle = new BoxBoundsHandle(typeof(BakeryVolumeInspector).GetHashCode()); SerializedProperty ftraceAdaptiveRes, ftraceResX, ftraceResY, ftraceResZ, ftraceVoxelsPerUnit, ftraceAdjustSamples, ftraceEnableBaking, ftraceEncoding, ftraceShadowmaskEncoding, ftraceShadowmaskFirstLightIsAlwaysAlpha; SerializedProperty ftraceDenoise, ftraceGlobal, ftraceRotation, ftraceRotationY, ftraceMultiVolumePriority; bool showExperimental = false; ftLightmapsStorage storage; static BakeryProjectSettings pstorage; void OnEnable() { ftraceAdaptiveRes = serializedObject.FindProperty("adaptiveRes"); ftraceVoxelsPerUnit = serializedObject.FindProperty("voxelsPerUnit"); ftraceResX = serializedObject.FindProperty("resolutionX"); ftraceResY = serializedObject.FindProperty("resolutionY"); ftraceResZ = serializedObject.FindProperty("resolutionZ"); ftraceEnableBaking = serializedObject.FindProperty("enableBaking"); ftraceEncoding = serializedObject.FindProperty("encoding"); ftraceShadowmaskEncoding = serializedObject.FindProperty("shadowmaskEncoding"); ftraceShadowmaskFirstLightIsAlwaysAlpha = serializedObject.FindProperty("firstLightIsAlwaysAlpha"); ftraceDenoise = serializedObject.FindProperty("denoise"); ftraceGlobal = serializedObject.FindProperty("isGlobal"); ftraceRotation = serializedObject.FindProperty("supportRotationAfterBake"); ftraceRotationY = serializedObject.FindProperty("rotateAroundY"); ftraceMultiVolumePriority = serializedObject.FindProperty("multiVolumePriority"); //ftraceAdjustSamples = serializedObject.FindProperty("adjustSamples"); } string F(float f) { // Unity keeps using comma for float printing on some systems since ~2018, even if system-wide decimal symbol is "." return (f + "").Replace(",", "."); } string FormatSize(int b) { float mb = b / (float)(1024*1024); return mb.ToString("0.0"); } public override void OnInspectorGUI() { var vol = target as BakeryVolume; if (pstorage == null) pstorage = ftLightmaps.GetProjectSettings(); //if (targets.Length == 1) { serializedObject.Update(); EditorGUILayout.PropertyField(ftraceEnableBaking, new GUIContent("Enable baking", "Should the volume be (re)computed? Disable to prevent overwriting existing data.")); bool wasGlobal = ftraceGlobal.boolValue; EditorGUILayout.PropertyField(ftraceGlobal, new GUIContent("Global", "Automatically assign this volume to all volume-compatible shaders, unless they have overrides.")); if (!wasGlobal && ftraceGlobal.boolValue) { for(int i=0; i 1; for(int i=0; i() as MeshRenderer[]; if (mrs.Length > 0) { var b = mrs[0].bounds; for(int i=1; i(); if (boxCol != null) { if (GUILayout.Button("Set from box collider")) { Undo.RecordObject(vol, "Change Bounds"); vol.bounds = boxCol.bounds; } if (GUILayout.Button("Set to box collider")) { boxCol.center = Vector3.zero; boxCol.size = vol.bounds.size; } } var bmin = vol.bounds.min; var bmax = vol.bounds.max; var bsize = vol.bounds.size; EditorGUILayout.LabelField("Min: " + bmin.x+", "+bmin.y+", "+bmin.z); EditorGUILayout.LabelField("Max: " + bmax.x+", "+bmax.y+", "+bmax.z); if (GUILayout.Button("Copy bounds to clipboard")) { GUIUtility.systemCopyBuffer = "float3 bmin = float3(" + F(bmin.x)+", "+F(bmin.y)+", "+F(bmin.z) + "); float3 bmax = float3(" + F(bmax.x)+", "+F(bmax.y)+", "+F(bmax.z) + "); float3 binvsize = float3(" + F(1.0f/bsize.x)+", "+F(1.0f/bsize.y)+", "+F(1.0f/bsize.z) + ");"; } GUILayout.Space(5); BakeryVolume.showProbesPreview = EditorGUILayout.Foldout(BakeryVolume.showProbesPreview, "Show Probes", EditorStyles.foldout); if (BakeryVolume.showProbesPreview) { BakeryVolume.showIndirectOnly = EditorGUILayout.Toggle("Indirect Light Only", BakeryVolume.showIndirectOnly); BakeryVolume.showBakedTexture = EditorGUILayout.Toggle("Baked Texture", BakeryVolume.showBakedTexture); BakeryVolume.probesPreviewMul = EditorGUILayout.Slider("Brightness", BakeryVolume.probesPreviewMul, 0.01f, 1.0f); BakeryVolume.probesPreviewSize = EditorGUILayout.Slider("Size", BakeryVolume.probesPreviewSize, 0.01f, 1.0f); } serializedObject.ApplyModifiedProperties(); } } protected virtual void OnSceneGUI() { var vol = (BakeryVolume)target; if (vol.rotateAroundY) { var e = vol.transform.eulerAngles; var r = Quaternion.Euler(0, e.y, 0); Handles.matrix = Matrix4x4.TRS(r * -vol.transform.position + vol.transform.position, r, Vector3.one); } boundsHandle.center = vol.transform.position; boundsHandle.size = vol.bounds.size; // Draw Handle twice for semi-transparent look EditorGUI.BeginChangeCheck(); Handles.color = new Color(1f, 1f, 1f, 0.3f); boundsHandle.DrawHandle(); Handles.zTest = UnityEngine.Rendering.CompareFunction.Less; Handles.color = new Color(1f, 1f, 1f, 1f); boundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(vol, "Change Bounds"); Undo.RecordObject(vol.transform, "Change Bounds"); Bounds newBounds = new Bounds(); newBounds.center = boundsHandle.center; newBounds.size = boundsHandle.size; vol.bounds = newBounds; if (vol.rotateAroundY) { var c = boundsHandle.center; var sc = vol.GetRotationY(); var delta = c - vol.transform.position; vol.transform.position += new Vector3(delta.x*sc.y + delta.z*sc.x, delta.y, delta.x*-sc.x + delta.z*sc.y); } else { vol.transform.position = boundsHandle.center; } } else if ((vol.bounds.center - boundsHandle.center).sqrMagnitude > 0.0001f) { Bounds newBounds = new Bounds(); newBounds.center = boundsHandle.center; newBounds.size = boundsHandle.size; vol.bounds = newBounds; } if (vol.rotateAroundY) { Handles.matrix = Matrix4x4.identity; } } } #endif