Ejemplo n.º 1
0
    public void DragComponent_DragOutEffects()
    {
        MechaComponentBase mcb = MechaComponentBase.BaseInitialize(new MechaComponentInfo(MechaComponentInfo.MechaComponentType, new GridPos(0, 0), MechaComponentInfo.TotalLife, 0), BattleManager.Instance.PlayerMecha);
        GridPos            gp  = GridPos.GetGridPosByMousePos(BattleManager.Instance.PlayerMecha.transform, Vector3.up, GameManager.GridSize);

        mcb.SetGridPosition(gp);
        BattleManager.Instance.PlayerMecha.AddMechaComponent(mcb);
        DragManager.Instance.CancelCurrentDrag();
        DragManager.Instance.CurrentDrag = mcb.Draggable;
        mcb.Draggable.IsOnDrag           = true;
        BagManager.Instance.RemoveMechaComponentFromBag(this, false);
        PoolRecycle();

        if (BagManager.Instance.InfiniteComponents)
        {
            BagManager.Instance.AddMechaComponentToBag(MechaComponentInfo, out BagItem _);
        }
    }
Ejemplo n.º 2
0
    private void CommonDrag()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!CurrentDrag)
            {
                {
                    // Drag items in bag
                    Ray ray = UIManager.Instance.UICamera.ScreenPointToRay(Input.mousePosition);
                    Physics.Raycast(ray, out RaycastHit hit, 1000f, GameManager.Instance.LayerMask_ComponentHitBox);
                    if (hit.collider)
                    {
                        BagItem bagItem = hit.collider.gameObject.GetComponentInParent <BagItem>();
                        if (bagItem)
                        {
                            CurrentDrag          = bagItem.gameObject.GetComponent <Draggable>();
                            CurrentDrag.IsOnDrag = true;
                        }
                        else
                        {
                            CancelCurrentDrag();
                        }
                    }
                    else
                    {
                        CancelCurrentDrag();
                    }
                }

                //Drag components in scene
                if (!CurrentDrag)
                {
                    Ray ray = GameManager.Instance.MainCamera.ScreenPointToRay(Input.mousePosition);
                    Physics.Raycast(ray, out RaycastHit hit, 1000f, GameManager.Instance.LayerMask_ComponentHitBox);
                    if (hit.collider)
                    {
                        HitBox hitBox = hit.collider.gameObject.GetComponent <HitBox>();
                        if (hitBox)
                        {
                            CurrentDrag_MechaComponentBase = hitBox.ParentHitBoxRoot.MechaComponentBase;
                            CurrentDrag          = CurrentDrag_MechaComponentBase.gameObject.GetComponent <Draggable>();
                            CurrentDrag.IsOnDrag = true;
                        }
                        else
                        {
                            CancelCurrentDrag();
                        }
                    }
                    else
                    {
                        CancelCurrentDrag();
                    }
                }

                // Drag items dropped
                if (!CurrentDrag)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        Ray ray = GameManager.Instance.MainCamera.ScreenPointToRay(Input.mousePosition);
                        Physics.Raycast(ray, out RaycastHit hit, 1000f, GameManager.Instance.LayerMask_ItemDropped);
                        if (hit.collider)
                        {
                            MechaComponentDropSprite mcds = hit.collider.GetComponentInParent <MechaComponentDropSprite>();
                            if (mcds)
                            {
                                MechaComponentBase mcb = MechaComponentBase.BaseInitialize(mcds.MechaComponentInfo.Clone(), BattleManager.Instance.PlayerMecha);
                                GridPos            gp  = GridPos.GetGridPosByMousePos(BattleManager.Instance.PlayerMecha.transform, Vector3.up, GameManager.GridSize);
                                mcb.SetGridPosition(gp);
                                BattleManager.Instance.PlayerMecha.AddMechaComponent(mcb);
                                CurrentDrag          = mcb.GetComponent <Draggable>();
                                CurrentDrag.IsOnDrag = true;
                                mcds.PoolRecycle();
                            }
                        }
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            CancelCurrentDrag();
        }
    }