コード例 #1
0
        private void OnLoadBaseGrid(DisplayData data)
        {
            try
            {
                if (_isBeingDestroyed || _baseGrid == null || _mono?.SubRoot == null)
                {
                    return;
                }

                _baseGrid.ClearPage();

                var grouped = BaseManager.Managers;

                if (grouped == null)
                {
                    QuickLogger.Debug("Grouped returned null canceling operation");
                    return;
                }

                if (data.EndPosition > grouped.Count)
                {
                    data.EndPosition = grouped.Count;
                }

                if (data.ItemsGrid?.transform == null)
                {
                    QuickLogger.Debug("Items Grid returned null canceling operation");
                    return;
                }

                if (_baseGrid.GetCurrentPage() < 2)
                {
                    CreateButton(data, Instantiate(data.ItemsPrefab), new ButtonData {
                        Manager = _mono.Manager
                    }, ButtonType.Home, AuxPatchers.Home(), "BaseBTN");
                    CreateButton(data, Instantiate(data.ItemsPrefab), new ButtonData(), ButtonType.None, AuxPatchers.GoToVehicles(), "VehiclesPageBTN");
                }

                // QuickLogger.Debug($"Bases Count: {grouped.Count}");
                //QuickLogger.Debug($"Bases Antenna: {_mono.Manager.GetCurrentBaseAntenna()}");

                if (_mono.Manager.GetCurrentBaseAntenna() != null || _mono.Manager.Habitat.isCyclops)
                {
                    for (int i = data.StartPosition; i < data.EndPosition; i++)
                    {
                        //QuickLogger.Debug($"Hab{grouped[i].Habitat} || AS{grouped[i].Habitat.gameObject.activeSelf} || TN{grouped[i].InstanceID == _mono.Manager.InstanceID} || HAN {grouped[i].HasAntenna()} || VIS {grouped[i].IsVisible} || Instance ID : {grouped[i].InstanceID}");
                        if (grouped[i].Habitat == null || !grouped[i].Habitat.gameObject.activeSelf || grouped[i].InstanceID == _mono.Manager.InstanceID || !grouped[i].HasAntenna() || !grouped[i].IsVisible)
                        {
                            continue;
                        }
                        //QuickLogger.Debug($"Adding Base {grouped[i].InstanceID}");

                        GameObject buttonPrefab = Instantiate(data.ItemsPrefab);

                        if (buttonPrefab == null || data.ItemsGrid == null)
                        {
                            if (buttonPrefab != null)
                            {
                                QuickLogger.Debug("Destroying Tab", true);
                                Destroy(buttonPrefab);
                            }
                            return;
                        }

                        QuickLogger.Debug($"Adding Base: {grouped[i].GetBaseName()}", true);
                        CreateButton(data, buttonPrefab, new ButtonData {
                            Manager = grouped[i]
                        }, ButtonType.Base, grouped[i].GetBaseName().TruncateWEllipsis(30), "BaseBTN");
                    }
                }
                else
                {
                    QuickLogger.Debug("GetCurrentBaseAntenna most likely is null");
                }

                _baseGrid.UpdaterPaginator(grouped.Count);
            }
            catch (Exception e)
            {
                QuickLogger.Error("Error Caught");
                QuickLogger.Error($"Error Message: {e.Message}");
                QuickLogger.Error($"Error StackTrace: {e.StackTrace}");
            }
        }