Ejemplo n.º 1
0
    /// <summary>
    /// 加载房间列表
    /// </summary>
    private void LoadRoomList(List <UserData> userDataList)
    {
        //在加载房间列表之前先清空列表,防止重复加载
        RoomItem[] roomItems = roomLayout.GetComponentsInChildren <RoomItem>();
        //逐个调用销毁自身的方法
        foreach (RoomItem roomItem in roomItems)
        {
            roomItem.DestorySelf();
        }

        foreach (UserData userData in userDataList) //逐个创建房间信息对象,并添加到房间列表布局中
        {
            GameObject roomItem = GameObject.Instantiate(roomItemPrefab);
            roomItem.transform.SetParent(roomLayout.transform);
            //逐个设置房间信息
            roomItem.GetComponent <RoomItem>().SetRoomItemInfo(userData.Id, userData.Username, userData.TotalCount, userData.WinCount, this);
        }

        //获取所有子物体中RoomItem对象的个数,即房间个数
        int roomCount = GetComponentsInChildren <RoomItem>().Length;
        //房间列表原来的大小
        Vector2 size = roomLayout.GetComponent <RectTransform>().sizeDelta;
        //单个房间信息框的高度
        float roomItemHeight = roomItemPrefab.GetComponent <RectTransform>().sizeDelta.y;

        //重新设置房间列表的长度,新的长度等于所有房间信息的个数×(一个roomItem的高度+两个roomItem之间的间隙)
        roomLayout.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x, roomCount * (roomItemHeight + roomLayout.spacing));
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Console sayfasına Label ekler
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="c"></param>
    /// <returns></returns>
    protected virtual void CreateTextLabel(object cmd, Color c)
    {
        string cmdText = cmd.ToString();
        //Debug.Log(cmdText);

        var t = Instantiate(Instance.ExampleText, Instance.Grid.transform);

        AllCalledCmds.Add(t.gameObject);
        t.fontSize = Instance.FontSize;
        //Kullanıcı tarafından geliyosa "<", uygulamadan geliyosa ">"
        t.text      = cmdText[0] == '<' || cmdText[0] == '>' ? cmdText : "> " + cmdText;
        t.color     = c;
        t.alignment = TextAnchor.UpperLeft;

        Grid.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.Unconstrained;
        Grid.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

        Instance.ScrollVertical.value = 0;

        if (AllCalledCmds.Count >= MaxVisibleCmdCount)
        {
            var objectToDestroy = AllCalledCmds[0];
            AllCalledCmds.RemoveAt(0);
            Destroy(objectToDestroy);
        }
    }
Ejemplo n.º 3
0
    private void LoadRoomItem(List <UserData> udList)
    {
        // 加载之前先进行清空操作 防止重复加载 得到roomLayout下的所有子物体
        RoomItem[] riArray = roomLayout.GetComponentsInChildren <RoomItem>();
        foreach (RoomItem ri in riArray)
        {
            ri.DestroySelf(); // 所有roomItem现存的物体销毁掉
        }

        int count = udList.Count;

        for (int i = 0; i < count; i++)
        {
            // 实例化后放在布局下
            GameObject roomItem = GameObject.Instantiate(roomItemPrefab);
            roomItem.transform.SetParent(roomLayout.transform);
            UserData ud = udList[i];
            roomItem.GetComponent <RoomItem>().SetRoomInfo(ud.Id, ud.Username,
                                                           ud.TotalCount, ud.WinCount, this);
        }

        // 设置房间列表高度
        // 得到子物体的个数
        int roomCount = GetComponentsInChildren <RoomItem>().Length;
        // 得到原有的size
        Vector2 size = roomLayout.GetComponent <RectTransform>().sizeDelta;

        // 房间个数乘以房间自身高度 需要加上房间与房间之间的间隔
        roomLayout.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x,
                                                                          roomCount * (roomItemPrefab.GetComponent <RectTransform>().sizeDelta.y + roomLayout.spacing));
    }
Ejemplo n.º 4
0
    private void LoadRoomItem(List <UserData> udList)//加载房间
    {
        RoomItem[] riArray = roomLayout.GetComponentsInChildren <RoomItem>();
        foreach (RoomItem ri in riArray)
        {
            ri.DestroySelf();
        }


        int count = udList.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject roomItem = GameObject.Instantiate(roomItemPrefab);
            roomItem.transform.SetParent(roomLayout.transform);
            UserData ud = udList[i];

            roomItem.GetComponent <RoomItem>().SetRoomInfo(ud.Id, ud.Username, ud.TotalCount, ud.WinCount, this);
        }
        //计算多少个子

        /*
         * int roomCount = roomLayout.GetComponentsInChildren<RoomItem>().Length;
         * Vector2 size = roomLayout.GetComponent<RectTransform>().sizeDelta;
         * roomLayout.GetComponent<RectTransform>().sizeDelta = new Vector2(size.x,
         *  (roomItemPrefab.GetComponent<RectTransform>().sizeDelta.y * roomCount)
         + (roomCount * roomLayout.spacing) - 420.4f
         +  );*/
        int     roomCount = roomLayout.GetComponentsInChildren <RoomItem>().Length;
        Vector2 size      = roomLayout.GetComponent <RectTransform>().sizeDelta;

        roomLayout.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x,
                                                                          roomCount * (roomItemPrefab.GetComponent <RectTransform>().sizeDelta.y + roomLayout.spacing) - 420.4f);
    }
Ejemplo n.º 5
0
    private void AddScriptListItem(string scriptName)
    {
        Vector3 position = ScriptListContent.GetComponent <RectTransform>().position;

        var newElement = Instantiate(ScriptListItemPrefab, position, Quaternion.identity, ScriptListContent.transform);

        newElement.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); // for some reasons it scales to big sizes
        newElement.GetComponent <TextMeshProUGUI>().text     = scriptName;

        Toggle itemToggle = newElement.GetComponent <Toggle>();

        itemToggle.group = ScriptListContent.GetComponent <ToggleGroup>();
        itemToggle.onValueChanged.AddListener(val =>
        {
            if (val)
            {
                Debug.Log($"BeltScriptMenu: Selected {scriptName}");
                m_currentSelection = scriptName;
            }
            else
            {
                m_currentSelection = null;
            }
        });

        m_scriptListItems.Add(newElement);
    }
Ejemplo n.º 6
0
    protected override Vector2 GetItemSize()
    {
        RectTransform content   = verticalLayoutGroup.GetComponent <RectTransform>();
        RectTransform child0    = content.GetChild(0) as RectTransform;
        RectTransform child1    = content.GetChild(1) as RectTransform;
        float         childSize = abs(child1.anchoredPosition.y - child0.anchoredPosition.y) - verticalLayoutGroup.spacing;

        return(new Vector2(0, childSize));
    }
Ejemplo n.º 7
0
    private void UpdateLayoutSize()
    {
        int     itemCount = GetComponentsInChildren <ChatItem>().Length;
        Vector2 size      = layoutGroup.GetComponent <RectTransform>().sizeDelta;

        layoutGroup.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x,
                                                                           itemCount * (chatItem.GetComponent <RectTransform>().sizeDelta.y
                                                                                        + layoutGroup.GetComponent <VerticalLayoutGroup>().spacing));
    }
Ejemplo n.º 8
0
    private void LoadRoomItem(int count)
    {
        for (int i = 0; i < count; i++)
        {
            GameObject roomItem = GameObject.Instantiate(roomItemPrefab);
            roomItem.transform.SetParent(roomLayout.transform);
        }
        Vector2 size      = roomLayout.GetComponent <RectTransform>().sizeDelta;
        int     roomCount = GetComponentsInChildren <RoomItem>().Length;

        roomLayout.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x,
                                                                          roomCount * (roomItemPrefab.GetComponent <RectTransform>().sizeDelta.y + roomLayout.spacing));
    }
Ejemplo n.º 9
0
    public void End()
    {
        Vector2 contentSize = ContentLayout.GetComponent <RectTransform>().sizeDelta;

        contentSize.y = ContentLayout.padding.top + ContentLayout.padding.bottom;

        foreach (RectTransform item in ContentLayout.transform)
        {
            contentSize.y += item.sizeDelta.y + ContentLayout.spacing;
        }

        ContentLayout.GetComponent <RectTransform>().sizeDelta = contentSize;
    }
Ejemplo n.º 10
0
 public static void ScrollToTop(this VerticalLayoutGroup verticalLayoutGroup)
 {
     if (verticalLayoutGroup != null)
     {
         ScrollToTop(verticalLayoutGroup.GetComponent <RectTransform>());
     }
 }
Ejemplo n.º 11
0
 private void OnToggleClicked()
 {
     _isPanelOpen = !_isPanelOpen;
     _panel.SetActive(_isPanelOpen);
     _toggleButton.ToggleOpenButton(_isPanelOpen);
     LayoutRebuilder.ForceRebuildLayoutImmediate(_verticalLayoutGroup.GetComponent <RectTransform>());
 }
Ejemplo n.º 12
0
    public static void ResizeForContent(this VerticalLayoutGroup _this)
    {
        RectTransform t = _this.GetComponent <RectTransform>();
        float         h = ComputeContentHeight(_this);

        t.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, h);
    }
Ejemplo n.º 13
0
 static void SetDynamicVerticalLayout(VerticalLayoutGroup layout, VerticalLayoutDynamicDirection direction)
 {
     layout.childAlignment = direction == VerticalLayoutDynamicDirection.Top ? TextAnchor.UpperCenter : TextAnchor.LowerCenter;
     layout.spacing        = 5;
     layout.GetOrAddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.MinSize;
     layout.GetComponent <RectTransform>().pivot = direction == VerticalLayoutDynamicDirection.Top ? new Vector2(0, 1) : new Vector2(0, 0);
 }
Ejemplo n.º 14
0
        public override void Initialize()
        {
            base.Initialize();
            LayoutRebuilder.ForceRebuildLayoutImmediate(_verticalLayoutGroup.GetComponent <RectTransform>());

            _widthCurveButton.buttonObject.onClick.AddListener(OnBrushWidthCurveClicked);

            _gradientButton.buttonObject.onClick.AddListener(OnBrushGradientClicked);
            _brushEmissionSlider.slider.onValueChanged.AddListener(OnBrushEmissionValueChanged);
            _emissionSwitch.toggle.onValueChanged.AddListener(OnEmissionValueChanged);

            _brushShapeDropdown.onItemSelected.AddListener(OnBrushShapeItemSelected);
            _brushShapeSizeSlider.slider.onValueChanged.AddListener(OnBrushSizeValueChanged);
            _brushEmissionColorButton.buttonObject.onClick.AddListener(OnBrushEmissionColorClicked);
            CreateTextureGradient();
        }
Ejemplo n.º 15
0
        public void RefreshContactsFrames()
        {
            _contactsGrid.GetComponent <RectTransform>().sizeDelta = new Vector2(GlobalVars.DEFAULT_SCREEN_WIDTH, CONTACT_FRAME_HEIGHT * GlobalContacts.GetInstance().Count);

            int i = 0;

            foreach (UserItem userItem in GlobalContacts.GetInstance())
            {
                if (i >= _contactFrameList.Count)
                {
                    GameObject go = UIManager.GetInstance().AddChild(_contactsGrid.gameObject, EUIType.ContactFrame);
                    _contactFrameList.Add(go.GetComponent <ContactFrame>());
                }
                _contactFrameList[i].Show(userItem);
                i++;
            }

            if (_contactFrameList.Count > GlobalContacts.GetInstance().Count)
            {
                for (i = GlobalContacts.GetInstance().Count; i < _contactFrameList.Count; i++)
                {
                    GameObject.Destroy(_contactFrameList[i].gameObject);
                }
                _contactFrameList = _contactFrameList.GetRange(0, GlobalContacts.GetInstance().Count);
            }
        }
Ejemplo n.º 16
0
        private void InitMemberFrames()
        {
            List <string> groupMemberIDs = new List <string>();

            if (_groupItem != null)
            {
                groupMemberIDs = _groupItem.memberUserId;
            }

            foreach (var friendItem in GlobalContacts.GetInstance())
            {
                GameObject go = UIManager.GetInstance().AddChild(_gridSelectMember.gameObject, EUIType.GroupMemberFrame);
                go.GetComponent <GroupMemberFrame>().Show(friendItem);

                if (groupMemberIDs.Contains(friendItem.userId))
                {
                    go.GetComponent <GroupMemberFrame>().SetToggleInactive();
                }
            }
            _gridSelectMember.GetComponent <RectTransform>().sizeDelta = new Vector2(
                GlobalVars.DEFAULT_SCREEN_WIDTH,
                GlobalContacts.GetInstance().Count *GROUP_MEMBER_FRAME_HEIGHT);

            _selectUserIdSet.Clear();
            RefreshGroupMember();
        }
Ejemplo n.º 17
0
    private IEnumerator LoadTroops()
    {
        List <FighterData> fighters = gameData.GetFightersOwned();

        for (int i = 0; i < fighters.Count; i++)
        {
            GameObject go = Instantiate(troopPrefab);
            go.AddComponent <FighterModel>();
            go.transform.SetParent(teamPanel);
            ((RectTransform)go.transform).localPosition = Vector3.zero;
            TroopController tc = go.GetComponent <TroopController>();
            model.troops.Add(tc);
            tc.SetTroop(fighters[i]);
        }

        // Resize scrollable background based on number of elements
        float         elementHeight = troopPrefab.GetComponent <LayoutElement>().minHeight + content.spacing;
        RectTransform rt            = content.GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2(rt.rect.width, elementHeight * fighters.Count + 1 + content.padding.right + content.padding.bottom);

        yield return(new WaitForEndOfFrame());

        ShowTroopDetails(fighters[0]);
    }
Ejemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        SMSpadding = (int)(SMSBoxParent.GetComponent <RectTransform> ().rect.width / 2);

        sliderContent = (RectTransform)SMSBoxParent.transform.parent;

        sliderContent.offsetMin = new Vector2(sliderContent.offsetMin.x, 0);
    }
Ejemplo n.º 19
0
    IEnumerator UpadteHeight()
    {
        yield return(new WaitForEndOfFrame());

        var height = _layout.preferredHeight;

        _layout.GetComponent <RectTransform>().sizeDelta = new Vector2(0, height);
    }
Ejemplo n.º 20
0
    public void SetCommunityLevelsSize()
    {
        RectTransform cRT  = communityContent.GetComponent <RectTransform>();
        Vector2       size = cRT.sizeDelta;

        size.y        = communityContent.preferredHeight;
        cRT.sizeDelta = size;
    }
Ejemplo n.º 21
0
    /// <summary>
    /// Waits for the next frame before scrolling the display list to show the most recently added object.
    /// </summary>
    public IEnumerator ScrollList()
    {
        yield return(null);

        RectTransform displayTransform = ObjectDisplayLayout.GetComponent <RectTransform> ();

        displayTransform.localPosition = new Vector2(displayTransform.localPosition.x, displayTransform.rect.height);
    }
        internal void Update()
        {
            var scrollPosition = ScrollRect.content.localPosition.y;
            // How many items are not visible in current view
            var offscreenItemCount = Mathf.Max(0, _items.Count - _cachedEntries.Count);
            // How many items are above current view rect and not visible
            var itemsAboveViewRect = Mathf.FloorToInt(Mathf.Clamp(scrollPosition / panelHeight, 0, offscreenItemCount));

            if (_lastItemsAboveViewRect == itemsAboveViewRect && !_dirty)
            {
                return;
            }

            _lastItemsAboveViewRect = itemsAboveViewRect;
            _dirty = false;

            // Store selected item to preserve selection when moving the list with mouse
            var selectedItem = EventSystem.current != null
                ? _cachedEntries.Find(x => x.gameObject == EventSystem.current.currentSelectedGameObject)?.CurrentItem
                : null;

            var count = 0;

            foreach (var item in _items.Skip(itemsAboveViewRect))
            {
                if (_cachedEntries.Count <= count)
                {
                    break;
                }

                var cachedEntry = _cachedEntries[count];

                count++;

                cachedEntry.SetItem(item, false);
                cachedEntry.SetVisible(true);

                if (ReferenceEquals(selectedItem, item))
                {
                    EventSystem.current?.SetSelectedGameObject(cachedEntry.gameObject);
                }
            }

            // If there are less items than cached list entries, disable unused cache entries
            if (_cachedEntries.Count > _items.Count)
            {
                foreach (var cacheEntry in _cachedEntries.Skip(_items.Count))
                {
                    cacheEntry.SetVisible(false);
                }
            }

            RecalculateOffsets(itemsAboveViewRect);

            // Needed after changing _verticalLayoutGroup.padding since it doesn't make the object dirty
            LayoutRebuilder.MarkLayoutForRebuild(_verticalLayoutGroup.GetComponent <RectTransform>());
        }
Ejemplo n.º 23
0
    private void LoadRoomItems(List <UserData> userDataList)
    {
        ClearCurrentRoomItems();
        for (int i = 0; i < userDataList.Count; i++)
        {
            GameObject roomItem = Instantiate(roomItemPrefab);
            roomItem.transform.SetParent(roomLayout.transform);
            UserData userData = userDataList[i];
            roomItem.GetComponent <RoomItem>().SetRoomItem(userData.ID, userData.Username, userData.TotalCount, userData.WinCount, this);
        }

        //动态设置Layout的高度
        int roomItemCount = GetComponentsInChildren <RoomItem>().Length;

        roomLayout.GetComponent <RectTransform>().sizeDelta
            = new Vector2(roomLayout.GetComponent <RectTransform>().sizeDelta.x,
                          roomItemCount * roomItemPrefab.GetComponent <RectTransform>().sizeDelta.y + roomLayout.spacing);
    }
    void Start()
    {
        if (manager.currentPlayer.credits < 10)
        {
            attackBtn.interactable = false;
        }

        contentPanel.Find("Credit").GetComponent <Text>().text = "You have " + manager.currentPlayer.credits + " credits.";

        NetworkManager.Send(ClashPlayerListProtocol.Prepare(), (res) => {
            var response = res as ResponseClashPlayerList;

            foreach (var pair in response.players)
            {
                Player player = new Player(pair.Key);
                player.name   = pair.Value;
                playerList.Add(player);

                var item = Instantiate(playerItemPrefab) as GameObject;
                item.transform.SetParent(playerListGroup.transform);
                item.transform.position   = new Vector3(item.transform.position.x, item.transform.position.y, 0.0f);
                item.transform.localScale = Vector3.one;

                item.GetComponentInChildren <Text>().text = player.name;

                var toggle = item.GetComponentInChildren <Toggle>().group = playerListGroup.GetComponent <ToggleGroup>();
                item.GetComponentInChildren <Toggle>().onValueChanged.AddListener((val) => {
                    contentPanel.Find("Message").GetComponent <Text>().enabled = !val;
                    if (val)
                    {
                        selectedPlayer        = player;
                        manager.currentTarget = new ClashDefenseConfig();
                        NetworkManager.Send(ClashPlayerViewProtocol.Prepare(player.GetID()), (resView) => {
                            var responseView = resView as ResponseClashPlayerView;
//                            Debug.Log(responseView.terrain);
                            contentPanel.GetComponent <RawImage>().texture = Resources.Load("Images/ClashOfSpecies/" + responseView.terrain) as Texture;
                            manager.currentTarget.owner   = player;
                            manager.currentTarget.terrain = responseView.terrain;
                            manager.currentTarget.layout  = responseView.layout.Select(x => {
                                var species   = manager.availableSpecies.Single(s => s.id == x.Key);
                                var positions = x.Value;
                                return(new {
                                    species,
                                    positions
                                });
                            }).ToDictionary(p => p.species, p => p.positions);
                        });
                    }
                    else
                    {
                        selectedPlayer = null;
                        contentPanel.GetComponent <RawImage>().texture = null;
                    }
                });
            }
        });
    }
Ejemplo n.º 25
0
    public void SetLocalLevelsSize()
    {
        RectTransform cRT  = communityLocal.GetComponent <RectTransform>();
        Vector2       size = cRT.sizeDelta;

        size.y        = communityLocal.preferredHeight;
        cRT.sizeDelta = size;

        ChangePuzzleSelectedShowing((int)PuzzlesSelected.Community);
    }
Ejemplo n.º 26
0
        /// <summary>
        /// Console sayfasına Label ekler
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        protected virtual void CreateTextLabel(CCmd cmd)
        {
            string cmdText = cmd.Text;

            Text t;

            if (AllCalledCmds.Count >= MaxVisibleCmdCount)
            {
                t = AllCalledCmds[0];
                t.transform.SetAsLastSibling();

                AllCalledCmds.RemoveAt(0);
                AllCalledCmds.Add(t);
            }
            else
            {
                t = Instantiate(Instance.ExampleText, Instance.Grid.transform);
            }
            AllCalledCmds.Add(t);
            t.fontSize = Instance.FontSize;

            //Kullanıcı tarafından geliyosa "<", uygulamadan geliyosa ">"
            if (cmdText[0] != '<' && cmdText[0] != '>')
            {
                StrBuilderForText.Append(ShowOnConsolePrefix);
            }
            StrBuilderForText.Append('[');
            StrBuilderForText.Append(cmd.Time.ToString("0.00"));
            StrBuilderForText.Append(']');
            StrBuilderForText.Append(' ');
            StrBuilderForText.Append(cmdText);
            t.text = StrBuilderForText.ToString();
            StrBuilderForText.Clear();

            t.color     = cmd.Color;
            t.alignment = TextAnchor.UpperLeft;

            Grid.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.Unconstrained;
            Grid.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            Instance.ScrollVertical.value = 0;
        }
Ejemplo n.º 27
0
        void InitializeUserEntries()
        {
            if (UserSession.Instance.Users == null)
            {
                DisplayState = LoginDisplayState.Login;
            }
            else
            {
                if (UserSession.Instance.Users.Count == 1)
                {
                    //UserSession.Instance.SetCurrentUser(UserSession.Instance.Users[0]);
                    Close();
                    return;
                }

                foreach (Transform child in UserPanel.transform)
                {
                    Destroy(child.gameObject);
                }

                var defaultIndex = 0; // UserSession.Instance.GetDefaultUserIndex();
                var toggleGroup  = UserPanel.GetComponent <ToggleGroup>();
                var UserList     = UserSession.Instance.Users;

                //foreach (AllUsers user in UserList) // foreach loops don't play nice with variables in delegates as UnityEvent listeners
                for (int u = 0; u < UserList.Count; u++)
                {
                    Spaces.Core.User user = UserList[u];

                    GameObject userEntry  = Instantiate(UserEntryPrefab);
                    Toggle     userToggle = userEntry.GetComponent <Toggle>();
                    Text       label      = userEntry.GetComponentInChildren <Text>();

                    userEntry.transform.SetParent(UserPanel.transform, false);

                    if (label)
                    {
                        label.text = user.name;
                    }

                    if (userToggle)
                    {
                        userToggle.onValueChanged.AddListener(delegate { User_Click(userToggle, user); });
                        userToggle.group = toggleGroup;

                        if (u == defaultIndex)
                        {
                            userToggle.isOn = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        protected void UpdateChatBubbleGrid()
        {
            float sumHeight = 0;

            foreach (var item in _chatBubbleList)
            {
                sumHeight += item.GetHeight();
            }

            _gridChatBubble.GetComponent <RectTransform>().sizeDelta = new Vector2(GlobalVars.DEFAULT_SCREEN_WIDTH, sumHeight);
            _scrollChatLog.verticalNormalizedPosition = 0;
        }
Ejemplo n.º 29
0
    public void LoadRoomItem(List <UserData> userdata)
    {
        RoomItem[] riArray = Layout.GetComponentsInChildren <RoomItem>();
        foreach (RoomItem ri in riArray)
        {
            ri.DestroySelf();
        }
        for (int i = 0; i < userdata.Count; i++)
        {
            GameObject roomitem = Instantiate(roomItem);

            roomitem.transform.parent = Layout.transform;
            RoomItemList.Add(roomitem.GetComponent <RoomItem>());
            roomitem.GetComponent <RoomItem>().SetRoomInfo(userdata[i], this);
            roomitem.transform.localScale = Vector3.one;
        }
        int     roomcount = GetComponentsInChildren <RoomItem>().Length;
        Vector2 size      = Layout.GetComponent <RectTransform>().sizeDelta;

        Layout.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x, roomcount * (roomItem.GetComponent <RectTransform>().sizeDelta.y + Layout.spacing));
    }
Ejemplo n.º 30
0
    private void LoadRoomItem(List <UserData> userList)
    {
        RoomItem[] ri = layoutGroup.GetComponentsInChildren <RoomItem>();
        foreach (RoomItem item in ri)
        {
            item.ChangeColor();
        }

        int count = userList.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject roomItem = GameObject.Instantiate(roomItemPrefab);
            roomItem.transform.SetParent(layoutGroup.transform);
            UserData ud = userList[i];
            roomItem.GetComponent <RoomItem>().SetRoomInfor(ud.UserId, ud.UserName, ud.TotalCount, ud.WinCount, this);
        }
        int     roomCount = GetComponentsInChildren <RoomItem>().Length;
        Vector2 group     = layoutGroup.GetComponent <RectTransform>().sizeDelta;

        layoutGroup.GetComponent <RectTransform>().sizeDelta = new Vector2(group.x, roomCount * (roomItemPrefab.GetComponent <RectTransform>().sizeDelta.y + layoutGroup.spacing));
    }
Ejemplo n.º 31
0
	VerticalLayoutGroup layout ;	//布局	

	protected override void InitLayoutInfo ()
	{
		layout = GetComponentInChildren<VerticalLayoutGroup>() ; 
		layoutRect = layout.GetComponent<RectTransform>() ; 
	}