本文整理汇总了C#中UnityEngine.Material.GetTexture方法的典型用法代码示例。如果您正苦于以下问题:C# Material.GetTexture方法的具体用法?C# Material.GetTexture怎么用?C# Material.GetTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Material
的用法示例。
在下文中一共展示了Material.GetTexture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: SetMaterialKeywords
static void SetMaterialKeywords(Material material)
{
SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap"));
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
var emissive = material.GetColor("_EmissionColor").maxColorComponent > 0.1f / 255;
SetKeyword(material, "_EMISSION", emissive);
}
示例3: AddTexturesInMaterialToList
static void AddTexturesInMaterialToList(ref ArrayList list, Material material)
{
// look for textures found in the built in shaders
string[] builtInShadersTextureNames =
{"_MainTex", "_BumpMap", "_Detail", "_ColorControl", "_ColorControlCube",
"_ReflectionTex", "_RefractionTex", "_Fresnel", "_LightMap",
"_Cube", "_FrontTex", "_BackTex", "_LeftTex", "_RightTex",
"_UpTex", "_DownTex", "_Tex"};
foreach (string textureName in builtInShadersTextureNames)
{
if (material.GetTexture(textureName) != null)
list.Add(material.GetTexture(textureName));
}
}
示例4: FromMaterial
public static SMaterial FromMaterial(Material mat)
{
if (mat == null)
return null;
Shader shader = mat.shader;
if (shader == null)
return null;
SMaterial result = new SMaterial();
result.instanceID = mat.GetInstanceID();
result.materialName = mat.name;
result.shaderName = shader.name;
ShaderProperties.Info info = ShaderPropertyHelper.GetShaderInfo(shader.name);
if (info != null){
ComposedByteStream rawData = new ComposedByteStream();
int iMax = info.propertyNames.Length;
for (int i = 0; i < iMax; i++)
{
string propName = info.propertyNames[i];
switch (info.propertyTypes[i])
{
case ShaderProperties.PropType.Color:
Color color = mat.GetColor(propName);
rawData.AddStream(new float[] { color.r, color.g, color.b, color.a });
break;
case ShaderProperties.PropType.Range:
case ShaderProperties.PropType.Float:
rawData.AddStream(new float[] { mat.GetFloat(propName) });
break;
case ShaderProperties.PropType.TexEnv:
Texture texture = mat.GetTexture(propName);
Vector2 offset = mat.GetTextureOffset(propName);
Vector2 scale = mat.GetTextureScale(propName);
rawData.AddStream(new int[] { texture != null ? texture.GetInstanceID() : -1 });
rawData.AddStream(texture != null ? texture.name : "" );
rawData.AddStream(new float[] { offset.x, offset.y });
rawData.AddStream(new float[] { scale.x, scale.y });
break;
case ShaderProperties.PropType.Vector:
Vector4 vector = mat.GetVector(propName);
rawData.AddStream(new float[] { vector.x, vector.y, vector.z, vector.w });
break;
}
}
result.rawData = rawData.Compose();
return result;
} else {
if (vBug.settings.general.debugMode)
Debug.LogError("No shader-info found @" + shader.name);
return null;
}
}
示例5: GetValues
public List<StoredValue> GetValues(Material m)
{
var list = GetShaderProperties(m);
var output = new List<StoredValue>();
foreach(var p in list)
{
var o = new StoredValue { Property = p };
output.Add(o);
switch(p.type)
{
case MaterialProperty.PropertyType.color:
o.Value = m.GetColor(p.name);
break;
case MaterialProperty.PropertyType.real:
o.Value = m.GetFloat(p.name);
break;
case MaterialProperty.PropertyType.texture:
o.Value = m.GetTexture(p.name);
break;
case MaterialProperty.PropertyType.vector:
o.Value = m.GetVector(p.name);
break;
case MaterialProperty.PropertyType.textureOffset:
o.Value = m.GetTextureOffset(p.name);
break;
case MaterialProperty.PropertyType.textureScale:
o.Value = m.GetTextureScale(p.name);
break;
case MaterialProperty.PropertyType.matrix:
o.Value = m.GetMatrix(p.name);
break;
}
}
return output;
}
示例6: 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;
}
}
}
}
示例7: 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;
}
示例8: Awake
void Awake ()
{
material = GetComponent<Renderer>().material;
cubemap = (Cubemap)material.GetTexture("_Cube");
rendererArray = GetComponentsInChildren<Renderer>();
rotation = material.GetFloat("_Rotation");
bookArray = GetComponentsInChildren<Book>();
}
示例9: 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);
}
示例10: ProcGUI
public void ProcGUI(Maid maid, string slotName, Material material, string propName) {
// material 抽出 => texture 抽出
var tex2d = material.GetTexture(propName) as Texture2D;
if (tex2d == null || string.IsNullOrEmpty(tex2d.name)) return ;
var key = CreateKey(maid.Param.status.guid, slotName, material.name, tex2d.name);
FilterParam fp = filterParams.GetOrAdd(key.ToString());
fp.ProcGUI(tex2d);
}
示例11: SetSkybox
public void SetSkybox(float blend, Material skybox1, Material skybox2)
{
foreach (Material mtl in transform.renderer.materials)
{
string texName = "_" + mtl.name.Replace(" (Instance)","").Substring(6) + "Tex";
mtl.SetFloat("_Blend", blend);
mtl.SetTexture("_MainTex", skybox1.GetTexture(texName));
mtl.SetTexture("_SubTex", skybox2.GetTexture(texName));
}
}
示例12: Awake
void Awake()
{
_material = GetComponent<Renderer>().material;
_texture = _material.GetTexture(TexturePropertyName);
_matSize = System.Math.Min(_texture.width, _texture.height);
_material.SetTextureScale(TexturePropertyName, new Vector2(1f / ((float)XCells), 1f / ((float)YCells)));
SetSpriteIndex(0);
}
示例13: WriteToJson
public void WriteToJson(IResMgr resmgr, Material mat, MyJson.JsonNode_Object json)
{
json["shaderName"] = new MyJson.JsonNode_ValueString(this.shaderName);
if (jsonConfig.ContainsKey("params"))
{
foreach (var item in jsonConfig["params"].asDict())
{
//Debug.Log(item.Value);
string type = item.Value.asDict()["type"].AsString();
string flag = item.Value.asDict()["flags"].AsString();
string name = item.Value.asDict()["name"].AsString();
if (type == "Float" || type == "Range")
{
json[name] = new MyJson.JsonNode_ValueNumber(mat.GetFloat(name));
}
else if (type == "Vector")
{
json[name] = new MyJson.JsonNode_ValueString(StringHelper.ToString(mat.GetVector(name)));
}
else if (type == "Color")
{
json[name] = new MyJson.JsonNode_ValueString(StringHelper.ToString((Color32)mat.GetColor(name)));
}
else if (type == "Texture")
{
string texdim = item.Value.asDict()["texdim"].AsString();
var tex = mat.GetTexture(name);
if (tex != null)
{
if (texdim == "Tex2D")
{
string texname = resmgr.SaveTexture(tex as Texture2D);
json[name] = new MyJson.JsonNode_ValueString(texname);
}
else
{
throw new Exception("not support texdim:" + texdim);
}
}
}
else
{
throw new Exception("not support type:" + type);
}
}
}
}
示例14: UpdateTex
public bool UpdateTex(Maid maid, Material mat, EditTarget texEdit)
{
var tex2d = mat.GetTexture(texEdit.propName) as Texture2D;
if (tex2d == null || string.IsNullOrEmpty(tex2d.name)) return false;
var key = CreateKey(maid.Param.status.guid, texEdit.slotName, mat.name, tex2d.name);
FilterParam filterParam = filterParams.GetOrAdd(key.ToString());
// スライダー変更がなければ何もしない
if (!filterParam.IsDirty) return false;
//LogUtil.DebugLogF("Update Texture. slot={0}, material={0}, tex={1}", texEdit.slotName, mat.name, tex2d.name);
FilterTexture(tex2d, filterParam);
return true;
}
示例15: Start
void Start() {
player = GameObject.FindWithTag("Player");
agent = GetComponent<NavMeshAgent>();
startPosition = transform.position;
seenByCharacter = false;
agent.speed = GlobalVariables.Instance.minotaurusSpeed;
mat = GetComponentInChildren<MeshRenderer>().material;
glowy = mat.GetTexture("_Illum");
mat.SetTexture("_Illum", schwarz);
}