コード例 #1
0
    public void InterpolateSize(ISlotListItem listItem)
    {
        ISlotListSlot currentSlot = listItem.GetCurrentSlot();

        if (currentSlot == null)
        {
            return;
        }

        ESlotListDirection direction  = CalculateOffsetDirection(listItem, Vector2.zero);
        ISlotListSlot      targetSlot = GetTargetSlot(listItem, direction);

        if (targetSlot == null)
        {
            listItem.SetSize(currentSlot.GetSize());
            return;
        }
        float offsetPercent = CalculateOffsetPositionPercent(
            listItem.GetPosition(),
            Vector2.zero,
            currentSlot.GetPosition(),
            targetSlot.GetPosition());

        InterpolateSize(listItem, targetSlot, offsetPercent);
    }
コード例 #2
0
    private ISlotListSlot GetTargetSlot(ISlotListItem listItem, ESlotListDirection direction)
    {
        switch (direction)
        {
        case ESlotListDirection.None: return(null);

        case ESlotListDirection.TowardsNextSlot: return(listItem.GetCurrentSlot().GetNextSlot());

        case ESlotListDirection.TowardsPreviousSlot: return(listItem.GetCurrentSlot().GetPreviousSlot());

        default: return(null);
        }
    }
コード例 #3
0
    public void OnDrag(ISlotListItem listItem, Vector2 dragDelta)
    {
        // Calculate direction
        offsetDirection = CalculateOffsetDirection(listItem, dragDelta);

        // Calculate offset from current slot
        ISlotListSlot targetSlot = GetTargetSlot(listItem, offsetDirection);

        offsetPositionPercent = targetSlot != null
            ? CalculateOffsetPositionPercent(listItem.GetPosition(), dragDelta, listItem.GetCurrentSlot().GetPosition(), targetSlot.GetPosition())
            : 0;

        // Apply this to all list items. This make them move in the same way towards their target slot.
        foreach (ISlotListItem otherListItem in ListItems)
        {
            ApplyOffsetPositionPercent(otherListItem);
        }

        // When the target has been reached, then adjust the current slot of all items
        if (offsetPositionPercent >= 0.6f)
        {
            slotChangeEventStream.OnNext(new SlotChangeEvent(offsetDirection, offsetPositionPercent));
        }
    }
コード例 #4
0
ファイル: SlotChangeEvent.cs プロジェクト: xxxDSSxxx/Play
 public SlotChangeEvent(ESlotListDirection direction, float offsetPositionPercent)
 {
     Direction             = direction;
     OffsetPositionPercent = offsetPositionPercent;
 }