Esempio n. 1
0
        public void ApplyToMaterial(IEnumerable <Material> mats)
        {
            if (material == null)
            {
                Debug.LogWarningFormat("[WF] Material is not set in the template: {0}", name);
                return;
            }
            Undo.RecordObjects(mats.ToArray(), "WF apply Template");

            // シェーダを揃える
            foreach (var mat in mats)
            {
                if (mat.shader != material.shader)
                {
                    mat.shader      = material.shader;
                    mat.renderQueue = material.renderQueue;
                }
            }

            // プロパティ類をコピー
            var prm = CopyPropParameter.Create();

            prm.materialSource      = material;
            prm.materialDestination = mats.ToArray();
            prm.labels = WFShaderFunction.GetEnableFunctionList(material).Select(f => f.Label).ToArray();
            prm.onlyOverrideBuiltinTextures = true; // テクスチャ類はビルトインテクスチャのみ上書き可能

            WFMaterialEditUtility.CopyPropertiesWithoutUndo(prm);
        }
Esempio n. 2
0
        private static bool IsOldMaterial(params object[] mats)
        {
            var editor = new WFMaterialEditUtility();

            bool result = false;

            foreach (Material mat in mats)
            {
                if (mat == null)
                {
                    continue;
                }
                if (newMaterialVersionCache.Contains(mat))
                {
                    continue;
                }
                if (oldMaterialVersionCache.Contains(mat))
                {
                    result |= true;
                    return(true);
                }
                bool old = editor.ExistsOldNameProperty(mat);
                if (old)
                {
                    oldMaterialVersionCache.Add(mat);
                }
                else
                {
                    newMaterialVersionCache.Add(mat);
                }
                result |= old;
            }
            return(result);
        }
Esempio n. 3
0
 private static bool Migration(Material mat)
 {
     if (!WFCommonUtility.IsSupportedShader(mat))
     {
         return(false);
     }
     WFMaterialEditUtility.MigrationMaterialWithoutUndo(mat);
     return(true);
 }
Esempio n. 4
0
        private void OnGUI()
        {
            ToolCommon.WindowHeader("UnlitWF / CleanUp material property", "CleanUp disabled values", "materialsから無効化されている機能の設定値をクリアします。");

            var so = new SerializedObject(param);

            so.Update();

            SerializedProperty prop;

            // スクロール開始
            scroll = EditorGUILayout.BeginScrollView(scroll);

            // マテリアルリスト
            EditorGUILayout.LabelField("materials", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(so.FindProperty("materials"), new GUIContent("list"), true);
            EditorGUILayout.Space();

            // マテリアルに UnlitWF 以外のシェーダが紛れている場合には警告
            bool removeOther = ToolCommon.NoticeIfIllegalMaterials(param.materials);

            EditorGUILayout.Space();

            // オプション
            EditorGUILayout.LabelField("options", EditorStyles.boldLabel);
            prop           = so.FindProperty("resetUnused");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "UnUsed Properties (未使用の値) も一緒にクリアする");
            prop           = so.FindProperty("resetKeywords");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "ShaderKeywords (Shaderキーワード) も一緒にクリアする");

            EditorGUILayout.Space();

            so.ApplyModifiedPropertiesWithoutUndo();
            so.SetIsDifferentCacheDirty();

            // UnlitWF 以外のマテリアルを除去
            if (removeOther)
            {
                param.materials = ToolCommon.FilterOnlyWFMaterial(param.materials);
            }

            if (ToolCommon.ExecuteButton("CleanUp", param.materials.Length == 0))
            {
                WFMaterialEditUtility.CleanUpProperties(param);
            }
            EditorGUILayout.Space();

            // スクロール終了
            EditorGUILayout.EndScrollView();
        }
Esempio n. 5
0
        private void OnGUI()
        {
            ToolCommon.WindowHeader("UnlitWF / Migration material", "Migration materials", "古いバージョンのUnlitWFで設定されたmaterialsを最新版に変換します。");

            var so = new SerializedObject(param);

            so.Update();

            // スクロール開始
            scroll = EditorGUILayout.BeginScrollView(scroll);

            // マテリアルリスト
            EditorGUILayout.LabelField("materials", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(so.FindProperty("materials"), new GUIContent("list"), true);
            EditorGUILayout.Space();

            // マテリアルに UnlitWF 以外のシェーダが紛れている場合には警告
            bool removeOther = ToolCommon.NoticeIfIllegalMaterials(param.materials);

            EditorGUILayout.Space();

            so.ApplyModifiedPropertiesWithoutUndo();
            so.SetIsDifferentCacheDirty();

            // UnlitWF 以外のマテリアルを除去
            if (removeOther)
            {
                param.materials = ToolCommon.FilterOnlyWFMaterial(param.materials);
            }

            if (ToolCommon.ExecuteButton("Convert", param.materials.Length == 0))
            {
                // 変換
                WFMaterialEditUtility.MigrationMaterial(param);
                // ShaderGUI側のマテリアルキャッシュをリセット
                ShaderCustomEditor.ResetOldMaterialTable();
                // 変更したマテリアルを保存
                AssetDatabase.SaveAssets();
            }

            EditorGUILayout.Space();

            // スクロール終了
            EditorGUILayout.EndScrollView();
        }
Esempio n. 6
0
        private void OnGUISub_MigrationHelpBox(MaterialEditor materialEditor)
        {
            var mats = WFCommonUtility.AsMaterials(materialEditor.targets);

            if (IsOldMaterial(mats))
            {
                var message = WFI18N.LangMode == EditorLanguage.日本語 ?
                              "このマテリアルは古いバージョンで作成されたようです。最新版に変換しますか?" :
                              "This Material may have been created in an older version. Convert to new version?";

                if (materialEditor.HelpBoxWithButton(new GUIContent(message, Styles.warnIcon), new GUIContent("Fix Now")))
                {
                    var editor = new WFMaterialEditUtility();
                    // 名称を全て変更
                    editor.RenameOldNameProperties(mats);
                    // リセット
                    ResetOldMaterialTable(mats);
                }
            }
        }
Esempio n. 7
0
        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);
                },
            });
        }
Esempio n. 8
0
        private void OnGUI()
        {
            ToolCommon.WindowHeader("UnlitWF / Copy material property", "Copy properties", "source material の設定値を destination materials にコピーします。");

            var so = new SerializedObject(param);

            so.Update();

            // スクロール開始
            scroll = EditorGUILayout.BeginScrollView(scroll);

            // マテリアルリスト
            EditorGUILayout.LabelField("destination materials", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(so.FindProperty("materialDestination"), new GUIContent("list"), true);
            EditorGUILayout.Space();

            // マテリアルに UnlitWF 以外のシェーダが紛れている場合には警告
            bool removeOther = ToolCommon.NoticeIfIllegalMaterials(param.materialDestination);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("source materials", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(so.FindProperty("materialSource"), new GUIContent("material"), true);
            EditorGUILayout.Space();

            ToolCommon.NoticeIfIllegalMaterials(new Material[] { param.materialSource }, false);
            EditorGUILayout.Space();

            so.ApplyModifiedPropertiesWithoutUndo();
            so.SetIsDifferentCacheDirty();

            // 対象
            EditorGUILayout.LabelField("copy target functions", EditorStyles.boldLabel);

            var updatedFunctions = new List <string>();

            foreach (var func in WFShaderFunction.GetEnableFunctionList(param.materialSource))
            {
                bool value = param.labels.Contains(func.Label);
                if (GUILayout.Toggle(value, string.Format("[{0}] {1}", func.Label, func.Name)))
                {
                    updatedFunctions.Add(func.Label);
                }
            }
            if (!updatedFunctions.SequenceEqual(param.labels))
            {
                param.labels = updatedFunctions.ToArray();
            }

            EditorGUILayout.Space();

            // UnlitWF 以外のマテリアルを除去
            if (removeOther)
            {
                param.materialDestination = ToolCommon.FilterOnlyWFMaterial(param.materialDestination);
            }

            using (new EditorGUI.DisabledGroupScope(param.labels.Length == 0))
            {
                if (ToolCommon.ExecuteButton("Copy Values", param.materialSource == null || param.materialDestination.Length == 0))
                {
                    WFMaterialEditUtility.CopyProperties(param);
                }
            }
            EditorGUILayout.Space();

            // スクロール終了
            EditorGUILayout.EndScrollView();
        }
Esempio n. 9
0
        private void OnGUI()
        {
            ToolCommon.WindowHeader("UnlitWF / Reset material property", "Reset properties", "materialsの設定値を初期化します。");

            var so = new SerializedObject(param);

            so.Update();

            SerializedProperty prop;

            // スクロール開始
            scroll = EditorGUILayout.BeginScrollView(scroll);

            // マテリアルリスト
            EditorGUILayout.LabelField("materials", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(so.FindProperty("materials"), new GUIContent("list"), true);
            EditorGUILayout.Space();

            // マテリアルに UnlitWF 以外のシェーダが紛れている場合には警告
            bool removeOther = ToolCommon.NoticeIfIllegalMaterials(param.materials);

            EditorGUILayout.Space();

            // 対象(種類から)
            EditorGUILayout.LabelField("Reset by Type", EditorStyles.boldLabel);
            prop           = so.FindProperty("resetColor");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "Color (色) をデフォルトに戻す");
            prop           = so.FindProperty("resetTexture");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "Texture (テクスチャ) をデフォルトに戻す");
            prop           = so.FindProperty("resetFloat");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "Float (数値) をデフォルトに戻す");

            EditorGUILayout.Space();

            // 対象(機能から)
            EditorGUILayout.LabelField("Reset by Function", EditorStyles.boldLabel);
            prop           = so.FindProperty("resetColorAlpha");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "Color (色) の Alpha を 1.0 にする");
            prop           = so.FindProperty("resetLit");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "Lit & Lit Advance の設定をデフォルトに戻す");

            EditorGUILayout.Space();

            // オプション
            EditorGUILayout.LabelField("options", EditorStyles.boldLabel);
            prop           = so.FindProperty("resetUnused");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "UnUsed Properties (未使用の値) も一緒にクリアする");
            prop           = so.FindProperty("resetKeywords");
            prop.boolValue = GUILayout.Toggle(prop.boolValue, "ShaderKeywords (Shaderキーワード) も一緒にクリアする");

            EditorGUILayout.Space();

            so.ApplyModifiedPropertiesWithoutUndo();
            so.SetIsDifferentCacheDirty();

            // UnlitWF 以外のマテリアルを除去
            if (removeOther)
            {
                param.materials = ToolCommon.FilterOnlyWFMaterial(param.materials);
            }

            if (ToolCommon.ExecuteButton("Reset Values", param.materials.Length == 0))
            {
                WFMaterialEditUtility.ResetProperties(param);
            }
            EditorGUILayout.Space();

            // スクロール終了
            EditorGUILayout.EndScrollView();
        }