I made a ShaderGraph Shader, that I applied to a material. In the SHader, I put in "public" a variable Color in order to change the material color. From the inspector, it do work if it is not runtime ;
I would like to change this material color depending on different elements during the game. The Material is applied to a lineRenderer. I tried many ways, but it never change color ;
GetComponent<EnemyType>().color; return a RGBA color. I tried :
LaserLine.material.color = GetComponent<EnemyType>().color;
LaserLine.startColor = GetComponent<EnemyType>().color;
LaserLine.endColor = GetComponent<EnemyType>().color;
LaserLine.material.SetColor("_Color", GetComponent<EnemyType>().color);
What Am I doing wrong ?
Thanks
As you are using a custom shader, properties might have different names
Based on the screenshot in your other question your color property is named "Color" not "_Color", though it's hard to see (because for some reason you scaled the images for that question) and I don't know what kind of code ShaderGraph actually outputs (e.g. it could just be a color node and its actual internal name is something like "_Node-2389").
If you hit this button and then "edit shader" it'll show you some information about the shader's properties, including the true string representation of each one.
Like this:
Ok I found out,
It is not the name of the property that count but the reference. To see it, go inside ShaderGraph, and click on the property, you will find the reference name on the property parameters (top left) :
Change the parameter value using the reference trough code like this
material.SetColor("_Color", new Color());
Related
I have a simple line that basically makes the light color switch according to 3 color values.
GameObject.Find("Directional Light").GetComponent<Light>().color = new Color(color.R, color.G, color.B, 255);
But when I actually use it (I made it so it gets triggered when I press C), the color value itself gets changed, but it's not updated until I change it manualy through inspector.
If anyone knows how I can fix it, I would be very grateful.
It's the same thing with Camera background color, and I am really unsure if it's me doing something wrong about changing the color, me not doing something that has to be done for it to update, or it just not working like that.
I tried changing the color property with a matching color value. It should have changed AND updated so the change can be observed in game, but instead the new color value is stored in the inspector's color menu, and won't change until I actually change it manually. There are no errors, and the color DOES appear in the inspector, it's just not changed to.
Color values had to be divided by 255 due to Color only accepting values from 0 to 1
So, it will be
color.R/255, color.G/255, color.B/255
Try this :
GameObject.Find("Directional Light").GetComponent<Light>().color = new Color(4, 191, 4, 255);
I am trying to use the solution provided by another SFO link - itextsharp: How to find the fill color of a rectangle
I have implemented the interface IExtRenderListener as per the above article. Everything works fine , however for some of the vectors, I get a NULL value for CurrentFillColor and CurrentStrokeColor. In such situations, I find that the properties ColorSpaceFill and ColorSpaceStroke have some non-NULL values.
What is the prescribed approach in such situations? (itextsharp 5.5.12)
Thanks,
Sau
If you study ISO 32000, you'll discover that colors can be defined in different ways.
When iText shows a StrokeColor or a FillColor value different from null, you can tell if it's a gray color, an RGB color or a CMYK color depending on the size of the array.
However, sometimes you get a ColorSpaceStroke and ColorSpaceFill value instead of a color value that can be interpreted directly. In your case, the color is stored separately as a reusable resource with name /Cs6. You need to examine the resources in this PDF, and look for the color object by its name.
In Visual Studio, please suggest how to make custom color for a control and add it to property-> backColor Section.?
You can type a comma separated RGB value into the BackColor value in the property grid, eg:
150, 250, 70
You can use this method:
Color clr = Color.FromArgb(int alpha, int red, int green, int blue)
If you want this done using some User interface:
You could find out where the custom colors are stored for the current user, and then add one.
Or, create your own UITypeEditor, that contains the colors you want. Probably you have to inherit from Form, and override the BackColor property to add the correct attributes.
Much easier is to just set it in code, using the Argb code from the other answers.
You can not.
What you see is a default editor for Color type (create own control, add there public property of Color type and it will also uses it). Web and System tabs working fine. First tab is a sort of custom color pickup part from standard color pickup dialog.
I think MS fails to make popup editor to show modal dialog (because popup will get closed). =D
Perhaps colors there are taken from Windows color dialog, so you have to arrange it there (perhaps you can use winapi to do that). /shrug
I have made a control in silverlight that has a SolidColorBrush property. In XAML, you can set this to be preexisting Colors such as Black, Yellow, White, etc. I assume there is a TypeConverter that takes the string "Black" and converts it to a Color object and creates a new SolidColorBrush based on this object. I want this functionality to remain, but with the added capability to also accept hex strings to set the color. I would need a TypeConverter for this, correct? Is there a way I can extend from the current one so that I can still pass in color names?
XAML already accepts hex. Eg:
Background="#FF9D661C"
Having the VS Properties pane open while on a XAML element helps indicate possibilities thats aren't necessarily obvious via intelisence (Eg setting Background as hex or a gradiant brush).
As #Ricibob said, the existing converter alreadys works how you want it to. In addition, it looks like all of the built in TypeConverters are sealed, so you can't inherit from them (although there's nothing keeping you from using composition to solve the problem).
I currently load controls at run time, and want to set the color, but not a named color.
I was thinking I need to create a color object , set the color of this then assign it, any direction?
Thanks
You can use Color.FromName() method to set colors :
txt.ForeColor = System.Drawing.Color.FromName("#00B300");
txt.ForeColor = System.Drawing.Color.FromName("red");