コード例 #1
0
        /// <summary>
        /// Shows and populate the panel if NetTool is active, hide if not.
        /// </summary>
        public override void Update()
        {
            base.Update();

            // Fine Road Heights Net Tool support
            var newSelectedPrefab = _netToolWrapper.GetCurrentPrefab();

            if (newSelectedPrefab != null)
            {
                if (_selectedPrefab == newSelectedPrefab)
                {
                    return;
                }
                _selectedPrefab = newSelectedPrefab;

                var newSubPrefabs = NetUtil.GetSubPrefabs(_selectedPrefab);

                if (_subPrefabs != null && _subPrefabs.SequenceEqual(newSubPrefabs))
                {
                    return;
                }
                _subPrefabs = newSubPrefabs;

                var visibleTabCount   = 0;
                var firstVisibleIndex = -1;

                var requiredHeight = 0;

                // Populate tabs and options
                for (var i = 0; i < _subPrefabs.Length; i++)
                {
                    var tabName = NetUtil.NET_TYPE_NAMES[i];

                    if (_subPrefabs[i] != null)
                    {
                        if (firstVisibleIndex < 0)
                        {
                            firstVisibleIndex = i;
                        }

                        var visibleOptionCount = 0;

                        foreach (var component in _netTypePages[i].components)
                        {
                            var option = component as UIOption;
                            if (option == null)
                            {
                                continue;
                            }

                            // Pass the current prefab to the context-sensitive option
                            if (option.Populate(_subPrefabs[i]))
                            {
                                visibleOptionCount++;
                            }
                        }

                        if (visibleOptionCount > 0)
                        {
                            visibleTabCount++;
                            requiredHeight = Math.Max(requiredHeight, visibleOptionCount * (30 + Padding));
                            _tabstrip.ShowTab(tabName);
                        }
                        else
                        {
                            _tabstrip.HideTab(tabName);
                        }
                    }
                    else
                    {
                        // Hide unrelevant tabs
                        _tabstrip.HideTab(tabName);
                    }
                }

                if (_subPrefabs[_tabstrip.selectedIndex] == null)
                {
                    if (_subPrefabs[(int)NetType.Ground] != null)
                    {
                        _tabstrip.selectedIndex = (int)NetType.Ground;
                    }
                    else if (firstVisibleIndex >= 0)
                    {
                        _tabstrip.selectedIndex = firstVisibleIndex;
                    }
                }
                else
                {
                    _tabstrip.selectedIndex = _tabstrip.selectedIndex;
                }

                isVisible = visibleTabCount > 0;

                _tabstrip.tabPages.height = requiredHeight + 2 * PagesPadding;
                this.FitChildren();

                return;
            }

            if (isVisible)
            {
                isVisible       = false;
                _selectedPrefab = null;
                _subPrefabs     = null;
            }
        }