Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Semicolon · Aug 19, 2012 at 02:48 PM · colorchangephotoshopdynamically

Creating a photoshop-esque slider for picking colors

Hey there!

I've tried my hands at creating something like this. If you haven't used photoshop and don't understand what's happening from looking at the pictures I'll try to explain it:

There are 3 sliders. Red, green and blue, all of them have a gradient applied to them from Color(0, 0, 0) to COlor(red, green, blue). They also each control the value of their color, so I want the slider to function as a slider would and simply change the background image in real-time.

Here's what I tried (with horrible results)

 Texture2D UpdateSliderTexture(Texture2D texture)
     {
         Texture2D returnTexture = texture;
         for (int y = 0; y < 8; y++)
         {
             for (int x = 0; x < 255; x++)
             {
                 returnTexture.SetPixel(x, y, new Color(colorR * x, colorG * x, colorB * x));
             }
         }
         returnTexture.Apply();
 
         return returnTexture;
     }

Horrible as in it freezes. The documentation told me that Apply() is expensive but I don't know how else I'd go about doing this.

Any ideas? Here's the slider code in case you'd like to know:

 colorR = GUI.HorizontalSlider(new Rect(16, 0, 255, 16), colorR, 0, 255, colorSliderStyle, colorSliderThumb);

I made a gif just to clarify: http://i.imgur.com/LshWC.gif

Edit: I also fixed the broken code... Sorry for the confusion

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Aug 19, 2012 at 03:44 PM 0
Share

umm .. WHAT IS IT you're trying to change?

a 2D square of color? A dinosaur? what ?

avatar image Fattie · Aug 19, 2012 at 03:46 PM 0
Share

FTR this sort of thing is trivial with the beloved 2DToolkit, you just do this:

 yourSprite.color.r = 0.7;

so that's one easy solution.

avatar image Semicolon · Aug 19, 2012 at 03:59 PM 0
Share

A 2d square of color indeed. I thought I gave enough info to convey that, but yes.

avatar image AlucardJay · Aug 19, 2012 at 04:18 PM 0
Share

Color needs values between 0 and 1, try changing your slider values

 colorR = GUI.HorizontalSlider(new Rect(16, 0, 255, 16), colorR, 0.0, 1.0, colorSliderStyle, colorSliderThumb);

http://docs.unity3d.com/Documentation/ScriptReference/Color.html

OR, you could divide the value by 255 in SetPixel

 returnTexture.SetPixel( x, y, new Color(colorR / 255, colorG / 255, colorB / 255) );
avatar image AlucardJay · Aug 19, 2012 at 04:55 PM 0
Share

nice GIF =]

Did you look at changing the slider values from between 0-255 to 0.0-1.0 ?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Semicolon · Aug 19, 2012 at 05:13 PM

Christ now I feel stupid... I changed it to go between 0 and 1 instead. I'm used to XNA and they used 0-255. The crashing also came from me using the wrong format. I changed it to ARGB 32 bit and it worked.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is changing the color of GUIText unavailable in the Free Edition? 1 Answer

Dynamically changing part of a texture v2 1 Answer

On Touch change color 2 Answers

Material doesn't have a color property '_Color' 4 Answers

Change the color of a child 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges