public static void SetMat(Material targetMat) { LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { if (ops == null) { ops = new string[23]; for (int i = 0; i < 23; ++i) { ops[i] = "Decal Layer " + i; } } Material targetMat = materialEditor.target as Material; UVType currUVType = UVType.UV; if (targetMat.IsKeywordEnabled("WORLDXZ_UV")) { currUVType = UVType.WorldPosXZ; } if (targetMat.IsKeywordEnabled("WORLDXY_UV")) { currUVType = UVType.WorldPosXY; } if (targetMat.IsKeywordEnabled("WORLDYZ_UV")) { currUVType = UVType.WorldPosYZ; } currUVType = (UVType)EditorGUILayout.EnumPopup("UV Type", currUVType); bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector"); useMotionVector = EditorGUILayout.Toggle("MotionVector", useMotionVector); targetMat.SetShaderPassEnabled("MotionVector", useMotionVector); bool targetMatEnabled = targetMat.IsKeywordEnabled("CUT_OFF"); bool targetUseTessellation = targetMat.IsKeywordEnabled("USE_TESSELLATION"); targetUseTessellation = EditorGUILayout.Toggle("Tessellation", targetUseTessellation); targetMatEnabled = EditorGUILayout.Toggle("Cut off", targetMatEnabled); int targetDecalLayer = targetMat.GetInt("_DecalLayer"); targetDecalLayer = EditorGUILayout.MaskField("Decal Layer", targetDecalLayer, ops); targetMat.SetInt("_DecalLayer", targetDecalLayer); LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); currentType = (LightingModelType)EditorGUILayout.EnumPopup("Lighting Model", currentType); Undo.RecordObject(targetMat, targetMat.name); targetMat.SetInt("_LightingModel", (int)currentType); if (targetUseTessellation) { targetMat.EnableKeyword("USE_TESSELLATION"); } else { targetMat.DisableKeyword("USE_TESSELLATION"); } if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } switch (currUVType) { case UVType.UV: targetMat.DisableKeyword("WORLDXZ_UV"); targetMat.DisableKeyword("WORLDXY_UV"); targetMat.DisableKeyword("WORLDYZ_UV"); break; case UVType.WorldPosXY: targetMat.DisableKeyword("WORLDXZ_UV"); targetMat.EnableKeyword("WORLDXY_UV"); targetMat.DisableKeyword("WORLDYZ_UV"); break; case UVType.WorldPosYZ: targetMat.DisableKeyword("WORLDXZ_UV"); targetMat.DisableKeyword("WORLDXY_UV"); targetMat.EnableKeyword("WORLDYZ_UV"); break; case UVType.WorldPosXZ: targetMat.EnableKeyword("WORLDXZ_UV"); targetMat.DisableKeyword("WORLDXY_UV"); targetMat.DisableKeyword("WORLDYZ_UV"); break; } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } if (!targetMatEnabled) { targetMat.DisableKeyword("CUT_OFF"); if (targetUseTessellation) { targetMat.renderQueue = 2450; } else { targetMat.renderQueue = 2000; } } else { targetMat.EnableKeyword("CUT_OFF"); targetMat.renderQueue = 2451; } base.OnGUI(materialEditor, properties); }
public static void SetMat(Material targetMat) { bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector"); targetMat.SetShaderPassEnabled("MotionVector", useMotionVector); bool targetMatEnabled = targetMat.IsKeywordEnabled("CUT_OFF"); bool targetUseTessellation = targetMat.shader.name.Contains("Tessellation"); int targetDecalLayer = targetMat.GetInt("_DecalLayer"); targetMat.SetInt("_DecalLayer", targetDecalLayer); LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); Undo.RecordObject(targetMat, targetMat.name); targetMat.SetInt("_LightingModel", (int)currentType); if (targetUseTessellation) { targetMat.EnableKeyword("USE_TESSELLATION"); } else { targetMat.DisableKeyword("USE_TESSELLATION"); } if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } if (targetMat.GetTexture("_SecondaryMainTex")) { targetMat.EnableKeyword("USE_SECONDARY_MAP"); } else { targetMat.DisableKeyword("USE_SECONDARY_MAP"); } if (!targetMatEnabled) { targetMat.DisableKeyword("CUT_OFF"); if (targetUseTessellation) { targetMat.renderQueue = 2450; } else { targetMat.renderQueue = 2000; } } else { targetMat.EnableKeyword("CUT_OFF"); targetMat.renderQueue = 2451; } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { Material targetMat = materialEditor.target as Material; bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector"); useMotionVector = EditorGUILayout.Toggle("MotionVector", useMotionVector); targetMat.SetShaderPassEnabled("MotionVector", useMotionVector); bool targetMatEnabled = targetMat.IsKeywordEnabled("CUT_OFF"); targetMatEnabled = EditorGUILayout.Toggle("Cut off", targetMatEnabled); LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); currentType = (LightingModelType)EditorGUILayout.EnumPopup("Lighting Model", currentType); Undo.RecordObject(targetMat, targetMat.name); targetMat.SetInt("_LightingModel", (int)currentType); if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } targetMat.SetInt("_ZTest", targetMatEnabled ? (int)UnityEngine.Rendering.CompareFunction.Equal : (int)UnityEngine.Rendering.CompareFunction.Less); targetMat.SetInt("_ZWrite", targetMatEnabled ? 0 : 1); if (!targetMatEnabled) { targetMat.DisableKeyword("CUT_OFF"); if (targetMat.renderQueue > 2450) { targetMat.renderQueue = 2000; } } else { targetMat.EnableKeyword("CUT_OFF"); if (targetMat.renderQueue < 2451) { targetMat.renderQueue = 2451; } } base.OnGUI(materialEditor, properties); if (targetMat.GetTexture("_DetailAlbedo") == null && targetMat.GetTexture("_DetailNormal") == null) { targetMat.DisableKeyword("DETAIL_ON"); } else { targetMat.EnableKeyword("DETAIL_ON"); } }
public static void SetMat(Material targetMat) { bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector"); LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } if (targetMat.GetTexture("_DetailAlbedo") == null && targetMat.GetTexture("_DetailNormal") == null) { targetMat.DisableKeyword("DETAIL_ON"); } else { targetMat.EnableKeyword("DETAIL_ON"); } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { if (ops == null) { ops = new string[23]; for (int i = 0; i < 23; ++i) { ops[i] = "Decal Layer " + i; } } Material targetMat = materialEditor.target as Material; Undo.RecordObject(targetMat, targetMat.name); bool useMotionVector = targetMat.IsKeywordEnabled("USE_MOTIONVECTOR"); useMotionVector = EditorGUILayout.Toggle("MotionVector", useMotionVector); if (useMotionVector) { targetMat.EnableKeyword("USE_MOTIONVECTOR"); } else { targetMat.DisableKeyword("USE_MOTIONVECTOR"); } bool targetMatEnabled = targetMat.IsKeywordEnabled("CUT_OFF"); bool targetUseTessellation = targetMat.shader.name.Contains("Tessellation"); targetMatEnabled = EditorGUILayout.Toggle("Cut off", targetMatEnabled); int targetDecalLayer = targetMat.GetInt("_DecalLayer"); targetDecalLayer = EditorGUILayout.MaskField("Decal Layer", targetDecalLayer, ops); targetMat.SetInt("_DecalLayer", targetDecalLayer); LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); currentType = (LightingModelType)EditorGUILayout.EnumPopup("Lighting Model", currentType); bool disableEmission = false; if (targetMat.GetTexture("_SecondaryMainTex")) { targetMat.EnableKeyword("USE_SECONDARY_MAP"); disableEmission = true; } else { targetMat.DisableKeyword("USE_SECONDARY_MAP"); } targetMat.SetInt("_LightingModel", (int)currentType); if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } if (!targetMatEnabled) { targetMat.DisableKeyword("CUT_OFF"); if (targetUseTessellation) { targetMat.renderQueue = 2450; } else { targetMat.renderQueue = 2000; } } else { targetMat.EnableKeyword("CUT_OFF"); targetMat.renderQueue = 2451; } base.OnGUI(materialEditor, properties); if (disableEmission) { targetMat.SetTexture("_EmissionMap", null); EditorGUILayout.LabelField("Emission Forced close with secondary maps!"); } }
public static void SetMat(Material targetMat) { bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector"); targetMat.SetShaderPassEnabled("MotionVector", useMotionVector); bool targetMatEnabled = targetMat.IsKeywordEnabled("CUT_OFF"); bool useRainning = targetMat.IsKeywordEnabled("USE_RANNING"); LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel"); targetMat.SetInt("_LightingModel", (int)currentType); if (currentType != LightingModelType.Unlit) { targetMat.EnableKeyword("LIT_ENABLE"); } else { targetMat.DisableKeyword("LIT_ENABLE"); } if (useRainning) { targetMat.EnableKeyword("USE_RANNING"); } else { targetMat.DisableKeyword("USE_RANNING"); } switch (currentType) { case LightingModelType.DefaultLit: targetMat.EnableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.SkinLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.EnableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClothLit: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.EnableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; case LightingModelType.ClearCoat: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.EnableKeyword("CLEARCOAT_LIT"); break; default: targetMat.DisableKeyword("DEFAULT_LIT"); targetMat.DisableKeyword("SKIN_LIT"); targetMat.DisableKeyword("CLOTH_LIT"); targetMat.DisableKeyword("CLEARCOAT_LIT"); break; } targetMat.SetInt("_ZTest", targetMatEnabled ? (int)UnityEngine.Rendering.CompareFunction.Equal : (int)UnityEngine.Rendering.CompareFunction.Less); targetMat.SetInt("_ZWrite", targetMatEnabled ? 0 : 1); if (!targetMatEnabled) { targetMat.DisableKeyword("CUT_OFF"); if (targetMat.renderQueue > 2450) { targetMat.renderQueue = 2000; } } else { targetMat.EnableKeyword("CUT_OFF"); if (targetMat.renderQueue < 2451) { targetMat.renderQueue = 2451; } } if (targetMat.GetTexture("_DetailAlbedo") == null && targetMat.GetTexture("_DetailNormal") == null) { targetMat.DisableKeyword("DETAIL_ON"); } else { targetMat.EnableKeyword("DETAIL_ON"); } }