public void ExecAutoConvertWithoutUndo(params Material[] mats) { foreach (var mat in mats) { if (mat == null) { continue; } if (!Validate(mat)) { continue; } var ctx = new ConvertContext(); ctx.target = mat; ctx.oldMaterial = new Material(mat); ctx.oldProps = ShaderSerializedProperty.AsDict(ctx.oldMaterial); foreach (var cnv in converters) { cnv(ctx); } Debug.LogFormat("[WF] Convert {0}: {1} -> {2}", ctx.target, ctx.oldMaterial.shader.name, ctx.target.shader.name); } }
private static List <RelacePropertyName> CreateReplacePropertyList(Material[] mats, IEnumerable <PropertyNameReplacement> replacement) { var result = new List <RelacePropertyName>(); foreach (var mat in mats) { var props = ShaderSerializedProperty.AsDict(mat); foreach (var pair in replacement) { var before = props.GetValueOrNull(pair.beforeName); if (before != null) { result.Add(new RelacePropertyName(before, props.GetValueOrNull(pair.afterName), pair.afterName, pair.onAfterCopy)); } } } return(result); }
protected static bool HasCustomValue(ConvertContext ctx, params string[] names) { var newProp = ShaderSerializedProperty.AsDict(ctx.target); foreach (var name in names) { // 新しいマテリアルから設定されていないかを調べる if (hasCustomValue(newProp, name)) { return(true); } // 古いマテリアルの側から設定されていないかを調べる if (hasCustomValue(ctx.oldProps, name)) { return(true); } } return(false); }
private Dictionary <ShaderSerializedProperty, ShaderSerializedProperty> CreateOldNamePropertyList(UnityEngine.Object[] objlist) // ShaderCustomEditor側から呼び出されるのでobject[] { var result = new Dictionary <ShaderSerializedProperty, ShaderSerializedProperty>(); foreach (var mat in WFCommonUtility.AsMaterials(objlist)) { if (mat.shader.name.Contains("MatcapShadows")) { // MatcapShadowsは古いので対象にしない continue; } var props = ShaderSerializedProperty.AsDict(mat); foreach (var pair in WFShaderDictionary.OldPropNameToNewPropNameMap) { var before = props.GetValueOrNull(pair.Key); if (before != null) { result[before] = props.GetValueOrNull(pair.Value); } } } return(result); }