示例#1
0
    void OnInteract(InputValue value)
    {
        var v = value.Get <float>();

        var newpress = v > 0.1f;

        if (newpress && newpress != press)
        {
            if (holdingItem != null)
            {
                var sewingtablehit = Physics2D.OverlapCircle(transform.position + new Vector3(0, 0.5f), 0.5f, SewingTableMask);

                if (sewingtablehit != null)
                {
                    var sewingTable = sewingtablehit.GetComponent <SewingTable>();
                    sewingTable.AddSewingKit();
                    Destroy(holdingItem.GetGameObject());
                    holdingItem = null;
                }
                else
                {
                    holdingItem.LetGo();
                    holdingItem = null;
                    goto finish;
                }
            }
        }

        var hitcol = Physics2D.OverlapCircle(transform.position + new Vector3(0, 0.5f), 0.5f, InteractableMask);

        if (hitcol != null && hitcol.TryGetComponent(out Interactable s))
        {
            if (newpress != press)
            {
                if (newpress)
                {
                    if (s is IPickup pickup)
                    {
                        pickup.Pickup(this);
                        holdingItem = pickup;
                    }
                    else
                    {
                        s.PressDown();
                        interactable = s;
                    }
                }
                else
                {
                    s.PressUp();
                    interactable = null;
                }
            }
        }

finish:

        press = newpress;
    }