本文整理汇总了C#中UnityEngine.Material类的典型用法代码示例。如果您正苦于以下问题:C# Material类的具体用法?C# Material怎么用?C# Material使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Material类属于UnityEngine命名空间,在下文中一共展示了Material类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDisable
private void OnDisable()
{
if (m_Material != null)
DestroyImmediate(m_Material);
m_Material = null;
}
示例2: ProcessSharedMaterials
protected MaterialDesc[] ProcessSharedMaterials( Material[] mats )
{
MaterialDesc[] matsDesc = new MaterialDesc [ mats.Length ];
for ( int i = 0; i < mats.Length; i++ )
{
matsDesc[ i ].material = mats[ i ];
bool legacyCoverage = ( mats[ i ].GetTag( "RenderType", false ) == "TransparentCutout" );
#if UNITY_4
bool isCoverage = legacyCoverage;
matsDesc[ i ].coverage = mats[ i ].HasProperty( "_MainTex" ) && isCoverage;
#else
bool isCoverage = legacyCoverage || mats[ i ].IsKeywordEnabled( "_ALPHATEST_ON" );
matsDesc[ i ].propertyBlock = new MaterialPropertyBlock();
matsDesc[ i ].coverage = mats[ i ].HasProperty( "_MainTex" ) && isCoverage;
#endif
matsDesc[ i ].cutoff = mats[ i ].HasProperty( "_Cutoff" );
if ( isCoverage && !matsDesc[ i ].coverage && !m_materialWarnings.Contains( matsDesc[ i ].material ) )
{
Debug.LogWarning( "[AmplifyMotion] TransparentCutout material \"" + matsDesc[ i ].material.name + "\" {" + matsDesc[ i ].material.shader.name + "} not using _MainTex standard property." );
m_materialWarnings.Add( matsDesc[ i ].material );
}
}
return matsDesc;
}
示例3: OnRenderImage
void OnRenderImage(RenderTexture src, RenderTexture dst)
{
if (m_material == null)
{
m_material = new Material(m_shader);
}
if (m_edge_highlighting)
{
m_material.EnableKeyword("ENABLE_EDGE_HIGHLIGHTING");
}
else
{
m_material.DisableKeyword("ENABLE_EDGE_HIGHLIGHTING");
}
if (m_mul_smoothness)
{
m_material.EnableKeyword("ENABLE_SMOOTHNESS_ATTENUAION");
}
else
{
m_material.DisableKeyword("ENABLE_SMOOTHNESS_ATTENUAION");
}
m_material.SetVector("_Color", GetLinearColor());
m_material.SetVector("_Params1", new Vector4(m_fresnel_bias, m_fresnel_scale, m_fresnel_pow, m_intensity));
m_material.SetVector("_Params2", new Vector4(m_edge_intensity, m_edge_threshold, m_edge_radius, 0.0f));
Graphics.Blit(src, dst, m_material);
}
示例4: CustomGraphicsBlit
static void CustomGraphicsBlit(RenderTexture source, RenderTexture dest, Material fxMaterial, int passNr)
{
RenderTexture.active = dest;
fxMaterial.SetTexture ("_MainTex", source);
GL.PushMatrix ();
GL.LoadOrtho ();
fxMaterial.SetPass (passNr);
GL.Begin (GL.QUADS);
GL.MultiTexCoord2 (0, 0.0f, 0.0f);
GL.Vertex3 (0.0f, 0.0f, 3.0f); // BL
GL.MultiTexCoord2 (0, 1.0f, 0.0f);
GL.Vertex3 (1.0f, 0.0f, 2.0f); // BR
GL.MultiTexCoord2 (0, 1.0f, 1.0f);
GL.Vertex3 (1.0f, 1.0f, 1.0f); // TR
GL.MultiTexCoord2 (0, 0.0f, 1.0f);
GL.Vertex3 (0.0f, 1.0f, 0.0f); // TL
GL.End ();
GL.PopMatrix ();
}
示例5: SetKeyword
static void SetKeyword(Material m, string keyword, bool state)
{
if (state)
m.EnableKeyword(keyword);
else
m.DisableKeyword(keyword);
}
示例6: ImportTexturesFromXml
private void ImportTexturesFromXml(XDocument xml)
{
var texData = xml.Root.Elements("ImportTexture");
foreach (var tex in texData)
{
string name = tex.Attribute("filename").Value;
string data = tex.Value;
// The data is gzip compressed base64 string. We need the raw bytes.
//byte[] bytes = ImportUtils.GzipBase64ToBytes(data);
byte[] bytes = ImportUtils.Base64ToBytes(data);
// Save and import the texture asset
{
string pathToSave = GetTextureAssetPath(name);
ImportUtils.ReadyToWrite(pathToSave);
File.WriteAllBytes(pathToSave, bytes);
AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport);
}
// Create a material if needed in prepartion for the texture being successfully imported
{
string materialPath = GetMaterialAssetPath(name);
Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
if (material == null)
{
// We need to create the material afterall
// Use our custom shader
material = new Material(Shader.Find("Tiled/TextureTintSnap"));
ImportUtils.ReadyToWrite(materialPath);
AssetDatabase.CreateAsset(material, materialPath);
}
}
}
}
示例7: Apply
public void Apply(CloudsMaterial material, float radius, Transform parent)
{
Remove();
particleMaterial.MaxScale = size.y;
particleMaterial.MaxTrans = maxTranslation;
particleMaterial.NoiseScale = new Vector3(noiseScale.x, noiseScale.y, noiseScale.z / radius);
ParticleMaterial = new Material(ParticleCloudShader);
particleMaterial.ApplyMaterialProperties(ParticleMaterial);
material.ApplyMaterialProperties(ParticleMaterial);
ParticleMaterial.EnableKeyword("SOFT_DEPTH_ON");
volumeHolder = new GameObject();
//Add the renderer here so othe rentities (shadows)
//can easily access it.
Renderer r = volumeHolder.AddComponent<MeshRenderer>();
r.material = ParticleMaterial;
ParticleMaterial.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, Matrix4x4.zero);
ParticleMaterial.renderQueue = (int)Tools.Queue.Transparent + 2;
r.enabled = false;
volumeHolder.transform.parent = parent;
volumeHolder.transform.localPosition = Vector3.zero;
volumeHolder.transform.localScale = Vector3.one;
volumeHolder.transform.localRotation = Quaternion.identity;
volumeHolder.layer = (int)Tools.Layer.Local;
volumeManager = new VolumeManager(radius, size, ParticleMaterial, volumeHolder.transform, area.x, (int)area.y);
}
示例8: SpriteAnimator
public SpriteAnimator(Material material, int columnCount)
{
this.material = material;
this.spriteSheetColumnCount = columnCount;
this.Sequences = new List<SpriteAnimationSequence>();
this.Settings = new SpriteAnimationSettings();
}
示例9: OnEnable
void OnEnable()
{
foreach(Transform child in transform)
{
//Search for child Loading Background to get the mesh renderer for the background texture
if(child.name == "Loading Background")
{
m_MeshRenderer = child.GetComponent<MeshRenderer>();
}
if(child.name == "Loading Percent")
{
m_LoadingText = child.GetComponent<TextMesh>();
}
}
if(m_MeshRenderer == null)
{
Debug.LogError("Missing a gameobject with the name \'Loading Background\' and a \'MeshRenderer\' component.");
gameObject.SetActive(false);
return;
}
if(m_LoadingText == null)
{
Debug.LogError("Missing a gameobject with the name \'Loading Text\' and a \'TextMesh\' component.");
gameObject.SetActive(false);
return;
}
Material material = new Material(m_MeshRenderer.sharedMaterial);
material.SetTexture("_MainTex", m_TextureToDisplay);
m_MeshRenderer.material = material;
}
示例10: FourierGPU
public FourierGPU(int size)
{
if(size > 256)
{
Debug.Log("FourierGPU::FourierGPU - fourier grid size must not be greater than 256, changing to 256");
size = 256;
}
if(!Mathf.IsPowerOfTwo(size))
{
Debug.Log("FourierGPU::FourierGPU - fourier grid size must be pow2 number, changing to nearest pow2 number");
size = Mathf.NextPowerOfTwo(size);
}
// Shader shader = Shader.Find("Math/Fourier");
Shader shader = ShaderTool.GetShader2 ("CompiledFourier.shader");
if(shader == null) Debug.Log("FourierGPU::FourierGPU - Could not find shader Math/Fourier");
m_fourier = new Material(shader);
m_size = size; //must be pow2 num
m_fsize = (float)m_size;
m_passes = (int)(Mathf.Log(m_fsize)/Mathf.Log(2.0f));
m_butterflyLookupTable = new Texture2D[m_passes];
ComputeButterflyLookupTable();
m_fourier.SetFloat("_Size", m_fsize);
}
示例11: CreateInstance
public static pb_Renderable CreateInstance(Mesh InMesh, Material InMaterial)
{
pb_Renderable ren = ScriptableObject.CreateInstance<pb_Renderable>();
ren.mesh = InMesh;
ren.materials = new Material[] { InMaterial };
return ren;
}
示例12: CreatePrefab
public void CreatePrefab()
{
if (prefabAtmosphere == null)
{
prefabAtmosphere = new GameObject ("RefractiveAtmosphere");
prefabAtmosphere.SetActive (false);
var mf = prefabAtmosphere.AddComponent<MeshFilter> ();
var mr = prefabAtmosphere.AddComponent<MeshRenderer> ();
mr.castShadows = false;
mr.receiveShadows = false;
var material = new Material (Shaders.RefractiveAtmosphere);
var _normals = new Texture2D (4, 4, TextureFormat.ARGB32, false);
_normals.LoadImage (Textures.RefractiveAtmosphereNormals);
material.SetTexture ("_BumpMap", _normals);
material.SetTextureScale ("_BumpMap", new Vector2 (4f, 4f));
material.SetVector ("_BumpMapOffset", new Vector4 (0, 0, 1, 0));
mr.sharedMaterial = material;
var sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere);
var sphereMesh = sphere.GetComponent<MeshFilter> ().mesh;
DestroyImmediate (sphere);
mf.sharedMesh = sphereMesh;
var behaviour = prefabAtmosphere.AddComponent<RefractiveAtmosphere> ();
prefabAtmosphere.transform.localScale = Vector3.one * 1250f;
DontDestroyOnLoad (prefabAtmosphere);
}
}
示例13: 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;
}
}
示例14: 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);
}
}
示例15: OnRecord
public override void OnRecord()
{
if (_material = material)
{
_original = _material.GetTextureScale(propertyName);
}
}