示例#1
0
        private void AddFavorite(FavStorageItem favStorageItem, bool initializing = false)
        {
            var fav = Instantiate(_favItem, _favItemHolder.transform, false);

            if (favStorageItem.Type == InputItemType.Storage)
            {
                // Save ID to object name for RefreshFavoriteStorageItemIcons()
                fav.name = $"FavItem_{favStorageItem.FactoryIndex}.{favStorageItem.StorageID}";
                fav.GetComponent <Button>().onClick.AddListener(() =>
                {
                    OpenStorage(favStorageItem.FactoryIndex, favStorageItem.StorageID);
                    CloseUI();
                });
                fav.transform.Find("StorageID").GetComponent <Text>().text =
                    $"{favStorageItem.FactoryIndex}.{favStorageItem.StorageID}";

                SetFavStorageItemIcon(favStorageItem.FactoryIndex, favStorageItem.StorageID, fav.transform);
            }
            else
            {
                fav.name = $"FavItem_s{favStorageItem.FactoryIndex}.{favStorageItem.StorageID}";
                fav.GetComponent <Button>().onClick.AddListener(() =>
                {
                    OpenStation(favStorageItem.FactoryIndex, favStorageItem.StorageID);
                    CloseUI();
                });
                fav.transform.Find("StorageID").GetComponent <Text>().text =
                    $"S{favStorageItem.FactoryIndex}.{favStorageItem.StorageID}";
                SetFavStorageItemIcon(favStorageItem.FactoryIndex, favStorageItem.StorageID, fav.transform, true);
            }

            fav.transform.Find("Remark").GetComponent <Text>().text = favStorageItem.Remark;

            fav.transform.Find("Btn_Del").GetComponent <Button>().onClick
            .AddListener(() => { OnFavDelBtnClick(fav.transform, favStorageItem); });

            if (!initializing)
            {
                fav.transform.SetAsFirstSibling();
                The4DPocket.FavStorages.Items.Insert(0, favStorageItem);
                The4DPocket.SaveFavoriteStorages();
            }
        }
示例#2
0
 private void OnFavDelBtnClick(Transform parent, FavStorageItem fav)
 {
     The4DPocket.FavStorages.Items.Remove(fav);
     Destroy(parent.gameObject);
     The4DPocket.SaveFavoriteStorages();
 }