private static void OnGuiSub_SwitchPrevShaderButton(MaterialEditor materialEditor) { // 編集中のマテリアルの配列 var mats = WFCommonUtility.AsMaterials(materialEditor.targets); // PrevShader タグを持っているものがひとつでもあればボタン表示 if (mats.Select(m => m.GetTag(TAG_PREV_SHADER, false)).Any(tag => !string.IsNullOrWhiteSpace(tag))) { if (GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), "Switch Prev Shader")) { // 元のシェーダに戻す Undo.RecordObjects(mats, "change shader"); // それぞれのマテリアルに設定された PrevShader へと切り替え foreach (var mat in mats) { var name = mat.GetTag(TAG_PREV_SHADER, false); var queue = mat.GetTag(TAG_PREV_QUEUE, false); // DebugViewの保存に使っているタグはクリア ClearDebugOverrideTag(mat); // シェーダ切り替え WFCommonUtility.ChangeShader(name, mat); // queue戻し if (queue != null && int.TryParse(queue, out int numQueue)) { mat.renderQueue = numQueue; } } } EditorGUILayout.Space(); } }
private static void ChangeFromMenu() { foreach (var mat in Selection.GetFiltered <Material>(SelectionMode.Assets)) { WFCommonUtility.ChangeShader(SHADER_NAME_DEBUGVIEW, mat); } }
protected static List <Action <ConvertContext> > CreateConverterList() { return(new List <Action <ConvertContext> >() { ctx => { bool cnv = false; var shader = ctx.target.shader; while (WFCommonUtility.IsSupportedShader(shader) && !WFCommonUtility.IsMobileSupportedShader(shader)) { // シェーダ切り替え var fallback = WFCommonUtility.GetShaderFallBackTarget(shader) ?? "Hidden/UnlitWF/WF_UnToon_Hidden"; WFCommonUtility.ChangeShader(fallback, ctx.target); // シェーダ切り替え後に RenderQueue をコピー ctx.target.renderQueue = ctx.oldMaterial.renderQueue; shader = ctx.target.shader; cnv = true; } if (cnv) { WFCommonUtility.SetupShaderKeyword(ctx.target); EditorUtility.SetDirty(ctx.target); } }, ctx => { if (IsMatchShaderName(ctx.oldMaterial.shader, "Transparent3Pass") && !IsMatchShaderName(ctx.target.shader, "Transparent3Pass")) { // Transparent3Pass からそうではないシェーダの切り替えでは、_AL_ZWrite を ON に変更する ctx.target.SetInt("_AL_ZWrite", 1); } }, }); }
private static void Menu_DebugView() { foreach (var mat in MaterialSeeker.GetSelectionAllMaterial(MatSelectMode.FromAsset)) { WFCommonUtility.ChangeShader(WF_DebugViewEditor.SHADER_NAME_DEBUGVIEW, mat); } }
private void OnGuiSub_ShowCurrentShaderName(MaterialEditor materialEditor, Material mat) { // シェーダ名の表示 var rect = EditorGUILayout.GetControlRect(); rect.y += 2; GUI.Label(rect, "Current Shader", EditorStyles.boldLabel); GUILayout.Label(new Regex(@".*/").Replace(mat.shader.name, "")); for (int idx = ShaderUtil.GetPropertyCount(mat.shader) - 1; 0 <= idx; idx--) { if ("_CurrentVersion" == ShaderUtil.GetPropertyName(mat.shader, idx)) { rect = EditorGUILayout.GetControlRect(); rect.y += 2; GUI.Label(rect, "Current Version", EditorStyles.boldLabel); GUILayout.Label(ShaderUtil.GetPropertyDescription(mat.shader, idx)); break; } } // シェーダ切り替えボタン var snm = WFShaderNameDictionary.TryFindFromName(mat.shader.name); if (snm != null) { var targets = WFCommonUtility.AsMaterials(materialEditor.targets); rect = EditorGUILayout.GetControlRect(); rect.y += 2; GUI.Label(rect, "Current Shader Variants", EditorStyles.boldLabel); // バリアント { var variants = WFShaderNameDictionary.GetVariantList(snm); var labels = variants.Select(nm => nm.Variant).ToArray(); int idx = Array.IndexOf(labels, snm.Variant); EditorGUI.BeginChangeCheck(); int select = EditorGUILayout.Popup("Variant", idx, labels); if (EditorGUI.EndChangeCheck() && idx != select) { WFCommonUtility.ChangeShader(variants[select].Name, targets); } } // Render Type { var variants = WFShaderNameDictionary.GetRenderTypeList(snm); var labels = variants.Select(nm => nm.RenderType).ToArray(); int idx = Array.IndexOf(labels, snm.RenderType); EditorGUI.BeginChangeCheck(); int select = EditorGUILayout.Popup("RenderType", idx, labels); if (EditorGUI.EndChangeCheck() && idx != select) { WFCommonUtility.ChangeShader(variants[select].Name, targets); } } } }
public static void ChangeFromMenu(MenuCommand cmd) { WFCommonUtility.ChangeShader(SHADER_NAME_DEBUGVIEW, cmd.context as Material); }
protected static List <Action <ConvertContext> > CreateConverterList() { return(new List <Action <ConvertContext> >() { ctx => { // アウトライン有無を判定する if (IsMatchShaderName(ctx, "outline") && !IsMatchShaderName(ctx, "nooutline")) { ctx.outline = true; } else if (HasCustomValue(ctx, "_OutlineMask", "_OutLineMask", "_OutlineWidthMask", "_Outline_Sampler", "_OutLineEnable", "_OutlineMode", "_UseOutline")) { ctx.outline = true; } }, ctx => { // RenderType からシェーダタイプを判定する if (IsMatchShaderName(ctx, "InternalErrorShader")) { return; } if (ctx.renderType == ShaderType.NoMatch) { switch (ctx.oldMaterial.GetTag("RenderType", false, "")) { case "Opaque": ctx.renderType = ShaderType.Opaque; break; case "TransparentCutout": ctx.renderType = ShaderType.Cutout; break; case "Transparent": ctx.renderType = ShaderType.Transparent; break; } } }, ctx => { // シェーダ名からシェーダタイプを判定する if (ctx.renderType == ShaderType.NoMatch) { if (IsMatchShaderName(ctx, "opaque") || IsMatchShaderName(ctx, "texture")) { ctx.renderType = ShaderType.Opaque; } else if (IsMatchShaderName(ctx, "cutout")) { ctx.renderType = ShaderType.Cutout; } else if (IsMatchShaderName(ctx, "trans")) { ctx.renderType = ShaderType.Transparent; } } }, ctx => { // RenderQueue からシェーダタイプを判定する if (IsMatchShaderName(ctx, "InternalErrorShader")) { return; } if (ctx.renderType == ShaderType.NoMatch) { var queue = ctx.oldMaterial.renderQueue; if (queue < 0) { queue = ctx.oldMaterial.shader.renderQueue; } if (queue < 2450) { ctx.renderType = ShaderType.Opaque; } else if (queue < 2500) { ctx.renderType = ShaderType.Cutout; } else { ctx.renderType = ShaderType.Transparent; } } }, ctx => { // _ClippingMask の有無からシェーダタイプを判定する if (ctx.renderType == ShaderType.NoMatch) { if (HasCustomValue(ctx, "_ClippingMask")) { ctx.renderType = ShaderType.Cutout; } } }, ctx => { if (IsURP()) { switch (ctx.renderType) { case ShaderType.Transparent: WFCommonUtility.ChangeShader("UnlitWF_URP/WF_UnToon_Transparent", ctx.target); break; case ShaderType.Cutout: WFCommonUtility.ChangeShader("UnlitWF_URP/WF_UnToon_TransCutout", ctx.target); break; default: WFCommonUtility.ChangeShader("UnlitWF_URP/WF_UnToon_Opaque", ctx.target); break; } } else if (ctx.outline) { switch (ctx.renderType) { case ShaderType.Transparent: WFCommonUtility.ChangeShader("UnlitWF/UnToon_Outline/WF_UnToon_Outline_Transparent", ctx.target); break; case ShaderType.Cutout: WFCommonUtility.ChangeShader("UnlitWF/UnToon_Outline/WF_UnToon_Outline_TransCutout", ctx.target); break; default: WFCommonUtility.ChangeShader("UnlitWF/UnToon_Outline/WF_UnToon_Outline_Opaque", ctx.target); break; } } else { switch (ctx.renderType) { case ShaderType.Transparent: WFCommonUtility.ChangeShader("UnlitWF/WF_UnToon_Transparent", ctx.target); break; case ShaderType.Cutout: WFCommonUtility.ChangeShader("UnlitWF/WF_UnToon_TransCutout", ctx.target); break; default: WFCommonUtility.ChangeShader("UnlitWF/WF_UnToon_Opaque", ctx.target); break; } } // シェーダ切り替え後に RenderQueue をコピー ctx.target.renderQueue = ctx.oldMaterial.renderQueue; }, ctx => { if (HasCustomValue(ctx, "_MainTex")) { // メインテクスチャがあるならば _Color は白にする ctx.target.SetColor("_Color", Color.white); } }, ctx => { // アルファマスク WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target, new PropertyNameReplacement("_AlphaMask", "_AL_MaskTex"), new PropertyNameReplacement("_ClippingMask", "_AL_MaskTex")); if (HasCustomValue(ctx, "_AL_MaskTex")) { ctx.target.SetInt("_AL_Source", 1); // AlphaSource = MASK_TEX_RED } }, ctx => { // ノーマルマップ WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target, new PropertyNameReplacement("_NormalMap", "_BumpMap")); if (HasCustomValue(ctx, "_BumpMap", "_DetailNormalMap")) { ctx.target.SetInt("_NM_Enable", 1); } }, ctx => { // メタリック if (HasCustomValue(ctx, "_MetallicGlossMap", "_SpecGlossMap")) { ctx.target.SetInt("_MT_Enable", 1); } }, ctx => { // AO if (HasCustomValue(ctx, "_OcclusionMap")) { ctx.target.SetInt("_AO_Enable", 1); } }, ctx => { // Emission WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target, new PropertyNameReplacement("_Emissive_Tex", "_EmissionMap"), new PropertyNameReplacement("_Emissive_Color", "_EmissionColor")); if (HasCustomValue(ctx, "_EmissionMap", "_UseEmission", "_EmissionEnable", "_EnableEmission")) { ctx.target.SetInt("_ES_Enable", 1); } }, ctx => { // Toon影 ctx.target.SetInt("_TS_Enable", 1); WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target, // 1影 new PropertyNameReplacement("_1st_ShadeMap", "_TS_1stTex"), new PropertyNameReplacement("_ShadowColorTex", "_TS_1stTex"), new PropertyNameReplacement("_1st_ShadeColor", "_TS_1stColor"), new PropertyNameReplacement("_ShadowColor", "_TS_1stColor"), // 2影 new PropertyNameReplacement("_2nd_ShadeMap", "_TS_2ndTex"), new PropertyNameReplacement("_Shadow2ndColorTex", "_TS_2ndTex"), new PropertyNameReplacement("_2nd_ShadeColor", "_TS_2ndColor"), new PropertyNameReplacement("_Shadow2ndColor", "_TS_2ndColor") ); // これらのテクスチャが設定されているならば _MainTex を _TS_BaseTex にも設定する if (HasCustomValue(ctx, "_TS_1stTex", "_TS_2ndTex")) { if (!HasCustomValue(ctx, "_TS_BaseTex")) { ctx.target.SetTexture("_TS_BaseTex", ctx.target.GetTexture("_MainTex")); } if (!HasCustomValue(ctx, "_TS_1stTex")) { ctx.target.SetTexture("_TS_1stTex", ctx.target.GetTexture("_TS_BaseTex")); } if (!HasCustomValue(ctx, "_TS_2ndTex")) { ctx.target.SetTexture("_TS_2ndTex", ctx.target.GetTexture("_TS_1stTex")); } if (!HasCustomValue(ctx, "_TS_3rdTex")) { ctx.target.SetTexture("_TS_3rdTex", ctx.target.GetTexture("_TS_2ndTex")); } // ただし _TS_BaseTex, _TS_1stTex, _TS_2ndTex, _TS_3rdTex が全て同じ Texture を指しているならば全てクリアする if (ctx.target.GetTexture("_TS_BaseTex") == ctx.target.GetTexture("_TS_1stTex") && ctx.target.GetTexture("_TS_1stTex") == ctx.target.GetTexture("_TS_2ndTex") && ctx.target.GetTexture("_TS_2ndTex") == ctx.target.GetTexture("_TS_3rdTex")) { ctx.target.SetTexture("_TS_BaseTex", null); ctx.target.SetTexture("_TS_1stTex", null); ctx.target.SetTexture("_TS_2ndTex", null); ctx.target.SetTexture("_TS_3rdTex", null); } } }, ctx => { // リムライト if (HasCustomValue(ctx, "_UseRim", "_RimLight", "_RimLitEnable", "_EnableRimLighting")) { ctx.target.SetInt("_TR_Enable", 1); WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target, new PropertyNameReplacement("_RimColor", "_TR_Color"), new PropertyNameReplacement("_RimLitColor", "_TR_Color"), new PropertyNameReplacement("_RimLightColor", "_TR_Color"), new PropertyNameReplacement("_RimLitMask", "_TR_MaskTex"), new PropertyNameReplacement("_RimBlendMask", "_TR_MaskTex"), new PropertyNameReplacement("_Set_RimLightMask", "_TR_Color"), new PropertyNameReplacement("_RimMask", "_TR_Color") ); } }, ctx => { // アウトライン WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target, new PropertyNameReplacement("_OutlineColor", "_TL_LineColor"), new PropertyNameReplacement("_Outline_Color", "_TL_LineColor"), new PropertyNameReplacement("_OutLineColor", "_TL_LineColor"), new PropertyNameReplacement("_LineColor", "_TL_LineColor"), // ColorTex new PropertyNameReplacement("_OutlineTex", "_TL_CustomColorTex"), new PropertyNameReplacement("_OutLineTexture", "_TL_CustomColorTex"), new PropertyNameReplacement("_OutlineTexture", "_TL_CustomColorTex"), // MaskTex new PropertyNameReplacement("_OutlineWidthMask", "_TL_MaskTex"), new PropertyNameReplacement("_Outline_Sampler", "_TL_MaskTex"), new PropertyNameReplacement("_OutlineMask", "_TL_MaskTex"), new PropertyNameReplacement("_OutLineMask", "_TL_MaskTex") ); }, ctx => { // アルファをリセットし、キーワードを整理する var resetParam = ResetParameter.Create(); resetParam.materials = new Material[] { ctx.target }; resetParam.resetColorAlpha = true; // resetParam.resetUnused = true; resetParam.resetKeywords = true; WFMaterialEditUtility.ResetPropertiesWithoutUndo(resetParam); }, }); }
private static void ContextMenu_DebugView(MenuCommand cmd) { WFCommonUtility.ChangeShader(WF_DebugViewEditor.SHADER_NAME_DEBUGVIEW, cmd.context as Material); }