本文整理汇总了C#中UnityEngine.Material.GetTextureScale方法的典型用法代码示例。如果您正苦于以下问题:C# Material.GetTextureScale方法的具体用法?C# Material.GetTextureScale怎么用?C# Material.GetTextureScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Material
的用法示例。
在下文中一共展示了Material.GetTextureScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRecord
public override void OnRecord()
{
if (_material = material)
{
_original = _material.GetTextureScale(propertyName);
}
}
示例2: SetFromToCurrent
public void SetFromToCurrent()
{
if (_material = material)
{
from = _material.GetTextureScale(propertyName);
}
}
示例3: 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;
}
示例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: Start
// Use this for initialization
void Start()
{
bar = renderer.material;
tiling = bar.GetTextureScale("_MainTex").x;
PlayerController = GameObject.FindGameObjectWithTag("PlayerController");
if(PlayerController!=null)
life = PlayerController.GetComponent<Life>();
health = 1;
}
示例6: OnTween
public override void OnTween(float factor)
{
if (_material = material)
{
_temp = _material.GetTextureScale(propertyName);
if (mask.GetBit(0)) _temp.x = from.x + (to.x - from.x) * factor;
if (mask.GetBit(1)) _temp.y = from.y + (to.y - from.y) * factor;
_material.SetTextureScale(propertyName, _temp);
}
}
示例7: ACCTexture
public ACCTexture(Texture tex, Material mate, ShaderPropTex texProp, ShaderType type) :this(texProp.key) {
this.tex = tex;
this.type = type;
this.prop = texProp;
this.editname = tex.name;
if (tex is Texture2D) {
texOffset = mate.GetTextureOffset(propName);
texScale = mate.GetTextureScale(propName);
} else {
LogUtil.DebugF("propName({0}): texture type:{1}", propName, tex.GetType());
}
// } else {
// // シェーダ切り替えなどで、元々存在しないテクスチャの場合
// LogUtil.DebugF("texture not found. propname={0}, material={1}", propName, mate.name);
// // 空のテクスチャは作成しない
//// this.tex = new Texture2D(2, 2);
//// this.tex.name = string.Empty;
//// // テクスチャを追加セット
//// mate.SetTexture(propName, this.tex);
// }
}
示例8: DumpGlossinessReflectivity
private void DumpGlossinessReflectivity(Material material, bool metallic, BabylonPBRMaterial babylonPbrMaterial)
{
if (material.HasProperty("_Glossiness"))
{
babylonPbrMaterial.microSurface = material.GetFloat("_Glossiness");
}
if (metallic)
{
if (material.HasProperty("_Metallic"))
{
var metalness = material.GetFloat("_Metallic");
babylonPbrMaterial.reflectivity = new float[] { metalness * babylonPbrMaterial.albedo[0],
metalness * babylonPbrMaterial.albedo[1],
metalness * babylonPbrMaterial.albedo[2] };
if (babylonPbrMaterial.albedoTexture != null)
{
var albedoTexture = material.GetTexture("_MainTex") as Texture2D;
if (albedoTexture != null)
{
var albedoPixels = GetPixels(albedoTexture);
var reflectivityTexture = new Texture2D(albedoTexture.width, albedoTexture.height, TextureFormat.RGBA32, false);
reflectivityTexture.alphaIsTransparency = true;
babylonPbrMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
var metallicTexture = material.GetTexture("_MetallicGlossMap") as Texture2D;
if (metallicTexture == null)
{
for (var i = 0; i < albedoTexture.width; i++)
{
for (var j = 0; j < albedoTexture.height; j++)
{
albedoPixels[j * albedoTexture.width + i].r *= metalness;
albedoPixels[j * albedoTexture.width + i].g *= metalness;
albedoPixels[j * albedoTexture.width + i].b *= metalness;
albedoPixels[j * albedoTexture.width + i].a = babylonPbrMaterial.microSurface;
}
}
}
else
{
var metallicPixels = GetPixels(metallicTexture);
for (var i = 0; i < albedoTexture.width; i++)
{
for (var j = 0; j < albedoTexture.height; j++)
{
var pixel = albedoPixels[j * albedoTexture.width + i];
var metallicPixel = metallicPixels[j * albedoTexture.width + i];
albedoPixels[j * albedoTexture.width + i].r *= metallicPixel.r;
albedoPixels[j * albedoTexture.width + i].g *= metallicPixel.r;
albedoPixels[j * albedoTexture.width + i].b *= metallicPixel.r;
albedoPixels[j * albedoTexture.width + i].a = metallicPixel.a;
}
}
}
reflectivityTexture.SetPixels(albedoPixels);
reflectivityTexture.Apply();
var textureName = albedoTexture.name + "_MetallicGlossMap.png";
var babylonTexture = new BabylonTexture { name = textureName };
var textureScale = material.GetTextureScale("_MainTex");
babylonTexture.uScale = textureScale.x;
babylonTexture.vScale = textureScale.y;
var textureOffset = material.GetTextureOffset("_MainTex");
babylonTexture.uOffset = textureOffset.x;
babylonTexture.vOffset = textureOffset.y;
var reflectivityTexturePath = Path.Combine(Path.GetTempPath(), textureName);
File.WriteAllBytes(reflectivityTexturePath, reflectivityTexture.EncodeToPNG());
babylonScene.AddTexture(reflectivityTexturePath);
if (File.Exists(reflectivityTexturePath))
{
File.Delete(reflectivityTexturePath);
}
babylonPbrMaterial.reflectivityTexture = babylonTexture;
}
}
//else
//{
// TODO. Manage Albedo Cube Texture.
//}
}
}
else
{
if (material.HasProperty("_SpecColor"))
{
babylonPbrMaterial.reflectivity = material.GetColor("_SpecColor").ToFloat();
}
babylonPbrMaterial.reflectivityTexture = DumpTextureFromMaterial(material, "_SpecGlossMap");
if (babylonPbrMaterial.reflectivityTexture != null && babylonPbrMaterial.reflectivityTexture.hasAlpha)
{
babylonPbrMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
}
}
//.........这里部分代码省略.........
示例9: GetValues
/// <summary>
/// Gets the values given a material
/// </summary>
/// <param name="m">The material</param>
/// <returns>A StoredValue containing value and type information</returns>
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 = new object[1];
o.value[0] = m.GetColor(p.name);
break;
case MaterialProperty.PropertyType.Float:
o.value = new object[1];
o.value[0] = m.GetFloat(p.name);
break;
case MaterialProperty.PropertyType.Range:
o.value = new object[1];
o.value[0] = m.GetFloat(p.name);
break;
case MaterialProperty.PropertyType.TexEnv:
o.value = new object[3];
o.value[0] = m.GetTexture(p.name);
o.value[1] = m.GetTextureOffset(p.name);
o.value[2] = m.GetTextureScale(p.name);
break;
case MaterialProperty.PropertyType.Vector:
o.value = new object[1];
o.value[0] = m.GetVector(p.name);
break;
default:
Debug.LogError("Unsupported type: " + p.type.ToString());
break;
}
}
return output;
}
示例10: AddColorChannel
public void AddColorChannel(string channelName, string propertyName, string texturePropertyName, Material material)
{
Color value = material.GetColor(propertyName);
Texture texture = material.GetTexture(texturePropertyName);
Vector2 offset = material.GetTextureOffset(texturePropertyName);
Vector2 scale = material.GetTextureScale(texturePropertyName);
ColorChannel channel = new ColorChannel();
channel.value = value;
channel.texture = texture is Texture2D ? (texture as Texture2D) : null;
channel.offset = offset;
channel.scale = scale;
this.colorChannels[channelName] = channel;
}
示例11: Start
// Use this for initialization
void Start()
{
bar = renderer.material;
tiling = bar.GetTextureScale("_MainTex").x;
}
示例12: GetTextureTransformation
private Vector4 GetTextureTransformation(Material material) {
Vector2 offset;
Vector2 scale;
if (!m_hasParentTexture) {
offset = m_offset.vector2Value;
scale = m_scale.vector2Value;
}
else {
offset = material.GetTextureOffset(m_parentTexture);
scale = material.GetTextureScale(m_parentTexture);
}
return new Vector4(offset.x, offset.y, scale.x, scale.y);
}
示例13: _GetShaderTexProp
private static KSerializeMaterialProperty _GetShaderTexProp(Material mm, string texProp, float scaleTexture = 1f)
{
if (mm.HasProperty(texProp))
{
Texture tex = mm.GetTexture(texProp);
if (tex != null)
{
KSerializeMaterialProperty shaderProp = new KSerializeMaterialProperty();
shaderProp.PropName = texProp;
if (tex is Texture2D)
{
var texTiling = mm.GetTextureScale(texProp); // 纹理+tiling+offset
var texOffset = mm.GetTextureOffset(texProp);
var texPath = KDependencyBuild.BuildDepTexture(tex, scaleTexture);
shaderProp.Type = KSerializeMaterialProperty.ShaderType.Texture;
shaderProp.PropValue = string.Format("{0}|{1}|{2}|{3}|{4}", texPath, texTiling.x, texTiling.y,
texOffset.x, texOffset.y);
}
else
{
Log.Warning("找到一个非Texture2D, Type:{0} Mat:{1} PropName:{2}", tex.GetType(), mm.name, texProp);
shaderProp.Type = KSerializeMaterialProperty.ShaderType.RenderTexture;
// Shader的RenderTexture不打包,一般由脚本动态生成
shaderProp.PropValue = null;
}
return shaderProp;
}
else
{
Log.Info("[_GetShaderTexProp]处理纹理时发现获取不到纹理, 材质{0} Shader属性{1}", mm.name, texProp);
return null;
}
}
return null;
}
示例14: AddTextureChannel
public void AddTextureChannel(string channelName, string texturePropertyName, Material material)
{
Texture texture = material.GetTexture(texturePropertyName);
Vector2 offset = material.GetTextureOffset(texturePropertyName);
Vector2 scale = material.GetTextureScale(texturePropertyName);
TextureChannel channel = new TextureChannel();
channel.texture = texture is Texture2D ? (texture as Texture2D) : null;
channel.offset = offset;
channel.scale = scale;
this.textureChannels[channelName] = channel;
}
示例15: AddSingleChannel
public void AddSingleChannel(string channelName, string propertyName, string texturePropertyName, Material material)
{
float value = material.GetFloat(propertyName);
Texture texture = material.GetTexture(texturePropertyName);
Vector2 offset = material.GetTextureOffset(texturePropertyName);
Vector2 scale = material.GetTextureScale(texturePropertyName);
SingleChannel channel = new SingleChannel();
channel.value = value;
channel.texture = texture is Texture2D ? (texture as Texture2D) : null;
channel.offset = offset;
channel.scale = scale;
this.singleChannels[channelName] = channel;
}