Author Topic: UISprite and drawing issues  (Read 1296 times)

The-Arrival

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 29
    • View Profile
UISprite and drawing issues
« on: November 09, 2014, 08:17:13 AM »
Hello,

I'm having issues with my UI-Setup. I'm pretty new to Unity and NGUI so expect some noob-mistakes and try to answer in easy words :)

I wanna have a build menu with blue buttons and the one selected should be orange. If i start the game, the buttons don't get colored or depending what i set as structureIndex, don't get drawn at all.

My Setup is like this:

I set up two buttons for testing. The Sprites linked to the buttons are set to "Sprite Type: Sliced" and "Fill Center: checked" by default in the Inspector. I colored them both in white, cause i wanna set the color through my build-menue script.

The Script ( i just posted the parts concerning the UI issue):

public Color onColor;
public Color offColor;
public UISprite[] buildBtnGraphics;
public int structureIndex;
   
void Start ()
{
   structureIndex = 1;
   UpdateGUI ();
}

public void UpdateGUI ()
{
   for (int i=0; i==buildBtnGraphics.Length; i++)
         {
        buildBtnGraphics .color = offColor;
     }

   buildBtnGraphics [structureIndex].color = onColor;
}

So the variable buildBtnGraphics is giving me an Array in the Inspector, where i can drag´n´drop the sprites in. I tired to use UISlicedSprite[] here, but then i couldn´t drag´n´drop anything in. This is the first thing i can´t get my head around. Why can´t i use UISlicedSprite[] here, if "Sprite Type" is set to sliced. I also tried to set the "Sprite Type" to "simple", but it didn't change anything.

So whenever the player clicks a button, the structureIndex is set to whatever is clicked and the UpdateGUI function is called. The UpdateGUI function should draw every element in the UISprite-Array to the offColor and the one selected (structureIndex) to the onColor.

Funny fact: Both Buttonsprites seem to get treated differently. If i set structureIndex to 0 (first sprite), everything is drawn in white and in the inspector of the sprite (during runtime) no orange is applied. When i set it to 1 (second Buttonsprite), the button is not drawn at all, but in the inspector i see, that the orange color is applied to the button.

So it seems that the hole problem is down to the Sprite-Types (sliced or not?) and how to set them up properly, but i can't figure it out

« Last Edit: November 09, 2014, 08:35:08 AM by The-Arrival »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UISprite and drawing issues
« Reply #1 on: November 09, 2014, 09:18:53 PM »
There is no such thing as a UISlicedSprite. Hasn't been since NGUI 2 days. What version of NGUi are you using?

You shouldn't be doing any of what you're doing either. You should instead listen to OnSelect (bool isSelected), and change the color within.

The-Arrival

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UISprite and drawing issues
« Reply #2 on: November 14, 2014, 12:42:45 PM »
Unfortunately I'm using the free version right now. Sorry, i recognised too late that this forum is only for the standart version.

I'm about to buy myself into the standart version to make it up for my misstake (and because this plug-in is great) :)

So I'm waiting with my other question concerning my problem (and your answer) until i have it.

By the way, i got the method i tried before from this tutorial and in my mind i made totally sense :)

http://cgcookie.com/unity/lessons/3a-turret-placement-hud/

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UISprite and drawing issues
« Reply #3 on: November 15, 2014, 04:27:25 PM »
Button script caches the color of the sprite. Your script should work fine with stand-alone sprites. If you want to use a button script, don't use your script as both would effectively fight for the color, and the button script will win.