public override void OnUpdate(float deltaTime) { base.OnUpdate(deltaTime); if (selectedId >= 0) { if (!isDragging && (mouseDownPoint - WMouse.Position).LengthSquared() >= 10f) { isDragging = true; dragging_ghost.GetFirst <TextRenderer>().text = listboxComponent[selectedId]; AddChild(dragging_ghost); } if (isDragging) { dragging_ghost.transform.Position = WMouse.Position + mouseDownOffset; } if (WMouse.LeftMouseClickUp()) { if (isDragging) { OnItemDrop?.Invoke(this, files[selectedId]); RemoveChild(dragging_ghost); } isDragging = false; selectedId = -1; } } }
public void DropItem(int itemIndexToRemove) { //AudioSource.PlayClipAtPoint(items[itemIndexToRemove].dropSFX, Camera.main.transform.position, 0.5f); OnItemDrop?.Invoke(this, new ItemEventArgs() { itemIndex = itemIndexToRemove }); items.RemoveAt(itemIndexToRemove); }
public void DropItem(LootItem itemEntity, Cell cell) { if (!HasItems(cell)) { CreateItemBag(cell); } itemEntity.Drop(cell); OnItemDrop?.Invoke(itemEntity, cell); }
public void OnEndDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } transform.SetParent(parent); transform.localPosition = iconInitialPos; List <RaycastResult> raycastResults = new List <RaycastResult>(); graphicRaycaster.Raycast(eventData, raycastResults); OnItemDrop?.Invoke(GetComponentInParent <ISlot>(), raycastResults.Select(rr => rr.gameObject).ToList()); }
private void OnDropItemOnSpacing(int newIndex) { if (!IsDropAllowed()) { DragDropService.Reset(); return; } var activeItem = DragDropService.ActiveItem; var oldIndex = Items.IndexOf(activeItem); var sameDropZone = false; if (oldIndex == -1) // item not present in target dropzone { if (CopyItem == null) { if (DragDropService.Items != null) { DragDropService.Items.Remove(activeItem); } } } else // same dropzone drop { sameDropZone = true; Items.RemoveAt(oldIndex); // the actual index could have shifted due to the removal if (newIndex > oldIndex) { newIndex--; } } if (CopyItem == null) { Items.Insert(newIndex, activeItem); } else { // for the same zone - do not call CopyItem Items.Insert(newIndex, sameDropZone ? activeItem : CopyItem(activeItem)); } OnItemDrop.InvokeAsync(activeItem); //Operation is finished DragDropService.Reset(); }
private void OnDrop() { if (!IsDropAllowed()) { this.Reset(); return; } var activeItem = this.ActiveItem; if (this.DragTargetItem == null) //no direct drag target { if (!Items.Contains(activeItem)) //if dragged to another dropzone { if (CopyItem == null) { Items.Insert(Items.Count, activeItem); //insert item to new zone this.Items.Remove(activeItem); //remove from old zone } else { Items.Insert(Items.Count, CopyItem(activeItem)); //insert item to new zone } } else { //what to do here? } } else // we have a direct target { if (!InstantReplace) { Swap(this.DragTargetItem, activeItem); //swap target with active item OnItemDroped?.Invoke(this.ActiveItem, this.DragTargetItem); } } this.Reset(); StateHasChanged(); OnItemDrop.InvokeAsync(activeItem); }
private void OnDropItemOnSpacing(int newIndex) { if (!IsDropAllowed()) { this.Reset(); return; } var activeItem = this.ActiveItem; var oldIndex = Items.IndexOf(activeItem); if (oldIndex == -1) // item not present in target dropzone { if (CopyItem == null) { this.Items.Remove(activeItem); } } else // same dropzone drop { Items.RemoveAt(oldIndex); // the actual index could have shifted due to the removal if (newIndex > oldIndex) { newIndex--; } } if (CopyItem == null) { Items.Insert(newIndex, activeItem); } else { Items.Insert(newIndex, CopyItem(activeItem)); } //Operation is finished this.Reset(); OnItemDrop.InvokeAsync(activeItem); }
private void OnDrop() { DragDropService.ShouldRender = true; if (!IsDropAllowed()) { DragDropService.Reset(); return; } var activeItem = DragDropService.ActiveItem; if (DragDropService.DragTargetItem == null) //no direct drag target { if (!Items.Contains(activeItem)) //if dragged to another dropzone { if (CopyItem == null) { Items.Insert(Items.Count, activeItem); //insert item to new zone if (DragDropService.Items != null) { DragDropService.Items.Remove(activeItem); //remove from old zone } } else { Items.Insert(Items.Count, CopyItem(activeItem)); //insert item to new zone } } else { //what to do here? } } else // we have a direct target { if (!Items.Contains(activeItem)) // if dragged to another dropzone { if (CopyItem == null) { if (!InstantReplace) { Swap(DragDropService.DragTargetItem, activeItem); //swap target with active item } } else { if (!InstantReplace) { Swap(DragDropService.DragTargetItem, CopyItem(activeItem)); //swap target with a copy of active item } } } else { // if dragged to the same dropzone if (!InstantReplace) { Swap(DragDropService.DragTargetItem, activeItem); //swap target with active item } } } OnItemDrop.InvokeAsync(activeItem); DragDropService.Reset(); StateHasChanged(); }