Beispiel #1
0
    /// <summary>
    /// loops through all children of parent and attaches a fadeout script
    /// </summary>
    /// <param name="parent"></param>
    private void AttachFadeOut(GameObject parent, bool deactivate = true)
    {
        // loop through all children
        int j = parent.transform.childCount;

        for (int i = 0; i < j; i++)
        {
            // get the child
            GameObject child = parent.transform.GetChild(i).gameObject;

            // skip if disabled
            if (!child.active)
            {
                continue;
            }

            // check if we already have a fade script attached
            TweenFade Twf = child.GetComponent <TweenFade>();

            // call reset if we have one
            if (Twf != null)
            {
                Twf.Reset();
            }

            // attach the tween fade script
            else
            {
                Twf = child.AddComponent <TweenFade>();
            }

            // finish
            Twf.AttachFadeout(Duration.Value, deactivate);


            // NOTE: sliders and progressbars do not fade out the background image
            // I tried to find a work around (the code below attaches a fade script to each background image),
            // BUT, during Fade In, the background images do not reappear. I believe this is a bug in how NGUI
            // handles SetActive (and SetActiveSelf).

            //// continue if NOT progressbar or slider
            //if (child.GetComponent<UISlider>() == null)
            //    continue;

            //// if this is a progressbar or slider, then add one to the background image also
            //AttachFadeOut(child, false);
        }
    }
    /// <summary>
    /// loops through all children of parent and attaches a fade in script
    /// </summary>
    /// <param name="parent"></param>
    private void AttachFadeIn(GameObject parent)
    {
        // activate parent and all children
        NGUITools.SetActive(parent, true);

        // loop through all children
        int j = parent.transform.childCount;

        for (int i = 0; i < j; i++)
        {
            // get the child
            GameObject child = parent.transform.GetChild(i).gameObject;

            // activate the child if disabled
            if (!child.active)
            {
                NGUITools.SetActive(child, true);
            }

            // check if we already have a fade script attached
            TweenFade Twf = child.GetComponent <TweenFade>();

            // call reset if we have one
            if (Twf != null)
            {
                Twf.Reset();
            }

            // attach the tween fade script
            else
            {
                Twf = child.AddComponent <TweenFade>();
            }

            // finish
            Twf.AttachFadeIn(Duration.Value);
        }
    }