예제 #1
0
#pragma warning restore 0067


        void Awake()
        {
            _RT = transform as RectTransform;
            _ResolvedAVGScreenSize = (Screen.width + Screen.height) / 2f;
            _ScrollRect            = GetComponent <ScrollRect>();
            _RefreshGizmo          = GetComponentInChildren <PullToRefreshGizmo>(); // self or children
            if (_ScrollRect)
            {
                // May be null
                externalScrollRectProxy = _ScrollRect.GetComponent(typeof(IScrollRectProxy)) as IScrollRectProxy;
            }
            else
            {
                externalScrollRectProxy = GetComponentInParent(typeof(IScrollRectProxy)) as IScrollRectProxy;
                if (externalScrollRectProxy == null)
                {
                    if (enabled)
                    {
                        Debug.Log(GetType().Name + ": no scrollRect provided and found no " + typeof(IScrollRectProxy).Name + " component among ancestors. Disabling...");
                        enabled = false;
                    }
                    return;
                }
            }
        }
예제 #2
0
        public void KeepItemInViewport()
        {
            ScrollRect scrollRect = GetComponentInChildren <ScrollRect> ();

            if (scrollRect != null)
            {
                RectTransform viewport      = scrollRect.gameObject.transform.GetChild(0).GetChild(0).GetComponent <RectTransform> ();
                float         offsetY       = viewport.offsetMax.y;
                float         upperBoundY   = 0f;
                float         lowerBoundY   = -scrollRect.GetComponent <RectTransform> ().rect.height;
                Button        currentButton = buttonList[currentSelectedButtonIdx];
                float         MaxY          = currentButton.GetComponent <RectTransform> ().offsetMax.y + offsetY;
                float         MinY          = currentButton.GetComponent <RectTransform> ().offsetMin.y + offsetY;
                //Rect rectTarget = buttonList[(buttonNum + currentSelectedButtonIdx - 1) % buttonNum].GetComponent<RectTransform>().rect;
                float deltaY = Mathf.Max(lowerBoundY - MinY, MaxY - upperBoundY);
                if (lowerBoundY > MinY)
                {
                    StartCoroutine(MoveScrollRectPosition(-20f / 4, 0.2f));
                }
                else if (upperBoundY < MaxY)
                {
                    StartCoroutine(MoveScrollRectPosition(20f / 4, 0.2f));
                }
                //Debug.Log(rectTarget);
            }
        }
예제 #3
0
    /// <summary>
    /// 设置渲染项
    /// </summary>
    /// <param name="goItemRender"></param>
    /// <param name="itemRenderType"></param>
    public void SetItemRender(GameObject goItemRender, Type itemRenderType)
    {
        m_goItemRender   = goItemRender;
        m_itemRenderType = itemRenderType.IsSubclassOf(typeof(ItemRender)) ? itemRenderType : null;
        var layoutEle = goItemRender.GetComponent <LayoutElement>();

        if (layoutEle == null)
        {
            return;
        }

        var layoutGroup = m_LayoutGroup as HorizontalOrVerticalLayoutGroup;

        if (layoutGroup == null)
        {
            return;
        }

        if (m_tranScrollRect == null)
        {
            m_scrollRect     = transform.GetComponentInParent <ScrollRect>();
            m_tranScrollRect = m_scrollRect.GetComponent <RectTransform>();
        }
        m_itemSpace     = (int)(layoutEle.preferredHeight + (int)layoutGroup.spacing);
        m_viewItemCount = Mathf.CeilToInt(ViewSpace / m_itemSpace);
    }
예제 #4
0
    private Vector2 CenterPoint(RectTransform target)
    {
        var     content          = worldMap.content.GetChild(0).GetComponent <RectTransform>();
        var     viewport         = worldMap.viewport;
        Vector3 targetPosition   = worldMap.GetComponent <RectTransform>().InverseTransformPoint(Clear_Pivot_Offset(target));
        Vector3 viewportPosition = worldMap.GetComponent <RectTransform>().InverseTransformPoint(Clear_Pivot_Offset(viewport));
        Vector3 distance_vec     = viewportPosition - targetPosition; //向目标滑动的位移向量
        var     height_Delta     = content.rect.height - viewport.rect.height;
        var     width_Delta      = content.rect.width - viewport.rect.width;
        var     ratio_x          = distance_vec.x / width_Delta;
        var     ratio_y          = distance_vec.y / height_Delta;
        var     ratioDistance    = new Vector2(ratio_x, ratio_y);
        var     newPosition      = worldMap.normalizedPosition - ratioDistance;

        return(new Vector2(Mathf.Clamp01(newPosition.x), Mathf.Clamp01(newPosition.y)));
    }
예제 #5
0
    //float startime = 0f;
    //float delay = 0.1f;

    // Use this for initialization
    void Start()
    {
        //适配rect的大小
        float fixwidth = scrollrect.GetComponent <RectTransform>().rect.width;

        foreach (Transform element in scrollrect.transform.Find("PageList"))
        {
            element.GetComponent <LayoutElement>().preferredWidth = fixwidth;
        }

        //添加页面位置进入page列表中
        int count = scrollrect.content.childCount;

        pages = new float[count];
        for (int i = 0; i < count; i++)
        {
            float page = 0;
            if (count != 1)
            {
                page = i / ((float)(count - 1));
            }
            pages[i] = page;
        }

        OnPageChanged(pages.Length, currentPageIndex);
    }
예제 #6
0
    /// <summary>
    /// 设置Grid宽高
    /// </summary>
    /// <param name="count">数据总长度</param>
    private void SetScrollView(int count)
    {
        var rectTrans   = _grid.GetComponent <RectTransform>();
        var scrollTrans = _scrollView.GetComponent <RectTransform>();

        rectTrans.sizeDelta = scrollTrans.sizeDelta;

        //排列数量
        var constraint = _grid.constraintCount;
        //预制宽度
        var width = _grid.cellSize.x;
        //预制高度
        var heigth = _grid.cellSize.y;

        switch (_grid.constraint)
        {
        //纵向排列
        case GridLayoutGroup.Constraint.FixedColumnCount:
            // ReSharper disable once PossibleLossOfFraction
            rectTrans.sizeDelta = new Vector2(x: width * constraint, y: heigth * Mathf.Ceil((float)count / constraint));
            break;

        //横向排列排列
        case GridLayoutGroup.Constraint.FixedRowCount:
            // ReSharper disable once PossibleLossOfFraction
            rectTrans.sizeDelta = new Vector2(x: Mathf.Ceil((float)count / constraint), y: heigth * constraint);
            break;
        }
    }
예제 #7
0
    void Awake()
    {
        m_ScrollRect = this.transform.GetComponent <ScrollRect>();
        if (m_ScrollRect == null)
        {
            Debug.LogError("Need ScrollRect");
            return;
        }

        m_ContentTrans = m_ScrollRect.content;
        if (m_ContentTrans == null)
        {
            Debug.LogError("ScrollRect.Content is null");
            return;
        }

        //m_ContentTrans.pivot = Vector2.one * 0.5f;
        //m_ContentTrans.anchorMin = Vector2.one * 0.5f;
        //m_ContentTrans.anchorMax = Vector2.one * 0.5f;

        m_ScrollRectTrans           = m_ScrollRect.GetComponent <RectTransform>();
        m_ScrollRectTrans.pivot     = Vector2.one * 0.5f;
        m_ScrollRectTrans.anchorMin = Vector2.one * 0.5f;
        m_ScrollRectTrans.anchorMax = Vector2.one * 0.5f;

        m_Awaked = true;
        TryDoInit();
    }
예제 #8
0
        void Awake()
        {
            _scrollView = GetComponent <ScrollRect>();
            if (_scrollView == null)
            {
                Debug.LogError("CenterOnChild: No ScrollRect");
                return;
            }
            _container = _scrollView.content;

            GridLayoutGroup grid;

            grid = _container.GetComponent <GridLayoutGroup>();
            if (grid == null)
            {
                Debug.LogError("CenterOnChild: No GridLayoutGroup on the ScrollRect's content");
                return;
            }

            _scrollView.movementType = ScrollRect.MovementType.Unrestricted;

            //计算第一个子物体位于中心时的位置
            float childPosX = _scrollView.GetComponent <RectTransform>().rect.width * 0.5f - grid.cellSize.x * 0.5f;

            _childrenPos.Add(childPosX);
            //缓存所有子物体位于中心时的位置
            for (int i = 0; i < _container.childCount - 1; i++)
            {
                childPosX -= grid.cellSize.x + grid.spacing.x;
                _childrenPos.Add(childPosX);
            }
        }
    private IEnumerator AdjustListScroll(PaddedInputField input)
    {
        var rt         = input.transform as RectTransform;
        var listBottom = -metadataList.GetComponent <RectTransform>().rect.height;

        yield return(null);

        var rect       = rt.rect;
        var yPos       = rt.localPosition.y + metadataList.content.localPosition.y;
        var cellTop    = yPos + rect.yMax;
        var cellBottom = yPos + rect.yMin;

        AdjustListScroll(rt, cellTop, cellBottom, listBottom);

        while (true)
        {
            yield return(null);

            var caretPos = input.GetCaretPosition().y;

            rect      = rt.rect;
            yPos      = rt.localPosition.y + metadataList.content.localPosition.y;
            caretPos += yPos + rect.yMax;
            AdjustListScroll(rt, caretPos + MetadataListPadding, caretPos - MetadataListPadding, listBottom);
        }
    }
예제 #10
0
    private IEnumerator AdjustListScroll(float idealPosition)
    {
        yield return(null);

        var groupSection = activeSection.transform.parent as RectTransform;

        var rect          = groupSection.rect;
        var yPos          = groupSection.localPosition.y + layersList.content.localPosition.y;
        var sectionTop    = yPos + rect.yMax;
        var sectionBottom = yPos + rect.yMin;
        var listBottom    = -layersList.GetComponent <RectTransform>().rect.height;

        var shift = sectionTop - idealPosition;

        sectionTop    -= shift;
        sectionBottom -= shift;

        // Adjust list scroll if the section's bottom is below the list's bottom
        if (sectionBottom < listBottom)
        {
            shift += Math.Max(sectionTop + 8, sectionBottom - listBottom - 8);
        }
        // Or the section's top is above the list's top
        else if (sectionTop > 0)
        {
            shift += sectionTop + 8;
        }

        if (shift != 0)
        {
            var pos = layersList.content.localPosition;
            pos.y -= shift;
            layersList.content.localPosition = pos;
        }
    }
예제 #11
0
    //show commands from leader if there is any in instrBuffer
    public void ShowFollowerCommands()
    {
        txt = "";
        int           currInstrIdx = CommandCommunication.currInstrIdx;
        List <string> currBuff     = CommandCommunication.instrBuffer;

        // Only display the current one if there is a current one
        for (int i = 0; i <= currInstrIdx; i++)
        {
            if (i < currInstrIdx)
            {
                txt += "--- [DONE] " + currBuff[i] + "\n";
            }
            else if (currInstrIdx < currBuff.Count)
            {
                txt += "--- [CURRENT] " + currBuff[i] + "\n";
            }
        }
        // txt = txt + "<b>      " + dashes + dashes + "      </b>\n";

        followerCommandHistory.text = txt;
        followerScrollRect.verticalNormalizedPosition = 0;

        followerScrollRect.GetComponent <RectTransform>().ForceUpdateRectTransforms();
    }
예제 #12
0
    public void CrearPrefabs(List <DetalleAsistencia> _detalles, bool activarBoton)
    {
        BorrarPrefabs();

        foreach (var _detalle in _detalles)
        {
            GameObject detalleGO = Instantiate(detalleAsistenciaPrefab, detallesParentTransform, false);
            detalleGO.SetActive(true);

            detalleGO.GetComponent <DetalleAsistencia>().SetDetalle(_detalle, activarBoton);

            listaPrefabs.Add(detalleGO);
        }

        cantMinima = (int)(scrollRectDetalles.GetComponent <RectTransform>().rect.height / (prefabHeight + detallesParentTransform.GetComponent <VerticalLayoutGroup>().spacing + detallesParentTransform.GetComponent <VerticalLayoutGroup>().padding.top));
    }
예제 #13
0
    private static Vector2 CalculateScrollPosition(ScrollRect pScroll, RectTransform pScrollMask, RectTransform pCenterItem)
    {
        RectTransform mScrollTransform = pScroll.GetComponent <RectTransform>();
        RectTransform mContent         = pScroll.content;

        Vector2 vecTargetItemPos   = GetWorldPoint_InWidget(mScrollTransform, GetWorldPoint(pCenterItem));
        Vector2 vecScrollCenterPos = GetWorldPoint_InWidget(mScrollTransform, GetWorldPoint(pScrollMask));
        Vector2 fTargetDistance    = vecScrollCenterPos - vecTargetItemPos;

        if (pScroll.horizontal == false)
        {
            fTargetDistance.x = 0f;
        }

        if (pScroll.vertical == false)
        {
            fTargetDistance.y = 0f;
        }

        Vector3 vecSizeOffset = mContent.rect.size - mScrollTransform.rect.size;

        var normalizedDifference = new Vector2(
            fTargetDistance.x / vecSizeOffset.x,
            fTargetDistance.y / vecSizeOffset.y);

        var newNormalizedPosition = pScroll.normalizedPosition - normalizedDifference;

        // if (pScroll.movementType != ScrollRect.MovementType.Unrestricted)
        {
            newNormalizedPosition.x = Mathf.Clamp01(newNormalizedPosition.x);
            newNormalizedPosition.y = Mathf.Clamp01(newNormalizedPosition.y);
        }

        return(newNormalizedPosition);
    }
예제 #14
0
    public virtual void ScrollTo(Line targetLine)
    {
        float scrollHeight            = scrollRect_.GetComponent <RectTransform>().rect.height;
        float targetAbsolutePositionY = targetLine.TargetAbsolutePosition.y;
        float targetHeight            = -(targetAbsolutePositionY - this.transform.position.y);
        float heightPerLine           = GameContext.Config.HeightPerLine;

        // focusLineが下側に出て見えなくなった場合
        float targetUnderHeight = -(targetAbsolutePositionY - scrollRect_.transform.position.y) + heightPerLine / 2 - scrollHeight;

        if (targetUnderHeight > 0)
        {
            targetScrollValue_ = Mathf.Clamp01(1.0f - (targetHeight + heightPerLine * 1.5f - scrollHeight) / (layout_.preferredHeight - scrollHeight));
            isScrollAnimating_ = true;
            return;
        }

        // focusLineが上側に出て見えなくなった場合
        float targetOverHeight = (targetAbsolutePositionY - scrollRect_.transform.position.y);

        if (targetOverHeight > 0)
        {
            targetScrollValue_ = Mathf.Clamp01((layout_.preferredHeight - scrollHeight - targetHeight) / (layout_.preferredHeight - scrollHeight));
            isScrollAnimating_ = true;
            return;
        }
    }
예제 #15
0
        //-----------------------------------------------------------------------------
        private void CheckForScrolling()
        {
            int   count       = m_scrollView.content.childCount;
            float panelSize   = m_scrollView.GetComponent <RectTransform>().rect.height * 0.85f;
            float size        = m_textPanel.GetComponent <RectTransform>().sizeDelta.y;
            float contentSize = 0;

            for (int index = 0; index < count; index++)
            {
                var child = m_scrollView.content.GetChild(index);
                if (child.gameObject.activeSelf)
                {
                    contentSize += child.GetComponent <RectTransform>().rect.height;
                }
            }

            float alreadyScrolled = (MIN_SCROLL_SIZE * m_scrollEvents) * size;

            if (contentSize - alreadyScrolled >= panelSize)
            {
                m_scrollEvents++;
                DOTween.To(() => m_scrollView.verticalNormalizedPosition, _x => m_scrollView.verticalNormalizedPosition = _x, 1 - MIN_SCROLL_SIZE * m_scrollEvents, 1)
                .SetEase(Ease.Linear);
            }
        }
예제 #16
0
    private int popInitial;     //initial student population

    // Start is called before the first frame update
    void Start()
    {
        //Resource list
        string resc = "Students: " + students + "     Faculty: " + faculty + "     Alumni: " + alumni + "     Buildings: " + buildings + "     Materials: " + material;

        resources.text = resc;

        //Listeners for buttons
        Turns.onClick.AddListener(TaskOnClick);
        BuyShack.onClick.AddListener(ShackClick);
        BuyBuilding.onClick.AddListener(BuildingClick);
        BuyBigBuilding.onClick.AddListener(BigBuildingClick);
        Hire.onClick.AddListener(HireClick);
        RiskyBoost.onClick.AddListener(RiskyBoostClick);
        MedBoost.onClick.AddListener(MedBoostClick);
        BigBoost.onClick.AddListener(BigBoostClick);

        //set up auto scroll
        scrollRect.GetComponent <ScrollRect>();

        //set up random ranges (possibly based on difficulty later)
        students  = Mathf.FloorToInt(Random.Range(2.0f, 15.0f));
        faculty   = Mathf.FloorToInt(Random.Range(1.0f, 5.0f));
        alumni    = 1;
        buildings = 1;
        material  = Mathf.FloorToInt(Random.Range(100.0f, 1000.0f));

        popInitial = students;

        eventLog.text += "\n BREAKING: SADU's only alum has taken over for the school!";
    }
예제 #17
0
        private void Awake()
        {
            _viewH    = sr.GetComponent <RectTransform>().sizeDelta.y;
            _itemSize = itemPrefab.GetComponent <RectTransform>().sizeDelta;

            _maxItemCount = Mathf.CeilToInt(_viewH / _itemSize.y) + 2;
        }
예제 #18
0
        protected virtual void Init()
        {
            _scrollRect            = gameObject.GetComponent <ScrollRect>();
            _scrollRect.horizontal = false;
            _scrollRect.vertical   = true;
            _scrollRect.onValueChanged.AddListener(OnScroll);

            _containerParent = new GameObject("Container", typeof(RectTransform));
            _contentTrans    = _containerParent.GetComponent <RectTransform>();
            _containerParent.transform.SetParent(transform, false);

            _poolParent = new GameObject("Pool", typeof(RectTransform));
            _poolParent.transform.SetParent(transform, false);
            _poolParent.SetActive(false);

            _scrollRect.viewport = gameObject.GetComponent <RectTransform>();
            _scrollRect.content  = _contentTrans;

            InitPrefab();

            RectTransform viewRect = _scrollRect.GetComponent <RectTransform>();

            _viewWidth  = viewRect.sizeDelta.x;
            _viewHeight = viewRect.sizeDelta.y;

            ResetContentSize();
        }
예제 #19
0
        // Use this for initialization
        void Start()
        {
            _scroll_rect = gameObject.GetComponent<ScrollRect>();

            if (_scroll_rect.horizontalScrollbar || _scroll_rect.verticalScrollbar)
            {
                Debug.LogWarning("Warning, using scrollbors with the Scroll Snap controls is not advised as it causes unpredictable results");
            }

            _screensContainer = _scroll_rect.content;
            if (PageStep == 0)
            {
                PageStep = (int)_scroll_rect.GetComponent<RectTransform>().rect.width * 3;
            }
            DistributePages();

            _lerp = false;
            _currentScreen = StartingScreen;

            _scroll_rect.horizontalNormalizedPosition = (float)(_currentScreen - 1) / (_screens - 1);

            ChangeBulletsInfo(_currentScreen);

            if (NextButton)
                NextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); });

            if (PrevButton)
                PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); });
        }
	void Start () {
		scrollRect = GetComponent<ScrollRect>();
		scrollRectTransform = scrollRect.GetComponent<RectTransform>();
		scrollRectContent = scrollRect.content;

		scrollRect.verticalNormalizedPosition = 1f;
    }
예제 #21
0
    // Use this for initialization
    void Start()
    {
        cloudRecognition = gameObject.GetComponent <BaiduARCloudRecognition> ();

        exampleScrollView = scrollRect.GetComponent <ARExampleScrollView> ();
        tracker           = objectTracker.GetComponent <BaiduARObjectTracker> ();

        index = exampleScrollView.centerIndex;

        page    = null;
        message = GameObject.Find("message").GetComponent <Text> ();
        for (int i = 0; i < content.transform.childCount; i++)
        {
            string name  = content.transform.GetChild(i).GetComponent <ARExampleButtonInfo> ().FunctionName;
            int    count = i;
            content.transform.GetChild(i).GetComponent <Button>().onClick.AddListener(
                delegate()
            {
                this.ButtonOnClick(name, count);
            });
        }

        takePictureBtn.onClick.AddListener(TakePicture);
        content.transform.GetChild(index).GetComponent <Button> ().onClick.Invoke();

        dishItem   = new List <DishDataItem> ();
        sceneItem  = new List <SceneDataItem> ();
        commonItem = new List <CommonDataItem> ();

        CloudListener();
    }
 /// <summary>
 /// Called internally in <see cref="SRIA{TParams, TItemViewsHolder}.Init()"/> and every time the scrollview's size changes.
 /// This makes sure the content and viewport have valid values. It can also be overridden to initialize custom data
 /// </summary>
 public virtual void InitIfNeeded(ISRIA sria)
 {
     // Commented: null-coalescing operator doesn't work with unity's Object
     //content = content ?? scrollRect.content;
     if (!scrollRect)
     {
         scrollRect = sria.AsMonoBehaviour.GetComponent <ScrollRect>();
     }
     if (!scrollRect)
     {
         throw new UnityException("Can't find ScrollRect component!");
     }
     if (!viewport)
     {
         viewport = scrollRect.transform as RectTransform;
     }
     if (!content)
     {
         content = scrollRect.content;
     }
     if (!Snapper)
     {
         Snapper = scrollRect.GetComponent <Snapper8>();
     }
 }
예제 #23
0
	public static void Adjust(ScrollRect rect )
	{
		ScrollViewAdjust com = rect.GetComponent<ScrollViewAdjust>() ;
		if(com != null)
		{
			GameObject.Destroy(com) ;
			com  = null ;
		}

		if(rect.GetComponentInChildren<GridLayoutGroup>()!=null)
		{
			com = rect.gameObject.AddComponent<ScrollViewAdjust>() ;
		}
		else if(rect.GetComponentInChildren<VerticalLayoutGroup>()!=null)
		{
			com = rect.gameObject.AddComponent<ScrollViewVerticalAdjust>() ; 
		}
		else if(rect.GetComponentInChildren<HorizontalLayoutGroup>()!=null)
		{
			com = rect.gameObject.AddComponent<ScrollViewHarizonAdjust>() ; 
		}
		else
		{
			Debug.LogWarning("Cannot Auto adjust scrollview without layout !!! ") ; 
		}
	}
예제 #24
0
    private void SetupScrollView(List <PlayerLeaderboardEntry> playerLeaderboardEntries)
    {
        var           content = scrollRect.content;
        RectTransform myself  = null;

        foreach (var entry in playerLeaderboardEntries)
        {
            var isMyself  = entry.PlayFabId == PlayFabLoginManagerSingleton.Instance.PlayFabId;
            var entryItem = Instantiate(leaderboardEntryItemPrefab, content.transform);
            entryItem.Initialize(entry, isMyself);
            if (isMyself)
            {
                myself = entryItem.GetComponent <RectTransform>();
            }
        }

        if (myself != null)
        {
            LayoutRebuilder.ForceRebuildLayoutImmediate(content);
            var scrollRectHeight = scrollRect.GetComponent <RectTransform>().rect.height;
            var y = -myself.localPosition.y - scrollRectHeight / 2;
            y = Mathf.Max(Mathf.Min(y, content.rect.height - scrollRectHeight), 0);
            scrollRect.content.localPosition = new Vector3(0, y, 0);
        }
    }
예제 #25
0
    //Set UI interactable properties
    private void Awake()
    {
        //Start Client
        m_StartClientButton.onClick.AddListener(base.StartClient);

        //Send to Server
        m_SendToServerButton.interactable = false;
        m_SendToServerButton.onClick.AddListener(SendMessageToServer);

        //SendClose
        m_SendCloseButton.interactable = false;
        m_SendCloseButton.onClick.AddListener(SendCloseToServer);

        //Populate Client delegates
        OnClientStarted = () =>
        {
            //Set UI interactable properties
            m_StartClientButton.interactable  = false;
            m_SendToServerButton.interactable = true;
            m_SendCloseButton.interactable    = true;
        };

        OnClientClosed = () =>
        {
            //Set UI interactable properties
            m_StartClientButton.interactable  = true;
            m_SendToServerButton.interactable = false;
            m_SendCloseButton.interactable    = false;
        };

        //UI References
        m_ClientLoggerRectTransform = m_ClientLoggerScrollRect.GetComponent <RectTransform>();
        m_ClientLoggerText          = m_ClientLoggerScrollRect.content.gameObject.GetComponent <Text>();
    }
    void StartPositionItems()
    {
        //Первый элемент выше остальных
        ItemsMenu[0].localPosition = new Vector3(
            ScrollR.GetComponent <RectTransform>().sizeDelta.x / 2,
            PositionSelectionItem,
            PositionItems.z);

        //Первый элемент размера ScaleItemsSelection
        ItemsMenu[0].localScale = ScaleItemsSelection;

        //Каждый элемент становится на свою позицию
        for (int i = 1; i < CountPanel; i++)
        {
            ItemsMenu[i].localPosition = new Vector3(
                ItemsMenu[i - 1].localPosition.x + ItemsMenu[i - 1].GetComponent <RectTransform>().sizeDelta.x + DistanceBetweenItems,
                PositionItems.y,
                PositionItems.z);
            //Кроме первого, меньше размера, i=1
            ItemsMenu[i].localScale = ScaleItemsNextAndBack;
        }

        //Размер контейнера с модами
        ObjectsWithGridLayoutGroup.GetComponent <RectTransform>().sizeDelta = new Vector2(
            ExampleLevelPrefab.GetComponent <RectTransform>().sizeDelta.x *(CountPanel - 1) + DistanceBetweenItems * (CountPanel - 1),
            ObjectsWithGridLayoutGroup.GetComponent <RectTransform>().sizeDelta.y);
    }
예제 #27
0
        public void OnValueChanged(Vector2 normalizedPosition)
        {
            if (_transCount == _itemCount)
            {
                return;
            }

            Vector2 scrollerSize = _scroller.GetComponent <RectTransform>().rect.size;
            Vector2 gridSize     = _grid.GetComponent <RectTransform>().rect.size;

            int startIndex = 0;

            if (_moveType == Movement.Horizontal)
            {
                float scrollLength = -_grid.GetComponent <RectTransform>().anchoredPosition.x;
                int   scrollCol    = (int)(scrollLength / ItemSize.x);
                startIndex = scrollCol * _row;
            }
            else
            {
                float scrollLength = _grid.GetComponent <RectTransform>().anchoredPosition.y;
                int   scrollRow    = (int)(scrollLength / ItemSize.y);
                startIndex = scrollRow * _col;
            }

            SwapIndex(startIndex);
        }
예제 #28
0
    /// <summary>
    /// 指定一个 item让其定位到ScrollRect中间
    /// </summary>
    /// <param name="target">需要定位到的目标</param>
    public void CenterOnItem(int index, GameObject scroll)
    {
        ScrollRect    scrollView       = scroll.GetComponent <ScrollRect>();
        RectTransform viewPort         = scrollView.viewport;
        RectTransform contentTransform = scrollView.content;

        if (_childrenPos.Count == 0)
        {
            float childPosX             = scrollView.GetComponent <RectTransform>().rect.width * 0.5f - GetChildItemWidth(0, contentTransform) * 0.5f;
            HorizontalLayoutGroup group = contentTransform.GetComponent <HorizontalLayoutGroup>();
            float spacing = group.spacing;
            _childrenPos.Add(childPosX);
            for (int i = 1; i < contentTransform.childCount; i++)
            {
                childPosX -= GetChildItemWidth(i, contentTransform) * 0.5f + GetChildItemWidth(i - 1, contentTransform) * 0.5f + spacing;
                _childrenPos.Add(childPosX);
            }
        }
        Vector3 newPos = Vector3.zero;

        if (index >= 2)
        {
            newPos = new Vector3(_childrenPos[index], 0, 0);
        }
        DOTween.To(() => contentTransform.localPosition, x => contentTransform.localPosition = x, newPos, 1);
    }
예제 #29
0
    public void SetearListaJugadores()
    {
        gameObject.SetActive(true);

        CanvasController.instance.overlayPanel.SetNombrePanel("SELECCION JUGADORES", AppController.Idiomas.Español);
        CanvasController.instance.overlayPanel.SetNombrePanel("PLAYERS SELECTION", AppController.Idiomas.Ingles);

        listaJugadores         = AppController.instance.equipoActual.GetJugadores();
        jugadoresSeleccionados = new List <Jugador>();
        listaBotonesJugador    = new List <BotonSeleccionJugador>();

        foreach (var jugador in listaJugadores)
        {
            GameObject go = Instantiate(botonJugador, transformParent, false);
            go.GetComponentInChildren <Text>().text = jugador.GetNombre();
            go.SetActive(true);
            listaBotonesJugador.Add(go.GetComponent <BotonSeleccionJugador>());
        }

        if (prefabHeight == 0)
        {
            prefabHeight = botonJugador.GetComponent <RectTransform>().rect.height;
        }
        cantMinima = (int)(scrollRect.GetComponent <RectTransform>().rect.height / (prefabHeight + transformParent.GetComponent <VerticalLayoutGroup>().spacing + transformParent.GetComponent <VerticalLayoutGroup>().padding.top));
    }
예제 #30
0
    //flat means unsigned
    public static float ClampScrollPos(float flat_pos, RectTransform rt, ScrollRect scroll)
    {
        if (scroll != null && rt != null)
        {
            //Vector2 v = rt.anchoredPosition;
            RectTransform scrollTransform = scroll.viewport as RectTransform;
            if (scrollTransform == null)
            {
                scrollTransform = scroll.GetComponent <RectTransform>();
            }
            if (scrollTransform != null)
            {
                float max = scroll.vertical ? rt.rect.height - scrollTransform.rect.height : rt.rect.width - scrollTransform.rect.width;

                if (flat_pos > max)
                {
                    flat_pos = max;
                }
                if (flat_pos < 0)
                {
                    flat_pos = 0;
                }
                //float_pos = max>0? Mathf.Clamp01(flat_pos / max):0;
            }
        }
        return(flat_pos);
    }
        void Awake()
        {
            //Get the current scroll rect so we can disable it if the other one is scrolling
            _myScrollRect = this.GetComponent <ScrollRect>();
            //If the current scroll Rect has the vertical checked then the other one will be scrolling horizontally.
            scrollOtherHorizontally = _myScrollRect.vertical;
            //Check some attributes to let the user know if this wont work as expected
            if (scrollOtherHorizontally)
            {
                if (_myScrollRect.horizontal)
                {
                    Debug.LogError("You have added the SecondScrollRect to a scroll view that already has both directions selected");
                }
                if (!ParentScrollRect.horizontal)
                {
                    Debug.LogError("The other scroll rect doesnt support scrolling horizontally");
                }
            }
            else if (!ParentScrollRect.vertical)
            {
                Debug.LogError("The other scroll rect doesnt support scrolling vertically");
            }

            if (ParentScrollRect && !ParentScrollSnap)
            {
                ParentScrollSnap = ParentScrollRect.GetComponent <ScrollSnapBase>();
            }
        }
예제 #32
0
    protected virtual void Awake()
    {
        scrollRect  = scroll.GetComponent <RectTransform>();
        contentRect = gridLayout.GetComponent <RectTransform>();
        minSize     = contentRect.rect.size.y;

        SetupScrollingComponets();

        //set listener for end of list
        scroll.onValueChanged.AddListener(delegate(Vector2 v)
        {
            if (userInteraction && scroll.velocity.magnitude > scrollVelocityThreshold)
            {
                if (shouldAlingCoroutine != null)
                {
                    StopCoroutine(shouldAlingCoroutine);
                }
                shouldAlingCoroutine = StartCoroutine(ShouldAlingRoutine());
            }


            if (GetNormalizedPosition() <= 0.0f && onReachEndOfList != null)
            {
                onReachEndOfList();
            }
        });
    }
예제 #33
0
        // Use this for initialization
        void Start()
        {
            _scroll_rect = gameObject.GetComponent <ScrollRect>();

            if (_scroll_rect.horizontalScrollbar || _scroll_rect.verticalScrollbar)
            {
                Debug.LogWarning("Warning, using scrollbors with the Scroll Snap controls is not advised as it causes unpredictable results");
            }

            _screensContainer = _scroll_rect.content;
            if (PageStep == 0)
            {
                PageStep = (int)_scroll_rect.GetComponent <RectTransform>().rect.height * 3;
            }
            DistributePages();

            _lerp          = false;
            _currentScreen = StartingScreen;

            _scroll_rect.verticalNormalizedPosition = (float)(_currentScreen - 1) / (float)(_screens - 1);

            ChangeBulletsInfo(_currentScreen);

            if (NextButton)
            {
                NextButton.GetComponent <Button>().onClick.AddListener(() => { NextScreen(); });
            }

            if (PrevButton)
            {
                PrevButton.GetComponent <Button>().onClick.AddListener(() => { PreviousScreen(); });
            }
        }
        private void Start()
        {
            _parentPlannerUI = GetComponentInParent<VisualizationUI>();

            _scrollRect = GetComponentInParent<ScrollRect>();

            _scrollRectRectTransform = _scrollRect.GetComponent<RectTransform>();
        }
예제 #35
0
        /// <summary>
        /// Caches and initializes the scroller
        /// </summary>
        void Awake()
        {
            GameObject go;

            // cache some components
            _scrollRect = this.GetComponent<ScrollRect>();
            _scrollRectTransform = _scrollRect.GetComponent<RectTransform>();

            // destroy any content objects if they exist. Likely there will be
            // one at design time because Unity gives errors if it can't find one.
            if (_scrollRect.content != null)
            {
                DestroyImmediate(_scrollRect.content.gameObject);
            }

            // Create a new active cell view container with a layout group
            go = new GameObject("Container", typeof(RectTransform));
            go.transform.SetParent(_scrollRectTransform, false);
            if (scrollDirection == ScrollDirectionEnum.Vertical)
                go.AddComponent<VerticalLayoutGroup>();
            else
                go.AddComponent<HorizontalLayoutGroup>();
            _container = go.GetComponent<RectTransform>();

            // set the containers anchor and pivot
            if (scrollDirection == ScrollDirectionEnum.Vertical)
            {
                _container.anchorMin = new Vector2(0, 1);
                _container.anchorMax = Vector2.one;
                _container.pivot = new Vector2(0.5f, 1f);
            }
            else
            {
                _container.anchorMin = Vector2.zero;
                _container.anchorMax = new Vector2(0, 1f);
                _container.pivot = new Vector2(0, 0.5f);
            }
            _container.offsetMax = Vector2.zero;
            _container.offsetMin = Vector2.zero;
            _container.localScale = Vector3.one;

            _scrollRect.content = _container;

            // cache the scrollbar if it exists
            if (scrollDirection == ScrollDirectionEnum.Vertical)
            {
                _scrollbar = _scrollRect.verticalScrollbar;
            }
            else
            {
                _scrollbar = _scrollRect.horizontalScrollbar;
            }

            // cache the layout group and set up its spacing and padding
            _layoutGroup = _container.GetComponent<HorizontalOrVerticalLayoutGroup>();
            _layoutGroup.spacing = spacing;
            _layoutGroup.padding = padding;
            _layoutGroup.childAlignment = TextAnchor.UpperLeft;
            _layoutGroup.childForceExpandHeight = (scrollDirection == ScrollDirectionEnum.Vertical ? false : true);
            _layoutGroup.childForceExpandWidth = (scrollDirection == ScrollDirectionEnum.Vertical ? true : false);

            // force the scroller to scroll in the direction we want
            _scrollRect.horizontal = scrollDirection == ScrollDirectionEnum.Horizontal;
            _scrollRect.vertical = scrollDirection == ScrollDirectionEnum.Vertical;

            // create the padder objects

            go = new GameObject("First Padder", typeof(RectTransform), typeof(LayoutElement));
            go.transform.SetParent(_container, false);
            _firstPadder = go.GetComponent<LayoutElement>();

            go = new GameObject("Last Padder", typeof(RectTransform), typeof(LayoutElement));
            go.transform.SetParent(_container, false);
            _lastPadder = go.GetComponent<LayoutElement>();

            // create the recycled cell view container
            go = new GameObject("Recycled Cells", typeof(RectTransform));
            go.transform.SetParent(_scrollRect.transform, false);
            _recycledCellViewContainer = go.GetComponent<RectTransform>();
            _recycledCellViewContainer.gameObject.SetActive(false);

            // set up the last values for updates
            _lastScrollRectSize = ScrollRectSize;
            _lastLoop = loop;
            _lastScrollbarVisibility = scrollbarVisibility;
        }
 // Use this for initialization
 private void Start()
 {
     targetScrollRect = GetComponent<ScrollRect>();
     scrollWindow = targetScrollRect.GetComponent<RectTransform>();
 }
	//*** METHODS - PUBLIC ***//
	 
	 
	//*** METHODS - PROTECTED ***//
		protected virtual void Awake (){
			TargetScrollRect = GetComponent<ScrollRect>();
			ScrollWindow = TargetScrollRect.GetComponent<RectTransform>();
		}
예제 #38
0
        private void InitScroller()
        {
            // Init Scroller //
            _scroller = GetComponent<ScrollRect>();
            _scrollerRect = _scroller.GetComponent<RectTransform>().rect;

            if (_moveType == Movement.Horizontal)
            {
                _scroller.vertical = false;
                _scroller.horizontal = true;
            }
            else
            {
                _scroller.vertical = true;
                _scroller.horizontal = false;
            }
        }
 // Use this for initialization
 private void Start()
 {
     targetScrollRect = GetComponent<ScrollRect>();
     scrollWindow = targetScrollRect.GetComponent<RectTransform>();
     currentCanvas = transform.root.GetComponent<RectTransform>();
 }