So I bought NGUI, I love it, and now I am at the point of pulling my hair out.
I'm making a dynamic main menu that incorporates many menus, fading submenus in and out of the screen.
First of all, I made this class a while back that lets me Hide and Show any object or group of objects.:
using UnityEngine;
using System.Collections;
public class scrFadeChildren : MonoBehaviour {
// Use this for initialization
static public void show(GameObject go, float time)
{
Transform[] arrChildren = go.GetComponentsInChildren<Transform>();
foreach (Transform child in arrChildren)
{
if (child.gameObject.GetComponent<BoxCollider>() != null)
child.gameObject.GetComponent<BoxCollider>().enabled = true;
TweenAlpha ta = TweenAlpha.Begin(child.gameObject,time,1);
ta.tweenGroup = 99;
ta.eventReceiver = child.gameObject;
ta.unclickableOnFinish = false;
}
}
static public void hide(GameObject go,float time)
{
Transform[] arrChildren = go.GetComponentsInChildren<Transform>();
foreach (Transform child in arrChildren)
{
TweenAlpha ta = TweenAlpha.Begin(child.gameObject,time,0);
ta.tweenGroup = 99;
ta.eventReceiver = child.gameObject;
ta.unclickableOnFinish = true;
}
}
}
Unclickableonfinish is a modification that lets me disable the box colliders when an object is being hidden, such that it can't be clicked. (This is preferable to just disabling the object, because disabling prevents the object from being found again using GameObject.Find, which I have had to use plenty of in my situation.)
Usage is as simple as something like:
scrFadeChildren.hide(_guiPlanet,2f);
scrFadeChildren.show(_guiHome,2f);
This works absolutely fine and looks wonderful! HOWEVER: if I use this script on buttons, the buttons' will fade out on hover! And not only that, the colors in the Button Color change to black, such that when hovering over, the button color becomes (0,0,0,1).
And so the crux of this problem, as I seem to have worked out, is that TweenAlpha.Begin will screw up the TweenColors that are used by the Button Color and Button Tween scripts.
My question is just why does this happen? I'd think it's something about the Alpha and Color tweens being related to each other. Things i've tried:
I've tried destroying the TweenAlpha that is created on TweenAlpha.Begin, but even when I destroy it, it appears that there is some memory of the Alpha left because the ButtonTween colors still glitch out on hover.
These little niggles in NGUI are killing me. Any help would be appreciated! Please don't advise to just not use TweenAlpha.Begin and use an animation or whatnot - I don't see how I can have an all purpose Hide and Show function without TweenAlpha.Begin.