/// <summary>
    /// Create a popup list or a menu.
    /// </summary>

    void CreatePopup(GameObject go, bool isDropDown)
    {
        if (NGUISettings.atlas != null)
        {
            NGUIEditorTools.DrawSpriteField("Foreground", "Foreground sprite (shown on the button)", NGUISettings.atlas, mListFG, OnListFG, GUILayout.Width(120f));
            NGUIEditorTools.DrawSpriteField("Background", "Background sprite (envelops the options)", NGUISettings.atlas, mListBG, OnListBG, GUILayout.Width(120f));
            NGUIEditorTools.DrawSpriteField("Highlight", "Sprite used to highlight the selected option", NGUISettings.atlas, mListHL, OnListHL, GUILayout.Width(120f));
        }

        if (ShouldCreate(go, NGUISettings.atlas != null && NGUISettings.ambigiousFont != null))
        {
            int depth = NGUITools.CalculateNextDepth(go);
            go      = NGUITools.AddChild(go);
            go.name = isDropDown ? "Popup List" : "Popup Menu";

            UISpriteData sphl = NGUISettings.atlas.GetSprite(mListHL);
            UISpriteData spfg = NGUISettings.atlas.GetSprite(mListFG);

            Vector2 hlPadding = new Vector2(Mathf.Max(4f, sphl.paddingLeft), Mathf.Max(4f, sphl.paddingTop));
            Vector2 fgPadding = new Vector2(Mathf.Max(4f, spfg.paddingLeft), Mathf.Max(4f, spfg.paddingTop));

            // Background sprite
            UISprite sprite = NGUITools.AddSprite(go, NGUISettings.atlas, mListFG);
            sprite.depth  = depth;
            sprite.atlas  = NGUISettings.atlas;
            sprite.pivot  = UIWidget.Pivot.Left;
            sprite.width  = Mathf.RoundToInt(150f + fgPadding.x * 2f);
            sprite.height = Mathf.RoundToInt(NGUISettings.fontSize + fgPadding.y * 2f);
            sprite.transform.localPosition = Vector3.zero;
            sprite.MakePixelPerfect();

            // Text label
            UILabel lbl = NGUITools.AddWidget <UILabel>(go);
            lbl.ambigiousFont = NGUISettings.ambigiousFont;
            lbl.fontSize      = NGUISettings.fontSize;
            lbl.fontStyle     = NGUISettings.fontStyle;
            lbl.text          = go.name;
            lbl.pivot         = UIWidget.Pivot.Left;
            lbl.cachedTransform.localPosition = new Vector3(fgPadding.x, 0f, 0f);
            lbl.AssumeNaturalSize();

            // Add a collider
            NGUITools.AddWidgetCollider(go);

            // Add the popup list
            UIPopupList list = go.AddComponent <UIPopupList>();
            list.atlas            = NGUISettings.atlas;
            list.ambigiousFont    = NGUISettings.ambigiousFont;
            list.fontSize         = NGUISettings.fontSize;
            list.fontStyle        = NGUISettings.fontStyle;
            list.backgroundSprite = mListBG;
            list.highlightSprite  = mListHL;
            list.padding          = hlPadding;
            if (isDropDown)
            {
                EventDelegate.Add(list.onChange, lbl.SetCurrentSelection);
            }
            for (int i = 0; i < 5; ++i)
            {
                list.items.Add(isDropDown ? ("List Option " + i) : ("Menu Option " + i));
            }

            // Add the scripts
            go.AddComponent <UIButton>().tweenTarget = sprite.gameObject;
            go.AddComponent <UIPlaySound>();

            Selection.activeGameObject = go;
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Perform any logic related to starting the drag & drop operation.
    /// </summary>

    protected virtual void OnDragDropStart()
    {
        // Automatically disable the scroll view
        if (mDragScrollView != null)
        {
            mDragScrollView.enabled = false;
        }

        // Disable the collider so that it doesn't intercept events
        if (mButton != null)
        {
            mButton.isEnabled = false;
        }
        else if (mCollider != null)
        {
            mCollider.enabled = false;
        }

        mTouchID = UICamera.currentTouchID;
        mParent  = mTrans.parent;
        mRoot    = NGUITools.FindInParents <UIRoot>(mParent);
        mGrid    = NGUITools.FindInParents <UIGrid>(mParent);
        mTable   = NGUITools.FindInParents <UITable>(mParent);

        // Re-parent the item
        if (UIDragDropRoot.root != null)
        {
            mTrans.parent = UIDragDropRoot.root;
        }

        Vector3 pos = mTrans.localPosition;

        pos.z = 0f;
        mTrans.localPosition = pos;

        TweenPosition tp = GetComponent <TweenPosition>();

        if (tp != null)
        {
            tp.enabled = false;
        }

        SpringPosition sp = GetComponent <SpringPosition>();

        if (sp != null)
        {
            sp.enabled = false;
        }

        // Notify the widgets that the parent has changed
        NGUITools.MarkParentAsChanged(gameObject);

        if (mTable != null)
        {
            mTable.repositionNow = true;
        }
        if (mGrid != null)
        {
            mGrid.repositionNow = true;
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Add commonly NGUI context menu options.
    /// </summary>

    static public void AddCommonItems(GameObject target)
    {
        if (target != null)
        {
            UIWidget widget = target.GetComponent <UIWidget>();

            string myName = string.Format("Selected {0}", (widget != null) ? NGUITools.GetTypeName(widget) : "Object");

            AddItem(myName + "/Bring to Front", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.BringForward(Selection.gameObjects[i]);
                }
            },
                    null);

            AddItem(myName + "/Push to Back", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.PushBack(Selection.gameObjects[i]);
                }
            },
                    null);

            AddItem(myName + "/Nudge Forward", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.AdjustDepth(Selection.gameObjects[i], 1);
                }
            },
                    null);

            AddItem(myName + "/Nudge Back", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.AdjustDepth(Selection.gameObjects[i], -1);
                }
            },
                    null);

            if (widget != null)
            {
                NGUIContextMenu.AddSeparator(myName + "/");

                AddItem(myName + "/Make Pixel-Perfect", false, OnMakePixelPerfect, Selection.activeTransform);

                if (target.GetComponent <BoxCollider>() != null)
                {
                    AddItem(myName + "/Reset Collider Size", false, OnBoxCollider, target);
                }
            }

            NGUIContextMenu.AddSeparator(myName + "/");
            AddItem(myName + "/Delete", false, OnDelete, target);
            NGUIContextMenu.AddSeparator("");

            if (Selection.activeTransform.parent != null && widget != null)
            {
                AddChildWidget("Create/Sprite/Child", false, NGUISettings.AddSprite);
                AddChildWidget("Create/Label/Child", false, NGUISettings.AddLabel);
                AddChildWidget("Create/Invisible Widget/Child", false, NGUISettings.AddWidget);
                AddChildWidget("Create/Simple Texture/Child", false, NGUISettings.AddTexture);
                AddChildWidget("Create/Unity 2D Sprite/Child", false, NGUISettings.Add2DSprite);
                AddSiblingWidget("Create/Sprite/Sibling", false, NGUISettings.AddSprite);
                AddSiblingWidget("Create/Label/Sibling", false, NGUISettings.AddLabel);
                AddSiblingWidget("Create/Invisible Widget/Sibling", false, NGUISettings.AddWidget);
                AddSiblingWidget("Create/Simple Texture/Sibling", false, NGUISettings.AddTexture);
                AddSiblingWidget("Create/Unity 2D Sprite/Sibling", false, NGUISettings.Add2DSprite);
            }
            else
            {
                AddChildWidget("Create/Sprite", false, NGUISettings.AddSprite);
                AddChildWidget("Create/Label", false, NGUISettings.AddLabel);
                AddChildWidget("Create/Invisible Widget", false, NGUISettings.AddWidget);
                AddChildWidget("Create/Simple Texture", false, NGUISettings.AddTexture);
                AddChildWidget("Create/Unity 2D Sprite", false, NGUISettings.Add2DSprite);
            }

            NGUIContextMenu.AddSeparator("Create/");

            AddItem("Create/Panel", false, AddPanel, target);
            AddItem("Create/Scroll View", false, AddScrollView, target);
            AddItem("Create/Grid", false, AddChild <UIGrid>, target);
            AddItem("Create/Table", false, AddChild <UITable>, target);
            AddItem("Create/Anchor (Legacy)", false, AddChild <UIAnchor>, target);

            if (target.GetComponent <UIPanel>() != null)
            {
                if (target.GetComponent <UIScrollView>() == null)
                {
                    AddItem("Attach/Scroll View", false, Attach, typeof(UIScrollView));
                    NGUIContextMenu.AddSeparator("Attach/");
                }
            }
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
            else if (target.collider == null && target.GetComponent <Collider2D>() == null)
#else
            else if (target.GetComponent <Collider>() == null && target.GetComponent <Collider2D>() == null)
#endif
            {
                AddItem("Attach/Box Collider", false, AttachCollider, null);
                NGUIContextMenu.AddSeparator("Attach/");
            }

            bool         header     = false;
            UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(target);

            if (scrollView != null)
            {
                if (scrollView.GetComponentInChildren <UICenterOnChild>() == null)
                {
                    AddItem("Attach/Center Scroll View on Child", false, Attach, typeof(UICenterOnChild));
                    header = true;
                }
            }

#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
            if (target.collider != null || target.GetComponent <Collider2D>() != null)
#else
            if (target.GetComponent <Collider>() != null || target.GetComponent <Collider2D>() != null)
#endif
            {
                if (scrollView != null)
                {
                    if (target.GetComponent <UIDragScrollView>() == null)
                    {
                        AddItem("Attach/Drag Scroll View", false, Attach, typeof(UIDragScrollView));
                        header = true;
                    }

                    if (target.GetComponent <UICenterOnClick>() == null && NGUITools.FindInParents <UICenterOnChild>(target) != null)
                    {
                        AddItem("Attach/Center Scroll View on Click", false, Attach, typeof(UICenterOnClick));
                        header = true;
                    }
                }

                if (header)
                {
                    NGUIContextMenu.AddSeparator("Attach/");
                }

                AddItem("Attach/Button Script", false, Attach, typeof(UIButton));
                AddItem("Attach/Toggle Script", false, Attach, typeof(UIToggle));
                AddItem("Attach/Slider Script", false, Attach, typeof(UISlider));
                AddItem("Attach/Scroll Bar Script", false, Attach, typeof(UIScrollBar));
                AddItem("Attach/Progress Bar Script", false, Attach, typeof(UISlider));
                AddItem("Attach/Popup List Script", false, Attach, typeof(UIPopupList));
                AddItem("Attach/Input Field Script", false, Attach, typeof(UIInput));
                NGUIContextMenu.AddSeparator("Attach/");

                if (target.GetComponent <UIDragResize>() == null)
                {
                    AddItem("Attach/Drag Resize Script", false, Attach, typeof(UIDragResize));
                }

                if (target.GetComponent <UIDragScrollView>() == null)
                {
                    for (int i = 0; i < UIPanel.list.Count; ++i)
                    {
                        UIPanel pan = UIPanel.list[i];
                        if (pan.clipping == UIDrawCall.Clipping.None)
                        {
                            continue;
                        }

                        UIScrollView dr = pan.GetComponent <UIScrollView>();
                        if (dr == null)
                        {
                            continue;
                        }

                        AddItem("Attach/Drag Scroll View", false, delegate(object obj)
                                { target.AddComponent <UIDragScrollView>().scrollView = dr; }, null);

                        header = true;
                        break;
                    }
                }

                AddItem("Attach/Key Binding Script", false, Attach, typeof(UIKeyBinding));

                if (target.GetComponent <UIKeyNavigation>() == null)
                {
                    AddItem("Attach/Key Navigation Script", false, Attach, typeof(UIKeyNavigation));
                }

                NGUIContextMenu.AddSeparator("Attach/");

                AddItem("Attach/Play Tween Script", false, Attach, typeof(UIPlayTween));
                AddItem("Attach/Play Animation Script", false, Attach, typeof(UIPlayAnimation));
                AddItem("Attach/Play Sound Script", false, Attach, typeof(UIPlaySound));
            }

            AddItem("Attach/Property Binding", false, Attach, typeof(PropertyBinding));

            if (target.GetComponent <UILocalize>() == null)
            {
                AddItem("Attach/Localization Script", false, Attach, typeof(UILocalize));
            }

            if (widget != null)
            {
                AddMissingItem <TweenAlpha>(target, "Tween/Alpha");
                AddMissingItem <TweenColor>(target, "Tween/Color");
                AddMissingItem <TweenWidth>(target, "Tween/Width");
                AddMissingItem <TweenHeight>(target, "Tween/Height");
            }
            else if (target.GetComponent <UIPanel>() != null)
            {
                AddMissingItem <TweenAlpha>(target, "Tween/Alpha");
            }

            NGUIContextMenu.AddSeparator("Tween/");

            AddMissingItem <TweenPosition>(target, "Tween/Position");
            AddMissingItem <TweenRotation>(target, "Tween/Rotation");
            AddMissingItem <TweenScale>(target, "Tween/Scale");
            AddMissingItem <TweenTransform>(target, "Tween/Transform");

            if (target.GetComponent <AudioSource>() != null)
            {
                AddMissingItem <TweenVolume>(target, "Tween/Volume");
            }

            if (target.GetComponent <Camera>() != null)
            {
                AddMissingItem <TweenFOV>(target, "Tween/Field of View");
                AddMissingItem <TweenOrthoSize>(target, "Tween/Orthographic Size");
            }
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Update the visual text label.
    /// </summary>

    protected void UpdateLabel()
    {
        if (label != null)
        {
            if (mDoInit)
            {
                Init();
            }
            bool   selected = isSelected;
            string fullText = value;
            bool   isEmpty  = string.IsNullOrEmpty(fullText) && string.IsNullOrEmpty(Input.compositionString);
            label.color = (isEmpty && !selected) ? mDefaultColor : activeTextColor;
            string processed;

            if (isEmpty)
            {
                processed = selected ? "" : mDefaultText;
                RestoreLabelPivot();
            }
            else
            {
                if (inputType == InputType.Password)
                {
                    processed = "";
                    for (int i = 0, imax = fullText.Length; i < imax; ++i)
                    {
                        processed += "*";
                    }
                }
                else
                {
                    processed = fullText;
                }

                // Start with text leading up to the selection
                int    selPos = selected ? Mathf.Min(processed.Length, cursorPosition) : 0;
                string left   = processed.Substring(0, selPos);

                // Append the composition string and the cursor character
                if (selected)
                {
                    left += Input.compositionString;
                }

                // Append the text from the selection onwards
                processed = left + processed.Substring(selPos, processed.Length - selPos);

                // Clamped content needs to be adjusted further
                if (selected && label.overflowMethod == UILabel.Overflow.ClampContent)
                {
                    // Determine what will actually fit into the given line
                    int offset = label.CalculateOffsetToFit(processed);

                    if (offset == 0)
                    {
                        mDrawStart = 0;
                        RestoreLabelPivot();
                    }
                    else if (selPos < mDrawStart)
                    {
                        mDrawStart = selPos;
                        SetPivotToLeft();
                    }
                    else if (offset < mDrawStart)
                    {
                        mDrawStart = offset;
                        SetPivotToLeft();
                    }
                    else
                    {
                        offset = label.CalculateOffsetToFit(processed.Substring(0, selPos));

                        if (offset > mDrawStart)
                        {
                            mDrawStart = offset;
                            SetPivotToRight();
                        }
                    }

                    // If necessary, trim the front
                    if (mDrawStart != 0)
                    {
                        processed = processed.Substring(mDrawStart, processed.Length - mDrawStart);
                    }
                }
                else
                {
                    mDrawStart = 0;
                    RestoreLabelPivot();
                }
            }

            label.text = processed;
#if !MOBILE
            if (selected)
            {
                int start = mSelectionStart - mDrawStart;
                int end   = mSelectionEnd - mDrawStart;

                // Blank texture used by selection and caret
                if (mBlankTex == null)
                {
                    mBlankTex = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                    for (int y = 0; y < 2; ++y)
                    {
                        for (int x = 0; x < 2; ++x)
                        {
                            mBlankTex.SetPixel(x, y, Color.white);
                        }
                    }
                    mBlankTex.Apply();
                }

                // Create the selection highlight
                if (start != end)
                {
                    if (mHighlight == null)
                    {
                        mHighlight              = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                        mHighlight.name         = "Input Highlight";
                        mHighlight.mainTexture  = mBlankTex;
                        mHighlight.fillGeometry = false;
                        mHighlight.pivot        = label.pivot;
                        mHighlight.SetAnchor(label.cachedTransform);
                    }
                    else
                    {
                        mHighlight.pivot = label.pivot;
                        mHighlight.MarkAsChanged();
                    }
                }

                // Create the caret
                if (mCaret == null)
                {
                    mCaret              = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                    mCaret.name         = "Input Caret";
                    mCaret.mainTexture  = mBlankTex;
                    mCaret.fillGeometry = false;
                    mCaret.pivot        = label.pivot;
                    mCaret.SetAnchor(label.cachedTransform);
                }
                else
                {
                    mCaret.pivot = label.pivot;
                    mCaret.MarkAsChanged();
                    mCaret.enabled = true;
                }

                // Fill the selection
                if (start != end)
                {
                    label.PrintOverlay(start, end, mCaret.geometry, mHighlight.geometry, caretColor, selectionColor);
                    mHighlight.enabled = mHighlight.geometry.hasVertices;
                }
                else
                {
                    label.PrintOverlay(start, end, mCaret.geometry, null, caretColor, selectionColor);
                    if (mHighlight != null)
                    {
                        mHighlight.enabled = false;
                    }
                }

                // Reset the blinking time
                mNextBlink = RealTime.time + 0.5f;
            }
            else
            {
                Cleanup();
            }
#endif
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Set the widget's rectangle.
    /// </summary>

    public override void SetRect(float x, float y, float width, float height)
    {
        Vector2 po = pivotOffset;

        float fx = Mathf.Lerp(x, x + width, po.x);
        float fy = Mathf.Lerp(y, y + height, po.y);

        int finalWidth  = Mathf.FloorToInt(width + 0.5f);
        int finalHeight = Mathf.FloorToInt(height + 0.5f);

        if (po.x == 0.5f)
        {
            finalWidth = ((finalWidth >> 1) << 1);
        }
        if (po.y == 0.5f)
        {
            finalHeight = ((finalHeight >> 1) << 1);
        }

        Transform t   = cachedTransform;
        Vector3   pos = t.localPosition;

        pos.x = Mathf.Floor(fx + 0.5f);
        pos.y = Mathf.Floor(fy + 0.5f);

        if (finalWidth < minWidth)
        {
            finalWidth = minWidth;
        }
        if (finalHeight < minHeight)
        {
            finalHeight = minHeight;
        }

        t.localPosition = pos;
        this.width      = finalWidth;
        this.height     = finalHeight;

        if (isAnchored)
        {
            t = t.parent;

            if (leftAnchor.target)
            {
                leftAnchor.SetHorizontal(t, x);
            }
            if (rightAnchor.target)
            {
                rightAnchor.SetHorizontal(t, x + width);
            }
            if (bottomAnchor.target)
            {
                bottomAnchor.SetVertical(t, y);
            }
            if (topAnchor.target)
            {
                topAnchor.SetVertical(t, y + height);
            }
#if UNITY_EDITOR
            NGUITools.SetDirty(this);
#endif
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Show the popup list dialog.
    /// </summary>

    public virtual void Show()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && isValid && items.Count > 0)
        {
            mLabelList.Clear();
            StopCoroutine("CloseIfUnselected");

            // Ensure the popup's source has the selection
            UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject);
            mSelection = UICamera.selectedObject;
            source     = UICamera.selectedObject;

            if (source == null)
            {
                Debug.LogError("Popup list needs a source object...");
                return;
            }

            mOpenFrame = Time.frameCount;

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

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Vector3 min;
            Vector3 max;

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

            if (separatePanel)
            {
                if (GetComponent <Collider>() != null)
                {
                    Rigidbody rb = mChild.AddComponent <Rigidbody>();
                    rb.isKinematic = true;
                }
                else if (GetComponent <Collider2D>() != null)
                {
                    Rigidbody2D rb = mChild.AddComponent <Rigidbody2D>();
                    rb.isKinematic = true;
                }

                var panel = mChild.AddComponent <UIPanel>();
                panel.depth        = 1000000;
                panel.sortingOrder = mPanel.sortingOrder;
            }
            current = this;

            Transform t = mChild.transform;
            t.parent = mPanel.cachedTransform;

            // Manually triggered popup list on some other game object
            if (openOn == OpenOn.Manual && mSelection != gameObject)
            {
                startingPosition = UICamera.lastEventPosition;
                min              = mPanel.cachedTransform.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(startingPosition));
                max              = min;
                t.localPosition  = min;
                startingPosition = t.position;
            }
            else
            {
                Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, transform, false, false);
                min              = bounds.min;
                max              = bounds.max;
                t.localPosition  = min;
                startingPosition = t.position;
            }

            StartCoroutine("CloseIfUnselected");

            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            int depth = separatePanel ? 0 : NGUITools.CalculateNextDepth(mPanel.gameObject);

            // Add a sprite for the background
            if (background2DSprite != null)
            {
                UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(depth);
                sp2.sprite2D = background2DSprite;
                mBackground  = sp2;
            }
            else if (atlas != null)
            {
                mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite, depth);
            }
            else
            {
                return;
            }

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

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(mSelection.layer);

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

            mBackground.pivot = UIWidget.Pivot.TopLeft;
            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, placeAbove ? bgPadding.y * 2f - overlap : overlap, 0f);

            // Add a sprite used for the selection
            if (highlight2DSprite != null)
            {
                UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(++depth);
                sp2.sprite2D = highlight2DSprite;
                mHighlight   = sp2;
            }
            else if (atlas != null)
            {
                mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite, ++depth);
            }
            else
            {
                return;
            }

            float hlspHeight = 0f, hlspLeft = 0f;

            if (mHighlight.hasBorder)
            {
                hlspHeight = mHighlight.border.w;
                hlspLeft   = mHighlight.border.x;
            }

            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            float          fontHeight = activeFontSize;
            float          dynScale = activeFontScale;
            float          labelHeight = fontHeight * dynScale;
            float          lineHeight = labelHeight + padding.y;
            float          x = 0f, y = placeAbove ? bgPadding.y - padding.y - overlap : -padding.y - bgPadding.y + overlap;
            float          contentHeight = bgPadding.y * 2f + padding.y;
            List <UILabel> labels        = new List <UILabel>();

            // Clear the selection if it's no longer present
            if (!items.Contains(mSelectedItem))
            {
                mSelectedItem = null;
            }

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

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild, mBackground.depth + 2);
                lbl.name         = i.ToString();
                lbl.pivot        = UIWidget.Pivot.TopLeft;
                lbl.bitmapFont   = bitmapFont;
                lbl.trueTypeFont = trueTypeFont;
                lbl.fontSize     = fontSize;
                lbl.fontStyle    = fontStyle;
                lbl.text         = isLocalized ? Localization.Get(s) : s;
                lbl.color        = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
                lbl.alignment      = alignment;
                labels.Add(lbl);

                contentHeight += lineHeight;

                y -= lineHeight;
                x  = Mathf.Max(x, lbl.printedSize.x);

                // Add an event listener
                UIEventListener listener = UIEventListener.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 || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                {
                    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, (max.x - min.x) - (bgPadding.x + padding.x) * 2f);

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

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                NGUITools.AddWidgetCollider(lbl.gameObject);
                lbl.autoResizeBoxCollider = false;
                BoxCollider bc = lbl.GetComponent <BoxCollider>();

                if (bc != null)
                {
                    bcCenter.z = bc.center.z;
                    bc.center  = bcCenter;
                    bc.size    = bcSize;
                }
                else
                {
                    BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>();
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
                    b2d.center = bcCenter;
#else
                    b2d.offset = bcCenter;
#endif
                    b2d.size = bcSize;
                }
            }

            int lblWidth = Mathf.RoundToInt(x);
            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(contentHeight);

            // Set the label width to make alignment work
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                lbl.overflowMethod = UILabel.Overflow.ShrinkContent;
                lbl.width          = lblWidth;
            }

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = (atlas != null) ? 2f * atlas.pixelSize : 2f;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlspLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                AnimateColor(mBackground);

                if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
                {
                    float bottom = y + labelHeight;
                    Animate(mHighlight, placeAbove, bottom);
                    for (int i = 0, imax = labels.Count; i < imax; ++i)
                    {
                        Animate(labels[i], placeAbove, bottom);
                    }
                    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)
            {
                min.y           = max.y - bgPadding.y;
                max.y           = min.y + mBackground.height;
                max.x           = min.x + mBackground.width;
                t.localPosition = new Vector3(min.x, max.y - bgPadding.y, min.z);
            }
            else
            {
                max.y = min.y + bgPadding.y;
                min.y = max.y - mBackground.height;
                max.x = min.x + mBackground.width;
            }

            Transform pt = mPanel.cachedTransform.parent;

            if (pt != null)
            {
                min = mPanel.cachedTransform.TransformPoint(min);
                max = mPanel.cachedTransform.TransformPoint(max);
                min = pt.InverseTransformPoint(min);
                max = pt.InverseTransformPoint(max);
            }

            // Ensure that everything fits into the panel's visible range
            Vector3 offset = mPanel.hasClipping ? Vector3.zero : mPanel.CalculateConstrainOffset(min, max);
            Vector3 pos    = t.localPosition + offset;
            pos.x           = Mathf.Round(pos.x);
            pos.y           = Mathf.Round(pos.y);
            t.localPosition = pos;
        }
        else
        {
            OnSelect(false);
        }
    }
Esempio n. 7
0
 private void Set(bool state)
 {
     if (!mStarted)
     {
         mIsActive    = state;
         startsActive = state;
         if (activeSprite != null)
         {
             activeSprite.alpha = ((!state) ? 0f : 1f);
         }
     }
     else if (mIsActive != state)
     {
         if (group != 0 && state)
         {
             int num  = 0;
             int size = list.size;
             while (num < size)
             {
                 UIToggle uIToggle = list[num];
                 if (uIToggle != this && uIToggle.group == group)
                 {
                     uIToggle.Set(state: false);
                 }
                 if (list.size != size)
                 {
                     size = list.size;
                     num  = 0;
                 }
                 else
                 {
                     num++;
                 }
             }
         }
         mIsActive = state;
         if (activeSprite != null)
         {
             if (instantTween || !NGUITools.GetActive(this))
             {
                 activeSprite.alpha = ((!mIsActive) ? 0f : 1f);
             }
             else
             {
                 TweenAlpha.Begin(activeSprite.gameObject, 0.15f, (!mIsActive) ? 0f : 1f);
             }
         }
         if (current == null)
         {
             UIToggle uIToggle2 = current;
             current = this;
             if (EventDelegate.IsValid(onChange))
             {
                 EventDelegate.Execute(onChange);
             }
             else if (eventReceiver != null && !string.IsNullOrEmpty(functionName))
             {
                 eventReceiver.SendMessage(functionName, mIsActive, SendMessageOptions.DontRequireReceiver);
             }
             current = uIToggle2;
         }
         if (this.activeAnimation != null)
         {
             ActiveAnimation activeAnimation = ActiveAnimation.Play(this.activeAnimation, null, state ? Direction.Forward : Direction.Reverse, EnableCondition.IgnoreDisabledState, DisableCondition.DoNotDisable);
             if (activeAnimation != null && (instantTween || !NGUITools.GetActive(this)))
             {
                 activeAnimation.Finish();
             }
         }
     }
 }
Esempio n. 8
0
 // Token: 0x060032B1 RID: 12977 RVA: 0x000FEB8E File Offset: 0x000FCF8E
 public static AudioSource PlaySound(AudioClip clip)
 {
     return(NGUITools.PlaySound(clip, 1f, 1f));
 }
Esempio n. 9
0
 // Token: 0x060032B2 RID: 12978 RVA: 0x000FEBA0 File Offset: 0x000FCFA0
 public static AudioSource PlaySound(AudioClip clip, float volume)
 {
     return(NGUITools.PlaySound(clip, volume, 1f));
 }
Esempio n. 10
0
 // Token: 0x060032BA RID: 12986 RVA: 0x000FEF70 File Offset: 0x000FD370
 public static void UpdateWidgetCollider(GameObject go)
 {
     NGUITools.UpdateWidgetCollider(go, false);
 }
Esempio n. 11
0
 // Token: 0x060032C2 RID: 12994 RVA: 0x000FF2F6 File Offset: 0x000FD6F6
 public static GameObject AddChild(GameObject parent)
 {
     return(NGUITools.AddChild(parent, true));
 }
Esempio n. 12
0
 // Token: 0x060032B8 RID: 12984 RVA: 0x000FEE6C File Offset: 0x000FD26C
 public static void AddWidgetCollider(GameObject go)
 {
     NGUITools.AddWidgetCollider(go, false);
 }
Esempio n. 13
0
    /// <summary>
    /// Initialize the grid. Executed only once.
    /// </summary>

    protected virtual void Init()
    {
        mInitDone = true;
        mPanel    = NGUITools.FindInParents <UIPanel>(gameObject);
    }
Esempio n. 14
0
    /// <summary>
    /// Activate the tweeners.
    /// </summary>

    public void Play(bool forward)
    {
        mActive = 0;
        var go = (tweenTarget == null) ? gameObject : tweenTarget;

        if (!NGUITools.GetActive(go))
        {
            // If the object is disabled, don't do anything
            if (ifDisabledOnPlay != EnableCondition.EnableThenPlay)
            {
                return;
            }

            // Enable the game object before tweening it
            NGUITools.SetActive(go, true);
        }

        // Gather the tweening components
        mTweens = includeChildren ? go.GetComponentsInChildren <UITweener>() : go.GetComponents <UITweener>();

        if (mTweens.Length == 0)
        {
            // No tweeners found -- should we disable the object?
            if (disableWhenFinished != DisableCondition.DoNotDisable)
            {
                NGUITools.SetActive(tweenTarget, false);
            }
        }
        else
        {
            var activated = false;
            if (playDirection == Direction.Reverse)
            {
                forward = !forward;
            }

            // Run through all located tween components
            for (int i = 0, imax = mTweens.Length; i < imax; ++i)
            {
                var tw = mTweens[i];

                // If the tweener's group matches, we can work with it
                if (tw.tweenGroup == tweenGroup)
                {
                    // Ensure that the game objects are enabled
                    if (!activated && !NGUITools.GetActive(go))
                    {
                        activated = true;
                        NGUITools.SetActive(go, true);
                    }

                    ++mActive;

                    // Toggle or activate the tween component
                    if (playDirection == Direction.Toggle)
                    {
                        // Listen for tween finished messages
                        EventDelegate.Add(tw.onFinished, OnFinished, true);
                        tw.Toggle();
                    }
                    else
                    {
                        if (resetOnPlay || (resetIfDisabled && !tw.enabled))
                        {
                            tw.Play(forward);
                            tw.ResetToBeginning();
                        }
                        // Listen for tween finished messages
                        EventDelegate.Add(tw.onFinished, OnFinished, true);
                        tw.Play(forward);
                    }
                }
            }
        }
    }
Esempio n. 15
0
 // Token: 0x060032E3 RID: 13027 RVA: 0x000FFF3D File Offset: 0x000FE33D
 private static void Deactivate(Transform t)
 {
     NGUITools.SetActiveSelf(t.gameObject, false);
 }
Esempio n. 16
0
 // Token: 0x060032CB RID: 13003 RVA: 0x000FF646 File Offset: 0x000FDA46
 public static void NormalizeDepths()
 {
     NGUITools.NormalizeWidgetDepths();
     NGUITools.NormalizePanelDepths();
 }
Esempio n. 17
0
 // Token: 0x060032E4 RID: 13028 RVA: 0x000FFF4B File Offset: 0x000FE34B
 public static void SetActive(GameObject go, bool state)
 {
     NGUITools.SetActive(go, state, true);
 }
Esempio n. 18
0
 // Token: 0x060032CC RID: 13004 RVA: 0x000FF652 File Offset: 0x000FDA52
 public static void NormalizeWidgetDepths()
 {
     NGUITools.NormalizeWidgetDepths(NGUITools.FindActive <UIWidget>());
 }
Esempio n. 19
0
    /// <summary>
    /// Show the popup list dialog.
    /// </summary>

    public void Show()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
        {
            mLabelList.Clear();

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

            // Disable the navigation script
            handleEvents = 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 = UIWidget.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 = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

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

            float          hlspHeight = hlsp.borderTop;
            float          fontHeight = activeFontSize;
            float          dynScale = activeFontScale;
            float          labelHeight = fontHeight * dynScale;
            float          x = 0f, y = -padding.y;
            List <UILabel> labels = new List <UILabel>();

            // Clear the selection if it's no longer present
            if (!items.Contains(mSelectedItem))
            {
                mSelectedItem = null;
            }

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

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild);
                lbl.name         = i.ToString();
                lbl.pivot        = UIWidget.Pivot.TopLeft;
                lbl.bitmapFont   = bitmapFont;
                lbl.trueTypeFont = trueTypeFont;
                lbl.fontSize     = fontSize;
                lbl.fontStyle    = fontStyle;
                lbl.text         = isLocalized ? Localization.Get(s) : s;
                lbl.color        = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
                lbl.alignment      = alignment;
                labels.Add(lbl);

                y -= labelHeight;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.printedSize.x);

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

                // Move the selection here if this is the right label
                if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                {
                    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 * dynScale - (bgPadding.x + padding.x) * 2f);

            float   cx       = x;
            Vector3 bcCenter = new Vector3(cx * 0.5f, -fontHeight * 0.5f, 0f);
            Vector3 bcSize   = new Vector3(cx, (labelHeight + padding.y), 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                NGUITools.AddWidgetCollider(lbl.gameObject);
                lbl.autoResizeBoxCollider = false;
                BoxCollider bc = lbl.GetComponent <BoxCollider>();

                if (bc != null)
                {
                    bcCenter.z = bc.center.z;
                    bc.center  = bcCenter;
                    bc.size    = bcSize;
                }
                else
                {
                    BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>();
                    b2d.offset = bcCenter;
                    b2d.size   = bcSize;
                }
            }

            int lblWidth = Mathf.RoundToInt(x);
            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(-y + bgPadding.y);

            // Set the label width to make alignment work
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                lbl.overflowMethod = UILabel.Overflow.ShrinkContent;
                lbl.width          = lblWidth;
            }

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = 2f * atlas.pixelSize;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

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

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.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 + labelHeight;
                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);
        }
    }
Esempio n. 20
0
 // Token: 0x060032CD RID: 13005 RVA: 0x000FF65E File Offset: 0x000FDA5E
 public static void NormalizeWidgetDepths(GameObject go)
 {
     NGUITools.NormalizeWidgetDepths(go.GetComponentsInChildren <UIWidget>());
 }
Esempio n. 21
0
    /// <summary>
    /// Mark all widgets associated with this atlas as having changed.
    /// </summary>

    public void MarkAsChanged()
    {
#if UNITY_EDITOR
        NGUITools.SetDirty(gameObject);
#endif
        if (mReplacement != null)
        {
            mReplacement.MarkAsChanged();
        }

        UISprite[] list = NGUITools.FindActive <UISprite>();

        for (int i = 0, imax = list.Length; i < imax; ++i)
        {
            UISprite sp = list[i];

            if (CheckIfRelated(this, sp.atlas))
            {
                UIAtlas atl = sp.atlas;
                sp.atlas = null;
                sp.atlas = atl;
#if UNITY_EDITOR
                NGUITools.SetDirty(sp);
#endif
            }
        }

        UIFont[] fonts = Resources.FindObjectsOfTypeAll(typeof(UIFont)) as UIFont[];

        for (int i = 0, imax = fonts.Length; i < imax; ++i)
        {
            UIFont font = fonts[i];

            if (CheckIfRelated(this, font.atlas))
            {
                UIAtlas atl = font.atlas;
                font.atlas = null;
                font.atlas = atl;
#if UNITY_EDITOR
                NGUITools.SetDirty(font);
#endif
            }
        }

        UILabel[] labels = NGUITools.FindActive <UILabel>();

        for (int i = 0, imax = labels.Length; i < imax; ++i)
        {
            UILabel lbl = labels[i];

            if (lbl.bitmapFont != null && CheckIfRelated(this, lbl.bitmapFont.atlas))
            {
                UIFont font = lbl.bitmapFont;
                lbl.bitmapFont = null;
                lbl.bitmapFont = font;
#if UNITY_EDITOR
                NGUITools.SetDirty(lbl);
#endif
            }
        }
    }
Esempio n. 22
0
 // Token: 0x060032D0 RID: 13008 RVA: 0x000FF78E File Offset: 0x000FDB8E
 public static UIPanel CreateUI(bool advanced3D)
 {
     return(NGUITools.CreateUI(null, advanced3D, -1));
 }
Esempio n. 23
0
	void Start () 
	{
		GameObject OptionsPanel = GameObject.Find ("OptionsPanel");
		NGUITools.SetActive(OptionsPanel , false);
	}
Esempio n. 24
0
 // Token: 0x060032D1 RID: 13009 RVA: 0x000FF798 File Offset: 0x000FDB98
 public static UIPanel CreateUI(bool advanced3D, int layer)
 {
     return(NGUITools.CreateUI(null, advanced3D, layer));
 }
Esempio n. 25
0
    /// <summary>
    /// This callback is sent inside the editor notifying us that some property has changed.
    /// </summary>

    protected override void OnValidate()
    {
        if (NGUITools.GetActive(this))
        {
            base.OnValidate();

            // Prior to NGUI 2.7.0 width and height was specified as transform's local scale
            if ((mWidth == 100 || mWidth == minWidth) &&
                (mHeight == 100 || mHeight == minHeight) && cachedTransform.localScale.magnitude > 8f)
            {
                UpgradeFrom265();
                cachedTransform.localScale = Vector3.one;
            }

            if (mWidth < minWidth)
            {
                mWidth = minWidth;
            }
            if (mHeight < minHeight)
            {
                mHeight = minHeight;
            }
            if (autoResizeBoxCollider)
            {
                ResizeCollider();
            }

            // If the texture is changing, we need to make sure to rebuild the draw calls
            if (mOldTex != mainTexture || mOldShader != shader)
            {
                mOldTex    = mainTexture;
                mOldShader = shader;
            }

            if (panel != null)
            {
                panel.RemoveWidget(this);
                panel = null;
            }

            aspectRatio = (keepAspectRatio == AspectRatioSource.Free) ?
                          (float)mWidth / mHeight : Mathf.Max(0.01f, aspectRatio);

            if (keepAspectRatio == AspectRatioSource.BasedOnHeight)
            {
                mWidth = Mathf.RoundToInt(mHeight * aspectRatio);
            }
            else if (keepAspectRatio == AspectRatioSource.BasedOnWidth)
            {
                mHeight = Mathf.RoundToInt(mWidth / aspectRatio);
            }
            CreatePanel();
        }
        else
        {
            if (mWidth < minWidth)
            {
                mWidth = minWidth;
            }
            if (mHeight < minHeight)
            {
                mHeight = minHeight;
            }
        }
    }
Esempio n. 26
0
    // Token: 0x060032D2 RID: 13010 RVA: 0x000FF7A4 File Offset: 0x000FDBA4
    public static UIPanel CreateUI(Transform trans, bool advanced3D, int layer)
    {
        UIRoot uiroot = (!(trans != null)) ? null : NGUITools.FindInParents <UIRoot>(trans.gameObject);

        if (uiroot == null && UIRoot.list.Count > 0)
        {
            foreach (UIRoot uiroot2 in UIRoot.list)
            {
                if (uiroot2.gameObject.layer == layer)
                {
                    uiroot = uiroot2;
                    break;
                }
            }
        }
        if (uiroot != null)
        {
            UICamera componentInChildren = uiroot.GetComponentInChildren <UICamera>();
            if (componentInChildren != null && componentInChildren.GetComponent <Camera>().orthographic == advanced3D)
            {
                trans  = null;
                uiroot = null;
            }
        }
        if (uiroot == null)
        {
            GameObject gameObject = NGUITools.AddChild(null, false);
            uiroot = gameObject.AddComponent <UIRoot>();
            if (layer == -1)
            {
                layer = LayerMask.NameToLayer("UI");
            }
            if (layer == -1)
            {
                layer = LayerMask.NameToLayer("2D UI");
            }
            gameObject.layer = layer;
            if (advanced3D)
            {
                gameObject.name     = "UI Root (3D)";
                uiroot.scalingStyle = UIRoot.Scaling.Constrained;
            }
            else
            {
                gameObject.name     = "UI Root";
                uiroot.scalingStyle = UIRoot.Scaling.Flexible;
            }
        }
        UIPanel uipanel = uiroot.GetComponentInChildren <UIPanel>();

        if (uipanel == null)
        {
            Camera[] array = NGUITools.FindActive <Camera>();
            float    num   = -1f;
            bool     flag  = false;
            int      num2  = 1 << uiroot.gameObject.layer;
            foreach (Camera camera in array)
            {
                if (camera.clearFlags == CameraClearFlags.Color || camera.clearFlags == CameraClearFlags.Skybox)
                {
                    flag = true;
                }
                num = Mathf.Max(num, camera.depth);
                camera.cullingMask &= ~num2;
            }
            Camera camera2 = NGUITools.AddChild <Camera>(uiroot.gameObject, false);
            camera2.gameObject.AddComponent <UICamera>();
            camera2.clearFlags      = ((!flag) ? CameraClearFlags.Color : CameraClearFlags.Depth);
            camera2.backgroundColor = Color.grey;
            camera2.cullingMask     = num2;
            camera2.depth           = num + 1f;
            if (advanced3D)
            {
                camera2.nearClipPlane           = 0.1f;
                camera2.farClipPlane            = 4f;
                camera2.transform.localPosition = new Vector3(0f, 0f, -700f);
            }
            else
            {
                camera2.orthographic     = true;
                camera2.orthographicSize = 1f;
                camera2.nearClipPlane    = -10f;
                camera2.farClipPlane     = 10f;
            }
            AudioListener[] array2 = NGUITools.FindActive <AudioListener>();
            if (array2 == null || array2.Length == 0)
            {
                camera2.gameObject.AddComponent <AudioListener>();
            }
            uipanel = uiroot.gameObject.AddComponent <UIPanel>();
        }
        if (trans != null)
        {
            while (trans.parent != null)
            {
                trans = trans.parent;
            }
            if (NGUITools.IsChild(trans, uipanel.transform))
            {
                uipanel = trans.gameObject.AddComponent <UIPanel>();
            }
            else
            {
                trans.parent        = uipanel.transform;
                trans.localScale    = Vector3.one;
                trans.localPosition = Vector3.zero;
                NGUITools.SetChildLayer(uipanel.cachedTransform, uipanel.cachedGameObject.layer);
            }
        }
        return(uipanel);
    }
Esempio n. 27
0
    /// <summary>
    /// Drop the item onto the specified object.
    /// </summary>

    protected virtual void OnDragDropRelease(GameObject surface)
    {
        if (!cloneOnDrag)
        {
            mTouchID = int.MinValue;

            // Re-enable the collider
            if (mButton != null)
            {
                mButton.isEnabled = true;
            }
            else if (mCollider != null)
            {
                mCollider.enabled = true;
            }

            // Is there a droppable container?
            UIDragDropContainer container = surface ? NGUITools.FindInParents <UIDragDropContainer>(surface) : null;

            if (container != null)
            {
                // Container found -- parent this object to the container
                mTrans.parent = (container.reparentTarget != null) ? container.reparentTarget : container.transform;

                Vector3 pos = mTrans.localPosition;
                pos.z = 0f;
                mTrans.localPosition = pos;
            }
            else
            {
                // No valid container under the mouse -- revert the item's parent
                mTrans.parent = mParent;
            }

            // Update the grid and table references
            mParent = mTrans.parent;
            mGrid   = NGUITools.FindInParents <UIGrid>(mParent);
            mTable  = NGUITools.FindInParents <UITable>(mParent);

            // Re-enable the drag scroll view script
            if (mDragScrollView != null)
            {
                mDragScrollView.enabled = true;
            }

            // Notify the widgets that the parent has changed
            NGUITools.MarkParentAsChanged(gameObject);

            if (mTable != null)
            {
                mTable.repositionNow = true;
            }
            if (mGrid != null)
            {
                mGrid.repositionNow = true;
            }
        }
        else
        {
            NGUITools.Destroy(gameObject);
        }
    }
Esempio n. 28
0
 // Token: 0x060032E1 RID: 13025 RVA: 0x000FFEB7 File Offset: 0x000FE2B7
 private static void Activate(Transform t)
 {
     NGUITools.Activate(t, false);
 }
Esempio n. 29
0
 static void OnMakePixelPerfect(object obj)
 {
     NGUITools.MakePixelPerfect(obj as Transform);
 }
Esempio n. 30
0
    /// <summary>
    /// Progress bar creation function.
    /// </summary>

    void CreateSlider(GameObject go, bool slider)
    {
        if (NGUISettings.atlas != null)
        {
            NGUIEditorTools.DrawSpriteField("Empty", "Sprite for the background (empty bar)", NGUISettings.atlas, mSliderBG, OnSliderBG, GUILayout.Width(120f));
            NGUIEditorTools.DrawSpriteField("Full", "Sprite for the foreground (full bar)", NGUISettings.atlas, mSliderFG, OnSliderFG, GUILayout.Width(120f));

            if (slider)
            {
                NGUIEditorTools.DrawSpriteField("Thumb", "Sprite for the thumb indicator", NGUISettings.atlas, mSliderTB, OnSliderTB, GUILayout.Width(120f));
            }
        }

        if (ShouldCreate(go, NGUISettings.atlas != null))
        {
            int depth = NGUITools.CalculateNextDepth(go);
            go      = NGUITools.AddChild(go);
            go.name = slider ? "Slider" : "Progress Bar";

            // Background sprite
            UISpriteData bgs  = NGUISettings.atlas.GetSprite(mSliderBG);
            UISprite     back = (UISprite)NGUITools.AddWidget <UISprite>(go);

            back.type       = bgs.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple;
            back.name       = "Background";
            back.depth      = depth;
            back.pivot      = UIWidget.Pivot.Left;
            back.atlas      = NGUISettings.atlas;
            back.spriteName = mSliderBG;
            back.width      = 200;
            back.height     = 30;
            back.transform.localPosition = Vector3.zero;
            back.MakePixelPerfect();

            // Foreground sprite
            UISpriteData fgs   = NGUISettings.atlas.GetSprite(mSliderFG);
            UISprite     front = NGUITools.AddWidget <UISprite>(go);
            front.type       = fgs.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple;
            front.name       = "Foreground";
            front.pivot      = UIWidget.Pivot.Left;
            front.atlas      = NGUISettings.atlas;
            front.spriteName = mSliderFG;
            front.width      = 200;
            front.height     = 30;
            front.transform.localPosition = Vector3.zero;
            front.MakePixelPerfect();

            // Add a collider
            if (slider)
            {
                NGUITools.AddWidgetCollider(go);
            }

            // Add the slider script
            UISlider uiSlider = go.AddComponent <UISlider>();
            uiSlider.foregroundWidget = front;

            // Thumb sprite
            if (slider)
            {
                UISpriteData tbs = NGUISettings.atlas.GetSprite(mSliderTB);
                UISprite     thb = NGUITools.AddWidget <UISprite>(go);

                thb.type       = tbs.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple;
                thb.name       = "Thumb";
                thb.atlas      = NGUISettings.atlas;
                thb.spriteName = mSliderTB;
                thb.width      = 20;
                thb.height     = 40;
                thb.transform.localPosition = new Vector3(200f, 0f, 0f);
                thb.MakePixelPerfect();

                NGUITools.AddWidgetCollider(thb.gameObject);
                thb.gameObject.AddComponent <UIButtonColor>();
                thb.gameObject.AddComponent <UIButtonScale>();

                uiSlider.thumb = thb.transform;
            }
            uiSlider.value = 1f;

            // Select the slider
            Selection.activeGameObject = go;
        }
    }