Beispiel #1
0
    /// <summary>
    /// We want to receive drag events from the thumb.
    /// </summary>

    void Start()
    {
        Init();

        if (Application.isPlaying && thumb != null && thumb.collider != null)
        {
            NGUIEventListener listener = NGUIEventListener.Get(thumb.gameObject);
            listener.onPress += OnPressThumb;
            listener.onDrag  += OnDragThumb;
        }
        Set(rawValue, true);
    }
Beispiel #2
0
    /// <summary>
    /// Register the event listeners.
    /// </summary>

    void Start()
    {
        if (background != null && background.collider != null)
        {
            NGUIEventListener listener = NGUIEventListener.Get(background.gameObject);
            listener.onPress += OnPressBackground;
            listener.onDrag  += OnDragBackground;
        }

        if (foreground != null && foreground.collider != null)
        {
            NGUIEventListener listener = NGUIEventListener.Get(foreground.gameObject);
            listener.onPress += OnPressForeground;
            listener.onDrag  += OnDragForeground;
        }
        ForceUpdate();
    }
Beispiel #3
0
    protected override void OnAwake()
    {
        ThreeObjectState = EnumThreeObjectState.LoadOver;

        base.OnAwake();

        NGUIEventListener.Get(this.transform.Find("Indoor").gameObject).SetEventHandle(EnumTouchEventType.OnClick, Indoor);

        NGUIEventListener.Get(this.transform.Find("ApartmentLayout").gameObject).SetEventHandle(EnumTouchEventType.OnClick, ApartmentLayout);

        NGUIEventListener.Get(this.transform.Find("Monomer").gameObject).SetEventHandle(EnumTouchEventType.OnClick, Monomer);

        NGUIEventListener.Get(this.transform.Find("Gardens").gameObject).SetEventHandle(EnumTouchEventType.OnClick, Gardens);

        NGUIEventListener.Get(this.transform.Find("Project").gameObject).SetEventHandle(EnumTouchEventType.OnClick, Project);

        NGUIEventListener.Get(this.transform.Find("Region").gameObject).SetEventHandle(EnumTouchEventType.OnClick, Region);

        NGUIEventListener.Get(this.transform.Find("OnClick").gameObject).SetEventHandle(EnumTouchEventType.OnClick, OnClickAmination);
    }
Beispiel #4
0
    /// <summary>
    /// Display the drop-down list when the game object gets clicked on.
    /// </summary>

    void OnClick()
    {
        if (mChild == null && atlas != null && font != null && items.Count > 0)
        {
            mLabelList.Clear();

            // Disable the navigation script
            handleEvents = true;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = NGUIPanel.Find(transform, true);
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds    bounds  = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            Transform t = mChild.transform;
            t.parent        = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = NGUIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;

            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = NGUIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            NGUIAtlas.Sprite hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float            hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin;
            float            fontScale = font.size * font.pixelSize * textScale;
            float            x = 0f, y = -padding.y;
            List <NGUILabel> labels = new List <NGUILabel>();

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(mChild);
                lbl.pivot = NGUIWidget.Pivot.TopLeft;
                lbl.font  = font;
                lbl.text  = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
                lbl.color = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f);
                lbl.MakePixelPerfect();

                if (textScale != 1f)
                {
                    Vector3 scale = lbl.cachedTransform.localScale;
                    lbl.cachedTransform.localScale = scale * textScale;
                }
                labels.Add(lbl);

                y -= fontScale;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.relativeSize.x * fontScale);

                // Add an event listener
                NGUIEventListener listener = NGUIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s)
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);

            Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f);
            Vector3 bcSize   = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                NGUILabel   lbl = labels[i];
                BoxCollider bc  = NGUITools.AddWidgetCollider(lbl.gameObject);
                bcCenter.z = bc.center.z;
                bc.center  = bcCenter;
                bc.size    = bcSize;
            }

            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.cachedTransform.localScale = new Vector3(x, -y + bgPadding.y, 1f);

            // Scale the highlight sprite to envelop a single item
            mHighlight.cachedTransform.localScale = new Vector3(
                x - (bgPadding.x + padding.x) * 2f + (hlsp.inner.xMin - hlsp.outer.xMin) * 2f,
                fontScale + hlspHeight * 2f, 1f);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                NGUICamera cam = NGUICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + fontScale;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i)
                {
                    Animate(labels[i], placeAbove, bottom);
                }
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else
        {
            OnSelect(false);
        }
    }