Example #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);
        }
Example #2
0
        public static void copyProperties(CopyPropParameter param, bool undo)
        {
            if (param.materialSource == null)
            {
                return;
            }
            var src_props = new List <ShaderMaterialProperty>();

            // Label経由とPrefix経由をどちらもPrefixにする
            var copy_target = new List <string>(WFShaderFunction.LabelToPrefix(param.labels.ToList()));

            copy_target.AddRange(param.prefixs);

            foreach (var src_prop in ShaderMaterialProperty.AsList(param.materialSource))
            {
                string prefix = WFCommonUtility.GetPrefixFromPropName(src_prop.Name);
                if (prefix == null)
                {
                    continue;
                }
                // Prefixの一致判定
                if (copy_target.Any(prefix.Contains))
                {
                    if (!param.withoutTextures || src_prop.Type != ShaderUtil.ShaderPropertyType.TexEnv)
                    {
                        src_props.Add(src_prop);
                    }
                }
            }
            if (src_props.Count == 0)
            {
                return;
            }

            if (undo)
            {
                Undo.RecordObjects(param.materialDestination, "WF copy materials");
            }

            for (int i = 0; i < param.materialDestination.Length; i++)
            {
                var dst = param.materialDestination[i];
                if (dst == null || dst == param.materialSource)
                { // コピー先とコピー元が同じ時もコピーしない
                    continue;
                }
                var dst_props = ShaderMaterialProperty.AsDict(dst);

                // コピー
                if (CopyProperties(src_props, dst_props, param.onlyOverrideBuiltinTextures))
                {
                    // キーワードを整理する
                    WFCommonUtility.SetupShaderKeyword(dst);
                    // ダーティフラグを付ける
                    EditorUtility.SetDirty(dst);
                }
            }
            AssetDatabase.SaveAssets();
        }
Example #3
0
        public void CopyProperties(CopyPropParameter param)
        {
            if (param.materialSource == null)
            {
                return;
            }
            var src_props = new List <ShaderMaterialProperty>();

            var copy_target = WFShaderFunction.LabelToPrefix(param.functions.ToList());

            foreach (var src_prop in ShaderMaterialProperty.AsList(param.materialSource))
            {
                string label = WFCommonUtility.GetPrefixFromPropName(src_prop.Name);
                if (label == null)
                {
                    continue;
                }
                // ラベルの一致判定
                if (copy_target.Any(label.Contains))
                {
                    src_props.Add(src_prop);
                }
            }
            if (src_props.Count == 0)
            {
                return;
            }

            for (int i = 0; i < param.materialDestination.Length; i++)
            {
                var dst = param.materialDestination[i];
                if (dst == null || dst == param.materialSource)   // コピー先とコピー元が同じ時もコピーしない
                {
                    continue;
                }
                var dst_props = ShaderMaterialProperty.AsDict(dst);

                // コピー
                if (CopyProperties(src_props, dst_props))
                {
                    EditorUtility.SetDirty(dst);
                }
            }
            AssetDatabase.SaveAssets();
        }
Example #4
0
        private void OnEnable()
        {
            minSize = new Vector2(480, 640);
            param   = ScriptableObject.CreateInstance <CopyPropParameter>();
            if (0 < arguments.Count)
            {
                param.materialDestination = 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,
            };
        }
Example #5
0
 public static void CopyPropertiesWithoutUndo(CopyPropParameter param)
 {
     copyProperties(param, false);
 }
Example #6
0
 public static void CopyProperties(CopyPropParameter param)
 {
     copyProperties(param, true);
 }
Example #7
0
 private void OnEnable()
 {
     minSize = new Vector2(480, 640);
     param   = CopyPropParameter.Create();
     ToolCommon.GetSelectedMaterials(ref param.materialDestination);
 }