Exemple #1
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();
        }
Exemple #2
0
        public static List <ShaderSerializedProperty> AsList(Material material)
        {
            var matProps        = ShaderMaterialProperty.AsDict(material);
            SerializedObject so = new SerializedObject(material);

            so.Update();
            var result            = new List <ShaderSerializedProperty>();
            var m_SavedProperties = so.FindProperty("m_SavedProperties");

            if (m_SavedProperties != null)
            {
                result.AddRange(AsList(material, so, m_SavedProperties.FindPropertyRelative("m_Floats"), matProps));
                result.AddRange(AsList(material, so, m_SavedProperties.FindPropertyRelative("m_Colors"), matProps));
                result.AddRange(AsList(material, so, m_SavedProperties.FindPropertyRelative("m_TexEnvs"), matProps));
            }
            return(result);
        }
Exemple #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();
        }