public override void OnInspectorGUI() { var cullingMask = EditorGUILayout.MaskField("Culling Mask", myTarget.cullingMask, InternalEditorUtility.layers); if (myTarget.cullingMask != cullingMask) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.cullingMask = cullingMask; } EditorGUILayout.Space(); var horizontalFieldOfView = EditorGUILayout.Slider("Horizontal FOV", myTarget.horizontalFieldOfView, 0f, 360f); if (myTarget.horizontalFieldOfView != horizontalFieldOfView) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.horizontalFieldOfView = horizontalFieldOfView; } var verticalFieldOfView = EditorGUILayout.Slider("Vertical FOV", myTarget.verticalFieldOfView, 0f, 180f); if (myTarget.verticalFieldOfView != verticalFieldOfView) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.verticalFieldOfView = verticalFieldOfView; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Clipping Planes"); var nearClipPlane = Mathf.Max(0, Mathf.Min(myTarget.farClipPlane, EditorGUILayout.FloatField("Near", myTarget.nearClipPlane))); if (myTarget.nearClipPlane != nearClipPlane) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.nearClipPlane = nearClipPlane; } var farClipPlane = Mathf.Max(myTarget.nearClipPlane, EditorGUILayout.FloatField("Far", myTarget.farClipPlane)); if (myTarget.farClipPlane != farClipPlane) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.farClipPlane = farClipPlane; } EditorGUILayout.Space(); var subCameraResolution = EditorGUILayout.Vector2Field("Resolution multiplier", myTarget.subCameraResolution); if (myTarget.subCameraResolution != subCameraResolution) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.subCameraResolution = subCameraResolution; } EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUILayout.LabelField("Beams", EditorStyles.boldLabel); var forceRefresh = false; var newDist = (Lidar.TBeamAnglesDistribution)EditorGUILayout.EnumPopup("Distribution", myTarget.beamAnglesDistribution); if (newDist != myTarget.beamAnglesDistribution) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.beamAnglesDistribution = newDist; forceRefresh = true; } int nb = Math.Max(1, EditorGUILayout.IntField("Number", myTarget.nbOfBeams)); if (nb != myTarget.nbOfBeams) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.nbOfBeams = nb; forceRefresh = true; } switch (myTarget.beamAnglesDistribution) { case Lidar.TBeamAnglesDistribution.Uniform: UniformBeamAngles(forceRefresh); break; case Lidar.TBeamAnglesDistribution.Custom: CustomBeamAngles(forceRefresh); break; } string[] labels = new string[myTarget.nbOfBeams]; for (int i = 0; i < labels.Length; i++) { labels[i] = $"{myTarget.GetVerticlAngleInDegreesForNormalizadValue(myTarget.GetAngle(i))}"; } var label = string.Join(", ", labels, 0, myTarget.nbOfBeams); EditorGUILayout.LabelField($"[{label}]"); } EditorGUILayout.EndHorizontal(); var rpm = EditorGUILayout.FloatField("RPM", myTarget.rpm); if (myTarget.rpm != rpm) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.rpm = rpm; } var pointsPerSecond = EditorGUILayout.IntField("Points per second", myTarget.pointsPerSecond); if (myTarget.pointsPerSecond != pointsPerSecond) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.pointsPerSecond = pointsPerSecond; } var noiseGenerator = INoiseGeneratorEditor.Field("Noise generator", myTarget.noiseGenerator); if (noiseGenerator != myTarget.noiseGenerator) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.noiseGenerator = noiseGenerator; } #if DEBUG_LIDAR myTarget.pointsPerRotationPerBeam = EditorGUILayout.IntField("Points per beam", myTarget.pointsPerRotationPerBeam); if (GUILayout.Button("Save sub-texture to disk")) { foreach (var depthCamera in myTarget.subCameras) { if (depthCamera.linkedCamera.targetTexture == null) { continue; } Texture2D texture2D = new Texture2D( depthCamera.linkedCamera.targetTexture.width, depthCamera.linkedCamera.targetTexture.height, TextureFormat.ARGB32, false); RenderTexture.active = depthCamera.linkedCamera.targetTexture; texture2D.ReadPixels(new Rect(0, 0, texture2D.width, texture2D.height), 0, 0); texture2D.Apply(); RenderTexture.active = null; byte[] bytes = texture2D.EncodeToPNG(); string filePath = Path.Combine(Application.dataPath, "..", $"{myTarget.gameObject.name} {depthCamera.gameObject.name}.png"); File.WriteAllBytes(filePath, bytes); } } foreach (var subCamera in myTarget.subCameras) { subCamera.gameObject.hideFlags &= ~HideFlags.HideInHierarchy; } #else foreach (var subCamera in myTarget.subCameras) { subCamera.gameObject.hideFlags |= HideFlags.HideInHierarchy; } #endif SceneView.RepaintAll(); Repaint(); }
public override void OnInspectorGUI() { #if !DEBUG_RADAR myTarget.linkedCamera.hideFlags |= HideFlags.HideInInspector; #else myTarget.linkedCamera.hideFlags &= ~HideFlags.HideInInspector; EditorGUILayout.ObjectField("Output Texture", myTarget.output, typeof(RenderTexture), true); #endif myTarget.linkedCamera.clearFlags = CameraClearFlags.Color; myTarget.linkedCamera.nearClipPlane = 0.01f; myTarget.linkedCamera.backgroundColor = new Color(0, 0, 0, 0); var cullingMask = EditorGUILayout.MaskField("Culling Mask", myTarget.cullingMask, InternalEditorUtility.layers); if (myTarget.cullingMask != cullingMask) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.cullingMask = cullingMask; } var depth = EditorGUILayout.FloatField("Depth", myTarget.depth); if (myTarget.depth != depth) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.depth = depth; } var range = Mathf.Max(myTarget.linkedCamera.nearClipPlane, EditorGUILayout.FloatField("Range", myTarget.range)); if (myTarget.range != range) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.range = range; } var verticalFOV = EditorGUILayout.Slider("Vertical FOV", myTarget.verticalfieldOfView, 1, 179); if (myTarget.verticalfieldOfView != verticalFOV) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.verticalfieldOfView = verticalFOV; } var minIntensity = EditorGUILayout.Slider("Min. intensity", myTarget.minIntensity, 0, 1); if (myTarget.minIntensity != minIntensity) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.minIntensity = minIntensity; } var outputResolution = EditorGUILayout.Vector2IntField("Output resolution", myTarget.outputResolution); if (myTarget.outputResolution != outputResolution) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.outputResolution = outputResolution; } EditorGUILayout.BeginVertical("box"); var startColor = EditorGUILayout.ColorField("Start color", myTarget.startColor); if (myTarget.startColor != startColor) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.startColor = startColor; } var endColor = EditorGUILayout.ColorField("End color", myTarget.endColor); if (myTarget.endColor != endColor) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.endColor = endColor; } EditorGUILayout.EndVertical(); var noiseGenerator = INoiseGeneratorEditor.Field("Noise generator", myTarget.noiseGenerator); if (noiseGenerator != myTarget.noiseGenerator) { if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } myTarget.noiseGenerator = noiseGenerator; } EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(myTarget.onOutput))); serializedObject.ApplyModifiedProperties(); }