Пример #1
0
 public void CloseBackpack()
 {
     if (BackpackPanel != null && BackpackPanel.activeSelf)
     {
         BackpackPanel.SetActive(false);
     }
 }
        public void Initialize(IInventoryItemContentInfo iInventoryItemContentInfo, BackpackPanel backpackPanel)
        {
            ((RectTransform)transform).anchoredPosition = new Vector2(-((RectTransform)backpackPanel.Container.transform).sizeDelta.x, ((RectTransform)transform).anchoredPosition.y);

            IInventoryItemContentInfo = iInventoryItemContentInfo;
            Color bgColor = IInventoryItemContentInfo.ItemColor;

            ItemNameBG.color  = bgColor;
            ItemNameText.text = IInventoryItemContentInfo.ItemName;

            ItemImage.sprite = BackpackManager.Instance.GetBackpackItemSprite(iInventoryItemContentInfo.ItemSpriteKey);
            Rect  rect  = ItemImage.sprite.rect;
            float ratio = Mathf.Min(ItemImageContainer.sizeDelta.x / rect.width, ItemImageMaxHeight / rect.height);

            rect.height = rect.height * ratio;
            ItemImageContainer.sizeDelta = new Vector2(ItemImageContainer.sizeDelta.x, rect.height);

            ItemCategoryText.text     = IInventoryItemContentInfo.ItemCategoryName;
            ItemCategoryText.color    = IInventoryItemContentInfo.ItemColor;
            ItemQualityText.text      = IInventoryItemContentInfo.ItemQuality;
            ItemQualityText.color     = IInventoryItemContentInfo.ItemColor;
            ItemBasicInfoText.text    = IInventoryItemContentInfo.ItemBasicInfo;
            ItemDetailedInfoText.text = IInventoryItemContentInfo.ItemDetailedInfo;

            foreach (Image image in Decorators)
            {
                image.color = bgColor;
            }

            StartCoroutine(CommonUtils.UpdateLayout((RectTransform)transform));
        }
Пример #3
0
 public void OpenBackpack()
 {
     if (BackpackPanel != null && !BackpackPanel.activeSelf)
     {
         BackpackPanel.SetActive(true);
     }
 }
Пример #4
0
        private void InitBackpack()
        {
            Backpack myBackPack = new Backpack(
                DragAreaDefines.BattleInventory.DragAreaName,
                DragAreaDefines.BattleInventory,
                ConfigManager.BackpackGridSize,
                10,
                8,
                false,
                true,
                true,
                65,
                () => ControlManager.Instance.Common_Tab.Down,
                () => ControlManager.Instance.Building_RotateItem.Down,
                (parent) => GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.BackpackGrid].AllocateGameObject <BackpackGrid>(parent),
                (parent) => GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.BackpackItem].AllocateGameObject <BackpackItem>(parent),
                (parent) => GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.BackpackItemGrid].AllocateGameObject <BackpackItemGrid>(parent),
                (parent) => GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.BackpackVirtualOccupationQuad].AllocateGameObject <BackpackVirtualOccupationQuad>(parent)
                );

            myBackPack.ToggleDebugKeyDownHandler   = () => ControlManager.Instance.Common_Debug.Down;
            myBackPack.ToggleBackpackCallback      = ToggleBattleInventory;
            myBackPack.ToggleDebugCallback         = null;
            myBackPack.DragItemOutBackpackCallback = (backpackItem) =>
            {
                switch (backpackItem.InventoryItem.ItemContentInfo)
                {
                case MechaComponentInfo mechaComponentInfo:
                {
                    Ray                ray       = CameraManager.Instance.MainCamera.ScreenPointToRay(ControlManager.Instance.Building_MousePosition);
                    GridPos            gp        = GridUtils.GetGridPosByMousePos(ClientBattleManager.Instance.PlayerMecha.transform, ray, Vector3.up, ConfigManager.GridSize);
                    GridPosR           gp_matrix = ClientBattleManager.Instance.PlayerMecha.MechaInfo.MechaEditorInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(gp);
                    MechaComponentInfo mci       = mechaComponentInfo.Clone();
                    ClientBattleManager.Instance.PlayerMecha.MechaInfo.AddMechaComponentInfo(mci, gp_matrix);
                    MechaComponent mc = ClientBattleManager.Instance.PlayerMecha.MechaComponentDict[mci.GUID];
                    mci.InventoryItem.SetGridPosition(gp_matrix);
                    DragManager.Instance.CurrentDrag = mc.Draggable;
                    mc.Draggable.SetOnDrag(true, null, DragManager.Instance.GetDragProcessor <MechaComponent>());
                    return(true);
                }
                }

                return(false);
            };

            BackpackPanel backpackPanel = Instantiate(PrefabManager.Instance.GetPrefab("BattleInventoryPanel"), UIManager.Instance.UINormalRoot).GetComponent <BackpackPanel>();

            backpackPanel.Init(myBackPack,
                               delegate(BackpackItem bi) { UIManager.Instance.ShowUIForms <BackpackItemInfoPanel>().Initialize(bi.InventoryItem.ItemContentInfo, backpackPanel); },
                               delegate(BackpackItem bi) { UIManager.Instance.CloseUIForm <BackpackItemInfoPanel>(); });
            backpackPanel.gameObject.SetActive(false);
            BackpackManager.AddBackPack(myBackPack);
        }