public override void OnToolGUI(EditorWindow window) { var view = window as SceneView; if (!view || !Selection.activeTransform || Tools.s_Hidden) { return; } if (!StageUtility.IsGameObjectRenderedByCameraAndPartOfEditableScene(Selection.activeTransform.gameObject, Camera.current)) { return; } GUIContent disabledLabel; bool isDisabled = ShouldToolGUIBeDisabled(out disabledLabel); using (new EditorGUI.DisabledScope(isDisabled)) { Vector3 handlePosition = Tools.handlePosition; ToolGUI(view, handlePosition, isDisabled); if (isDisabled) { Handles.ShowSceneViewLabel(handlePosition, disabledLabel); } } }
// Draw Reflection probe preview sphere private void OnPreSceneGUICallback(SceneView sceneView) { if (Event.current.type != EventType.Repaint) { return; } foreach (var t in targets) { ReflectionProbe p = (ReflectionProbe)t; if (!reflectiveMaterial) { return; } if (!StageUtility.IsGameObjectRenderedByCameraAndPartOfEditableScene(p.gameObject, Camera.current)) { return; } Matrix4x4 m = new Matrix4x4(); // @TODO: use MaterialPropertyBlock instead - once it actually works! // Tried to use MaterialPropertyBlock in 5.4.0b2, but would get incorrectly set parameters when using with Graphics.DrawMesh if (!m_CachedGizmoMaterials.ContainsKey(p)) { m_CachedGizmoMaterials.Add(p, Instantiate(reflectiveMaterial)); } Material mat = m_CachedGizmoMaterials[p] as Material; if (!mat) { return; } { // Get mip level float mipLevel = 0.0F; TextureInspector cubemapEditor = m_CubemapEditor as TextureInspector; if (cubemapEditor) { mipLevel = cubemapEditor.GetMipLevelForRendering(); } mat.SetTexture("_MainTex", p.texture); mat.SetMatrix("_CubemapRotation", Matrix4x4.identity); mat.SetFloat("_Mip", mipLevel); mat.SetFloat("_Alpha", 0.0f); mat.SetFloat("_Intensity", GetProbeIntensity(p)); // draw a preview sphere that scales with overall GO scale, but always uniformly var scale = p.transform.lossyScale.magnitude * 0.5f; m.SetTRS(p.transform.position, Quaternion.identity, new Vector3(scale, scale, scale)); Graphics.DrawMesh(sphereMesh, m, mat, 0, SceneView.currentDrawingSceneView.camera, 0); } } }