public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); PropertyField(layerProperty); PropertyField(matProperty); // featuresProperty.intValue = MaskField(new GUIContent(featuresProperty.displayName), featuresProperty.intValue, featuresProperty.enumDisplayNames); if (EditorGUI.EndChangeCheck() || (matProperty.objectReferenceValue != null && editor == null)) { if (matProperty.objectReferenceValue != null) { editor = (MaterialEditor)CreateEditor(matProperty.objectReferenceValue); } else { editor?.OnDisable(); editor = null; } } if (editor) { editor.DrawHeader(); editor.OnInspectorGUI(); editor.serializedObject.ApplyModifiedProperties(); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(serializedObject.FindProperty("material")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); if (editor != null) { DestroyImmediate(editor); } if (cs != null && cs.material != null) { editor = (MaterialEditor)CreateEditor(cs.material); } } if (editor == null) { return; } editor.DrawHeader(); bool isDefault = cs != null && !AssetDatabase.GetAssetPath(cs.material).StartsWith("Assets"); using (new EditorGUI.DisabledGroupScope(isDefault)) editor.OnInspectorGUI(); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); base.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (m_MaterialEditor != null) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); // We need to prevent the user to edit default decal materials bool isDefaultMaterial = false; var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; if (hdrp != null) { isDefaultMaterial = m_DecalProjectorComponent.Mat == hdrp.GetDefaultDecalMaterial(); } using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } }
public override void OnInspectorGUI() { DrawBlockSet(blockSet); EditorGUILayout.Separator(); if (selectedBlock != null) { BlockEditor.DrawBlockEditor(selectedBlock, blockSet); if (materialEditor == null || materialEditor.target != selectedBlock.Material) { materialEditor = (MaterialEditor)CreateEditor(selectedBlock.Material); } if (materialEditor != null) { materialEditor.DrawHeader(); materialEditor.OnInspectorGUI(); } } if (GUI.changed) { EditorUtility.SetDirty(blockSet); } }
public override void OnInspectorGUI() { PropertyField(m_Enabled, new GUIContent("Enable")); EditorGUI.BeginChangeCheck(); PropertyField(m_CloudMap); if (EditorGUI.EndChangeCheck()) { CreateEditor(m_CloudMap); } if (IsMapFormatInvalid(m_CloudMap)) { EditorGUILayout.HelpBox("The cloud map needs to be a 2D Texture in LatLong layout.", MessageType.Info); } PropertyField(m_UpperHemisphereOnly); PropertyField(m_Tint); PropertyField(m_IntensityMultiplier); PropertyField(m_Rotation); PropertyField(m_EnableDistortion); if (m_EnableDistortion.value.boolValue) { EditorGUI.indentLevel++; using (new EditorGUILayout.HorizontalScope()) { DrawOverrideCheckbox(m_Procedural); using (new EditorGUI.DisabledScope(!m_Procedural.overrideState.boolValue)) m_Procedural.value.boolValue = EditorGUILayout.IntPopup(new GUIContent("Distortion Mode"), (int)m_Procedural.value.intValue, m_DistortionModes, m_DistortionModeValues) == 1; } if (!m_Procedural.value.boolValue) { EditorGUI.indentLevel++; PropertyField(m_Flowmap); if (IsMapFormatInvalid(m_Flowmap)) { EditorGUILayout.HelpBox("The flowmap needs to be a 2D Texture in LatLong layout.", MessageType.Info); } EditorGUI.indentLevel--; } PropertyField(m_ScrollDirection); PropertyField(m_ScrollSpeed); EditorGUI.indentLevel--; } if (materialEditor != null) { EditorGUILayout.Space(); materialEditor.DrawHeader(); materialEditor.OnInspectorGUI(); EditorGUILayout.Space(); } }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); base.OnInspectorGUI(); if (GUILayout.Button("Place")) { foreach (Object obj in targets) { MultiMaterialPlacer m = obj as MultiMaterialPlacer; Material[] materials = PlaceObjects(m); if (materials != null) { foreach (Material mat in materials) { UnityEditor.Experimental.Rendering.HDPipeline.HDEditorUtils.ResetMaterialKeywords(mat); } } } } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); if (_materialEditor != null) { // Free the memory used by the previous MaterialEditor DestroyImmediate(_materialEditor); } if (!serializedObject.FindProperty("material").hasMultipleDifferentValues&& (serializedObject.FindProperty("material") != null)) { // Create a new instance of the default MaterialEditor _materialEditor = (MaterialEditor)CreateEditor((Material)serializedObject.FindProperty("material").objectReferenceValue); } } if (_materialEditor != null) { // Draw the material's foldout and the material shader field // Required to call _materialEditor.OnInspectorGUI (); _materialEditor.DrawHeader(); // We need to prevent the user to edit Unity default materials bool isDefaultMaterial = !AssetDatabase.GetAssetPath((Material)serializedObject.FindProperty("material").objectReferenceValue).StartsWith("Assets"); using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of _materialEditor.DrawHeader () is open _materialEditor.OnInspectorGUI(); } } }
void ExternalEditors() { int oldEditor = currentEditor; EditorGUILayout.LabelField("<b>Other Inspectors:</b>", style); currentEditor = GUILayout.Toolbar(currentEditor, new string[] { "None", "Material", "TextMeshPro" }); Lines(); if (currentEditor == 1) { if (matEditor == null || oldEditor != 1) { mat = dn.GetMaterial(); if (matEditor != null) { DestroyImmediate(matEditor); } matEditor = (MaterialEditor)CreateEditor(mat); } if (matEditor != null) { matEditor.DrawHeader(); matEditor.OnInspectorGUI(); Lines(); } } else if (currentEditor == 2) { if (textEditor == null || oldEditor != 2) { if (textEditor != null) { DestroyImmediate(textEditor); } textEditor = CreateEditor(textA); } if (textEditor != null) { textEditor.DrawHeader(); textEditor.OnInspectorGUI(); EditorUtility.CopySerializedIfDifferent(textA, textB); if (currentFadeIn == 0 && currentFadeOut == 0) { dn.UpdateAlpha(1); } textB.GetComponent <MeshRenderer>().material = textA.GetComponent <MeshRenderer>().material = textA.font.material; Lines(); } } }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_IsCropModeEnabledProperty, new GUIContent("Crop Decal with Gizmo")); EditorGUILayout.PropertyField(m_Size); EditorGUILayout.PropertyField(m_MaterialProperty); EditorGUILayout.PropertyField(m_DrawDistanceProperty); EditorGUILayout.Slider(m_FadeScaleProperty, 0.0f, 1.0f, new GUIContent("Distance fade scale")); EditorGUILayout.PropertyField(m_UVScaleProperty); EditorGUILayout.PropertyField(m_UVBiasProperty); EditorGUILayout.Slider(m_FadeFactor, 0.0f, 1.0f); // only display the affects transparent property if material is HDRP/decal if (DecalSystem.IsHDRenderPipelineDecal(m_DecalProjectorComponent.Mat.shader.name)) { EditorGUILayout.PropertyField(m_AffectsTransparencyProperty, new GUIContent("Affects Transparent Material")); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (m_LayerMask != m_DecalProjectorComponent.gameObject.layer) { m_DecalProjectorComponent.OnValidate(); } if (m_MaterialEditor != null) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); // We need to prevent the user to edit default decal materials bool isDefaultMaterial = false; var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; if (hdrp != null) { isDefaultMaterial = m_DecalProjectorComponent.Mat == hdrp.GetDefaultDecalMaterial(); } using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } }
public override void OnInspectorGUI() { PsyiaSystem myTarget = (PsyiaSystem)target; EditorGUILayout.LabelField("Global Settings", EditorStyles.boldLabel); myTarget.Global.MaxParticleCount = EditorGUILayout.IntSlider("Max Particle Count (1000s)", myTarget.Global.MaxParticleCount, 1, 1000); //myTarget.Global.DefaultParticleSize = EditorGUILayout.FloatField("Default Particle Size", myTarget.Global.DefaultParticleSize); myTarget.Global.ParticleLifetime = EditorGUILayout.FloatField("Particle Lifetime", myTarget.Global.ParticleLifetime); myTarget.Global.SimulationSpace = (Space)EditorGUILayout.EnumPopup("Simulation Space", myTarget.Global.SimulationSpace); EditorGUILayout.Space(); EditorGUILayout.LabelField("Emission Settings", EditorStyles.boldLabel); EditorGUILayout.LabelField("No emission settings!"); EditorGUILayout.Space(); EditorGUILayout.LabelField("Physics Settings", EditorStyles.boldLabel); myTarget.Physics.ParticleMinimumMass = EditorGUILayout.FloatField("Particle Minimum Mass", myTarget.Physics.ParticleMinimumMass); myTarget.Physics.ParticleDrag = EditorGUILayout.FloatField("Particle Drag", myTarget.Physics.ParticleDrag); myTarget.Physics.ForceMultiplier = EditorGUILayout.FloatField("Force Multiplier", myTarget.Physics.ForceMultiplier); EditorGUILayout.Space(); EditorGUILayout.LabelField("Rendering Settings", EditorStyles.boldLabel); Material NewParticleMat = (Material)EditorGUILayout.ObjectField("Particle Material", myTarget.Renderer.ParticleMaterial, typeof(Material), true); if (NewParticleMat != myTarget.Renderer.ParticleMaterial) { Debug.Log("Setting particle material"); myTarget.Renderer.ParticleMaterial = NewParticleMat; matEditor = (MaterialEditor)CreateEditor(myTarget.Renderer.ParticleMaterial); } myTarget.Renderer.ChromaY = EditorGUILayout.Slider("Chroma Y", myTarget.Renderer.ChromaY, 0f, 1f); if (myTarget.Renderer.ParticleMaterial != null) { if (matEditor == null) { matEditor = (MaterialEditor)CreateEditor(myTarget.Renderer.ParticleMaterial); } if (matEditor != null) { matEditor.DrawHeader(); bool isDefaultMaterial = !AssetDatabase.GetAssetPath(myTarget.Renderer.ParticleMaterial).StartsWith("Assets"); using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { matEditor.OnInspectorGUI(); } } } }
void DrawMaterialEditor() { // Multiple selection cant be handled for Material inspector... var selectionCount = Selection.objects.Length; if (selectionCount > 1) { EditorGUILayout.HelpBox("Multiple Object editing is not supported for Material Options.", MessageType.Warning); return; } // Default Material Editor EditorGUILayout.Space(); m_MaterialEditor.DrawHeader(); m_MaterialEditor.OnInspectorGUI(); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); { // Draw the material field of ImageFx.cs SerializedProperty materialProperty = serializedObject.FindProperty("_material"); EditorGUILayout.PropertyField(materialProperty); } if (EditorGUI.EndChangeCheck()) { // Free the memory used by the previous MaterialEditor serializedObject.ApplyModifiedProperties(); if (_materialEditor != null) { // Free the memory used by the previous MaterialEditor DestroyImmediate(_materialEditor); } if (_imageFx.material != null) { // Create a new instance of the default MaterialEditor _materialEditor = (MaterialEditor)CreateEditor(_imageFx.material); } } if (_materialEditor == null) { return; } // Draw the material's foldout and the material shader field // Required to call _materialEditor.OnInspectorGUI (); _materialEditor.DrawHeader(); // We need to prevent the user to edit Unity default materials bool isDefaultMaterial = !AssetDatabase.GetAssetPath(_imageFx.material).StartsWith("Assets"); using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of _materialEditor.DrawHeader () is open _materialEditor.OnInspectorGUI(); } }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); serializedObject.UpdateIfRequiredOrScript(); var effectMat = ((SimpleImageEffect) target).EffectMaterial; if (effectMat != null && m_materialEditor == null) m_materialEditor = (MaterialEditor)CreateEditor(effectMat, typeof(MaterialEditor)); DrawDefaultInspector(true); EditorGUILayout.PropertyField(serializedObject.FindProperty("m_shader")); DrawDefaultInspector(false); if (m_materialEditor != null) { MaterialProperty[] props = MaterialEditor.GetMaterialProperties(new[] {m_materialEditor.target}).Where(p => p.name != "_MainTex").ToArray(); if (props.Length > 0) GuiLine(); var foldoutShow = typeof(Editor).GetProperty("firstInspectedEditor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (foldoutShow != null) { foldoutShow.SetValue(m_materialEditor, true); } else { m_materialEditor.DrawHeader(); } DrawMaterialProps(props); ResetMaterialEditor(); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_Center); EditorGUILayout.PropertyField(m_Size); EditorGUILayout.PropertyField(m_MaterialProperty); EditorGUILayout.PropertyField(m_DrawDistanceProperty); EditorGUILayout.Slider(m_FadeScaleProperty, 0.0f, 1.0f, new GUIContent("Fade scale")); EditorGUILayout.PropertyField(m_UVScaleProperty); EditorGUILayout.PropertyField(m_UVBiasProperty); EditorGUILayout.PropertyField(m_AffectsTransparencyProperty); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (m_MaterialEditor != null) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); // We need to prevent the user to edit default decal materials bool isDefaultMaterial = false; var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; if (hdrp != null) { isDefaultMaterial = m_DecalProjectorComponent.Mat == hdrp.GetDefaultDecalMaterial(); } using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } }
public override void OnInspectorGUI() { serializedObject.Update(); if (m_RequireUpdateMaterialEditor) { UpdateMaterialEditor(); m_RequireUpdateMaterialEditor = false; } EditorGUI.BeginChangeCheck(); { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); DoInspectorToolbar(k_EditVolumeModes, editVolumeLabels, GetBoundsGetter(target as DecalProjector), this); DoInspectorToolbar(k_EditUVAndPivotModes, editPivotLabels, GetBoundsGetter(target as DecalProjector), this); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); Rect rect = EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, k_SizeContent)); EditorGUI.BeginProperty(rect, k_SizeSubContent[0], m_SizeValues[0]); EditorGUI.BeginProperty(rect, k_SizeSubContent[1], m_SizeValues[1]); float[] size = new float[2] { m_SizeValues[0].floatValue, m_SizeValues[1].floatValue }; EditorGUI.BeginChangeCheck(); EditorGUI.MultiFloatField(rect, k_SizeContent, k_SizeSubContent, size); if (EditorGUI.EndChangeCheck()) { for (int i = 0; i < 2; ++i) { UpdateSize(i, Mathf.Max(0, size[i]), m_SizeValues[i].floatValue); } } EditorGUI.EndProperty(); EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); float oldSizeZ = m_SizeValues[2].floatValue; EditorGUILayout.PropertyField(m_SizeValues[2], k_ProjectionDepthContent); if (EditorGUI.EndChangeCheck()) { UpdateSize(2, Mathf.Max(0, m_SizeValues[2].floatValue), oldSizeZ); } EditorGUILayout.PropertyField(m_Offset, k_Offset); EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent); bool decalLayerEnabled = false; HDRenderPipelineAsset hdrp = HDRenderPipeline.currentAsset; if (hdrp != null) { decalLayerEnabled = hdrp.currentPlatformRenderPipelineSettings.supportDecals && hdrp.currentPlatformRenderPipelineSettings.supportDecalLayers; using (new EditorGUI.DisabledScope(!decalLayerEnabled)) { EditorGUILayout.PropertyField(m_DecalLayerMask, k_DecalLayerMaskContent); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_DrawDistanceProperty, k_DistanceContent); if (EditorGUI.EndChangeCheck() && m_DrawDistanceProperty.floatValue < 0f) { m_DrawDistanceProperty.floatValue = 0f; } EditorGUILayout.PropertyField(m_FadeScaleProperty, k_FadeScaleContent); using (new EditorGUI.DisabledScope(!decalLayerEnabled)) { float angleFadeMinValue = m_StartAngleFadeProperty.floatValue; float angleFadeMaxValue = m_EndAngleFadeProperty.floatValue; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(k_AngleFadeContent, ref angleFadeMinValue, ref angleFadeMaxValue, 0.0f, 180.0f); if (EditorGUI.EndChangeCheck()) { m_StartAngleFadeProperty.floatValue = angleFadeMinValue; m_EndAngleFadeProperty.floatValue = angleFadeMaxValue; } } if (!decalLayerEnabled) { EditorGUILayout.HelpBox("Enable 'Decal Layers' in your HDRP Asset if you want to control the Angle Fade. There is a performance cost of enabling this option.", MessageType.Info); } EditorGUILayout.PropertyField(m_UVScaleProperty, k_UVScaleContent); EditorGUILayout.PropertyField(m_UVBiasProperty, k_UVBiasContent); EditorGUILayout.PropertyField(m_FadeFactor, k_FadeFactorContent); // only display the affects transparent property if material is HDRP/decal if (showAffectTransparencyHaveMultipleDifferentValue) { using (new EditorGUI.DisabledScope(true)) EditorGUILayout.LabelField(EditorGUIUtility.TrTextContent("Multiple material type in selection")); } else if (showAffectTransparency) { EditorGUILayout.PropertyField(m_AffectsTransparencyProperty, k_AffectTransparentContent); } } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (layerMaskHasMultipleValue || layerMask != (target as Component).gameObject.layer) { foreach (var decalProjector in targets) { (decalProjector as DecalProjector).OnValidate(); } } if (m_MaterialEditor != null) { // We need to prevent the user to edit default decal materials bool isDefaultMaterial = false; bool isValidDecalMaterial = true; var hdrp = HDRenderPipeline.currentAsset; if (hdrp != null) { foreach (var decalProjector in targets) { var mat = (decalProjector as DecalProjector).material; isDefaultMaterial |= mat == hdrp.GetDefaultDecalMaterial(); isValidDecalMaterial &= mat != null && DecalSystem.IsDecalMaterial(mat); } } if (isValidDecalMaterial) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } else { EditorGUILayout.HelpBox("Decal only work with Decal Material. Decal Material can be selected in the shader list HDRP/Decal or can be created from a Decal Master Node.", MessageType.Error); } } }
void DrawSettingsGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField("Blade Params", bold); int instanceCount = EditorGUILayout.DelayedIntField(GetContent(() => grassFlow.instanceCount), grassFlow.instanceCount); bool updateBuffers = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.updateBuffers), grassFlow.updateBuffers); EditorGUILayout.Space(); EditorGUILayout.LabelField("Grass Render Properties", bold); int renderLayer = EditorGUILayout.LayerField(GetContent(() => grassFlow.renderLayer), grassFlow.renderLayer); GrassFlowRenderer.GrassRenderType renderType = (GrassFlowRenderer.GrassRenderType)EditorGUILayout.EnumPopup(GetContent(() => grassFlow.renderType), grassFlow.renderType); Terrain terrainObject = grassFlow.terrainObject; Mesh terrainMesh = grassFlow.grassMesh; int meshSubdivCount = grassFlow.grassPerTri; GUIContent subDivContent; float terrainExpansion = grassFlow.terrainExpansion; switch (renderType) { case GrassFlowRenderer.GrassRenderType.Mesh: subDivContent = GetContent(() => grassFlow.grassPerTri); meshSubdivCount = EditorGUILayout.IntField(subDivContent, grassFlow.grassPerTri); terrainMesh = EditorGUILayout.ObjectField(GetContent(() => grassFlow.grassMesh), grassFlow.grassMesh, typeof(Mesh), true) as Mesh; break; case GrassFlowRenderer.GrassRenderType.Terrain: subDivContent = new GUIContent("Grass Per Chunk", "Amount of grass to render per chunk in terrain mode. Technically controls the amount of grass per instance, per chunk, meaning maximum total grass per chunk = " + "GrassPerChunk * InstanceCount."); meshSubdivCount = EditorGUILayout.IntField(subDivContent, grassFlow.grassPerTri); terrainObject = EditorGUILayout.ObjectField(GetContent(() => grassFlow.terrainObject), grassFlow.terrainObject, typeof(Terrain), true) as Terrain; terrainExpansion = EditorGUILayout.FloatField(GetContent(() => grassFlow.terrainExpansion), grassFlow.terrainExpansion); break; } Transform terrainTransform = EditorGUILayout.ObjectField(GetContent(() => grassFlow.terrainTransform), grassFlow.terrainTransform, typeof(Transform), true) as Transform; bool highQualityHeightmap = grassFlow.highQualityHeightmap; if (renderType == GrassFlowRenderer.GrassRenderType.Terrain) { highQualityHeightmap = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.highQualityHeightmap), grassFlow.highQualityHeightmap); } bool useIndirectInstancing = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.useIndirectInstancing), grassFlow.useIndirectInstancing); bool useMaterialInstance = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.useMaterialInstance), grassFlow.useMaterialInstance); Material grassMaterial = EditorGUILayout.ObjectField(GetContent(() => grassFlow.grassMaterial), grassFlow.grassMaterial, typeof(Material), true) as Material; bool receiveShadows = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.receiveShadows), grassFlow.receiveShadows); bool castShadows = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.castShadows), grassFlow.castShadows); EditorGUILayout.Space(); EditorGUILayout.LabelField("LOD", bold); float maxRenderDist = EditorGUILayout.FloatField(GetContent(() => grassFlow.maxRenderDist), grassFlow.maxRenderDist); Vector3 lodParams = EditorGUILayout.Vector3Field(GetContent(() => grassFlow.lodParams), grassFlow.lodParams); Vector3 lodChunks; bool discardEmptyChunks = grassFlow.discardEmptyChunks; const string lodChunkTooltip = "Number of chunks to use for LOD culling. Distance to each chunk controls amount of grass that will be rendered there. " + "Generally you wont need more than one chunk in the Y direction but if you have incredibly vertical terrain, well, y'know. Too many chunks is bad for performance, " + "but not enough chunks will look bad and blocky when culling grass, so set this to have as few chunks as you can while also not looking bad. (Tip: you don't need as many as you think you do.)"; if (renderType == GrassFlowRenderer.GrassRenderType.Mesh) { lodChunks = EditorGUILayout.Vector3Field(new GUIContent("Mesh Lod Chunks", lodChunkTooltip), new Vector3(grassFlow.chunksX, grassFlow.chunksY, grassFlow.chunksZ)); } else { lodChunks = EditorGUILayout.Vector2Field(new GUIContent("Terrain Lod Chunks", lodChunkTooltip), new Vector2(grassFlow.chunksX, grassFlow.chunksZ)); discardEmptyChunks = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.discardEmptyChunks), grassFlow.discardEmptyChunks); } bool visualizeChunkBounds = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.visualizeChunkBounds), grassFlow.visualizeChunkBounds); bool useManualCulling = EditorGUILayout.ToggleLeft(GetContent(() => grassFlow.useManualCulling), grassFlow.useManualCulling); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(grassFlow, "GrassFlow Change Variable"); grassFlow.instanceCount = instanceCount; grassFlow.updateBuffers = updateBuffers; if (grassFlow.grassMaterial != grassMaterial) { grassFlow.grassMaterial = grassMaterial; matEditor = (MaterialEditor)CreateEditor(grassFlow.grassMaterial); grassFlow.Refresh(); } grassFlow.terrainExpansion = terrainExpansion; if (grassFlow.useIndirectInstancing != useIndirectInstancing) { grassFlow.useIndirectInstancing = useIndirectInstancing; grassFlow.OnEnable(); } grassFlow.useMaterialInstance = useMaterialInstance; grassFlow.renderLayer = renderLayer; grassFlow.renderType = renderType; grassFlow.terrainTransform = terrainTransform; grassFlow.terrainObject = terrainObject; grassFlow.highQualityHeightmap = highQualityHeightmap; grassFlow.grassMesh = terrainMesh; grassFlow.grassPerTri = meshSubdivCount; grassFlow.receiveShadows = receiveShadows; grassFlow.castShadows = castShadows; grassFlow.lodParams = lodParams; grassFlow.maxRenderDist = maxRenderDist; grassFlow.visualizeChunkBounds = visualizeChunkBounds; grassFlow.useManualCulling = useManualCulling; grassFlow.discardEmptyChunks = discardEmptyChunks; if (renderType == GrassFlowRenderer.GrassRenderType.Mesh) { grassFlow.chunksX = Mathf.RoundToInt(lodChunks.x); grassFlow.chunksY = Mathf.RoundToInt(lodChunks.y); grassFlow.chunksZ = Mathf.RoundToInt(lodChunks.z); } else { grassFlow.chunksX = Mathf.RoundToInt(lodChunks.x); grassFlow.chunksZ = Mathf.RoundToInt(lodChunks.y); } Undo.FlushUndoRecordObjects(); } DrawMapsInspector(); EditorGUILayout.Space(); if (grassFlow.grassMaterial) { if (matEditor == null) { matEditor = (MaterialEditor)CreateEditor(grassFlow.grassMaterial); } matEditor.DrawHeader(); matEditor.OnInspectorGUI(); } }
public override void OnInspectorGUI() { GraphData GetGraphData(AssetImporter importer) { var textGraph = File.ReadAllText(importer.assetPath, Encoding.UTF8); var graphObject = CreateInstance <GraphObject>(); graphObject.hideFlags = HideFlags.HideAndDontSave; bool isSubGraph; var extension = Path.GetExtension(importer.assetPath).Replace(".", ""); switch (extension) { case ShaderGraphImporter.Extension: isSubGraph = false; break; case ShaderGraphImporter.LegacyExtension: isSubGraph = false; break; case ShaderSubGraphImporter.Extension: isSubGraph = true; break; default: throw new Exception($"Invalid file extension {extension}"); } var assetGuid = AssetDatabase.AssetPathToGUID(importer.assetPath); graphObject.graph = new GraphData { assetGuid = assetGuid, isSubGraph = isSubGraph, messageManager = null }; MultiJson.Deserialize(graphObject.graph, textGraph); graphObject.graph.OnEnable(); graphObject.graph.ValidateGraph(); return(graphObject.graph); } if (GUILayout.Button("Open Shader Editor")) { AssetImporter importer = target as AssetImporter; Debug.Assert(importer != null, "importer != null"); ShowGraphEditWindow(importer.assetPath); } using (var horizontalScope = new GUILayout.HorizontalScope("box")) { AssetImporter importer = target as AssetImporter; string assetName = Path.GetFileNameWithoutExtension(importer.assetPath); string path = String.Format("Temp/GeneratedFromGraph-{0}.shader", assetName.Replace(" ", "")); bool alreadyExists = File.Exists(path); bool update = false; bool open = false; if (GUILayout.Button("View Generated Shader")) { update = true; open = true; } if (alreadyExists && GUILayout.Button("Regenerate")) { update = true; } if (update) { var graphData = GetGraphData(importer); var generator = new Generator(graphData, null, GenerationMode.ForReals, assetName, humanReadable: true); if (!GraphUtil.WriteToFile(path, generator.generatedShader)) { open = false; } } if (open) { GraphUtil.OpenFile(path); } } if (Unsupported.IsDeveloperMode()) { if (GUILayout.Button("View Preview Shader")) { AssetImporter importer = target as AssetImporter; string assetName = Path.GetFileNameWithoutExtension(importer.assetPath); string path = String.Format("Temp/GeneratedFromGraph-{0}-Preview.shader", assetName.Replace(" ", "")); var graphData = GetGraphData(importer); var generator = new Generator(graphData, null, GenerationMode.Preview, $"{assetName}-Preview", humanReadable: true); if (GraphUtil.WriteToFile(path, generator.generatedShader)) { GraphUtil.OpenFile(path); } } } if (GUILayout.Button("Copy Shader")) { AssetImporter importer = target as AssetImporter; string assetName = Path.GetFileNameWithoutExtension(importer.assetPath); var graphData = GetGraphData(importer); var generator = new Generator(graphData, null, GenerationMode.ForReals, assetName, humanReadable: true); GUIUtility.systemCopyBuffer = generator.generatedShader; } ApplyRevertGUI(); if (materialEditor) { EditorGUILayout.Space(); materialEditor.DrawHeader(); using (new EditorGUI.DisabledGroupScope(true)) materialEditor.OnInspectorGUI(); } }
public override void OnInspectorGUI() { // update serializedObject with NFA's values serializedObject.Update(); FindProperties(); GUILayout.Space(15); projectIssueNotifications.OnGUI(); if (!TopSection(nfa)) { //early out serializedObject.ApplyModifiedProperties(); return; } GUILayout.Space(25); //fur material, only allow changes editor time if (!Application.isPlaying) { EditorGUILayout.PropertyField(matProp, Styles.labelFurryMat); } //fur submesh index //don't allow changing this at game time if (!Application.isPlaying) { EditorGUILayout.PropertyField(subMeshIndexProp, Styles.labelFurSubMesh); } // shell count, fur length, shell fade EditorGUILayout.PropertyField(shellCountProp, Styles.labelShellCount); EditorGUILayout.PropertyField(shellDistanceProp, Styles.labelFurLength); EditorGUILayout.PropertyField(shellDistanceScaleProp, Styles.labelShellFade); EditorGUILayout.PropertyField(shellOffsetProp, Styles.labelShellOffset); GUILayout.Space(25); //Preprocessing foldout //skip if not in editor mode if (!Application.isPlaying) { PreProcessSection(nfa); } bShadowsFolded = NeoGUIHelper.HeaderWithFoldout(Styles.foldoutShadows.text, bShadowsFolded); if (bShadowsFolded) { EditorGUI.indentLevel++; //shadow settings EditorGUILayout.PropertyField(renderSettingsProp, Styles.labelUseRenderSettings); if (!nfa.useRendererSettings) { EditorGUILayout.PropertyField(castShadowProp, Styles.labelShadowCastingMode); EditorGUILayout.PropertyField(receiveShadowsProp, Styles.labelRecieveShadows); } EditorGUI.indentLevel--; } //LOD foldout //In the past here we'd check for an assigned scene camera, as LOD is kind of meaningless //without the ability to check the distance to the camera. But alot of users are setting //up cameras in code, so they need to be able to edit these numbers. { bLODFolded = NeoGUIHelper.HeaderWithFoldout(Styles.foldoutLOD.text, bLODFolded); if (bLODFolded) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(lodStartDistProp, Styles.labelLODStartDist); EditorGUILayout.PropertyField(lodEndDistProp, Styles.labelLODEndDist); EditorGUILayout.PropertyField(lodMinShellCountProp, Styles.labelLODMinShellCount); EditorGUILayout.PropertyField(maxCamDistProp, Styles.labelLODMaxCamDist); //near compression stuff EditorGUILayout.PropertyField(nearCompressionDistProp, Styles.labelNearCompressionDist); EditorGUILayout.PropertyField(nearCompressionMinProp, Styles.labelNearCompressionMin); EditorGUILayout.PropertyField(nearCompressionMaxProp, Styles.labelNearCompressionMax); EditorGUI.indentLevel--; } } // Physics foldout bPhysicsFolded = NeoGUIHelper.HeaderWithFoldout(Styles.foldoutPhysics.text, bPhysicsFolded); if (bPhysicsFolded) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(velocityInfluenceProp, Styles.labelVelocityInfluence); EditorGUILayout.PropertyField(springLenStiffProp, Styles.labelSpringLenStiff); EditorGUILayout.PropertyField(springAngleStiffProp, Styles.labelSpringAngleStiff); EditorGUILayout.PropertyField(springDampMultProp, Styles.labelSpringDampMult); EditorGUILayout.PropertyField(gravityInfluenceProp, Styles.labelGravityInfluence); EditorGUILayout.PropertyField(airResistMultProp, Styles.labelAirResistMult); EditorGUILayout.PropertyField(maxStretchDistMultProp, Styles.labelMaxStretchDistMult); EditorGUILayout.PropertyField(minStretchDistMultProp, Styles.labelMinStretchDistMult); EditorGUILayout.PropertyField(maxRotFromNormalProp, Styles.labelMaxRotFromNormal); EditorGUILayout.PropertyField(radialForceInfluenceProp, Styles.labelRadialForceInfluence); EditorGUILayout.PropertyField(windProp, Styles.labelWind); if (windProp.objectReferenceValue != null) { NeoGUIHelper.PushIndent(); EditorGUILayout.PropertyField(windInfluenceProp, Styles.labelWindInfluence); NeoGUIHelper.PopIndent(); } EditorGUILayout.PropertyField(bendExponentProp, Styles.labelBendExponent); // normal direction blend EditorGUILayout.PropertyField(normalDirectionBlendProp, Styles.labelNormalDirection); EditorGUI.indentLevel--; } // Debug Draw foldout bDebugDrawFolded = NeoGUIHelper.HeaderWithFoldout(Styles.foldoutDebugDraw.text, bDebugDrawFolded); if (bDebugDrawFolded) { NeoFurAsset neoFurAsset = ((NeoFurAsset)target); EditorGUI.indentLevel++; if (neoFurAsset.vertexProcessor != null) { GUILayout.Label($"Average compute time: {(neoFurAsset.vertexProcessor.averageProcessTime*1000).ToString("0.00")}ms"); GUILayout.Label($"Active shells: {(neoFurAsset.lodShellCount)}"); } // debug: draw control points? EditorGUILayout.PropertyField(drawControlPointsProp, Styles.labelDrawControlPoints); // debug: draw fur guides? EditorGUILayout.PropertyField(drawGuidesProp, Styles.labelDrawFurGuides); // if the application is playing, then show the section for debug textures if (Application.isPlaying) { bDebugDrawTexturesFolded = NeoGUIHelper.HeaderWithFoldout(Styles.foldoutDebugDrawTextures.text, bDebugDrawTexturesFolded); if (bDebugDrawTexturesFolded) { int originalIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (neoFurAsset.vertexProcessor != null) { repaintDebugTextures = EditorGUILayout.Toggle("Live Update", repaintDebugTextures); neoFurAsset.vertexProcessor.DebugDraw(); } if (repaintDebugTextures) { Repaint(); } EditorGUI.indentLevel = originalIndent; } } EditorGUI.indentLevel--; } // send values from property fields back to NFA serializedObject.ApplyModifiedProperties(); //if runtime, do material editor at the bottom if (Application.isPlaying) { ValidateMaterialEditor(); // only do stuff with the material editor if it was instantiated if (mMatEdit && mMatEdit.target) { GUI.changed = false; EditorGUIUtility.labelWidth = 0; mMatEdit.DrawHeader(); mMatEdit.OnInspectorGUI(); bool didUndo = Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed"; if (GUI.changed || didUndo) { nfa.CreateMaterialInstance(); } } } }
public override void OnInspectorGUI() { bool isLite = _target.material != null && _target.material.shader.name.Contains("Lite"); LPWHiddenProps.Scale(_target); bool guiChanged = false; // Banner if (_bannerTex != null) { GUILayout.Space(5); var rect = GUILayoutUtility.GetRect(0, int.MaxValue, 30, 30); EditorGUI.DrawPreviewTexture(rect, _bannerTex, null, ScaleMode.ScaleAndCrop); //EditorGUI.LabelField(rect, "Rate \u2605\u2605\u2605\u2605\u2605", rateTxt); EditorGUI.LabelField(rect, "Rate | Review", _rateTxt); EditorGUI.LabelField(rect, "Low Poly Water", _title); if (GUI.Button(rect, "", _linkStyle)) { Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/account/downloads/search=Low%20Poly%20Water"); } GUILayout.Space(3); } EditorGUI.BeginChangeCheck(); serializedObject.Update(); EditorGUILayout.PropertyField(serializedObject.FindProperty("material")); bool matChanged = EditorGUI.EndChangeCheck(); guiChanged = guiChanged || matChanged; if (matChanged || _materialEditor == null) { if (_materialEditor != null) { // Free the memory used by the previous MaterialEditor DestroyImmediate(_materialEditor); } if (_target.material != null) { // Create a new instance of the default MaterialEditor _materialEditor = (MaterialEditor)CreateEditor(_target.material); } } EditorGUI.BeginChangeCheck(); if (isLite) { EditorGUILayout.PropertyField(serializedObject.FindProperty("gridTypeLite")); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("gridType")); } if (_target.gridType == LowPolyWaterScript.GridType.Custom) { EditorGUILayout.PropertyField(serializedObject.FindProperty("customMesh")); } else if (_target.gridType == LowPolyWaterScript.GridType.HexagonalLOD) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(serializedObject.FindProperty("LOD")); EditorGUILayout.PropertyField(serializedObject.FindProperty("LODPower")); EditorGUI.indentLevel--; } if (_target.gridType != LowPolyWaterScript.GridType.Custom) { var sizeX = serializedObject.FindProperty("sizeX"); var sizeZ = serializedObject.FindProperty("sizeZ"); // size X Z on the same line EditorGUILayout.BeginHorizontal(); if (_target.sizeX > 150 || _target.sizeZ > 150) { EditorGUILayout.LabelField("Size (Regenerate)", GUILayout.MinWidth(30)); } else { EditorGUILayout.LabelField("Size", GUILayout.MinWidth(30)); } GUILayout.FlexibleSpace(); var lblW = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 15; sizeX.intValue = EditorGUILayout.IntField("X", sizeX.intValue); sizeZ.intValue = EditorGUILayout.IntField("Z", sizeZ.intValue); EditorGUIUtility.labelWidth = lblW; EditorGUILayout.EndHorizontal(); } guiChanged = guiChanged || EditorGUI.EndChangeCheck(); //Scale var lScale = _target.transform.localScale; EditorGUILayout.BeginHorizontal(); var lblWi = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 30; EditorGUILayout.LabelField("Scale"); GUILayout.FlexibleSpace(); EditorGUIUtility.labelWidth = 15; lScale.x = EditorGUILayout.FloatField("X", lScale.x); lScale.z = EditorGUILayout.FloatField("Z", lScale.z); EditorGUIUtility.labelWidth = lblWi; EditorGUILayout.EndHorizontal(); _target.transform.localScale = lScale; // Noise EditorGUI.BeginChangeCheck(); if (_target.gridType != LowPolyWaterScript.GridType.Custom) { EditorGUILayout.PropertyField(serializedObject.FindProperty("noise")); } guiChanged = guiChanged || EditorGUI.EndChangeCheck(); if (!isLite) { EditorGUI.BeginChangeCheck(); var shadows = serializedObject.FindProperty("receiveShadows"); EditorGUILayout.PropertyField(shadows); var recShadChanged = EditorGUI.EndChangeCheck(); guiChanged = guiChanged || recShadChanged; if (recShadChanged && _target.material != null && _target.material.HasProperty("_EnableShadows")) { _target.material.SetFloat("_EnableShadows", shadows.boolValue ? 1f : 0); } bool reflChanged = false; EditorGUI.BeginChangeCheck(); var refl = serializedObject.FindProperty("enableReflection"); var refr = serializedObject.FindProperty("enableRefraction"); EditorGUILayout.PropertyField(refl); EditorGUILayout.PropertyField(refr); reflChanged = EditorGUI.EndChangeCheck(); guiChanged = guiChanged || reflChanged; if (refl.boolValue || refr.boolValue) { var refOptions = serializedObject.FindProperty("reflection"); if (reflChanged) { refOptions.isExpanded = true; if (_target.material != null && _target.material.HasProperty("_ZWrite")) { _target.material.SetFloat("_ZWrite", 1); } } EditorGUILayout.PropertyField(refOptions, _reflCfgLbl, true); } } else { _target.enableReflection = false; _target.enableRefraction = false; _target.receiveShadows = false; } EditorGUI.BeginChangeCheck(); if (_target.material != null && _target.material.HasProperty("_Sun")) { EditorGUILayout.PropertyField(serializedObject.FindProperty("sun")); } guiChanged = guiChanged || EditorGUI.EndChangeCheck(); serializedObject.ApplyModifiedProperties(); _target.sizeX = Mathf.Clamp(_target.sizeX, 1, 400); _target.sizeZ = Mathf.Clamp(_target.sizeZ, 1, 400); bool doGenerate = false; if (_target.sizeX > 150 || _target.sizeZ > 150) { _target.displayProgress = true; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); doGenerate = GUILayout.Button("Regenerate", GUILayout.MaxWidth(200)); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (doGenerate) { guiChanged = true; } } else { _target.displayProgress = false; doGenerate = true; } if (guiChanged) { _target.reflection.textureSize = Mathf.Clamp(_target.reflection.textureSize, 1, 4096); if (isLite) { _target.gridType = (LowPolyWaterScript.GridType)(_target.gridTypeLite); } LPWHiddenProps.SetKeywords(_target); if (doGenerate) { _target.Generate(); } } if (_materialEditor != null) { // Draw the material's foldout and the material shader field // Required to call _materialEditor.OnInspectorGUI (); _materialEditor.DrawHeader(); // We need to prevent the user to edit Unity default materials bool isDefaultMaterial = !AssetDatabase.GetAssetPath(_target.material).StartsWith("Assets"); using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of _materialEditor.DrawHeader () is open _materialEditor.OnInspectorGUI(); } } }
public override void OnInspectorGUI() { serializedObject.Update(); if (m_RequireUpdateMaterialEditor) { UpdateMaterialEditor(); m_RequireUpdateMaterialEditor = false; } EditorGUI.BeginChangeCheck(); { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); DoInspectorToolbar(k_EditVolumeModes, editVolumeLabels, GetBoundsGetter, this); //[TODO: add editable pivot. Uncomment this when ready] //DoInspectorToolbar(k_EditPivotModes, editPivotLabels, GetBoundsGetter, this); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_Size, k_SizeContent); EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent); bool decalLayerEnabled = false; HDRenderPipelineAsset hdrp = HDRenderPipeline.currentAsset; if (hdrp != null) { decalLayerEnabled = hdrp.currentPlatformRenderPipelineSettings.supportDecals && hdrp.currentPlatformRenderPipelineSettings.supportDecalLayers; using (new EditorGUI.DisabledScope(!decalLayerEnabled)) { EditorGUILayout.PropertyField(m_DecalLayerMask, k_DecalLayerMaskContent); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_DrawDistanceProperty, k_DistanceContent); if (EditorGUI.EndChangeCheck() && m_DrawDistanceProperty.floatValue < 0f) { m_DrawDistanceProperty.floatValue = 0f; } EditorGUILayout.PropertyField(m_FadeScaleProperty, k_FadeScaleContent); using (new EditorGUI.DisabledScope(!decalLayerEnabled)) { EditorGUILayout.PropertyField(m_StartAngleFadeProperty, k_StartAngleFadeContent); if (EditorGUI.EndChangeCheck() && m_StartAngleFadeProperty.floatValue > m_EndAngleFadeProperty.floatValue) { m_EndAngleFadeProperty.floatValue = m_StartAngleFadeProperty.floatValue; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_EndAngleFadeProperty, k_EndAngleFadeContent); if (EditorGUI.EndChangeCheck() && m_EndAngleFadeProperty.floatValue < m_StartAngleFadeProperty.floatValue) { m_StartAngleFadeProperty.floatValue = m_EndAngleFadeProperty.floatValue; } } if (!decalLayerEnabled) { EditorGUILayout.HelpBox("Enable 'Decal Layers' in your HDRP Asset if you want to control the Angle Fade. There is a performance cost of enabling this option.", MessageType.Info); } EditorGUILayout.PropertyField(m_UVScaleProperty, k_UVScaleContent); EditorGUILayout.PropertyField(m_UVBiasProperty, k_UVBiasContent); EditorGUILayout.PropertyField(m_FadeFactor, k_FadeFactorContent); // only display the affects transparent property if material is HDRP/decal if (showAffectTransparencyHaveMultipleDifferentValue) { using (new EditorGUI.DisabledScope(true)) EditorGUILayout.LabelField(EditorGUIUtility.TrTextContent("Multiple material type in selection")); } else if (showAffectTransparency) { EditorGUILayout.PropertyField(m_AffectsTransparencyProperty, k_AffectTransparentContent); } } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (layerMaskHasMultipleValue || layerMask != (target as Component).gameObject.layer) { foreach (var decalProjector in targets) { (decalProjector as DecalProjector).OnValidate(); } } if (m_MaterialEditor != null) { // We need to prevent the user to edit default decal materials bool isDefaultMaterial = false; bool isValidDecalMaterial = true; var hdrp = HDRenderPipeline.currentAsset; if (hdrp != null) { foreach (var decalProjector in targets) { var mat = (decalProjector as DecalProjector).material; isDefaultMaterial |= mat == hdrp.GetDefaultDecalMaterial(); isValidDecalMaterial = isValidDecalMaterial && DecalSystem.IsDecalMaterial(mat); } } if (isValidDecalMaterial) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } else { EditorGUILayout.HelpBox("Decal only work with Decal Material. Decal Material can be selected in the shader list HDRP/Decal or can be created from a Decal Master Node.", MessageType.Error); } } }
public override void OnInspectorGUI() { if (targets.OfType <VFXShaderGraphParticleOutput>().Any(context => context.GetOrRefreshShaderGraphObject() == null)) { base.OnInspectorGUI(); return; } serializedObject.Update(); if (m_RequireUpdateMaterialEditor) { UpdateMaterialEditor(); m_RequireUpdateMaterialEditor = false; } var materialChanged = false; var previousBlendMode = ((VFXShaderGraphParticleOutput)target).GetMaterialBlendMode(); if (m_MaterialEditor != null) { if (m_MaterialEditor.target == null || (m_MaterialEditor.target as Material)?.shader == null) { EditorGUILayout.HelpBox("Material Destroyed.", MessageType.Warning); } else { using (new EditorGUI.DisabledScope(true)) { // Required to draw the header to draw OnInspectorGUI. m_MaterialEditor.DrawHeader(); } EditorGUI.BeginChangeCheck(); // This will correctly handle the configuration of keyword and pass setup. m_MaterialEditor.OnInspectorGUI(); materialChanged = EditorGUI.EndChangeCheck(); } // Indicate caution to the user if transparent motion vectors are disabled and motion vectors are enabled. if ((m_MaterialEditor.target != null) && ((VFXAbstractParticleOutput)target).hasMotionVector && ((VFXShaderGraphParticleOutput)target).GetMaterialBlendMode() != VFXAbstractRenderedOutput.BlendMode.Opaque && !VFXLibrary.currentSRPBinder.TransparentMotionVectorEnabled(m_MaterialEditor.target as Material)) { EditorGUILayout.HelpBox("Transparent Motion Vectors pass is disabled. Consider disabling Generate Motion Vector to improve performance.", MessageType.Warning); } } base.OnInspectorGUI(); if (serializedObject.ApplyModifiedProperties()) { foreach (var context in targets.OfType <VFXShaderGraphParticleOutput>()) { context.Invalidate(VFXModel.InvalidationCause.kSettingChanged); } } if (materialChanged) { foreach (var context in targets.OfType <VFXShaderGraphParticleOutput>()) { context.UpdateMaterialSettings(); var currentBlendMode = ((VFXShaderGraphParticleOutput)target).GetMaterialBlendMode(); // If the blend mode is changed to one that may require sorting (Auto), we require a full recompilation. if (previousBlendMode != currentBlendMode) { context.Invalidate(VFXModel.InvalidationCause.kSettingChanged); } else { context.Invalidate(VFXModel.InvalidationCause.kMaterialChanged); } } } }
public override void OnInspectorGUI() { serializedObject.Update(); bool materialChanged = false; bool isDefaultMaterial = false; bool isValidDecalMaterial = true; bool isDecalSupported = DecalProjector.isSupported; if (!isDecalSupported) { EditorGUILayout.HelpBox("No renderer has a Decal Renderer Feature added.", MessageType.Warning); } EditorGUI.BeginChangeCheck(); { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); DoInspectorToolbar(k_EditVolumeModes, editVolumeLabels, GetBoundsGetter(target as DecalProjector), this); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); // Info box for tools GUIStyle style = new GUIStyle(EditorStyles.miniLabel); style.richText = true; GUILayout.BeginVertical(EditorStyles.helpBox); string helpText = k_BaseSceneEditingToolText; if (EditMode.editMode == k_EditShapeWithoutPreservingUV && EditMode.IsOwner(this)) { helpText = k_EditShapeWithoutPreservingUVName; } if (EditMode.editMode == k_EditShapePreservingUV && EditMode.IsOwner(this)) { helpText = k_EditShapePreservingUVName; } if (EditMode.editMode == k_EditUVAndPivot && EditMode.IsOwner(this)) { helpText = k_EditUVAndPivotName; } GUILayout.Label(helpText, style); GUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_ScaleMode, k_ScaleMode); bool negativeScale = false; foreach (var target in targets) { var decalProjector = target as DecalProjector; float combinedScale = decalProjector.transform.lossyScale.x * decalProjector.transform.lossyScale.y * decalProjector.transform.lossyScale.z; negativeScale |= combinedScale < 0 && decalProjector.scaleMode == DecalScaleMode.InheritFromHierarchy; } if (negativeScale) { EditorGUILayout.HelpBox("Does not work with negative odd scaling (When there are odd number of scale components)", MessageType.Warning); } var widthRect = EditorGUILayout.GetControlRect(); EditorGUI.BeginProperty(widthRect, k_WidthContent, m_SizeValues[0]); EditorGUI.BeginChangeCheck(); float newSizeX = EditorGUI.FloatField(widthRect, k_WidthContent, m_SizeValues[0].floatValue); if (EditorGUI.EndChangeCheck()) { UpdateSize(0, Mathf.Max(0, newSizeX)); } EditorGUI.EndProperty(); var heightRect = EditorGUILayout.GetControlRect(); EditorGUI.BeginProperty(heightRect, k_HeightContent, m_SizeValues[1]); EditorGUI.BeginChangeCheck(); float newSizeY = EditorGUI.FloatField(heightRect, k_HeightContent, m_SizeValues[1].floatValue); if (EditorGUI.EndChangeCheck()) { UpdateSize(1, Mathf.Max(0, newSizeY)); } EditorGUI.EndProperty(); var projectionRect = EditorGUILayout.GetControlRect(); EditorGUI.BeginProperty(projectionRect, k_ProjectionDepthContent, m_SizeValues[2]); EditorGUI.BeginChangeCheck(); float newSizeZ = EditorGUI.FloatField(projectionRect, k_ProjectionDepthContent, m_SizeValues[2].floatValue); if (EditorGUI.EndChangeCheck()) { UpdateSize(2, Mathf.Max(0, newSizeZ)); } EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_Offset, k_Offset); if (EditorGUI.EndChangeCheck()) { ReinitSavedRatioSizePivotPosition(); } EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent); materialChanged = EditorGUI.EndChangeCheck(); foreach (var target in targets) { var decalProjector = target as DecalProjector; var mat = decalProjector.material; isDefaultMaterial |= decalProjector.material == DecalProjector.defaultMaterial; isValidDecalMaterial &= decalProjector.IsValid(); } if (m_MaterialEditor && !isValidDecalMaterial) { CoreEditorUtils.DrawFixMeBox("Decal only work with Decal Material. Use default material or create from decal shader graph sub target.", () => { m_MaterialProperty.objectReferenceValue = DecalProjector.defaultMaterial; materialChanged = true; }); } EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_UVScaleProperty, k_UVScaleContent); EditorGUILayout.PropertyField(m_UVBiasProperty, k_UVBiasContent); EditorGUILayout.PropertyField(m_FadeFactor, k_OpacityContent); EditorGUI.indentLevel--; bool angleFadeSupport = false; foreach (var decalProjector in targets) { var mat = (decalProjector as DecalProjector).material; if (mat == null) { continue; } angleFadeSupport = mat.HasProperty("_DecalAngleFadeSupported"); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_DrawDistanceProperty, k_DistanceContent); if (EditorGUI.EndChangeCheck() && m_DrawDistanceProperty.floatValue < 0f) { m_DrawDistanceProperty.floatValue = 0f; } EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_FadeScaleProperty, k_FadeScaleContent); EditorGUI.indentLevel--; using (new EditorGUI.DisabledScope(!angleFadeSupport)) { float angleFadeMinValue = m_StartAngleFadeProperty.floatValue; float angleFadeMaxValue = m_EndAngleFadeProperty.floatValue; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(k_AngleFadeContent, ref angleFadeMinValue, ref angleFadeMaxValue, 0.0f, 180.0f); if (EditorGUI.EndChangeCheck()) { m_StartAngleFadeProperty.floatValue = angleFadeMinValue; m_EndAngleFadeProperty.floatValue = angleFadeMaxValue; } } if (!angleFadeSupport && isValidDecalMaterial) { EditorGUILayout.HelpBox($"Decal Angle Fade is not enabled in Shader. In ShaderGraph enable Angle Fade option.", MessageType.Info); } EditorGUILayout.Space(); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (materialChanged) { UpdateMaterialEditor(); } if (layerMaskHasMultipleValues || layerMask != (target as Component).gameObject.layer) { foreach (var decalProjector in targets) { (decalProjector as DecalProjector).OnValidate(); } } if (m_MaterialEditor != null) { // We need to prevent the user to edit default decal materials if (isValidDecalMaterial) { using (new DecalProjectorScope()) { using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } } } }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); DoInspectorToolbar(k_EditVolumeModes, editVolumeLabels, GetBoundsGetter, this); //[TODO: add editable pivot. Uncomment this when ready] //DoInspectorToolbar(k_EditPivotModes, editPivotLabels, GetBoundsGetter, this); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_Size, k_SizeContent); EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_DrawDistanceProperty, k_DistanceContent); if (EditorGUI.EndChangeCheck() && m_DrawDistanceProperty.floatValue < 0f) { m_DrawDistanceProperty.floatValue = 0f; } EditorGUILayout.PropertyField(m_FadeScaleProperty, k_FadeScaleContent); EditorGUILayout.PropertyField(m_UVScaleProperty, k_UVScaleContent); EditorGUILayout.PropertyField(m_UVBiasProperty, k_UVBiasContent); EditorGUILayout.PropertyField(m_FadeFactor, k_FadeFactorContent); // only display the affects transparent property if material is HDRP/decal if (showAffectTransparencyHaveMultipleDifferentValue) { using (new EditorGUI.DisabledScope(true)) EditorGUILayout.LabelField(EditorGUIUtility.TrTextContent("Multiple material type in selection")); } else if (showAffectTransparency) { EditorGUILayout.PropertyField(m_AffectsTransparencyProperty, k_AffectTransparentContent); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (layerMaskHasMultipleValue || layerMask != (target as Component).gameObject.layer) { foreach (var decalProjector in targets) { (decalProjector as DecalProjector).OnValidate(); } } if (m_MaterialEditor != null) { // Draw the material's foldout and the material shader field // Required to call m_MaterialEditor.OnInspectorGUI (); m_MaterialEditor.DrawHeader(); // We need to prevent the user to edit default decal materials bool isDefaultMaterial = false; var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; if (hdrp != null) { foreach (var decalProjector in targets) { isDefaultMaterial |= (decalProjector as DecalProjector).material == hdrp.GetDefaultDecalMaterial(); } } using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) { // Draw the material properties // Works only if the foldout of m_MaterialEditor.DrawHeader () is open m_MaterialEditor.OnInspectorGUI(); } } }
public void MaterialEditor(UnityEngine.Object target, Material material, SerializedObject serializedObject) { if (target == null || material == null) { return; } HashSet <Material> mats = new HashSet <Material>(); foreach (UnityEngine.Object obj in serializedObject.targetObjects) { if (obj.GetType() == target.GetType()) { if (obj.GetType() == typeof(HvrActor)) { HvrActor actor = (HvrActor)obj; mats.Add(actor.material); } } } if (materialEditor == null) { materialEditor = (MaterialEditor)UnityEditor.Editor.CreateEditor(material); } else { if (materialEditor.target != material) { materialEditor = (MaterialEditor)UnityEditor.Editor.CreateEditor(material); } } if (mats.Count > 1) { EditorGUILayout.HelpBox("Material properties on selected components with different materials cannot be multi-edited", MessageType.Warning); } MaterialProperty[] properties_previous = UnityEditor.MaterialEditor.GetMaterialProperties(new UnityEngine.Object[1] { materialEditor.target }); EditorGUI.BeginChangeCheck(); { EditorGUI.BeginDisabledGroup(mats.Count > 1); { // Draw the material's foldout and the material shader field // Required to call _materialEditor.OnInspectorGUI (); materialEditor.DrawHeader(); // Draw the material properties // Works only if the foldout of _materialEditor.DrawHeader () is open materialEditor.OnInspectorGUI(); } EditorGUI.EndDisabledGroup(); } if (EditorGUI.EndChangeCheck()) { MaterialProperty[] properties_new = UnityEditor.MaterialEditor.GetMaterialProperties(new UnityEngine.Object[1] { materialEditor.target }); foreach (MaterialProperty prop_new in properties_new) { MaterialProperty match = properties_previous.First(x => (x.name == prop_new.name) && (x.type == prop_new.type)); if (match != null) { foreach (Material mat in mats) { switch (prop_new.type) { case MaterialProperty.PropType.Color: if (prop_new.colorValue != match.colorValue) { mat.SetColor(prop_new.name, prop_new.colorValue); } break; case MaterialProperty.PropType.Float: if (prop_new.floatValue != match.floatValue) { mat.SetFloat(prop_new.name, prop_new.floatValue); } break; case MaterialProperty.PropType.Range: if (prop_new.floatValue != match.floatValue) { mat.SetFloat(prop_new.name, prop_new.floatValue); } break; case MaterialProperty.PropType.Texture: if (prop_new.textureValue != match.textureValue) { mat.SetTexture(prop_new.name, prop_new.textureValue); } break; case MaterialProperty.PropType.Vector: if (prop_new.vectorValue != match.vectorValue) { mat.SetVector(prop_new.name, prop_new.vectorValue); } break; } } } } } }