Author Topic: Dynamically added buttons and AlphaFade not jiving?  (Read 2685 times)

mvesich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Dynamically added buttons and AlphaFade not jiving?
« on: July 17, 2013, 04:01:23 PM »
[Edited] Sorry so long on 1st pass, tried to shorten it.

My app has multiple menus; 1st determines the contents of the 2nd.

  • The 1st menu makes a selection, then fades out and works every time.
  • The selection builds content of the 2nd menu adding "button" Prefabs to a uigrid. Buttons are created (per hierarchy), but don't show on initial display.
  • I'm using TweenAlpha to fade menus in and out. This works correctly on everything except the grid with the buttons.
  • The first time the 2nd menu fades in, only the background (UISprite) shows, NO buttons.
  • If I click the UIScrollBar, on this initial use, the buttons suddenly appear (no fade, just show up as if they were refreshed).
  • The second time the menu fades in, it all works.
  • NOTE: When running the code, I can watch panels enable, buttons created, and Alpha change acorrectly. But why can't I see the buttons?

I've attached screen shots of the post-Fade In with no buttons, and the button shown after clicking the Scroll Bar.

Can anyone point me in the right direction?

Question: If I''m using the NGUI TweenAlpha script, and "Play" it forward. Shouldn't it fade all the child panels under it?


Project Hierarchy (misbehaving menu)
* uipanelTrainingSet  Transform_Position_Z = 0
  - Background  Transform_Position_Z = 0  <UISprite>
  - uidragTrainingSet  Transform_Position_Z = -1  <UIPanel>, <UIDraggable Panel>, <TweenAlpha>
    - uigridTrainingSet  Transform_Position_Z = 0  <UIGrid>
      - Button(s)  Transform_Position_Z = 0  <Box Collider>, <UIDrag Panel Contents>, <UIButton Sound>, <Proprietary script>
        - uispriteButton  Transform_Position_Z = 0  <UISprite>
        - Name  Transform_Position_Z = -1  <UILabel>
  - uiscrollTrainingSet <UIPanel>, <TweenAlpha>
        - uispriteButton  Transform_Position_Z = -1  <UISprite>
    - Background  Transform_Position_Z = 0  <UITiled Sprite>
    - Foreground  Transform_Position_Z = 0  <UITiled Sprite>
« Last Edit: July 17, 2013, 09:39:57 PM by mvesich »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamically added buttons and AlphaFade not jiving?
« Reply #1 on: July 18, 2013, 04:34:21 AM »
That's due to your positioning of buttons vs positioning of the clipped area. Show the menu in the editor (if you dynamically add buttons, just drag & drop instantiate the prefab a couple of times as if you were doing it at run-time, test, then delete them later). You should see the same result as at run-time. Adjust the clip rect -- there is also a "reposition now" checkbox that might help you.

mvesich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Dynamically added buttons and AlphaFade not jiving?
« Reply #2 on: July 18, 2013, 11:22:10 AM »
Ah! So it was that I'm an inexperienced noob.  I was worried about the Z and depth all this time and overlooked the simplest possibility.  ::)

Perfect!

Thank you ArenMook! Great product, great advice!!