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); }
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); } }
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)); } }
public SlotChangeEvent(ESlotListDirection direction, float offsetPositionPercent) { Direction = direction; OffsetPositionPercent = offsetPositionPercent; }