本文整理汇总了C#中UnityEngine.Material.HasProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Material.HasProperty方法的具体用法?C# Material.HasProperty怎么用?C# Material.HasProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Material
的用法示例。
在下文中一共展示了Material.HasProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
void Update()
{
terrain = GetComponent<Terrain>();
tData = terrain ? terrain.terrainData : null;
tMaterial = terrain ? terrain.materialTemplate : null;
if (!terrain || !tData || !tMaterial)
return;
if(disableBasemap && !Application.isPlaying && GetComponent<Terrain>().basemapDistance != 1000000) // only reset on update in edit mode
GetComponent<Terrain>().basemapDistance = 1000000;
if (cutoutMode)
{
if (tMaterial.HasProperty("_CutoutModeHideAlpha") && tMaterial.GetFloat("_CutoutModeHideAlpha") != cutoutModeHideAlpha)
tMaterial.SetFloat("_CutoutModeHideAlpha", cutoutModeHideAlpha);
}
else
if (tMaterial.HasProperty("_CutoutModeHideAlpha") && tMaterial.GetFloat("_CutoutModeHideAlpha") != -1)
tMaterial.SetFloat("_CutoutModeHideAlpha", -1);
if (!Application.isPlaying)
ApplyTransparencyMap();
else
if (!transparencyMap && autoUpdateTransparencyMap)
{
UpdateTransparencyMap();
ApplyTransparencyMap();
}
else
ApplyTransparencyMap();
}
示例2: SetMaterialKeywords
public static void SetMaterialKeywords(Material material, WorkflowMode workflowMode)
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
// (MaterialProperty value might come from renderer material property block)
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap") || material.GetTexture("_DetailNormalMap"));
if (workflowMode == WorkflowMode.Specular && material.HasProperty("_SpecGlossMap"))
SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
else if (workflowMode == WorkflowMode.Metallic && material.HasProperty("_MetallicGlossMap"))
SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap"));
SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled(material.GetColor("_EmissionColor"));
SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
material.globalIlluminationFlags = flags;
}
SetKeyword(material, "_VERTEXCOLOR", material.GetFloat("_IntensityVC") > 0f);
}
示例3: checkSpecUsage
bool checkSpecUsage(Material mat, string label) {
if ((label.IndexOf("layer Spec+Gloss")<0) && (label.IndexOf("gloss mask")<0) && (label.IndexOf("Spec (RGB)")<0)) return true;
if (!mat.HasProperty("_DirectSpec")) return true;
if (!mat.HasProperty("_IBLSpec")) return true;
if (mat.GetFloat("_DirectSpec")==0 && mat.GetFloat("_IBLSpec")==0) return false;
return true;
}
示例4: CheckMaterial
public static string CheckMaterial(Material mat, BuildTarget buildTarget)
{
if (mat == null || mat.shader == null)
{
return null;
}
string shaderName = mat.shader.name;
int lOD = ShaderUtil.GetLOD(mat.shader);
bool flag = Array.Exists<string>(PerformanceChecks.kShadersWithMobileVariants, (string s) => s == shaderName);
bool flag2 = PerformanceChecks.IsMobileBuildTarget(buildTarget);
if (buildTarget == BuildTarget.Android && ShaderUtil.HasClip(mat.shader))
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderWithClipAndroid", new object[0]);
}
if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false"))
{
if (flag)
{
if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f))
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderUsesWhiteColor", new object[]
{
"Mobile/" + shaderName
});
}
if (flag2 && shaderName.StartsWith("Particles/"))
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderHasMobileVariant", new object[]
{
"Mobile/" + shaderName
});
}
if (shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f))
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderMobileSkybox", new object[]
{
"Mobile/Skybox"
});
}
}
if (lOD >= 300 && flag2 && !shaderName.StartsWith("Mobile/"))
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderExpensive", new object[0]);
}
if (shaderName.Contains("VertexLit") && mat.HasProperty("_Emission"))
{
Color color = mat.GetColor("_Emission");
if (color.r >= 0.5f && color.g >= 0.5f && color.b >= 0.5f)
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderUseUnlit", new object[0]);
}
}
if (mat.HasProperty("_BumpMap") && mat.GetTexture("_BumpMap") == null)
{
return PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderNoNormalMap", new object[0]);
}
}
return null;
}
示例5: CheckTexture
public static void CheckTexture (string n, Material m, List<string> l)
{
Debug.Log( "Has property " + n + " " + m.HasProperty (n) );
Debug.Log( "Get texture " + n + " " + m.GetTexture(n) );
if (m.HasProperty (n) && m.GetTexture(n) != null) {
l.Add (n);
}
}
示例6: ApplayColor
//--------------------------------------
// INITIALIZE
//--------------------------------------
//--------------------------------------
// PUBLIC METHODS
//--------------------------------------
public static void ApplayColor(Material m, Color c)
{
if(m.HasProperty("_Color")) {
m.color = c;
} else {
if(m.HasProperty ("_TintColor")) {
m.SetColor ("_TintColor", c);
}
}
}
示例7: GetPlaneHullVertices
private Vector2[] GetPlaneHullVertices(Material mat)
{
if (mat == null)
{
return null;
}
if (!mat.HasProperty("_MainTex"))
{
return null;
}
Texture mainTexture = mat.mainTexture;
if (mainTexture == null)
{
return null;
}
if ((s_TextureHulls == null) || s_TextureHullsDirty)
{
s_TextureHulls = new Dictionary<Texture, Vector2[]>();
s_TextureHullsDirty = false;
}
if (s_TextureHulls.ContainsKey(mainTexture))
{
return s_TextureHulls[mainTexture];
}
Vector2[] vectorArray2 = MeshUtility.ComputeTextureBoundingHull(mainTexture, 4);
Vector2 vector = vectorArray2[1];
vectorArray2[1] = vectorArray2[3];
vectorArray2[3] = vector;
s_TextureHulls.Add(mainTexture, vectorArray2);
return vectorArray2;
}
示例8: LinearDissolve
public static IEnumerator LinearDissolve(Material mat, float from, float to, float time)
{
float elapsedTime = 0f;
while (elapsedTime < time) {
if (mat.HasProperty(dissolveAmountID)) {
mat.SetFloat(dissolveAmountID, Mathf.Lerp(from, to, elapsedTime/time));
}
elapsedTime += Time.deltaTime;
yield return null;
}
if (mat.HasProperty(dissolveAmountID)) {
mat.SetFloat (dissolveAmountID, to);
}
}
示例9: CopyMaterialProperties
/// <summary>
/// Copy Shader properties from source to destination material.
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static void CopyMaterialProperties(Material source, Material destination)
{
MaterialProperty[] source_prop = MaterialEditor.GetMaterialProperties(new Material[] { source });
for (int i = 0; i < source_prop.Length; i++)
{
int property_ID = Shader.PropertyToID(source_prop[i].name);
if (destination.HasProperty(property_ID))
{
//Debug.Log(source_prop[i].name + " Type:" + ShaderUtil.GetPropertyType(source.shader, i));
switch (ShaderUtil.GetPropertyType(source.shader, i))
{
case ShaderUtil.ShaderPropertyType.Color:
destination.SetColor(property_ID, source.GetColor(property_ID));
break;
case ShaderUtil.ShaderPropertyType.Float:
destination.SetFloat(property_ID, source.GetFloat(property_ID));
break;
case ShaderUtil.ShaderPropertyType.Range:
destination.SetFloat(property_ID, source.GetFloat(property_ID));
break;
case ShaderUtil.ShaderPropertyType.TexEnv:
destination.SetTexture(property_ID, source.GetTexture(property_ID));
break;
case ShaderUtil.ShaderPropertyType.Vector:
destination.SetVector(property_ID, source.GetVector(property_ID));
break;
}
}
}
}
示例10: AssignNewShaderToMaterial
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
{
if (material.HasProperty("_Emission"))
{
material.SetColor("_EmissionColor", material.GetColor("_Emission"));
}
base.AssignNewShaderToMaterial(material, oldShader, newShader);
if ((oldShader == null) || !oldShader.name.Contains("Legacy Shaders/"))
{
SetupMaterialWithBlendMode(material, (BlendMode) ((int) material.GetFloat("_Mode")));
}
else
{
BlendMode opaque = BlendMode.Opaque;
if (oldShader.name.Contains("/Transparent/Cutout/"))
{
opaque = BlendMode.Cutout;
}
else if (oldShader.name.Contains("/Transparent/"))
{
opaque = BlendMode.Fade;
}
material.SetFloat("_Mode", (float) opaque);
Material[] mats = new Material[] { material };
this.DetermineWorkflow(MaterialEditor.GetMaterialProperties(mats));
MaterialChanged(material, this.m_WorkflowMode);
}
}
示例11: CurveDissolve
public static IEnumerator CurveDissolve(Material mat, AnimationCurve dissolveCurve, float time, float curveStartPercentage, float speed)
{
float elapsedTime = curveStartPercentage;
while (elapsedTime <= 1f && elapsedTime >= 0f) {
if (mat.HasProperty(dissolveAmountID)) {
mat.SetFloat(dissolveAmountID, Mathf.Clamp01(dissolveCurve.Evaluate(elapsedTime)));
}
elapsedTime += Time.deltaTime/time * speed;
yield return null;
}
if (mat.HasProperty(dissolveAmountID)) {
mat.SetFloat(dissolveAmountID, Mathf.Clamp01(dissolveCurve.Evaluate(Mathf.Clamp01(elapsedTime))));
}
}
示例12: CheckMaterial
public static string CheckMaterial(Material mat, BuildTarget buildTarget)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
PerformanceChecks.\u003CCheckMaterial\u003Ec__AnonStoreyBE materialCAnonStoreyBe = new PerformanceChecks.\u003CCheckMaterial\u003Ec__AnonStoreyBE();
if ((UnityEngine.Object) mat == (UnityEngine.Object) null || (UnityEngine.Object) mat.shader == (UnityEngine.Object) null)
return (string) null;
// ISSUE: reference to a compiler-generated field
materialCAnonStoreyBe.shaderName = mat.shader.name;
int lod = ShaderUtil.GetLOD(mat.shader);
// ISSUE: reference to a compiler-generated method
bool flag1 = Array.Exists<string>(PerformanceChecks.kShadersWithMobileVariants, new Predicate<string>(materialCAnonStoreyBe.\u003C\u003Em__22D));
bool flag2 = PerformanceChecks.IsMobileBuildTarget(buildTarget);
if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false"))
{
if (flag1)
{
if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f))
{
// ISSUE: reference to a compiler-generated field
return PerformanceChecks.FormattedTextContent("Shader is using white color which does nothing; Consider using {0} shader for performance.", (object) ("Mobile/" + materialCAnonStoreyBe.shaderName));
}
// ISSUE: reference to a compiler-generated field
if (flag2 && materialCAnonStoreyBe.shaderName.StartsWith("Particles/"))
{
// ISSUE: reference to a compiler-generated field
return PerformanceChecks.FormattedTextContent("Consider using {0} shader on this platform for performance.", (object) ("Mobile/" + materialCAnonStoreyBe.shaderName));
}
// ISSUE: reference to a compiler-generated field
if (materialCAnonStoreyBe.shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f))
return PerformanceChecks.FormattedTextContent("Skybox shader is using gray color which does nothing; Consider using {0} shader for performance.", (object) "Mobile/Skybox");
}
// ISSUE: reference to a compiler-generated field
if (lod >= 300 && flag2 && !materialCAnonStoreyBe.shaderName.StartsWith("Mobile/"))
return PerformanceChecks.FormattedTextContent("Shader might be expensive on this platform. Consider switching to a simpler shader; look under Mobile shaders.");
// ISSUE: reference to a compiler-generated field
if (materialCAnonStoreyBe.shaderName.Contains("VertexLit") && mat.HasProperty("_Emission"))
{
Color color = mat.GetColor("_Emission");
if ((double) color.r >= 0.5 && (double) color.g >= 0.5 && (double) color.b >= 0.5)
return PerformanceChecks.FormattedTextContent("Looks like you're using VertexLit shader to simulate an unlit object (white emissive). Use one of Unlit shaders instead for performance.");
}
if (mat.HasProperty("_BumpMap") && (UnityEngine.Object) mat.GetTexture("_BumpMap") == (UnityEngine.Object) null)
return PerformanceChecks.FormattedTextContent("Normal mapped shader without a normal map. Consider using a non-normal mapped shader for performance.");
}
return (string) null;
}
示例13: SetMaterialColor
public static void SetMaterialColor(Material mat, Color color)
{
string[] propertyNames = { "_Color", "_TintColor", "_EmisColor" };
if (mat != null)
foreach (string name in propertyNames)
if (mat.HasProperty(name))
mat.SetColor(name, color);
}
示例14: GetMaterialColor
public static Color GetMaterialColor(Material mat, Color defaultColor)
{
string[] propertyNames = { "_Color", "_TintColor", "_EmisColor" };
if (mat != null)
foreach (string name in propertyNames)
if (mat.HasProperty(name))
return mat.GetColor(name);
return defaultColor;
}
示例15: GetMaterialColorName
public static string GetMaterialColorName(Material mat)
{
string[] propertyNames = { "_Color", "_TintColor", "_EmisColor" };
if (mat != null)
foreach (string name in propertyNames)
if (mat.HasProperty(name))
return name;
return null;
}