Author Topic: Can you have Toggle in a toggle?  (Read 7540 times)

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Can you have Toggle in a toggle?
« on: October 10, 2013, 04:33:48 AM »
I get this error when i put a toggle in a toggle.


  1. NullReferenceException: Object reference not set to an instance of an object
  2. UIToggle.Set (Boolean state) (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/Interaction/UIToggle.cs:180)
  3. UIToggle.set_value (Boolean value) (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/Interaction/UIToggle.cs:93)
  4. UIToggle.OnClick () (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/Interaction/UIToggle.cs:158)
  5. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  6. UICamera:Notify(GameObject, String, Object) (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/UI/UICamera.cs:730)
  7. UICamera:ProcessTouch(Boolean, Boolean) (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/UI/UICamera.cs:1242)
  8. UICamera:ProcessMouse() (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/UI/UICamera.cs:996)
  9. UICamera:Update() (at C:/Users/k/Documents/GS/Assets/NGUI/Scripts/UI/UICamera.cs:851)

Thanks
« Last Edit: October 14, 2013, 07:52:40 PM by kuniojp »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #1 on: October 10, 2013, 05:09:29 AM »
Yo, dawg. I heard you like toggles, so I put a toggle in your toggle so you can toggle as you toggle!

Had to say it. :D

Obvious question is... what are you trying to do and why would you put a toggle in a toggle?

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #2 on: October 10, 2013, 09:58:01 AM »
Quote
Yo, dawg. I heard you like toggles, so I put a toggle in your toggle so you can toggle as you toggle!
;D





This is what i am trying to do.

The bottom Blue, Green, Yellow button, (toggle change button icon when press),
Will controls the Red area (toggle panel hide and show, control by Blue, Green, Yellow button)

The light blue and white button will toggle panel hide and show contents of the black drag-able button contents.
(The light blue and white button needs to be toggle button too, means if white turns on, light blue turn off vise versa)

Thanks in advance.
« Last Edit: October 10, 2013, 04:08:16 PM by kuniojp »

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #3 on: October 10, 2013, 06:09:11 PM »
Or a tab in a tab to make things simpler, tab is made with the toggle script right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #4 on: October 11, 2013, 08:14:16 AM »
Oh I think it's the same as another post I addressed a few days ago. It's solved the same way in the latest Pro version. You can fix it on your end like so:
  1.                         // Uncheck all other toggles
  2.                         if (group != 0 && state)
  3.                         {
  4.                                 for (int i = 0, imax = list.size; i < imax; )
  5.                                 {
  6.                                         UIToggle cb = list[i];
  7.                                         if (cb != this && cb.group == group) cb.Set(false);
  8.                                        
  9.                                         if (list.size != imax)
  10.                                         {
  11.                                                 imax = list.size;
  12.                                                 i = 0;
  13.                                         }
  14.                                         else ++i;
  15.                                 }
  16.                         }
This code replaces the same section around line 180 you had trouble with.

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #5 on: October 14, 2013, 08:01:11 PM »
Thanks for the toggle you let me put in my toggle cause now i get to toggle in a toggle  ;D

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #6 on: October 22, 2013, 01:04:38 AM »
Sorry,
I have another problem.
You might have already answer this but after a lot of searching in this forum and googling,
I couldn't find an answer.

After altering the script, I was able to put a set of taps in a tap,
But after hiding the (inner) taps(toggle),
when i came back to it, the buttons(toggle) doesn't work anymore?
(Works the first round but when I recall it again after hiding, the button(toggle) doesn't work anymore)

Thanks
« Last Edit: October 22, 2013, 02:05:50 AM by kuniojp »

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #7 on: October 22, 2013, 09:05:42 PM »
Or anyone find a link to the solution please let me know, Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #8 on: October 22, 2013, 11:03:30 PM »
Taps in a tap? I am not sure what you mean.

ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #9 on: October 23, 2013, 02:11:40 AM »
Ok,forget the taps in taps,
I have succeed in putting a toggle in toggle by adding the script you have provided.
The problem is it will work the first round, but if you go to other toggled scene and than back to the scene again,
the toggle in the toggled scene won't work anymore.

Let's say:
1.Go Scene1(Contains toggle inside),works.
2.Go to Scene2
3.Go back to Scene1, (Toggle no longer works)

PS: Scene1 and Scene2 is controlled by Toggled button.

npritchard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #10 on: October 23, 2013, 04:03:06 PM »
I was also getting a NullReferenceException, but I've now adjusted my code to include ArenMook's changes and it works now. Thanks Aren!

kunionjp - Have you looked at the contents of

  1. /// <summary>
  2. /// List of all the active toggles currently in the scene.
  3. /// </summary>
  4. static public BetterList<UIToggle> list = new BetterList<UIToggle>();
  5.  

Within UIToggle.cs?

Bearing in mind that the active Toggle list is static, that would suggest a UIToggle reference is being retained in between Scene changes, and I would guess that its "OnDestroy" isn't being called.


ikuniojp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Can you have Toggle in a toggle?
« Reply #11 on: November 08, 2013, 02:07:59 AM »
I was also getting a NullReferenceException, but I've now adjusted my code to include ArenMook's changes and it works now. Thanks Aren!

kunionjp - Have you looked at the contents of

  1. /// <summary>
  2. /// List of all the active toggles currently in the scene.
  3. /// </summary>
  4. static public BetterList<UIToggle> list = new BetterList<UIToggle>();
  5.  

Within UIToggle.cs?

Bearing in mind that the active Toggle list is static, that would suggest a UIToggle reference is being retained in between Scene changes, and I would guess that its "OnDestroy" isn't being called.

Hi,
Thanks for the legs up! ;)
But I still haven't found a correct way of doing it,
So I just disable the

//void OnDisable () { list.Remove(this); } on line 100 on the UIToggle.cs script.

Please let me know if anyone has a better way on how to preserve the groups of the toggles when disabled.

Thanks