void OnEnable() { var flags = BindingFlags.Static | BindingFlags.NonPublic; var propInfo = typeof(Camera).GetProperty ("PreviewCullingLayer", flags); int previewLayer = (int)propInfo.GetValue (null, new object[0]); previewRenderUtility = new PreviewRenderUtility (true); previewRenderUtility.m_CameraFieldOfView = 30f; previewRenderUtility.m_Camera.cullingMask = 1 << previewLayer; var component = (Component)target; previewObject = Instantiate (component.gameObject); previewObject.hideFlags = HideFlags.HideAndDontSave; previewObject.layer = previewLayer; foreach (Transform transform in previewObject.transform) { transform.gameObject.layer = previewLayer; } Bounds bounds = new Bounds (component.transform.position, Vector3.zero); foreach (var renderer in previewObject.GetComponentsInChildren<Renderer>()) { bounds.Encapsulate (renderer.bounds); } centerPosition = bounds.center; previewObject.SetActive (false); RotatePreviewObject (new Vector2 (-120, 20)); }
public void OnDestroy() { if (this.m_PreviewUtility == null) return; this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = (PreviewRenderUtility) null; }
public static void RenderMeshPreview(RoseMapObjectData mapObj, PreviewRenderUtility previewUtility, Vector2 direction) { if (mapObj == null || previewUtility == null) { return; } Bounds bounds = new Bounds(); Matrix4x4[] mats = new Matrix4x4[mapObj.subObjects.Count]; for (var i = 0; i < mapObj.subObjects.Count; ++i) { var subObj = mapObj.subObjects[i]; Matrix4x4 mat = new Matrix4x4(); mat.SetTRS(subObj.position, subObj.rotation, subObj.scale); if (i != 0) mat = mats[subObj.parent - 1] * mat; Utils.EncapsulateTransformedBounds(ref bounds, mat, subObj.mesh.bounds, i == 0); mats[i] = mat; } float magnitude = bounds.extents.magnitude; float num = 4f * magnitude; previewUtility.m_Camera.transform.position = -Vector3.forward * num; previewUtility.m_Camera.transform.rotation = Quaternion.identity; previewUtility.m_Camera.nearClipPlane = num - magnitude * 1.1f; previewUtility.m_Camera.farClipPlane = num + magnitude * 1.1f; previewUtility.m_Light[0].intensity = 1.4f; previewUtility.m_Light[0].transform.rotation = Quaternion.Euler(40f, 40f, 0f); previewUtility.m_Light[1].intensity = 1.4f; Color ambient = new Color(0.1f, 0.1f, 0.1f, 0f); RenderMeshPreviewSkipCameraAndLighting(mapObj, mats, bounds, previewUtility, null, direction); }
public void OnDisable() { if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } }
protected override void OnDisable() { base.OnDisable(); if (this.m_PreviewUtility == null) return; this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = (PreviewRenderUtility) null; }
protected override void OnDisable() { base.OnDisable(); if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } }
private void Init() { if (this.m_PreviewUtility != null) return; this.m_PreviewUtility = new PreviewRenderUtility(); this.m_PreviewUtility.m_CameraFieldOfView = 30f; this.m_Material = EditorGUIUtility.GetBuiltinExtraResource(typeof (Material), "Default-Material.mat") as Material; this.m_WireMaterial = ModelInspector.CreateWireframeMaterial(); }
private void InitPreview() { if (this.m_PreviewUtility != null) return; this.m_PreviewUtility = new PreviewRenderUtility() { m_CameraFieldOfView = 15f }; this.m_Mesh = PreviewRenderUtility.GetPreviewSphere(); }
private void InitPreview() { if (this.m_PreviewUtility == null) { PreviewRenderUtility utility = new PreviewRenderUtility { m_CameraFieldOfView = 15f }; this.m_PreviewUtility = utility; this.m_Mesh = PreviewRenderUtility.GetPreviewSphere(); } }
private void Init() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); this.m_PreviewUtility.m_CameraFieldOfView = 30f; this.m_Material = (EditorGUIUtility.GetBuiltinExtraResource(typeof(Material), "Default-Material.mat") as Material); this.m_WireMaterial = new Material(ModelInspector.WireframeShaderSource); this.m_WireMaterial.hideFlags = HideFlags.HideAndDontSave; this.m_WireMaterial.shader.hideFlags = HideFlags.HideAndDontSave; } }
public void OnDestroy() { if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } if (this.m_WireMaterial != null) { Object.DestroyImmediate(this.m_WireMaterial, true); } }
private void OnDisable() { if (this.m_PreviewUtility == null) return; this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = (PreviewRenderUtility) null; Object.DestroyImmediate((Object) this.m_ShadedMesh, true); Object.DestroyImmediate((Object) this.m_GeometryMesh, true); this.m_GeometryMaterial = (Material) null; if (!((Object) this.m_WireframeMaterial != (Object) null)) return; Object.DestroyImmediate((Object) this.m_WireframeMaterial, true); }
private void InitPreview() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); this.m_PreviewUtility.m_CameraFieldOfView = 30f; } if ((Object) this.m_Mesh == (Object) null) this.m_Mesh = PreviewRenderUtility.GetPreviewSphere(); if (!((Object) this.m_Material == (Object) null)) return; this.m_Material = EditorGUIUtility.LoadRequired("Previews/Preview3DTextureMaterial.mat") as Material; }
public void OnDisable() { if (this.m_EditorCache != null) this.m_EditorCache.Dispose(); if ((UnityEngine.Object) this.m_MaterialInspector != (UnityEngine.Object) null) { ((ProceduralMaterialInspector) this.m_MaterialInspector).ReimportSubstancesIfNeeded(); UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_MaterialInspector); } SubstanceImporterInspector.s_CachedSelectedMaterialInstanceName = this.m_SelectedMaterialInstanceName; if (this.m_PreviewUtility == null) return; this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = (PreviewRenderUtility) null; }
void SetupPreview() { if (previewRenderUtility == null) { previewRenderUtility = new PreviewRenderUtility(); previewRenderUtility.m_Camera.transform.position = cameraPosition; previewRenderUtility.m_Camera.transform.rotation = Quaternion.identity; } if (meshFilter == null) meshFilter = GetComponent<MeshFilter>(); if (meshRenderer == null) meshRenderer = GetComponent<MeshRenderer>(); }
private void OnDisable() { if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; UnityEngine.Object.DestroyImmediate(this.m_ShadedMesh, true); UnityEngine.Object.DestroyImmediate(this.m_GeometryMesh, true); this.m_GeometryMaterial = null; if (this.m_WireframeMaterial != null) { UnityEngine.Object.DestroyImmediate(this.m_WireframeMaterial.shader, true); UnityEngine.Object.DestroyImmediate(this.m_WireframeMaterial, true); } } }
private void InitPreview() { if (this.m_PreviewUtility != null) return; this.m_PreviewUtility = new PreviewRenderUtility(); this.m_ShadedMesh = new Mesh(); this.m_ShadedMesh.hideFlags = HideFlags.HideAndDontSave; this.m_ShadedMesh.MarkDynamic(); this.m_GeometryMesh = new Mesh(); this.m_GeometryMesh.hideFlags = HideFlags.HideAndDontSave; this.m_GeometryMesh.MarkDynamic(); this.m_ShadedMaterialProperties = new MaterialPropertyBlock(); this.m_GeometryMaterial = EditorGUIUtility.GetBuiltinExtraResource(typeof (Material), "Default-Material.mat") as Material; this.m_WireframeMaterial = ModelInspector.CreateWireframeMaterial(); EditorUtility.SetCameraAnimateMaterials(this.m_PreviewUtility.m_Camera, true); }
internal static void RenderMeshPreviewSkipCameraAndLighting(Mesh mesh, Bounds bounds, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, MaterialPropertyBlock customProperties, Vector2 direction, int meshSubset) { if (mesh == null || previewUtility == null) { return; } Quaternion quaternion = Quaternion.Euler(direction.y, 0f, 0f) * Quaternion.Euler(0f, direction.x, 0f); Vector3 pos = quaternion * -bounds.center; bool fog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); int subMeshCount = mesh.subMeshCount; if (litMaterial != null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; if (meshSubset < 0 || meshSubset >= subMeshCount) { for (int i = 0; i < subMeshCount; i++) { previewUtility.DrawMesh(mesh, pos, quaternion, litMaterial, i, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, quaternion, litMaterial, meshSubset, customProperties); } previewUtility.m_Camera.Render(); } if (wireMaterial != null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; GL.wireframe = true; if (meshSubset < 0 || meshSubset >= subMeshCount) { for (int j = 0; j < subMeshCount; j++) { previewUtility.DrawMesh(mesh, pos, quaternion, wireMaterial, j, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, quaternion, wireMaterial, meshSubset, customProperties); } previewUtility.m_Camera.Render(); GL.wireframe = false; } Unsupported.SetRenderSettingsUseFogNoDirty(fog); }
internal static void RenderMeshPreview(Mesh mesh, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, Vector2 direction, int meshSubset) { if ((Object) mesh == (Object) null || previewUtility == null) return; Bounds bounds = mesh.bounds; float magnitude = bounds.extents.magnitude; float num = 4f * magnitude; previewUtility.m_Camera.transform.position = -Vector3.forward * num; previewUtility.m_Camera.transform.rotation = Quaternion.identity; previewUtility.m_Camera.nearClipPlane = num - magnitude * 1.1f; previewUtility.m_Camera.farClipPlane = num + magnitude * 1.1f; previewUtility.m_Light[0].intensity = 1.4f; previewUtility.m_Light[0].transform.rotation = Quaternion.Euler(40f, 40f, 0.0f); previewUtility.m_Light[1].intensity = 1.4f; Color ambient = new Color(0.1f, 0.1f, 0.1f, 0.0f); InternalEditorUtility.SetCustomLighting(previewUtility.m_Light, ambient); ModelInspector.RenderMeshPreviewSkipCameraAndLighting(mesh, bounds, previewUtility, litMaterial, wireMaterial, (MaterialPropertyBlock) null, direction, meshSubset); InternalEditorUtility.RemoveCustomLighting(); }
public void OnDisable() { if (this.m_EditorCache != null) { this.m_EditorCache.Dispose(); } if (this.m_MaterialInspector != null) { ProceduralMaterialInspector proceduralMaterialInspector = (ProceduralMaterialInspector)this.m_MaterialInspector; proceduralMaterialInspector.ReimportSubstancesIfNeeded(); UnityEngine.Object.DestroyImmediate(this.m_MaterialInspector); } SubstanceImporterInspector.s_CachedSelectedMaterialInstanceName = this.m_SelectedMaterialInstanceName; if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } }
private void InitPreview() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility { m_CameraFieldOfView = 30f }; } if (this.m_Mesh == null) { this.m_Mesh = PreviewRenderUtility.GetPreviewSphere(); } CubemapPreview.s_SmallZoom = EditorGUIUtility.IconContent("PreTextureMipMapLow"); CubemapPreview.s_LargeZoom = EditorGUIUtility.IconContent("PreTextureMipMapHigh"); CubemapPreview.s_AlphaIcon = EditorGUIUtility.IconContent("PreTextureAlpha"); CubemapPreview.s_RGBIcon = EditorGUIUtility.IconContent("PreTextureRGB"); CubemapPreview.s_PreButton = "preButton"; CubemapPreview.s_PreSlider = "preSlider"; CubemapPreview.s_PreSliderThumb = "preSliderThumb"; CubemapPreview.s_PreLabel = "preLabel"; }
internal static void RenderMeshPreviewSkipCameraAndLighting(Mesh mesh, Bounds bounds, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, MaterialPropertyBlock customProperties, Vector2 direction, int meshSubset) { if ((Object) mesh == (Object) null || previewUtility == null) return; Quaternion rot = Quaternion.Euler(direction.y, 0.0f, 0.0f) * Quaternion.Euler(0.0f, direction.x, 0.0f); Vector3 pos = rot * -bounds.center; bool fog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); int subMeshCount = mesh.subMeshCount; if ((Object) litMaterial != (Object) null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; if (meshSubset < 0 || meshSubset >= subMeshCount) { for (int subMeshIndex = 0; subMeshIndex < subMeshCount; ++subMeshIndex) previewUtility.DrawMesh(mesh, pos, rot, litMaterial, subMeshIndex, customProperties); } else previewUtility.DrawMesh(mesh, pos, rot, litMaterial, meshSubset, customProperties); previewUtility.m_Camera.Render(); } if ((Object) wireMaterial != (Object) null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; GL.wireframe = true; if (meshSubset < 0 || meshSubset >= subMeshCount) { for (int subMeshIndex = 0; subMeshIndex < subMeshCount; ++subMeshIndex) previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, subMeshIndex, customProperties); } else previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, meshSubset, customProperties); previewUtility.m_Camera.Render(); GL.wireframe = false; } Unsupported.SetRenderSettingsUseFogNoDirty(fog); }
private void DrawMeshPreview(FrameDebuggerEvent curEvent, Rect previewRect, Rect meshInfoRect, Mesh mesh, int meshSubset) { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); this.m_PreviewUtility.m_CameraFieldOfView = 30f; } if (this.m_Material == null) { this.m_Material = (EditorGUIUtility.GetBuiltinExtraResource(typeof(Material), "Default-Material.mat") as Material); } if (this.m_WireMaterial == null) { this.m_WireMaterial = new Material(ModelInspector.WireframeShaderSource); this.m_WireMaterial.hideFlags = HideFlags.HideAndDontSave; this.m_WireMaterial.shader.hideFlags = HideFlags.HideAndDontSave; } this.m_PreviewUtility.BeginPreview(previewRect, "preBackground"); ModelInspector.RenderMeshPreview(mesh, this.m_PreviewUtility, this.m_Material, this.m_WireMaterial, this.m_PreviewDir, meshSubset); Texture image = this.m_PreviewUtility.EndPreview(); GUI.DrawTexture(previewRect, image, ScaleMode.StretchToFill, false); string text = mesh.name; if (string.IsNullOrEmpty(text)) { text = "<no name>"; } string text2 = string.Concat(new object[] { text, " subset ", meshSubset, "\n", curEvent.vertexCount, " verts, ", curEvent.indexCount, " indices" }); EditorGUI.DropShadowLabel(meshInfoRect, text2); }
internal void OnDisable() { if (this.m_WireMaterial != null) { UnityEngine.Object.DestroyImmediate(this.m_WireMaterial.shader, true); UnityEngine.Object.DestroyImmediate(this.m_WireMaterial, true); } if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } FrameDebuggerWindow.s_FrameDebuggers.Remove(this); EditorApplication.playmodeStateChanged = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.playmodeStateChanged, new EditorApplication.CallbackFunction(this.OnPlayModeStateChanged)); FrameDebuggerWindow.DisableFrameDebugger(); }
private void Init() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); } if (SubstanceImporterInspector.s_Meshes[0] == null) { GameObject gameObject = (GameObject)EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx"); gameObject.SetActive(false); IEnumerator enumerator = gameObject.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { Transform transform = (Transform)enumerator.Current; MeshFilter component = transform.GetComponent <MeshFilter>(); string name = transform.name; if (name == null) { goto IL_107; } if (!(name == "sphere")) { if (!(name == "cube")) { if (!(name == "cylinder")) { if (!(name == "torus")) { goto IL_107; } SubstanceImporterInspector.s_Meshes[3] = component.sharedMesh; } else { SubstanceImporterInspector.s_Meshes[2] = component.sharedMesh; } } else { SubstanceImporterInspector.s_Meshes[1] = component.sharedMesh; } } else { SubstanceImporterInspector.s_Meshes[0] = component.sharedMesh; } continue; IL_107: Debug.Log("Something is wrong, weird object found: " + transform.name); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } SubstanceImporterInspector.s_MeshIcons[0] = EditorGUIUtility.IconContent("PreMatSphere"); SubstanceImporterInspector.s_MeshIcons[1] = EditorGUIUtility.IconContent("PreMatCube"); SubstanceImporterInspector.s_MeshIcons[2] = EditorGUIUtility.IconContent("PreMatCylinder"); SubstanceImporterInspector.s_MeshIcons[3] = EditorGUIUtility.IconContent("PreMatTorus"); SubstanceImporterInspector.s_LightIcons[0] = EditorGUIUtility.IconContent("PreMatLight0"); SubstanceImporterInspector.s_LightIcons[1] = EditorGUIUtility.IconContent("PreMatLight1"); } }
public PreviewData(UnityEngine.Object targetObject) { this.renderUtility = new PreviewRenderUtility(); this.renderUtility.camera.fieldOfView = 30f; this.UpdateGameObject(targetObject); }
private void Init() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(true); this.m_PreviewUtility.m_CameraFieldOfView = 30f; this.m_PreviewUtility.m_Camera.cullingMask = ((int) 1) << Camera.PreviewCullingLayer; } if (s_Styles == null) { s_Styles = new Styles(); } if (this.m_FloorPlane == null) { this.m_FloorPlane = Resources.GetBuiltinResource(typeof(Mesh), "New-Plane.fbx") as Mesh; } if (this.m_FloorTexture == null) { this.m_FloorTexture = (Texture2D) EditorGUIUtility.Load("Avatar/Textures/AvatarFloor.png"); } if (this.m_FloorMaterial == null) { Shader shader = EditorGUIUtility.LoadRequired("Previews/PreviewPlaneWithShadow.shader") as Shader; this.m_FloorMaterial = new Material(shader); this.m_FloorMaterial.mainTexture = this.m_FloorTexture; this.m_FloorMaterial.mainTextureScale = (Vector2) ((Vector2.one * 5f) * 4f); this.m_FloorMaterial.SetVector("_Alphas", new Vector4(0.5f, 0.3f, 0f, 0f)); this.m_FloorMaterial.hideFlags = HideFlags.HideAndDontSave; this.m_FloorMaterialSmall = new Material(this.m_FloorMaterial); this.m_FloorMaterialSmall.mainTextureScale = (Vector2) ((Vector2.one * 0.2f) * 4f); this.m_FloorMaterialSmall.hideFlags = HideFlags.HideAndDontSave; } if (this.m_ShadowMaskMaterial == null) { Shader shader2 = EditorGUIUtility.LoadRequired("Previews/PreviewShadowMask.shader") as Shader; this.m_ShadowMaskMaterial = new Material(shader2); this.m_ShadowMaskMaterial.hideFlags = HideFlags.HideAndDontSave; } if (this.m_ShadowPlaneMaterial == null) { Shader shader3 = EditorGUIUtility.LoadRequired("Previews/PreviewShadowPlaneClip.shader") as Shader; this.m_ShadowPlaneMaterial = new Material(shader3); this.m_ShadowPlaneMaterial.hideFlags = HideFlags.HideAndDontSave; } }
private void EndPreviewInstance() { previewUtility.Render(); PreviewRenderUtility.SetEnabledRecursive(paletteInstance, false); Unsupported.SetRenderSettingsUseFogNoDirty(m_OldFog); }
private void Init() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); EditorUtility.SetCameraAnimateMaterials(this.m_PreviewUtility.m_Camera, true); } if (!((UnityEngine.Object) MaterialEditor.s_Meshes[0] == (UnityEngine.Object) null)) return; GameObject gameObject = (GameObject) EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx"); gameObject.SetActive(false); foreach (Transform transform in gameObject.transform) { MeshFilter component = transform.GetComponent<MeshFilter>(); string name = transform.name; if (name != null) { // ISSUE: reference to a compiler-generated field if (MaterialEditor.\u003C\u003Ef__switch\u0024map1C == null) { // ISSUE: reference to a compiler-generated field MaterialEditor.\u003C\u003Ef__switch\u0024map1C = new Dictionary<string, int>(4) { { "sphere", 0 }, { "cube", 1 }, { "cylinder", 2 }, { "torus", 3 } }; } int num; // ISSUE: reference to a compiler-generated field if (MaterialEditor.\u003C\u003Ef__switch\u0024map1C.TryGetValue(name, out num)) { switch (num) { case 0: MaterialEditor.s_Meshes[0] = component.sharedMesh; continue; case 1: MaterialEditor.s_Meshes[1] = component.sharedMesh; continue; case 2: MaterialEditor.s_Meshes[2] = component.sharedMesh; continue; case 3: MaterialEditor.s_Meshes[3] = component.sharedMesh; continue; } } } Debug.Log((object) ("Something is wrong, weird object found: " + transform.name)); } MaterialEditor.s_MeshIcons[0] = EditorGUIUtility.IconContent("PreMatSphere"); MaterialEditor.s_MeshIcons[1] = EditorGUIUtility.IconContent("PreMatCube"); MaterialEditor.s_MeshIcons[2] = EditorGUIUtility.IconContent("PreMatCylinder"); MaterialEditor.s_MeshIcons[3] = EditorGUIUtility.IconContent("PreMatTorus"); MaterialEditor.s_MeshIcons[4] = EditorGUIUtility.IconContent("PreMatQuad"); MaterialEditor.s_LightIcons[0] = EditorGUIUtility.IconContent("PreMatLight0"); MaterialEditor.s_LightIcons[1] = EditorGUIUtility.IconContent("PreMatLight1"); MaterialEditor.s_TimeIcons[0] = EditorGUIUtility.IconContent("PlayButton"); MaterialEditor.s_TimeIcons[1] = EditorGUIUtility.IconContent("PauseButton"); Mesh builtinResource = Resources.GetBuiltinResource(typeof (Mesh), "Quad.fbx") as Mesh; MaterialEditor.s_Meshes[4] = builtinResource; MaterialEditor.s_PlaneMesh = builtinResource; }
internal static void RenderMeshPreviewSkipCameraAndLighting(Mesh mesh, Bounds bounds, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, MaterialPropertyBlock customProperties, Vector2 direction, int meshSubset) { if ((Object)mesh == (Object)null || previewUtility == null) { return; } Quaternion rot = Quaternion.Euler(direction.y, 0.0f, 0.0f) * Quaternion.Euler(0.0f, direction.x, 0.0f); Vector3 pos = rot * -bounds.center; bool fog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); int subMeshCount = mesh.subMeshCount; if ((Object)litMaterial != (Object)null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; if (meshSubset < 0 || meshSubset >= subMeshCount) { for (int subMeshIndex = 0; subMeshIndex < subMeshCount; ++subMeshIndex) { previewUtility.DrawMesh(mesh, pos, rot, litMaterial, subMeshIndex, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, litMaterial, meshSubset, customProperties); } previewUtility.m_Camera.Render(); } if ((Object)wireMaterial != (Object)null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; GL.wireframe = true; if (meshSubset < 0 || meshSubset >= subMeshCount) { for (int subMeshIndex = 0; subMeshIndex < subMeshCount; ++subMeshIndex) { previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, subMeshIndex, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, meshSubset, customProperties); } previewUtility.m_Camera.Render(); GL.wireframe = false; } Unsupported.SetRenderSettingsUseFogNoDirty(fog); }
public void OnDestroy() { if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } if (this.m_WireMaterial) { UnityEngine.Object.DestroyImmediate(this.m_WireMaterial.shader, true); UnityEngine.Object.DestroyImmediate(this.m_WireMaterial, true); } }
private void Init() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); } if (s_Meshes[0] == null) { GameObject obj2 = (GameObject)EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx"); obj2.SetActive(false); IEnumerator enumerator = obj2.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { Transform current = (Transform)enumerator.Current; MeshFilter component = current.GetComponent <MeshFilter>(); switch (current.name) { case "sphere": { s_Meshes[0] = component.sharedMesh; continue; } case "cube": { s_Meshes[1] = component.sharedMesh; continue; } case "cylinder": { s_Meshes[2] = component.sharedMesh; continue; } case "torus": { s_Meshes[3] = component.sharedMesh; continue; } } Debug.Log("Something is wrong, weird object found: " + current.name); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } s_MeshIcons[0] = EditorGUIUtility.IconContent("PreMatSphere"); s_MeshIcons[1] = EditorGUIUtility.IconContent("PreMatCube"); s_MeshIcons[2] = EditorGUIUtility.IconContent("PreMatCylinder"); s_MeshIcons[3] = EditorGUIUtility.IconContent("PreMatTorus"); s_LightIcons[0] = EditorGUIUtility.IconContent("PreMatLight0"); s_LightIcons[1] = EditorGUIUtility.IconContent("PreMatLight1"); } }
public PreviewData(UnityObject targetObject) { renderUtility = new PreviewRenderUtility(); renderUtility.camera.fieldOfView = 30.0f; UpdateGameObject(targetObject); }
internal static void RenderMeshPreviewSkipCameraAndLighting(Mesh mesh, Bounds bounds, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, MaterialPropertyBlock customProperties, Vector2 direction, int meshSubset) { if ((mesh != null) && (previewUtility != null)) { Quaternion rot = Quaternion.Euler(direction.y, 0f, 0f) * Quaternion.Euler(0f, direction.x, 0f); Vector3 pos = (Vector3)(rot * -bounds.center); bool fog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); int subMeshCount = mesh.subMeshCount; if (litMaterial != null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; if ((meshSubset < 0) || (meshSubset >= subMeshCount)) { for (int i = 0; i < subMeshCount; i++) { previewUtility.DrawMesh(mesh, pos, rot, litMaterial, i, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, litMaterial, meshSubset, customProperties); } previewUtility.m_Camera.Render(); } if (wireMaterial != null) { previewUtility.m_Camera.clearFlags = CameraClearFlags.Nothing; GL.wireframe = true; if ((meshSubset < 0) || (meshSubset >= subMeshCount)) { for (int j = 0; j < subMeshCount; j++) { previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, j, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, meshSubset, customProperties); } previewUtility.m_Camera.Render(); GL.wireframe = false; } Unsupported.SetRenderSettingsUseFogNoDirty(fog); } }
public void OnDestroy() { if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } UnityEngine.Object.DestroyImmediate(this.m_PreviewInstance); UnityEngine.Object.DestroyImmediate(this.m_FloorMaterial); UnityEngine.Object.DestroyImmediate(this.m_FloorMaterialSmall); UnityEngine.Object.DestroyImmediate(this.m_ShadowMaskMaterial); UnityEngine.Object.DestroyImmediate(this.m_ShadowPlaneMaterial); UnityEngine.Object.DestroyImmediate(this.m_ReferenceInstance); UnityEngine.Object.DestroyImmediate(this.m_RootInstance); UnityEngine.Object.DestroyImmediate(this.m_PivotInstance); UnityEngine.Object.DestroyImmediate(this.m_DirectionInstance); if (this.timeControl != null) { this.timeControl.OnDisable(); } }
internal static void RenderMeshPreviewSkipCameraAndLighting( Mesh mesh, Bounds bounds, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, MaterialPropertyBlock customProperties, Vector2 direction, int meshSubset) // -1 for whole mesh { if (mesh == null || previewUtility == null) { return; } Quaternion rot = Quaternion.Euler(direction.y, 0, 0) * Quaternion.Euler(0, direction.x, 0); Vector3 pos = rot * (-bounds.center); bool oldFog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); int submeshes = mesh.subMeshCount; if (litMaterial != null) { previewUtility.camera.clearFlags = CameraClearFlags.Nothing; if (meshSubset < 0 || meshSubset >= submeshes) { for (int i = 0; i < submeshes; ++i) { previewUtility.DrawMesh(mesh, pos, rot, litMaterial, i, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, litMaterial, meshSubset, customProperties); } previewUtility.Render(); } if (wireMaterial != null) { previewUtility.camera.clearFlags = CameraClearFlags.Nothing; GL.wireframe = true; if (meshSubset < 0 || meshSubset >= submeshes) { for (int i = 0; i < submeshes; ++i) { previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, i, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, wireMaterial, meshSubset, customProperties); } previewUtility.Render(); GL.wireframe = false; } Unsupported.SetRenderSettingsUseFogNoDirty(oldFog); }
void InitPreview () { if (this.m_previewUtility == null) { this.m_lastTime = Time.realtimeSinceStartup; this.m_previewUtility = new PreviewRenderUtility(true); this.m_previewUtility.m_Camera.orthographic = true; this.m_previewUtility.m_Camera.orthographicSize = 1; this.m_previewUtility.m_Camera.cullingMask = -2147483648; this.m_previewUtility.m_Camera.nearClipPlane = 0.01f; this.m_previewUtility.m_Camera.farClipPlane = 1000f; this.CreatePreviewInstances(); } }
private void Init() { if (this.m_PreviewUtility == null) { this.m_PreviewUtility = new PreviewRenderUtility(); } if (!((UnityEngine.Object)SubstanceImporterInspector.s_Meshes[0] == (UnityEngine.Object)null)) { return; } GameObject gameObject = (GameObject)EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx"); gameObject.SetActive(false); foreach (Transform transform in gameObject.transform) { MeshFilter component = transform.GetComponent <MeshFilter>(); string name = transform.name; if (name != null) { // ISSUE: reference to a compiler-generated field if (SubstanceImporterInspector.\u003C\u003Ef__switch\u0024map1A == null) { // ISSUE: reference to a compiler-generated field SubstanceImporterInspector.\u003C\u003Ef__switch\u0024map1A = new Dictionary <string, int>(4) { { "sphere", 0 }, { "cube", 1 }, { "cylinder", 2 }, { "torus", 3 } }; } int num; // ISSUE: reference to a compiler-generated field if (SubstanceImporterInspector.\u003C\u003Ef__switch\u0024map1A.TryGetValue(name, out num)) { switch (num) { case 0: SubstanceImporterInspector.s_Meshes[0] = component.sharedMesh; continue; case 1: SubstanceImporterInspector.s_Meshes[1] = component.sharedMesh; continue; case 2: SubstanceImporterInspector.s_Meshes[2] = component.sharedMesh; continue; case 3: SubstanceImporterInspector.s_Meshes[3] = component.sharedMesh; continue; } } } Debug.Log((object)("Something is wrong, weird object found: " + transform.name)); } SubstanceImporterInspector.s_MeshIcons[0] = EditorGUIUtility.IconContent("PreMatSphere"); SubstanceImporterInspector.s_MeshIcons[1] = EditorGUIUtility.IconContent("PreMatCube"); SubstanceImporterInspector.s_MeshIcons[2] = EditorGUIUtility.IconContent("PreMatCylinder"); SubstanceImporterInspector.s_MeshIcons[3] = EditorGUIUtility.IconContent("PreMatTorus"); SubstanceImporterInspector.s_LightIcons[0] = EditorGUIUtility.IconContent("PreMatLight0"); SubstanceImporterInspector.s_LightIcons[1] = EditorGUIUtility.IconContent("PreMatLight1"); }
/// <summary> /// <para>Called when the editor is disabled, if overridden please call the base OnDisable() to ensure that the material inspector is set up properly.</para> /// </summary> public virtual void OnDisable() { this.m_ReflectionProbePicker.OnDisable(); if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = (PreviewRenderUtility) null; } Undo.undoRedoPerformed -= new Undo.UndoRedoCallback(this.UndoRedoPerformed); }
internal static void RenderMeshPreviewSkipCameraAndLighting( Mesh mesh, Bounds bounds, PreviewRenderUtility previewUtility, PreviewSettings settings, MaterialPropertyBlock customProperties, int meshSubset) // -1 for whole mesh { if (mesh == null || previewUtility == null) { return; } Quaternion rot = Quaternion.Euler(settings.previewDir.y, 0, 0) * Quaternion.Euler(0, settings.previewDir.x, 0); Vector3 pos = rot * (-bounds.center); bool oldFog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); int submeshes = mesh.subMeshCount; var tintSubmeshes = false; var colorPropID = 0; if (submeshes > 1 && settings.displayMode == DisplayMode.Shaded && customProperties == null & meshSubset == -1) { tintSubmeshes = true; customProperties = new MaterialPropertyBlock(); colorPropID = Shader.PropertyToID("_Color"); } if (settings.activeMaterial != null) { previewUtility.camera.clearFlags = CameraClearFlags.Nothing; if (meshSubset < 0 || meshSubset >= submeshes) { for (int i = 0; i < submeshes; ++i) { if (tintSubmeshes) { customProperties.SetColor(colorPropID, GetSubMeshTint(i)); } previewUtility.DrawMesh(mesh, pos, rot, settings.activeMaterial, i, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, settings.activeMaterial, meshSubset, customProperties); } previewUtility.Render(); } if (settings.wireMaterial != null && settings.drawWire) { previewUtility.camera.clearFlags = CameraClearFlags.Nothing; GL.wireframe = true; if (tintSubmeshes) { customProperties.SetColor(colorPropID, settings.wireMaterial.color); } if (meshSubset < 0 || meshSubset >= submeshes) { for (int i = 0; i < submeshes; ++i) { // lines/points already are wire-like; it does not make sense to overdraw // them again with dark wireframe color var topology = mesh.GetTopology(i); if (topology == MeshTopology.Lines || topology == MeshTopology.LineStrip || topology == MeshTopology.Points) { continue; } previewUtility.DrawMesh(mesh, pos, rot, settings.wireMaterial, i, customProperties); } } else { previewUtility.DrawMesh(mesh, pos, rot, settings.wireMaterial, meshSubset, customProperties); } previewUtility.Render(); GL.wireframe = false; } Unsupported.SetRenderSettingsUseFogNoDirty(oldFog); }