private void OnEnable() { minSize = new Vector2(480, 640); param = ScriptableObject.CreateInstance <ResetParameter>(); if (0 < arguments.Count) { param.materials = arguments.ToArray(); } styleTitle = new GUIStyle(EditorStyles.boldLabel) { fontSize = 18, fontStyle = FontStyle.Bold, fixedHeight = 32, }; styleBigText = new GUIStyle(EditorStyles.boldLabel) { fontSize = 16, fontStyle = FontStyle.Bold, fixedHeight = 32, }; }
public static void ResetPropertiesWithoutUndo(ResetParameter param) { foreach (Material material in param.materials) { if (material == null) { continue; } var props = ShaderSerializedProperty.AsList(material); var del_props = new HashSet <ShaderSerializedProperty>(); // ColorのAlphaチャンネルのみ変更 foreach (var p in props) { if (p.HasPropertyInShader && p.Type == ShaderUtil.ShaderPropertyType.Color) { var c = p.ColorValue; c.a = 1; p.ColorValue = c; } } ShaderSerializedProperty.AllApplyPropertyChange(props); // 条件に合致するプロパティを削除 foreach (var p in props) { if (param.resetColor && p.Type == ShaderUtil.ShaderPropertyType.Color) { del_props.Add(p); } else if (param.resetFloat && p.Type == ShaderUtil.ShaderPropertyType.Float) { del_props.Add(p); } else if (param.resetTexture && p.Type == ShaderUtil.ShaderPropertyType.TexEnv) { del_props.Add(p); } else if (param.resetUnused && !p.HasPropertyInShader) { del_props.Add(p); } else if (param.resetLit && p.name.StartsWith("_GL_")) { del_props.Add(p); } else if (param.resetPrefixs.Contains(WFCommonUtility.GetPrefixFromPropName(p.name))) { del_props.Add(p); } } // 削除実行 DeleteProperties(del_props); // キーワードクリア if (param.resetKeywords) { foreach (var so in ShaderSerializedProperty.GetUniqueSerialObject(props)) { DeleteShaderKeyword(so); } } // キーワードを整理する WFCommonUtility.SetupShaderKeyword(material); // 反映 EditorUtility.SetDirty(material); } }
public static void ResetProperties(ResetParameter param) { Undo.RecordObjects(param.materials, "WF reset materials"); ResetPropertiesWithoutUndo(param); }
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 void OnEnable() { minSize = new Vector2(480, 640); param = ResetParameter.Create(); ToolCommon.GetSelectedMaterials(ref param.materials); }