本文整理汇总了C#中UnityEngine.MaterialPropertyBlock.SetColor方法的典型用法代码示例。如果您正苦于以下问题:C# MaterialPropertyBlock.SetColor方法的具体用法?C# MaterialPropertyBlock.SetColor怎么用?C# MaterialPropertyBlock.SetColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.MaterialPropertyBlock
的用法示例。
在下文中一共展示了MaterialPropertyBlock.SetColor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCube
public static void DrawCube(Vector3 position, Quaternion rotation, float size, Color color, int p_layer = 0)
{
Matrix4x4 mat = Matrix4x4.TRS(position, rotation, size * Vector3.one);
MaterialPropertyBlock block = new MaterialPropertyBlock();
block.SetColor("_Color", color);
Graphics.DrawMesh(solidCube, mat, DebugMaterial, p_layer, null, 0, block);
}
示例2: DrawSphere
public static void DrawSphere(Vector3 position, float radius, Color color, int p_layer = 0)
{
Matrix4x4 mat = Matrix4x4.TRS(position, Quaternion.identity, radius * Vector3.one);
MaterialPropertyBlock block = new MaterialPropertyBlock();
block.SetColor("_Color", color);
Graphics.DrawMesh(solidSphere, mat, DebugMaterial, p_layer, null, 0, block);
}
示例3: UpdateOutline
void UpdateOutline(bool outline)
{
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
spriteRenderer.GetPropertyBlock(mpb);
mpb.SetFloat("_Outline", outline ? 1f : 0);
mpb.SetColor("_OutlineColor", color);
spriteRenderer.SetPropertyBlock(mpb);
}
示例4: Evaluate
/// <summary>
/// Evaluates the property at "t" and stores its value in the MaterialPropertyBlock.
/// </summary>
/// <param name="block"></param>
/// <param name="t"></param>
public void Evaluate( MaterialPropertyBlock block, float t )
{
if( type == Type.Color )
{
block.SetColor( Id, Color.Lerp( from, to, t ) );
}
else if( type == Type.Float )
{
block.SetFloat( Id, Mathf.Lerp( from.a, to.a, t ) );
}
}
示例5: InitializeColorChangeSystem
private void InitializeColorChangeSystem(GameColor color) {
Color32 primaryMeshColor = color.ToUnityColor(_primaryMeshAlpha);
_primaryMeshMPB = new MaterialPropertyBlock(); // default color is black
_primaryMeshRenderer.GetPropertyBlock(_primaryMeshMPB);
// renderer's existing MaterialPropertyBlock color is also black, implying that the existing property block is the default, at least wrt color
_primaryMeshMPB.SetColor(UnityConstants.StdShader_Property_AlbedoColor, primaryMeshColor);
//D.Log("{0}.PrimaryMeshMPB color after initialization = {1}.", DebugName, _primaryMeshMPB.GetVector(UnityConstants.StdShader_Property_AlbedoColor));
if (_hiddenMeshMPB == null) {
_hiddenMeshMPB = new MaterialPropertyBlock();
_primaryMeshRenderer.GetPropertyBlock(_hiddenMeshMPB);
_hiddenMeshMPB.SetColor(UnityConstants.StdShader_Property_AlbedoColor, HiddenMeshColor);
}
}
示例6: Update
void Update()
{
if (particles == null)
{
particles = new LinkedList<float>();
}
var interval = 1f / rate;
var now = Time.time;
//add new particle each interval
if (now > lastParticle + interval)
{
particles.AddFirst(now);
lastParticle = now;
}
//remove old particles
while (particles.Last != null && particles.Last.Value + lifetime < now)
{
particles.RemoveLast();
}
//render particles
foreach (var particle in particles)
{
float age = (now - particle) / lifetime;
var color = gradient.Evaluate(age);
var offset = transform.forward * speed * age * transform.localScale.z;
var pos = transform.position + offset;
var rot = transform.rotation;
var scale = transform.localScale;
var particleMat = Matrix4x4.TRS(pos, rot, scale);
var matProperties = new MaterialPropertyBlock();
if (materialTintProperty != null)
{
matProperties.SetColor("_TintColor", color);
}
if (mesh)
{
Graphics.DrawMesh(mesh, particleMat, material, 0, null, 0, matProperties);
}
}
}
示例7: DrawLine2D
public static void DrawLine2D(Vector2 p_initialPosition, Vector2 p_finalPosition, Color p_color, Color p_pointColor, int p_layer = 0)
{
Vector2 v_middlePosition = new Vector2( (p_initialPosition.x + p_finalPosition.x)/2.0f, (p_initialPosition.y + p_finalPosition.y)/2.0f);
Vector2 v_direction = VectorHelper.Direction(p_initialPosition, p_finalPosition);
float v_distance = Mathf.Abs(Vector2.Distance(p_initialPosition, p_finalPosition));
float v_angle = Vector2.Angle(new Vector2(1,0), v_direction);
v_angle = p_finalPosition.y < p_initialPosition.y ? -v_angle : v_angle;
Quaternion v_quaternion = Quaternion.identity;
v_quaternion.eulerAngles = new Vector3(0,0, v_angle);
Matrix4x4 mat = Matrix4x4.TRS(v_middlePosition, v_quaternion, new Vector3(v_distance*0.5f, 0.003f, 0.003f) );
MaterialPropertyBlock block = new MaterialPropertyBlock();
block.SetColor("_Color", p_color);
Graphics.DrawMesh(solidCube, mat, DebugMaterial, p_layer, null, 0, block);
//Draw Points
DrawSphere(p_initialPosition, 0.01f, p_pointColor, p_layer);
DrawSphere(p_finalPosition, 0.01f, p_pointColor, p_layer);
}
示例8: SetPropertyBlock
public void SetPropertyBlock(MaterialPropertyBlock block,
Transform modelTransform)
{
// model local space to world space matrix
var l2w = modelTransform.localToWorldMatrix;
// world space to effector local space matrix
var w2e = transform.worldToLocalMatrix;
// effector local space to normalized effector space matrix
var es = _effectorSize;
var invs = new Vector3(1.0f / es.x, 1.0f / es.y, 1.0f / es.z);
var e2n = Matrix4x4.Scale(invs);
block.SetMatrix("_Effector", e2n * w2e * l2w);
block.SetVector("_Steepness", new Vector3(
_transitionSteepness,
_emissionTransitionSteepness,
_scaleTransitionSteepness
));
block.SetColor("_InitialEmission", _initialEmission);
block.SetFloat("_InitialScale", _initialScale);
if (_effectType == EffectType.Destruction)
SetDestructionProps(block, modelTransform);
else
SetDisintegrationProps(block);
}
示例9: doAnimateColor
/**
* For all child objects, lerps between the in and out colors based on the animation curve.
* @since 4.1.4
*/
protected virtual void doAnimateColor(float interpolationPoint) {
float influence = ColorCurve.Evaluate(interpolationPoint);
Transform[] children = RootTransform.gameObject.GetComponentsInChildren<Transform>(true);
for (int g = 0; g < children.Length; g++) {
Renderer renderer = children[g].gameObject.GetComponent<Renderer>();
if (renderer != null) {
materialProperties = new MaterialPropertyBlock();
renderer.GetPropertyBlock(materialProperties);
materialProperties.SetColor(ColorShaderPropertyName, Color.Lerp(renderer.sharedMaterial.color, TransitionColor, influence));
renderer.SetPropertyBlock(materialProperties);
}
}
}
示例10: ChangeColor
public void ChangeColor(Toggle toggle)
{
if (!toggle.isOn) return;
var colorThingy = toggle.gameObject.GetComponent<ColorThingy>();
colorThingy.OnValidate(); // TODO Badness searches whole scene each button press, just in case things changed
foreach (var colorThingThing in colorThingy.things) {
var colorIntensified = colorThingThing.color*colorThingThing.intensity;
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
propertyBlock.SetColor("_EmissionColor", colorIntensified);
// Debug.Log("Setting color " + color + " on " + renderers.Count + " renderers");
if (colorThingy.randomDiscoMode) {
foreach (var thingThing in colorThingy.things) {
thingThing.color = colorThingy.randomColors.Evaluate(Random.Range(0f, 1f));
}
}
if (colorThingThing.affectMaterial) {
foreach (Renderer o in colorThingThing.renderers) {
if (o != null) {
o.SetPropertyBlock(propertyBlock);
//Debug.Log("Material uses: " + renderer.material.GetColor("_EmissionColor"));
//Debug.Log("Setting color: " + color);
DynamicGI.SetEmissive(o, colorIntensified);
}
}
}
foreach (var o in colorThingThing.lights) {
if (o != null) o.color = GetColor(colorThingThing);
}
foreach (var matprop in colorThingThing.matProps) {
if (matprop != null) {
matprop._color = new Gradient {
colorKeys = new[] {new GradientColorKey(colorThingThing.color, 0), new GradientColorKey(colorThingThing.color, 1)}
};
matprop.Run();
}
}
foreach (var lightprop in colorThingThing.lightProps) {
if (lightprop != null) {
lightprop.targetColor = GetColor(colorThingThing);
lightprop.Run();
}
}
foreach (var agentprop in colorThingThing.agentProps) {
if (agentprop != null) {
agentprop.ColorOverride(GetColor (colorThingThing));
}
}
}
}