Ejemplo n.º 1
0
    static int get_canvasRect(IntPtr L)
    {
        object     o   = LuaScriptMgr.GetLuaObject(L, 1);
        RectMask2D obj = (RectMask2D)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name canvasRect");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index canvasRect on a nil value");
            }
        }

        LuaScriptMgr.PushValue(L, obj.canvasRect);
        return(1);
    }
Ejemplo n.º 2
0
    static int get_rectTransform(IntPtr L)
    {
        object     o   = LuaScriptMgr.GetLuaObject(L, 1);
        RectMask2D obj = (RectMask2D)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name rectTransform");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index rectTransform on a nil value");
            }
        }

        LuaScriptMgr.Push(L, obj.rectTransform);
        return(1);
    }
Ejemplo n.º 3
0
    public static int IsRaycastLocationValid(IntPtr l)
    {
        int result;

        try
        {
            RectMask2D rectMask2D = (RectMask2D)LuaObject.checkSelf(l);
            Vector2    sp;
            LuaObject.checkType(l, 2, out sp);
            Camera eventCamera;
            LuaObject.checkType <Camera>(l, 3, out eventCamera);
            bool b = rectMask2D.IsRaycastLocationValid(sp, eventCamera);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, b);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 4
0
 //RectMask2Dの初期化
 private void initRectMask2D()
 {
     if (!rectMask)
     {
         if (rawImage)
         {
             //rawImageの親がRectMask2Dか判別
             if (rawImage.transform.parent.GetComponent <RectMask2D>())
             {
                 //rawImageの親がRectMask2D
                 rectMask = rawImage.transform.parent.GetComponent <RectMask2D>();
             }
             else
             {
                 //rawImageの親がRectMask2Dじゃないので作成する
                 GameObject rectMask2D = new GameObject("NKWebCamTextureMask");
                 rectMask2D.transform.SetParent(rawImage.transform.parent);
                 rectMask2D.AddComponent <RectMask2D>();
                 //RectMask2Dの位置はrawImageを元に設定
                 RectTransform maskTransform     = rectMask2D.GetComponent <RectTransform>();
                 RectTransform rawImageTransform = rawImage.GetComponent <RectTransform>();
                 maskTransform.sizeDelta = rawImageTransform.sizeDelta;
                 maskTransform.rotation  = rawImageTransform.rotation;
                 maskTransform.position  = rawImageTransform.position;
                 maskTransform.pivot     = rawImageTransform.pivot;
                 maskTransform.offsetMin = rawImageTransform.offsetMin;
                 maskTransform.offsetMax = rawImageTransform.offsetMax;
                 rawImage.transform.SetParent(rectMask2D.transform);
                 rectMask = rectMask2D.GetComponent <RectMask2D>();
             }
         }
         else
         {
             Debug.LogError("RawImageが指定されていません");
         }
     }
 }
Ejemplo n.º 5
0
            internal Selector(
                GameObject gameObject,
                HC.ReactorId pieceId,
                RectTransform rectTransform,
                CanvasRenderer canvasRenderer,

                Image backImage,
                ScrollRect scrollRect,
                RectMask2D rectMask2,
                VerticalLayoutGroup verticalLayout,
                ContentSizeFitter contentSize,

                Image vScrollbarImage,
                Scrollbar vScrollbar,
                Image vScrollbarHandleImage,

                Image hScrollbarImage,
                Scrollbar hScrollbar,
                Image hScrollbarHandleImage

                ) : base(gameObject, pieceId, rectTransform, canvasRenderer)
            {
                this.backImage      = backImage;
                this.scrollRect     = scrollRect;
                this.rectMask2      = rectMask2;
                this.verticalLayout = verticalLayout;
                this.contentSize    = contentSize;

                this.vScrollbarImage       = vScrollbarImage;
                this.vScrollbar            = vScrollbar;
                this.vScrollbarHandleImage = vScrollbarHandleImage;

                this.hScrollbarImage       = hScrollbarImage;
                this.hScrollbar            = hScrollbar;
                this.hScrollbarHandleImage = hScrollbarHandleImage;
            }
Ejemplo n.º 6
0
    public void Mask(string mode)
    {
        if (tag == "event")
        {
            throw new CYFException("sprite.Mask: Can not be applied to Overworld Event sprites.");
        }
        else if (mode == null)
        {
            throw new CYFException("sprite.Mask: No argument provided.");
        }

        mode = mode.ToLower();
        var list = new Dictionary <string, int>()
        {
            { "off", 0 },
            { "box", 1 },
            { "sprite", 2 },
            { "stencil", 3 },
            { "invertedsprite", 4 },
            { "invertedstencil", 5 }
        };
        int masked = -1;

        if (!list.TryGetValue(mode, out masked))
        {
            throw new CYFException("sprite.Mask: Invalid mask mode \"" + mode.ToString() + "\".");
        }

        if (masked != _masked)
        {
            //If children need to have their "inverted" property updated, then do so
            if ((_masked < 4 && masked > 3) || (_masked > 3 && masked < 4))
            {
                foreach (MaskImage ivi in img.GetComponentsInChildren <MaskImage>())
                {
                    ivi.inverted = masked > 3;
                }
            }
            RectMask2D box = img.GetComponent <RectMask2D>();
            Mask       spr = img.GetComponent <Mask>();

            //Box mask mode
            if (masked == 1)
            {
                //Remove sprite mask if applicable
                spr.enabled = false;
                box.enabled = true;
            }
            else if (masked > 1)
            {
                //The mask mode now can't possibly be box, so remove box mask if applicable
                spr.enabled = true;
                box.enabled = false;
                // Used to differentiate between "sprite" and "stencil"-like display modes
                spr.showMaskGraphic = masked == 2 || masked == 4;
                //Mask has been disabled
            }
            else if (masked == 0)
            {
                spr.enabled = false;
                box.enabled = false;
            }
        }

        _masked = masked;
    }
        protected override void Awake()
        {
            base.Awake();

            this.rectMask2D = GetComponent <RectMask2D>();
        }
Ejemplo n.º 8
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                rectTransform.anchorMin = new Vector2(0.3f, 0f);
                rectTransform.anchorMax = new Vector2(0.7f, 1f);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _songsTableView.PageScrollUp();
                });

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 11f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _songsTableView.PageScrollDown();
                });

                _songListTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell"));
                _songsTableView            = new GameObject().AddComponent <TableView>();
                _songsTableView.transform.SetParent(rectTransform, false);

                _songsTableView.SetPrivateField("_isInitialized", false);
                _songsTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _songsTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _songsTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _songsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_songsTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0.5f);
                (_songsTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 0.5f);
                (_songsTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                (_songsTableView.transform as RectTransform).position         = new Vector3(0f, 0f, 2.4f);
                (_songsTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f);

                _songsTableView.SetPrivateField("_pageUpButton", _pageUpButton);
                _songsTableView.SetPrivateField("_pageDownButton", _pageDownButton);

                _songsTableView.dataSource = this;
                _songsTableView.ScrollToRow(0, false);
                _lastSelectedRow = -1;
                _songsTableView.didSelectRowEvent += _songsTableView_DidSelectRowEvent;
            }
            else
            {
                _songsTableView.ReloadData();
                _songsTableView.ScrollToRow(0, false);
                _lastSelectedRow = -1;
            }
        }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                _songTableCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")));
                (_songTableCell.transform as RectTransform).anchoredPosition = new Vector2(18f, 39f);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -12f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollUp();
                });
                _pageUpButton.interactable = false;

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 6f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollDown();
                });
                _pageDownButton.interactable = false;

                _leaderboardTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(x => (x.name == "LeaderboardTableCell"));

                RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(rectTransform, false);
                container.anchorMin        = new Vector2(0.15f, 0.5f);
                container.anchorMax        = new Vector2(0.85f, 0.5f);
                container.sizeDelta        = new Vector2(0f, 56f);
                container.anchoredPosition = new Vector2(0f, -3f);

                _leaderboardTableView = new GameObject("CustomTableView").AddComponent <TableView>();
                _leaderboardTableView.gameObject.AddComponent <RectMask2D>();
                _leaderboardTableView.transform.SetParent(container, false);

                _leaderboardTableView.SetPrivateField("_isInitialized", false);
                _leaderboardTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _leaderboardTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _leaderboardTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_leaderboardTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 1f);
                (_leaderboardTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageDownButton", _pageDownButton);

                _leaderboardTableView.dataSource = this;

                _timerText           = BeatSaberUI.CreateText(rectTransform, "", new Vector2(0f, 34f));
                _timerText.fontSize  = 8f;
                _timerText.alignment = TextAlignmentOptions.Center;
                _timerText.rectTransform.sizeDelta = new Vector2(30f, 6f);
            }
        }
Ejemplo n.º 10
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                rectTransform.anchorMin = new Vector2(0.3f, 0f);
                rectTransform.anchorMax = new Vector2(0.7f, 1f);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    pageUpPressed?.Invoke();
                });
                _pageUpButton.interactable = false;

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 11f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    pageDownPressed?.Invoke();
                });

                _sortByButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(15f, 36.25f), new Vector2(30f, 6f), () => { SelectTopButtons(TopButtonsState.SortBy); }, "Sort by");
                _sortByButton.SetButtonTextSize(3f);

                _topButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(-20f, 36.25f), new Vector2(20f, 6f), () =>
                {
                    sortByTop?.Invoke();
                    SelectTopButtons(TopButtonsState.Select);
                },
                                                        "Downloads");

                _topButton.SetButtonTextSize(3f);
                _topButton.ToggleWordWrapping(false);
                _topButton.gameObject.SetActive(false);

                _newButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(0f, 36.25f), new Vector2(20f, 6f), () =>
                {
                    sortByNew?.Invoke();
                    SelectTopButtons(TopButtonsState.Select);
                }, "Newest");

                _newButton.SetButtonTextSize(3f);
                _newButton.ToggleWordWrapping(false);
                _newButton.gameObject.SetActive(false);


                _starButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(20f, 36.25f), new Vector2(20f, 6f), () =>
                {
                    sortByPlays?.Invoke();
                    SelectTopButtons(TopButtonsState.Select);
                }, "Plays");

                _starButton.SetButtonTextSize(3f);
                _starButton.ToggleWordWrapping(false);
                _starButton.gameObject.SetActive(false);

                _searchButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(-15, 36.25f), new Vector2(30f, 6f), () =>
                {
                    searchButtonPressed?.Invoke();
                    SelectTopButtons(TopButtonsState.Search);
                }, "Search");
                _searchButton.SetButtonTextSize(3f);

                _loadingIndicator = BeatSaberUI.CreateLoadingSpinner(rectTransform);
                (_loadingIndicator.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_loadingIndicator.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_loadingIndicator.transform as RectTransform).anchoredPosition = new Vector2(0f, 0f);
                _loadingIndicator.SetActive(true);

                _songListTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell"));
                _songsTableView            = new GameObject().AddComponent <TableView>();
                _songsTableView.transform.SetParent(rectTransform, false);

                _songsTableView.SetPrivateField("_isInitialized", false);
                _songsTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _songsTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _songsTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _songsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_songsTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0.5f);
                (_songsTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 0.5f);
                (_songsTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                (_songsTableView.transform as RectTransform).position         = new Vector3(0f, 0f, 2.4f);
                (_songsTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f);

                _songsTableView.dataSource         = this;
                _songsTableView.didSelectRowEvent += _songsTableView_DidSelectRowEvent;
            }
            else
            {
                _songsTableView.ReloadData();
            }
        }
Ejemplo n.º 11
0
        public static GameObject CreateInputField(Resources resources)
        {
            GameObject root = CreateUIElementRoot("InputField (TMP)", s_ThickElementSize);

            GameObject textArea         = CreateUIObject("Text Area", root);
            GameObject childPlaceholder = CreateUIObject("Placeholder", textArea);
            GameObject childText        = CreateUIObject("Text", textArea);

            Image image = root.AddComponent <Image>();

            image.sprite = resources.inputField;
            image.type   = Image.Type.Sliced;
            image.color  = s_DefaultSelectableColor;

            TMP_InputField inputField = root.AddComponent <TMP_InputField>();

            SetDefaultColorTransitionValues(inputField);

            // Use UI.Mask for Unity 5.0 - 5.1 and 2D RectMask for Unity 5.2 and up
            RectMask2D rectMask = textArea.AddComponent <RectMask2D>();

            #if UNITY_2019_4_OR_NEWER && !UNITY_2019_4_1 && !UNITY_2019_4_2 && !UNITY_2019_4_3 && !UNITY_2019_4_4 && !UNITY_2019_4_5 && !UNITY_2019_4_6 && !UNITY_2019_4_7 && !UNITY_2019_4_8 && !UNITY_2019_4_9 && !UNITY_2019_4_10 && !UNITY_2019_4_11
            rectMask.padding = new Vector4(-8, -5, -8, -5);
            #endif

            RectTransform textAreaRectTransform = textArea.GetComponent <RectTransform>();
            textAreaRectTransform.anchorMin = Vector2.zero;
            textAreaRectTransform.anchorMax = Vector2.one;
            textAreaRectTransform.sizeDelta = Vector2.zero;
            textAreaRectTransform.offsetMin = new Vector2(10, 6);
            textAreaRectTransform.offsetMax = new Vector2(-10, -7);


            TextMeshProUGUI text = childText.AddComponent <TextMeshProUGUI>();
            text.text = "";
            text.enableWordWrapping = false;
            text.extraPadding       = true;
            text.richText           = true;
            SetDefaultTextValues(text);

            TextMeshProUGUI placeholder = childPlaceholder.AddComponent <TextMeshProUGUI>();
            placeholder.text               = "Enter text...";
            placeholder.fontSize           = 14;
            placeholder.fontStyle          = FontStyles.Italic;
            placeholder.enableWordWrapping = false;
            placeholder.extraPadding       = true;

            // Make placeholder color half as opaque as normal text color.
            Color placeholderColor = text.color;
            placeholderColor.a *= 0.5f;
            placeholder.color   = placeholderColor;

            // Add Layout component to placeholder.
            placeholder.gameObject.AddComponent <LayoutElement>().ignoreLayout = true;

            RectTransform textRectTransform = childText.GetComponent <RectTransform>();
            textRectTransform.anchorMin = Vector2.zero;
            textRectTransform.anchorMax = Vector2.one;
            textRectTransform.sizeDelta = Vector2.zero;
            textRectTransform.offsetMin = new Vector2(0, 0);
            textRectTransform.offsetMax = new Vector2(0, 0);

            RectTransform placeholderRectTransform = childPlaceholder.GetComponent <RectTransform>();
            placeholderRectTransform.anchorMin = Vector2.zero;
            placeholderRectTransform.anchorMax = Vector2.one;
            placeholderRectTransform.sizeDelta = Vector2.zero;
            placeholderRectTransform.offsetMin = new Vector2(0, 0);
            placeholderRectTransform.offsetMax = new Vector2(0, 0);

            inputField.textViewport  = textAreaRectTransform;
            inputField.textComponent = text;
            inputField.placeholder   = placeholder;
            inputField.fontAsset     = text.font;

            return(root);
        }
Ejemplo n.º 12
0
 private void Start()
 {
     _mask      = GetComponent <RectMask2D>();
     _transform = GetComponent <RectTransform>();
 }
Ejemplo n.º 13
0
 public override void CreateUI()
 {
     Pivot(PivotPresets.TopLeft);
     mask = gameObject.AddComponent <RectMask2D>();
 }
Ejemplo n.º 14
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                _backButton = BeatSaberUI.CreateBackButton(rectTransform as RectTransform, delegate() { backButtonPressed?.Invoke(); });

                RectTransform container = new GameObject("VideoListContainer", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(rectTransform, false);
                container.sizeDelta = new Vector2(105f, 0f);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -10f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _videosTableView.PageScrollUp();
                });

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 10f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _videosTableView.PageScrollDown();
                });

                _searchButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(60, -20), new Vector2(30, 8), () =>
                {
                    searchButtonPressed?.Invoke();
                }, "Refine");

                _downloadButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(60, -30), new Vector2(30, 8), () =>
                {
                    downloadButtonPressed?.Invoke(resultsList[_lastSelectedRow]);
                }, "Download");
                _downloadButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(0, 0, 0, 0);

                _loadingIndicator = BeatSaberUI.CreateLoadingSpinner(rectTransform);
                (_loadingIndicator.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_loadingIndicator.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_loadingIndicator.transform as RectTransform).anchoredPosition = new Vector2(0f, 0f);
                _loadingIndicator.SetActive(true);

                _videoListTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell"));
                _videosTableView            = new GameObject().AddComponent <TableView>();
                _videosTableView.transform.SetParent(container, false);

                _videosTableView.SetPrivateField("_isInitialized", false);
                _videosTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _videosTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _videosTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _videosTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_videosTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0.5f);
                (_videosTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 0.5f);
                (_videosTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                (_videosTableView.transform as RectTransform).anchoredPosition = new Vector3(-10f, 0f);

                _videosTableView.dataSource         = this;
                _videosTableView.didSelectRowEvent += _songsTableView_DidSelectRowEvent;
            }
            else
            {
                _videosTableView.ReloadData();
            }
            _downloadButton.interactable = false;
        }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                Downloader.Instance.songDownloaded += SongDownloaded;

                _songListTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell"));

                _titleText           = BeatSaberUI.CreateText(rectTransform, "DOWNLOAD QUEUE", new Vector2(0f, 36f));
                _titleText.alignment = TextAlignmentOptions.Top;
                _titleText.fontSize  = 7;

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _queuedSongsTableView.PageScrollUp();
                });

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 8f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _queuedSongsTableView.PageScrollDown();
                });

                _queuedSongsTableView = new GameObject().AddComponent <TableView>();
                _queuedSongsTableView.transform.SetParent(rectTransform, false);

                _queuedSongsTableView.SetPrivateField("_isInitialized", false);
                _queuedSongsTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _queuedSongsTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _queuedSongsTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _queuedSongsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_queuedSongsTableView.transform as RectTransform).anchorMin        = new Vector2(0.3f, 0.5f);
                (_queuedSongsTableView.transform as RectTransform).anchorMax        = new Vector2(0.7f, 0.5f);
                (_queuedSongsTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                (_queuedSongsTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f);

                ReflectionUtil.SetPrivateField(_queuedSongsTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_queuedSongsTableView, "_pageDownButton", _pageDownButton);

                _queuedSongsTableView.dataSource = this;

                _abortButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(36f, -30f), new Vector2(20f, 10f), AbortDownloads, "Abort All");
                _abortButton.ToggleWordWrapping(false);

                Downloader.Instance.songDownloaded += (Song song) => { Refresh(); };
            }
        }
Ejemplo n.º 16
0
 public static ReadOnlyRectMask2D AsReadOnly(this RectMask2D self) => self.IsTrulyNull() ? null : new ReadOnlyRectMask2D(self);
Ejemplo n.º 17
0
    static void CreateSimpleScrollList(MenuCommand menuCommand)
    {
        //Scroll
        GameObject go     = new GameObject("SimpleScrollList");
        GameObject select = menuCommand.context as GameObject;

        if (select != null)
        {
            GameObjectUtility.SetParentAndAlign(go, select);
        }
        else
        {
            Canvas canvas = GameObject.FindObjectOfType <Canvas>();
            if (canvas)
            {
                GameObjectUtility.SetParentAndAlign(go, canvas.gameObject);
            }
        }
        Undo.RegisterCreatedObjectUndo(go, "Created " + go.name);

        RectTransform rectTrans = go.AddComponent <RectTransform>();

        rectTrans.sizeDelta = new Vector3(250, 100);
        rectTrans.pivot     = new Vector2(0, 0.5f);

        ScrollRect scroll = go.AddComponent <ScrollRect>();
        RectMask2D mask   = go.AddComponent <RectMask2D>();

        scroll.horizontal = true;
        scroll.vertical   = false;
        scroll.viewport   = rectTrans;

        //list
        RectTransform list = (new GameObject("List")).AddComponent <RectTransform>();

        GameObjectUtility.SetParentAndAlign(list.gameObject, go);
        list.anchorMin = new Vector2(0f, 0.5f);
        list.anchorMax = new Vector2(0f, 0.5f);
        list.pivot     = new Vector2(0f, 0.5f);

        HorizontalLayoutGroup hlg = list.gameObject.AddComponent <HorizontalLayoutGroup>();

        hlg.spacing = 1;
        hlg.childForceExpandHeight = false;
        hlg.childForceExpandWidth  = false;

        ContentSizeFitter csf = list.gameObject.AddComponent <ContentSizeFitter>();

        csf.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
        csf.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

        scroll.content = list;

        //item
        RectTransform item = (new GameObject("item")).AddComponent <RectTransform>();

        item.gameObject.AddComponent <Image>();
        GameObjectUtility.SetParentAndAlign(item.gameObject, list.gameObject);

        Selection.activeObject = item;
    }
Ejemplo n.º 18
0
 public static Tween TweenSoftness(this RectMask2D mask, Vector2Int to, float duration) =>
     Tweening.To(getter: () => mask.softness,
                 setter: softness => mask.softness = softness,
                 to, duration).SetTarget(mask);
Ejemplo n.º 19
0
        private void OnInit()
        {
            RectMask2D mask = gameObject.AddComponent <RectMask2D>();

            AddScrollRect();
        }
Ejemplo n.º 20
0
 public static Tween TweenPadding(this RectMask2D mask, Vector4 to, float duration) =>
     Tweening.To(getter: () => mask.padding,
                 setter: padding => mask.padding = padding,
                 to, duration).SetTarget(mask);
Ejemplo n.º 21
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                DownloadController.Instance.OnDownloaderListChanged -= Refresh;
                DownloadController.Instance.OnDownloadStateChanged  -= DownloaderStateChanged;

                _songListTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell"));

                _titleText           = BeatSaberUI.CreateText(rectTransform, "DOWNLOAD QUEUE", new Vector2(0f, 35f));
                _titleText.alignment = TextAlignmentOptions.Top;
                _titleText.fontSize  = 6f;

                _manualDownloadText           = BeatSaberUI.CreateText(rectTransform, "Manual Restart Required", new Vector2(37f, -3f));
                _manualDownloadText.alignment = TextAlignmentOptions.Top;
                _manualDownloadText.fontSize  = 4f;
                _manualDownloadText.gameObject.SetActive(false);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(TableXOffset, -14f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _currentlyUpdatingTableView.PageScrollUp();
                });

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(TableXOffset, 8f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _currentlyUpdatingTableView.PageScrollDown();
                });

                var gobj = new GameObject("DownloadTable");
                gobj.SetActive(false);
                _currentlyUpdatingTableView = gobj.AddComponent <TableView>();
                _currentlyUpdatingTableView.transform.SetParent(rectTransform, false);

                _currentlyUpdatingTableView.SetPrivateField("_isInitialized", false);
                _currentlyUpdatingTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _currentlyUpdatingTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _currentlyUpdatingTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _currentlyUpdatingTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_currentlyUpdatingTableView.transform as RectTransform).anchorMin        = new Vector2(0.3f, 0.5f);
                (_currentlyUpdatingTableView.transform as RectTransform).anchorMax        = new Vector2(0.7f, 0.5f);
                (_currentlyUpdatingTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                (_currentlyUpdatingTableView.transform as RectTransform).anchoredPosition = new Vector3(TableXOffset, -3f);

                ReflectionUtil.SetPrivateField(_currentlyUpdatingTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_currentlyUpdatingTableView, "_pageDownButton", _pageDownButton);

                _currentlyUpdatingTableView.selectionType = TableViewSelectionType.None;
                _currentlyUpdatingTableView.dataSource    = this;
                gobj.SetActive(true);

                _checkForUpdates = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -30f), ButtonSize, CheckUpdates, "Check for updates");
                _checkForUpdates.interactable = DownloadController.Instance.CanCheck || DownloadController.Instance.CanReset;
                _checkForUpdates.ToggleWordWrapping(false);

                _downloadUpdates = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -19f), ButtonSize, DownloadUpdates, "Download Updates");
                _downloadUpdates.interactable = DownloadController.Instance.CanDownload;
                _downloadUpdates.ToggleWordWrapping(false);

                _restartGame = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -8f), ButtonSize, Restart, "Restart Game");
                _restartGame.interactable = DownloadController.Instance.HadUpdates;
                _restartGame.ToggleWordWrapping(false);
            }

            DownloadController.Instance.OnDownloaderListChanged += Refresh;
            DownloadController.Instance.OnDownloadStateChanged  += DownloaderStateChanged;

            DownloaderStateChanged();
        }
Ejemplo n.º 22
0
 public override void OnParentChanged()
 {
     base.OnParentChanged();
     mMask = null;
 }
Ejemplo n.º 23
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation)
            {
                if (activationType == ActivationType.AddedToHierarchy)
                {
                    _serverTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell"));

                    _selectText           = BeatSaberUI.CreateText(rectTransform, "Select ServerHub", new Vector2(0f, 35f));
                    _selectText.alignment = TextAlignmentOptions.Center;
                    _selectText.fontSize  = 7f;

                    _backButton = BeatSaberUI.CreateBackButton(rectTransform);
                    _backButton.onClick.AddListener(delegate() { didFinishEvent?.Invoke(); });

                    _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                    (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                    (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                    (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f);
                    (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                    _pageUpButton.interactable = true;
                    _pageUpButton.onClick.AddListener(delegate()
                    {
                        _serverHubsTableView.PageScrollUp();
                    });
                    _pageUpButton.interactable = false;

                    _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                    (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                    (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                    (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 8f);
                    (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 10f);
                    _pageDownButton.interactable = true;
                    _pageDownButton.onClick.AddListener(delegate()
                    {
                        _serverHubsTableView.PageScrollDown();
                    });
                    _pageDownButton.interactable = false;

                    _serverHubsTableView = new GameObject().AddComponent <TableView>();
                    _serverHubsTableView.transform.SetParent(rectTransform, false);

                    _serverHubsTableView.SetPrivateField("_isInitialized", false);
                    _serverHubsTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                    _serverHubsTableView.Init();

                    RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _serverHubsTableView.transform, false);
                    viewportMask.transform.DetachChildren();
                    _serverHubsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                    (_serverHubsTableView.transform as RectTransform).anchorMin        = new Vector2(0.3f, 0.5f);
                    (_serverHubsTableView.transform as RectTransform).anchorMax        = new Vector2(0.7f, 0.5f);
                    (_serverHubsTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                    (_serverHubsTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f);

                    ReflectionUtil.SetPrivateField(_serverHubsTableView, "_pageUpButton", _pageUpButton);
                    ReflectionUtil.SetPrivateField(_serverHubsTableView, "_pageDownButton", _pageDownButton);

                    _serverHubsTableView.didSelectCellWithIdxEvent += ServerHubs_didSelectRowEvent;
                    _serverHubsTableView.dataSource = this;
                    _serverHubsTableView.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false);
                }
            }
            else
            {
                _serverHubsTableView.dataSource = this;
            }
        }
Ejemplo n.º 24
0
        public int GetPageCount()
        {
            // Use the scroll rect to determine how many cells can fit this page
            RectMask2D rectMask2D = mScrollRect.viewport.GetComponent <RectMask2D>();
            float      maskWidth  = rectMask2D.canvasRect.width;
            float      maskHeight = rectMask2D.canvasRect.height;

            if (mLayoutGroup is GridLayoutGroup)
            {
                GridLayoutGroup gridLayout    = (GridLayoutGroup)mLayoutGroup;
                int             numColsInPage = Mathf.FloorToInt(maskWidth / (gridLayout.cellSize.x + gridLayout.spacing.x));
                int             numRowsInPage = Mathf.FloorToInt(maskHeight / (gridLayout.cellSize.y + gridLayout.spacing.y));

                int numItemsPerPage = numColsInPage * numRowsInPage;
                return(Mathf.CeilToInt((float)mItems.Count / numItemsPerPage));
            }
            else
            {
                float itemWidth  = 0.0f;
                float itemHeight = 0.0f;

                foreach (UIItem item in mItems)
                {
                    RectTransform rectTransform = item.GetComponent <RectTransform>();

                    if (mLayoutGroup is VerticalLayoutGroup)
                    {
                        itemHeight += rectTransform.rect.height;
                    }
                    else
                    {
                        itemWidth += rectTransform.rect.width;
                    }
                }

                if (mLayoutGroup is VerticalLayoutGroup)
                {
                    if (itemHeight > maskHeight)
                    {
                        return(Mathf.CeilToInt(itemHeight / maskHeight));
                    }
                    else
                    {
                        return(1);
                    }
                }
                else if (mLayoutGroup is HorizontalLayoutGroup)
                {
                    if (itemWidth > maskWidth)
                    {
                        return(Mathf.CeilToInt(itemWidth / maskWidth));
                    }
                    else
                    {
                        return(1);
                    }
                }
            }

            return(0);
        }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                _songTableCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")), rectTransform);
                (_songTableCell.transform as RectTransform).anchoredPosition = new Vector2(100f, -1.5f);
                _songTableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]);
                _songTableCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]);
                _songTableCell.SetPrivateField("_bought", true);
                foreach (var icon in _songTableCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
                {
                    Destroy(icon.gameObject);
                }

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -12.5f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollUp();
                });
                _pageUpButton.interactable = false;

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 7f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollDown();
                });
                _pageDownButton.interactable = false;

                _playNowButton = this.CreateUIButton("QuitButton", new Vector2(-39f, 34.5f), new Vector2(28f, 8.8f), () => { playNowButtonPressed?.Invoke(); }, "Play now");
                _playNowButton.ToggleWordWrapping(false);
                _progressText = BeatSaberUI.CreateText(rectTransform, "0.0%", new Vector2(8f, 32f));
                _progressText.gameObject.SetActive(false);

                _leaderboardTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(x => (x.name == "LeaderboardTableCell"));

                RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(rectTransform, false);
                container.anchorMin        = new Vector2(0.15f, 0.5f);
                container.anchorMax        = new Vector2(0.85f, 0.5f);
                container.sizeDelta        = new Vector2(0f, 56f);
                container.anchoredPosition = new Vector2(0f, -3f);

                _leaderboardTableView = new GameObject("CustomTableView").AddComponent <TableView>();
                _leaderboardTableView.gameObject.AddComponent <RectMask2D>();
                _leaderboardTableView.transform.SetParent(container, false);

                _leaderboardTableView.SetPrivateField("_isInitialized", false);
                _leaderboardTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _leaderboardTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _leaderboardTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_leaderboardTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 1f);
                (_leaderboardTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageDownButton", _pageDownButton);

                _leaderboardTableView.dataSource = this;

                _timerText           = BeatSaberUI.CreateText(rectTransform, "", new Vector2(0f, 34f));
                _timerText.fontSize  = 8f;
                _timerText.alignment = TextAlignmentOptions.Center;
                _timerText.rectTransform.sizeDelta = new Vector2(30f, 6f);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// override this method in a dervied class to add custom clearing for any chart type. default implementation deletes all chartItem components from this transform
        /// </summary>
        protected virtual void ClearChart()
        {
//#if UNITY_2018_3_OR_NEWER
//#if UNITY_EDITOR

//            //  if (Application.isEditor == true && Application.isPlaying == false)
//            //  {
//            var path = UnityEditor.PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject);
//            if (!(path == null || path.Trim().Length == 0))
//            {
//                // Load the contents of the Prefab Asset.
//                GameObject contentsRoot = UnityEditor.PrefabUtility.LoadPrefabContents(path);

//                bool save = false;
//                // Modify Prefab contents.
//                foreach (var item in contentsRoot.GetComponentsInChildren<ChartItem>())
//                {
//                    if (item == null)
//                        continue;
//                    if (item.gameObject != null)
//                    {
//                        save = true;
//                        DestroyImmediate(item.gameObject);
//                    }
//                }
//                if (save)
//                {
//                    //  try
//                    //  {
//                    UnityEditor.PrefabUtility.SaveAsPrefabAsset(contentsRoot, path);
//                    //  }
//                    //  catch (Exception e)
//                    //  {
//                    //  }

//                }

//                UnityEditor.PrefabUtility.UnloadPrefabContents(contentsRoot);
//            }
//            // }
//#endif
//#endif
            mHovered.Clear();

            if (TextController != null) // destroy all child text object
            {
                TextController.DestroyAll();
                TextController.transform.SetParent(transform, false); // the text controller my not be a direct child of this gameobject , make it so that it is.
            }

            // destroy all child ChartItem objects
            ChartItem[] children = GetComponentsInChildren <ChartItem>();
            for (int i = 0; i < children.Length; ++i)
            {
                if (children[i] != null)
                {
                    RectMask2D mask = children[i].GetComponent <RectMask2D>();
                    if (mask != null)
                    {
                        //   Debug.Log(mask.gameObject);
                    }
                    if (TextController != null && children[i].gameObject == TextController.gameObject)
                    {
                        continue;
                    }
                    if (children[i].gameObject.GetComponent <ChartItemNoDelete>() != null)
                    {
                        continue;
                    }
                    if (children[i].gameObject.GetComponentInParent <AnyChart>() != this)
                    {
                        continue;
                    }
                    if (children[i].gameObject != gameObject)
                    {
                        ChartCommon.SafeDestroy(children[i].gameObject);
                    }
                }
            }
            // ensure the text controller has been created ( it is generated only when the graph chart is first created)
            EnsureTextController();


            //destroy all axis components in this chart
            for (int i = 0; i < mAxis.Count; i++)
            {
                if (mAxis[i] != null && mAxis[i].This() != null)
                {
                    ChartCommon.SafeDestroy(mAxis[i].GetGameObject());
                }
            }
            mAxis.Clear();
        }
Ejemplo n.º 27
0
        protected override void AddComponents()
        {
            // Add the gameObjects
            var viewportGO   = InstanciateObject("Viewport", gameObject);
            var containerGO  = InstanciateObject("Container", viewportGO);
            var vScrollbarGO = InstanciateScrollbar("Vertical Scrollbar", gameObject, out vScrollbarCmp, out vScrollbarImageCmp, out vScrollbarHandleImageCmp);
            var hScrollbarGO = InstanciateScrollbar("Horizontal Scrollbar", gameObject, out hScrollbarCmp, out hScrollbarImageCmp, out hScrollbarHandleImageCmp);

            // Set virtual parent
            virtualChildContainer = containerGO;

            // Add Components
            scrollRectCmp      = propsScrollRect().Set(gameObject);
            rectMask2Cmp       = propsRectMask2D().Set(viewportGO);
            gridLayoutGroupCmp = propsGridLayoutGroup().Set(containerGO);
            contentSizeCmp     = propsContentSizeFilter().Set(containerGO);

            propsVScrollbarImage().SetAllExceptType(vScrollbarImageCmp);
            propsVScrollbar().Set(vScrollbarCmp);
            propsVScrollbarHandleImageCmp().SetAllExceptType(vScrollbarHandleImageCmp);

            propsHScrollbarImage().SetAllExceptType(hScrollbarImageCmp);
            propsHScrollbar().Set(hScrollbarCmp);
            propsHScrollbarHandleImageCmp().SetAllExceptType(hScrollbarHandleImageCmp);

            // Relations
            scrollRectCmp.content             = containerGO.GetComponent <RectTransform>();
            scrollRectCmp.viewport            = viewportGO.GetComponent <RectTransform>();
            scrollRectCmp.horizontalScrollbar = hScrollbarCmp;
            scrollRectCmp.verticalScrollbar   = vScrollbarCmp;

            // Obtain percentage size
            SetReferenceSize(new RectTransformSetter());

            new RectTransformBSetter()
            {
                pivot         = new Vector2(0f, 1f),
                localPosition = new Vector2(0f, 0f),
                anchorMin     = new Vector2(0f, 0f),
                anchorMax     = new Vector2(1, 1f),
                sizeDelta     = new Vector2(0, 0),
            }.SetOrSearchBySizeDelta(viewportGO);

            new RectTransformBSetter()
            {
                pivot         = new Vector2(0f, 1f),
                localPosition = new Vector2(0, 0f),
                anchorMin     = new Vector2(0, 0f),
                anchorMax     = new Vector2(1, 1f),
                offsetMin     = new Vector2(0, 0f),
                offsetMax     = new Vector2(0, 0f),
            }.SetOrSearchByAnchors(containerGO);

            new RectTransformBSetter()
            {
                pivot         = new Vector2(1f, 1f),
                localPosition = new Vector2(0f, 0),
                anchorMin     = new Vector2(1, 0f),
                anchorMax     = new Vector2(1, 1f),
                sizeDelta     = new Vector2(20, 0f), // 20,0
            }.SetOrSearchBySizeDelta(vScrollbarGO);

            new RectTransformBSetter()
            {
                pivot         = new Vector2(0f, 0f),
                localPosition = new Vector2(0f, 0),
                anchorMin     = new Vector2(0f, 0f),
                anchorMax     = new Vector2(1f, 0f),
                sizeDelta     = new Vector2(-20, 20f), // -20,20
            }.SetOrSearchBySizeDelta(hScrollbarGO);
        }
Ejemplo n.º 28
0
    public void Mask(string mode)
    {
        switch (tag)
        {
        case "event":  throw new CYFException("sprite.Mask: Can not be applied to Overworld Event sprites.");

        case "letter": throw new CYFException("sprite.Mask: Can not be applied to Letter sprites.");

        default:       if (mode == null)
            {
                throw new CYFException("sprite.Mask: No argument provided.");
            }
            break;
        }

        MaskMode masked;

        try {
            masked = (MaskMode)Enum.Parse(typeof(MaskMode), mode, true);
        } catch {
            throw new CYFException("sprite.Mask: Invalid mask mode \"" + mode + "\".");
        }

        if (masked != _masked)
        {
            //If children need to have their "inverted" property updated, then do so
            if ((int)_masked < 4 && (int)masked > 3 || (int)_masked > 3 && (int)masked < 4)
            {
                foreach (Transform child in GetTarget())
                {
                    MaskImage childmask = child.gameObject.GetComponent <MaskImage>();
                    if (childmask != null)
                    {
                        childmask.inverted = (int)masked > 3;
                    }
                }
            }
            RectMask2D box = img.GetComponent <RectMask2D>();
            Mask       spr = img.GetComponent <Mask>();

            switch (masked)
            {
            case MaskMode.BOX:
                //Remove sprite mask if applicable
                spr.enabled = false;
                box.enabled = true;
                break;

            case MaskMode.OFF:
                //Mask has been disabled
                spr.enabled = false;
                box.enabled = false;
                break;

            default:
                //The mask mode now can't possibly be box, so remove box mask if applicable
                spr.enabled = true;
                box.enabled = false;
                // Used to differentiate between "sprite" and "stencil"-like display modes
                spr.showMaskGraphic = masked == MaskMode.SPRITE || masked == MaskMode.INVERTEDSPRITE;
                break;
            }
        }

        _masked = masked;
    }
Ejemplo n.º 29
0
        private void ConvertMask(RectMask2D mask)
        {
            var entity = GetPrimaryEntity(mask);

            DstEntityManager.AddComponent <RectMask>(entity);
        }
Ejemplo n.º 30
0
 private void CreateMask()
 {
     _mask = _mask ?? GetComponent <RectMask2D>() ?? gameObject.AddComponent <RectMask2D>();
 }