SetColor() public method

Set a color property.

public SetColor ( int nameID, Color value ) : void
nameID int The name ID of the property retrieved by Shader.PropertyToID.
value Color The Color value to set.
return void
Example #1
0
 static public int SetColor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Color)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             UnityEngine.Color a2;
             checkType(l, 3, out a2);
             self.SetColor(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Color)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             UnityEngine.Color a2;
             checkType(l, 3, out a2);
             self.SetColor(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetColor to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #2
0
    static int SetColor(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <int, UnityEngine.Color>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Color arg1 = ToLua.ToColor(L, 3);
                obj.SetColor(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, UnityEngine.Color>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                string            arg0 = ToLua.ToString(L, 2);
                UnityEngine.Color arg1 = ToLua.ToColor(L, 3);
                obj.SetColor(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.MaterialPropertyBlock.SetColor"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #3
0
	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);
	}
Example #4
0
	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);
	}
 void UpdateOutline(bool outline)
 {
     MaterialPropertyBlock mpb = new MaterialPropertyBlock();
     spriteRenderer.GetPropertyBlock(mpb);
     mpb.SetFloat("_Outline", outline ? 1f : 0);
     mpb.SetColor("_OutlineColor", color);
     spriteRenderer.SetPropertyBlock(mpb);
 }
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            try
            {
                var spriteRenderer   = context.GetUnityComponent <UnityEngine.SpriteRenderer>(entity);
                var sprite2DRenderer = context.GetComponentData <Sprite2DRenderer>(entity);
                var sprite           = context.GetUnityObject <UnityEngine.Sprite>(sprite2DRenderer.sprite);

                var block = new UnityEngine.MaterialPropertyBlock();
                spriteRenderer.GetPropertyBlock(block);
                block.Clear();

                spriteRenderer.color = sprite2DRenderer.color.Convert();
                block.SetColor("_Color", sprite2DRenderer.color.Convert());

                if (sprite)
                {
                    spriteRenderer.sprite = sprite;
                    var blending = sprite2DRenderer.blending;
                    if (k_BlendModes.TryGetValue(blending, out var blendMode))
                    {
                        spriteRenderer.sharedMaterial.SetFloat("_SrcMode", blendMode.x);
                        spriteRenderer.sharedMaterial.SetFloat("_DstMode", blendMode.y);
                    }
                    else
                    {
                        UnityEngine.Debug.Log($"Tiny: Unknown blending mode, of value '{blending}'");
                    }

                    block.SetTexture("_MainTex", sprite.texture);
                }
                else
                {
                    spriteRenderer.sprite = s_WhiteSprite;
                    if (!context.HasComponent <Sprite2DRendererOptions>(entity))
                    {
                        spriteRenderer.size = UnityEngine.Vector2.one;
                    }
                }

                spriteRenderer.SetPropertyBlock(block);

                if (context.HasComponent <Sprite2DRendererOptions>(entity))
                {
                    var options = context.GetComponentData <Sprite2DRendererOptions>(entity);
                    SetDrawMode(spriteRenderer, options.drawMode);
                    spriteRenderer.size = options.size;
                }
                else
                {
                    spriteRenderer.drawMode = UnityEngine.SpriteDrawMode.Simple;
                }
            }
            finally
            {
                UnityEditor.SceneView.RepaintAll();
            }
        }
 /// <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 ) );
     }
 }
Example #8
0
 static public int SetColor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Color)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             UnityEngine.Color a2;
             checkType(l, 3, out a2);
             self.SetColor(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Color)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             UnityEngine.Color a2;
             checkType(l, 3, out a2);
             self.SetColor(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetColor to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
        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);
            }
        }
    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);
            }
        }
    }
 static public int SetColor__Int32__Color(IntPtr l)
 {
     try {
         UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         UnityEngine.Color a2;
         checkType(l, 3, out a2);
         self.SetColor(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #12
0
	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);
	}
        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);
        }
 public bool AddToMaterialPropertyBlock(UnityEngine.MaterialPropertyBlock materialPropertyBlock)
 {
     materialPropertyBlock.SetColor(this.PropertyName, this.PropertyValue);
     return(false);
 }
Example #15
0
 /**
 * 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);
     }
   }
 }
Example #16
0
    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));
                }
            }

        }
    }