Welcome,
Guest
. Please
login
or
register
.
February 11, 2025, 09:22:42 AM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Make Panel and Widgets invisible without deactivating them
« previous
next »
Print
Pages: [
1
]
Author
Topic: Make Panel and Widgets invisible without deactivating them (Read 3071 times)
Joss
Guest
Make Panel and Widgets invisible without deactivating them
«
on:
June 25, 2012, 08:50:26 PM »
Is this possible? Or should I just move them somewhere off screen?
Logged
dlewis
Guest
Re: Make Panel and Widgets invisible without deactivating them
«
Reply #1 on:
June 25, 2012, 09:00:57 PM »
You could try turning the alpha all the way to 1 on all the child objects of the panel (Although if you have any objects which have a variable alpha then this won't work well at all).
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Make Panel and Widgets invisible without deactivating them
«
Reply #2 on:
June 25, 2012, 09:25:18 PM »
Moving them off-screen would be advisable.
Logged
Joss
Guest
Re: Make Panel and Widgets invisible without deactivating them
«
Reply #3 on:
June 26, 2012, 09:09:12 AM »
Thanks for that. I will do the movement option. In the meantime (prior to reading your response). I botched together an extension method for UIPanel (based on your UIPanel code). It seems to work for what I want at the moment (I have widgets being updated while the Panel is "deactivated") but I have only tested it briefly and with the single use case. I'm not aware of if there is any reason for not using Extension methods - so if you know of any; please let me know.
using
UnityEngine
;
using
System.Collections
;
using
System
;
public
static
class
UIPanelExtensions
{
/// <summary>
/// toggles a panels visibility while till allowing it to do stuff
/// </summary>
/// <remarks>
/// <b>Usage</b>
/// <code>
/// myPanel.TogglePanelState();
/// </code>
/// </remarks>
public
static
void
TogglePanelState
(
this
UIPanel panel
)
{
if
(
!
panel
.
gameObject
.
active
)
{
panel
.
gameObject
.
active
=
true
;
SetActiveState
(
panel
.
transform
,
true
)
;
}
else
{
SetActiveState
(
panel
.
transform
,
false
)
;
panel
.
gameObject
.
active
=
false
;
}
}
/// <summary>
/// This I swiped from UIPanel.cs
/// </summary>
static
void
SetActiveState
(
Transform t,
bool
state
)
{
for
(
int
i
=
0
;
i
<
t
.
childCount
;
++
i
)
{
Transform child
=
t
.
GetChild
(
i
)
;
//if (child.GetComponent<UIPanel>() != null) continue;
if
(
state
)
{
child
.
gameObject
.
active
=
true
;
SetActiveState
(
child,
true
)
;
}
else
{
SetActiveState
(
child,
false
)
;
child
.
gameObject
.
active
=
false
;
}
}
}
}
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Make Panel and Widgets invisible without deactivating them
«
Reply #4 on:
June 26, 2012, 04:40:25 PM »
Look into NGUITools.SetActive. It already does what you just coded.
Logged
Joss
Guest
Re: Make Panel and Widgets invisible without deactivating them
«
Reply #5 on:
June 26, 2012, 04:45:25 PM »
I will - i just like extension methods - they make things nice and neat - I think I took the code from there (or the UIPanel) - so i didn't really code anything. Many thanks
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Make Panel and Widgets invisible without deactivating them