public bool CopyTo(ShaderMaterialProperty dst) { var srcType = Type; var dstType = dst.Type; if (srcType == dstType) { switch (srcType) { case ShaderUtil.ShaderPropertyType.Color: dst.Material.SetColor(dst.Name, this.Material.GetColor(Name)); return(true); case ShaderUtil.ShaderPropertyType.Float: case ShaderUtil.ShaderPropertyType.Range: dst.Material.SetFloat(dst.Name, this.Material.GetFloat(Name)); return(true); case ShaderUtil.ShaderPropertyType.Vector: dst.Material.SetVector(dst.Name, this.Material.GetVector(Name)); return(true); case ShaderUtil.ShaderPropertyType.TexEnv: dst.Material.SetTexture(dst.Name, this.Material.GetTexture(Name)); dst.Material.SetTextureOffset(dst.Name, this.Material.GetTextureOffset(Name)); dst.Material.SetTextureScale(dst.Name, this.Material.GetTextureScale(Name)); return(true); default: break; } } return(false); }
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(); }
ShaderSerializedProperty(string name, ShaderMaterialProperty matProp, SerializedObject serialObject, SerializedProperty parent, SerializedProperty property) { this.name = name; this.materialProperty = matProp; this.serialObject = serialObject; this.parent = parent; this.property = property; this.value = property.FindPropertyRelative("second"); }
public void SetActive(Material[] targets) { foreach (var mat in WFCommonUtility.AsMaterials(targets)) { // リセット foreach (var p in ShaderMaterialProperty.AsList(mat).Where(p => p.Name.StartsWith("_Mode"))) { mat.SetInt(p.Name, 0); } // セット mat.SetInt(propertyName, value); } }
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); }
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(); }