• 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
1
Question by Cyrille-Paulhiac · Apr 22, 2017 at 08:32 PM · uiguitexturebuttoncolor

How to have correct color on imGUI Buttons (as dynamic textures) avoiding multiply effect ?

Hi, I am creating my own "button look" without using texture files, and I'm struggling with their display (Unity Editor Custom Window) with incorrect color values. They seems to be multiplied by some factor (maybe darken unity Editor skin color ?), and I can't find a way to retrieve my exact colors.

MultiplyEffect

Here are a snippet of what I am doing, simplified of course. I am using a picker to pick a color, and then the button that should be drawn with it has another color. Thanks for any help on this ! On a GUIMultiplyEffect_EditorWindow.cs file :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 public class GUIMultiplyEffect_EditorWindow :EditorWindow
     {
     Color buttonColor = Color.gray;
 
     [MenuItem("Window/GUIMultiply : EditorWindow", false, 42)]
     public static void ShowWindow()
         {
     EditorWindow.GetWindow(typeof(GUIMultiplyEffect_EditorWindow));
         }
 
 
     void OnGUI()
         {
         buttonColor = EditorGUILayout.ColorField(buttonColor);
 
         GUIStyle customButtonStyle = new GUIStyle(GUI.skin.button);
 
         Texture2D customBackgroundTexture = new Texture2D(2, 2);
         customBackgroundTexture.SetPixels(new Color[4] { buttonColor, buttonColor, buttonColor, buttonColor });
         customBackgroundTexture.Apply();
 
         customButtonStyle.normal.background = customBackgroundTexture;
 
         if (GUILayout.Button("My Button", customButtonStyle))
             {
             }
         }
     }







guimultiplyeffect.png (3.2 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Apr 23, 2017 at 10:26 AM

Make sure your color is completely opaque (alpha of 1.0) and you don't set GUI.color to anything else than "white". To be on the safe side you may want to manually set GUi.color to "Color.white".

Of course when in run-mode inside the editor, all the Editor GUI get additionally "tinted" with the play-mode-tint color which you set in the editor preferences.

edit
I just went ahead and used your code 1:1. This is my result:

Example

As you can see the displayed color is 100% the color i selected in the color field. I actually made a screenshot, cropped the editorwindow and checked the colors inside ms paint with the pipette tool. Both red areas are 100% red. Though the color picker has a frame around which blends slightly at the border. However the button itself is completely red as expected.

If you expected something different you should have said that in your question. You create a 2x2 texture that has a solid color and that's what is displayed.


guicolor.png (3.7 kB)
Comment
Add comment · Show 4 · 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
avatar image Cyrille-Paulhiac · Apr 24, 2017 at 12:41 PM 0
Share

Thanks for taking the time for answering me. I already tried overwriting both GUI.color and GUI.backgroundColor without any success of matching both colors T.T

avatar image Bunny83 Cyrille-Paulhiac · Apr 24, 2017 at 04:28 PM 0
Share

I've edited my answer and included my test results.

Unfortunately it seem that UA does no longer allow image uploads in comments so i had to include it in my answer. $$anonymous$$aybe it always has been that way though i can't remember ^^.

avatar image Cyrille-Paulhiac Bunny83 · Apr 24, 2017 at 04:58 PM 0
Share

Thanks again. You're right with a pure red value, but in my measures, smaller values in channels are modified. (color picked) => color measured Professional skin : 255,128,128 => 255,55,55 and Personnal skin : 255,128,128 => 255,55,55

(the 2x2 texture is only of the purpose to reproduce the issue of course)

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

144 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use part of an image for a button 1 Answer

Gathering GameObjects and then creating a button for each GameObject?? 2 Answers

Is there a better way to access the single active Toggle in a ToggleGroup? 4 Answers

Is this code enough to crash Unity? 1 Answer

Edit the color/properties of Gui border 0 Answers


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