Example #1
0
    void SetValues(IEnumerable <GMHelpInfo> infos)
    {
        var canvas = scrollView.GetComponentInChildren <UIGrid>();

        // remove all childer of canvas
        foreach (Transform d in canvas.transform)
        {
            DestroyObject(d.gameObject);
        }
        foreach (var i in infos)
        {
            var info = i;
            var item = GameObject.Instantiate(itemTemplate) as GameObject;
            item.transform.parent     = canvas.transform;
            item.transform.localScale = Vector3.one;

            item.GetComponentInChildren <UILabel>().text = info.method;
            UIEventListener.Get(item.GetComponentInChildren <UIButton>().gameObject).onClick = go =>
            {
                Debug.Log(info.Dump());
                BattleScene.Instance.Gui <ChatInputBox>().SetText(string.Format("//{0} {1}", info.method, info.example));
            };
        }

        canvas.gameObject.SetActive(true);
        canvas.Reposition();
        scrollView.ResetPosition();
    }
    /// <summary>
    /// Stop the active dragging operation.
    /// </summary>

    void OnDisable()
    {
        if (mPressed && mScroll != null && mScroll.GetComponentInChildren <UIWrapContent>() == null)
        {
            mScroll.Press(false);
            mScroll = null;
        }
    }
Example #3
0
    public BuyPackageItem(Transform head) :
        base(head)
    {
        ScView         = head.parent.GetComponent <UIScrollView>();
        ShopType       = UIShop.ShopSelectType.TypeBuy;
        buyPackageHead = head;
        orignalPos     = ScView.transform.localPosition;
        orignalRangle  = ScView.GetComponent <UIPanel>().baseClipRegion;
        orginalOffset  = ScView.GetComponent <UIPanel>().clipOffset;
        Transform btnParent = UIShop.Instance.transform.Find("SelectBG/InfoPageCtrl");

        for (int i = 0; i < 2; i++)
        {
            arrowUpDown[i] = btnParent.Find("Btn" + (i + 1).ToString());
        }
        arrowUpDown[0].gameObject.SetActive(false);
        arrowUpDown[1].gameObject.SetActive(true);

        //senlin
        ScView.onDragStarted      += OnDragFinished;
        turnPage                   = ScView.GetComponentInChildren <UICenterTurnPage>();
        turnPage.nextPageThreshold = 50f;
    }
Example #4
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) { NGUITools.BringForward(Selection.activeGameObject); }, null);

            AddItem(myName + "/Push to Back", false,
                    delegate(object obj) { NGUITools.PushBack(Selection.activeGameObject); }, null);

            AddItem(myName + "/Nudge Forward", false,
                    delegate(object obj) { NGUITools.AdjustDepth(Selection.activeGameObject, 1); }, null);

            AddItem(myName + "/Nudge Back", false,
                    delegate(object obj) { NGUITools.AdjustDepth(Selection.activeGameObject, -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);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                AddChildWidget("Create/Unity 2D Sprite/Child", false, NGUISettings.Add2DSprite);
#endif
                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);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                AddSiblingWidget("Create/Unity 2D Sprite/Sibling", false, NGUISettings.Add2DSprite);
#endif
            }
            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);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                AddChildWidget("Create/Unity 2D Sprite", false, NGUISettings.Add2DSprite);
#endif
            }

            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, delegate(object obj) { target.AddComponent <UIScrollView>(); }, null);
                    NGUIContextMenu.AddSeparator("Attach/");
                }
            }
            else if (target.collider == null)
            {
                AddItem("Attach/Box Collider", false, delegate(object obj) { NGUITools.AddWidgetCollider(target); }, 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, delegate(object obj) { target.AddComponent <UICenterOnChild>(); }, null);
                    header = true;
                }
            }

            if (target.collider != null)
            {
                if (scrollView != null)
                {
                    if (target.GetComponent <UIDragScrollView>() == null)
                    {
                        AddItem("Attach/Drag Scroll View", false, delegate(object obj) { target.AddComponent <UIDragScrollView>(); }, null);
                        header = true;
                    }

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

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

                AddItem("Attach/Button Script", false, delegate(object obj) { target.AddComponent <UIButton>(); }, null);
                AddItem("Attach/Toggle Script", false, delegate(object obj) { target.AddComponent <UIToggle>(); }, null);
                AddItem("Attach/Slider Script", false, delegate(object obj) { target.AddComponent <UISlider>(); }, null);
                AddItem("Attach/Scroll Bar Script", false, delegate(object obj) { target.AddComponent <UIScrollBar>(); }, null);
                AddItem("Attach/Progress Bar Script", false, delegate(object obj) { target.AddComponent <UISlider>(); }, null);
                AddItem("Attach/Popup List Script", false, delegate(object obj) { target.AddComponent <UIPopupList>(); }, null);
                AddItem("Attach/Input Field Script", false, delegate(object obj) { target.AddComponent <UIInput>(); }, null);
                NGUIContextMenu.AddSeparator("Attach/");

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

                if (target.GetComponent <UIDragScrollView>() == null)
                {
                    for (int i = 0; i < UIPanel.list.size; ++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, delegate(object obj) { target.AddComponent <UIKeyBinding>(); }, null);

                NGUIContextMenu.AddSeparator("Attach/");

                AddItem("Attach/Play Tween Script", false, delegate(object obj) { target.AddComponent <UIPlayTween>(); }, null);
                AddItem("Attach/Play Animation Script", false, delegate(object obj) { target.AddComponent <UIPlayAnimation>(); }, null);
                AddItem("Attach/Play Sound Script", false, delegate(object obj) { target.AddComponent <UIPlaySound>(); }, null);
            }

            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");
            }
        }
    }
Example #5
0
 public void ResetScrollPosition()
 {
     scrollView.GetComponentInChildren <UIScrollView>().GetComponent <Transform>().localPosition = new Vector3(-275, 135, 0);
     scrollView.GetComponentInChildren <UIScrollView>().GetComponent <UIPanel>().clipOffset      = new Vector2(0, -135);
 }