Skip to content

Commit

Permalink
Merge branch 'head_unity2019'
Browse files Browse the repository at this point in the history
  • Loading branch information
whiteflare committed Oct 11, 2023
2 parents 9cabb7a + 72177e0 commit 505c10c
Show file tree
Hide file tree
Showing 86 changed files with 285 additions and 121 deletions.
65 changes: 53 additions & 12 deletions Editor/WF_Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,42 @@ public static bool IsMaterialRenderType(Material mat, params string[] tags)
return tags.Contains(GetMaterialRenderType(mat));
}

public static bool IsVariant(Material mat)
{
#if UNITY_2022_1_OR_NEWER
return mat.isVariant;
#else
return false;
#endif
}

public static bool IsVariant(UnityEngine.Object[] mats)
{
#if UNITY_2022_1_OR_NEWER
return WFCommonUtility.AsMaterials(mats).Any(IsVariant);
#else
return false;
#endif
}

public static bool IsPropertyLockedByAncestor(Material mat, string name)
{
#if UNITY_2022_1_OR_NEWER
return mat.IsPropertyLockedByAncestor(name);
#else
return false;
#endif
}

public static bool IsPropertyLockedByAncestor(UnityEngine.Object[] mats, string name)
{
#if UNITY_2022_1_OR_NEWER
return WFCommonUtility.AsMaterials(mats).Any(mat => IsPropertyLockedByAncestor(mat, name));
#else
return false;
#endif
}

#endregion

#region マテリアル値の取得
Expand Down Expand Up @@ -1016,13 +1052,18 @@ public static Texture GetTexture(Material mat, string name)
return null;
}

#endregion
#endregion

#region マテリアル値の設定
#region マテリアル値の設定

private static bool CanWrite(Material mat, string name)
{
return mat.HasProperty(name) && !IsPropertyLockedByAncestor(mat, name);
}

public static bool SetBool(Material mat, string name, bool value)
{
if (mat.HasProperty(name))
if (CanWrite(mat, name))
{
mat.SetInt(name, value ? 1 : 0);
return true;
Expand All @@ -1032,7 +1073,7 @@ public static bool SetBool(Material mat, string name, bool value)

public static bool SetInt(Material mat, string name, int value)
{
if (mat.HasProperty(name))
if (CanWrite(mat, name))
{
mat.SetInt(name, value);
return true;
Expand All @@ -1042,7 +1083,7 @@ public static bool SetInt(Material mat, string name, int value)

public static bool SetFloat(Material mat, string name, float value)
{
if (mat.HasProperty(name))
if (CanWrite(mat, name))
{
mat.SetFloat(name, value);
return true;
Expand All @@ -1052,7 +1093,7 @@ public static bool SetFloat(Material mat, string name, float value)

public static bool SetColor(Material mat, string name, Color value)
{
if (mat.HasProperty(name))
if (CanWrite(mat, name))
{
mat.SetColor(name, value);
return true;
Expand All @@ -1062,7 +1103,7 @@ public static bool SetColor(Material mat, string name, Color value)

public static bool SetVector(Material mat, string name, Vector4 value)
{
if (mat.HasProperty(name))
if (CanWrite(mat, name))
{
mat.SetVector(name, value);
return true;
Expand All @@ -1072,7 +1113,7 @@ public static bool SetVector(Material mat, string name, Vector4 value)

public static bool SetTexture(Material mat, string name, Texture value)
{
if (mat.HasProperty(name))
if (CanWrite(mat, name))
{
mat.SetTexture(name, value);
return true;
Expand All @@ -1082,7 +1123,7 @@ public static bool SetTexture(Material mat, string name, Texture value)

public static bool CopyFloatValue(Material mat, string from, string to)
{
if (mat.HasProperty(from) && mat.HasProperty(to))
if (mat.HasProperty(from) && CanWrite(mat, to))
{
mat.SetFloat(to, mat.GetFloat(from));
return true;
Expand All @@ -1092,7 +1133,7 @@ public static bool CopyFloatValue(Material mat, string from, string to)

public static bool CopyIntValue(Material mat, string from, string to)
{
if (mat.HasProperty(from) && mat.HasProperty(to))
if (mat.HasProperty(from) && CanWrite(mat, to))
{
mat.SetInt(to, mat.GetInt(from));
return true;
Expand All @@ -1102,15 +1143,15 @@ public static bool CopyIntValue(Material mat, string from, string to)

public static bool CopyTextureValue(Material mat, string from, string to)
{
if (mat.HasProperty(from) && mat.HasProperty(to))
if (mat.HasProperty(from) && CanWrite(mat, to))
{
mat.SetTexture(to, mat.GetTexture(from));
return true;
}
return false;
}

#endregion
#endregion
}

abstract class WFCustomKeywordSetting
Expand Down
1 change: 1 addition & 0 deletions Editor/WF_Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ private static Dictionary<string, WFCustomKeywordSetting> ToWFCustomKeywordSetti
new WFI18NTranslation("AO", "Contrast", "コントラスト"),
// Distance Fade
new WFI18NTranslation("DFD", "Color", "色"),
new WFI18NTranslation("DFD", "Color Texture", "色テクスチャ"),
new WFI18NTranslation("DFD", "Fade Distance", "フェード距離"),
new WFI18NTranslation("DFD", "Fade Distance (Near)", "フェード距離 (Near)"),
new WFI18NTranslation("DFD", "Fade Distance (Far)", "フェード距離 (Far)"),
Expand Down
Loading

0 comments on commit 505c10c

Please sign in to comment.