本文整理汇总了C#中UnityEngine.Material.GetTextureOffset方法的典型用法代码示例。如果您正苦于以下问题:C# Material.GetTextureOffset方法的具体用法?C# Material.GetTextureOffset怎么用?C# Material.GetTextureOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Material
的用法示例。
在下文中一共展示了Material.GetTextureOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
private Vector2 offset = Vector2.zero; //Starting Offset
#endregion Fields
#region Methods
void Start()
{
material = GetComponent<Renderer>().material;
//"_MainTex" is the main diffuse texture. This is specified in the Unity Docs.
offset = material.GetTextureOffset("_MainTex");
}
示例2: Start
// Use this for initialization
void Start () {
material = GetComponent<Renderer>().material;
offset = material.GetTextureOffset("_MainTex");
}
示例3: Start
// Use this for initialization
void Start()
{
//get reference to the material tied to the background quad
material = GetComponent<Renderer> ().material;
offset = material.GetTextureOffset("_MainTex");
}
示例4: 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;
}
示例5: OnRecord
public override void OnRecord()
{
if (_material = material)
{
_original = _material.GetTextureOffset(propertyName);
}
}
示例6: 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;
}
}
示例7: SetFromToCurrent
public void SetFromToCurrent()
{
if (_material = material)
{
from = _material.GetTextureOffset(propertyName);
}
}
示例8: OnTween
public override void OnTween(float factor)
{
if (_material = material)
{
_temp = _material.GetTextureOffset(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.SetTextureOffset(propertyName, _temp);
}
}
示例9: 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);
// }
}
示例10: StartLevel
public override void StartLevel()
{
var camera = Camera.main;
var cameraWidth = camera.GetOrthographicWidth();
var cameraHeight = camera.GetOrthographicHeight();
bounds = new Rect( -cameraWidth / 2, -cameraHeight / 2, cameraWidth, cameraHeight );
background.transform.localScale = new Vector3( cameraWidth, cameraHeight, 1 );
background.sharedMaterial = Instantiate( background.sharedMaterial );
enemyShips = new LinkedList<EnemyShip>();
var shipConfig = new ShipConfig( 0.1f, 0.1f );
var shipModel = new ShipModel() { Lives = 3 };
var weaponConfig = new WeaponConfig( 5f, 1, 0.5f );
var weapon = Locator.ResLoader.LoadAndInstantiateAs< ProjectileWeapon >( "Weapons/Cannon" );
weapon.Init( IsRunning, TimeProvider, weaponConfig, bounds, 1 );
var enemyShipPrefab = Locator.ResLoader.Load< GameObject >( "Ships/Enemies/LaserCorvette" );
enemyShipPrefabLink = enemyShipPrefab.transform;
PrefabPoolManager.Prepare( enemyShipPrefabLink, 8 );
Player = Locator.ResLoader.LoadAndInstantiateAs< PlayerShip >( "Ships/PlayerShip" );
Player.transform.SetParent( transform, true );
Player.OnShipDestroyed += OnGameOver;
Player.Init( IsRunning, TimeProvider, shipConfig, shipModel, bounds);
Player.Weapon = weapon;
backgroundMaterial = background.GetComponent< Renderer >().sharedMaterial;
initialTextureOffset = backgroundMaterial.GetTextureOffset( "_MainTex" );
if ( musicTrack != null )
Locator.Sound.PlayMusic( musicTrack );
base.StartLevel();
}
示例11: Start
// Use this for initialization
void Start()
{
myMeshRenderer = GetComponent<MeshRenderer> ();
myMat = myMeshRenderer.material;
origOffset = myMat.GetTextureOffset ("_MainTex");
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}
}
//.........这里部分代码省略.........