private void BtnRightClick(ButtonExpand buttonExpand, PointerEventData eventData) { //Debug.Log("Right Click"); EventSystem.current.SetSelectedGameObject(null); SlotData curSlotData = (SlotData)buttonExpand.transform.parent.GetComponent <ItemSlot>().data; ItemContainer curContainer = GetTagContainer(curSlotData.slotType); if (curDragItem != null) { curContainer.AddItem(DragItem(null)); } else { ItemEntity oldItem = curContainer.GetItemFromSlot(curSlotData.slotIndex); if (oldItem != null) { if (oldItem.itemCount > 1) { int halfCount = oldItem.itemCount / 2; oldItem.Cost(halfCount); ItemEntity tagItem = new ItemEntity(oldItem, halfCount); DragItem(tagItem); } else { curContainer.RemoveItemFromSlot(curSlotData.slotIndex); DragItem(oldItem); } } } RefreshInventory(); }
private void BtnLeftClick(ButtonExpand buttonExpand, PointerEventData eventData) { Debug.Log("Left Click"); EventSystem.current.SetSelectedGameObject(null); SlotData curSlotData = (SlotData)buttonExpand.transform.parent.GetComponent <ItemSlot>().data; ItemContainer curContainer = GetTagContainer(curSlotData.slotType); ItemEntity oldItem = curContainer.AddItemToSlot(curSlotData.slotIndex, curDragItem); DragItem(oldItem); RefreshInventory(); }
private void BtnEndDragEvent(ButtonExpand buttonExpand, PointerEventData eventData) { SlotData curSlotData = (SlotData)buttonExpand.transform.parent.GetComponent <ItemSlot>().data; ItemContainer curContainer = GetTagContainer(curSlotData.slotType); if (buttonExpand.isDragging == false) { return; } //Debug.Log("End Drag"); List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(eventData, results); // 防止错误拖动,验证目标按钮 bool isDragSuccess = false; foreach (RaycastResult raycastResult in results) { var btnExpand = raycastResult.gameObject.GetComponent <ButtonExpand>(); if (btnExpand == null) { break; } var parent = btnExpand.transform.parent; if (parent == null) { break; } var tagItemSlot = parent.gameObject.GetComponent <ItemSlot>(); if (tagItemSlot.data is SlotData tagSlotData) { // 置换目标与原格子的物品 ItemContainer tagContainer = GetTagContainer(tagSlotData.slotType); ItemEntity oldItem = tagContainer.RemoveItemFromSlot(tagSlotData.slotIndex); tagContainer.AddItemToSlot(tagSlotData.slotIndex, DragItem(null)); curContainer.AddItemToSlot(curSlotData.slotIndex, oldItem); RefreshInventory(); isDragSuccess = true; break; } } // 如果未能拖拽成功,置回原状态 if (!isDragSuccess) { curContainer.AddItemToSlot(curSlotData.slotIndex, DragItem(null)); } }
private void BtnBeginDragEvent(ButtonExpand buttonExpand, PointerEventData eventData) { SlotData curSlotData = (SlotData)buttonExpand.transform.parent.GetComponent <ItemSlot>().data; ItemContainer curContainer = GetTagContainer(curSlotData.slotType); if (curDragItem != null) { buttonExpand.isDragging = false; return; } //Debug.Log("Start Drag"); EventSystem.current.SetSelectedGameObject(null); ItemEntity oldItem = curContainer.RemoveItemFromSlot(curSlotData.slotIndex); DragItem(oldItem); RefreshInventory(); }
public void SetColorText(string strColor) { if (IsAlert) { m_isColorAlert = true; ButtonExpand.SetColor("", strColorText: UIEvents.ColorAlert); return; } if (strColor == UIEvents.ColorAlert) { m_isColorAlert = true; } else { m_isColorAlert = false; } ButtonExpand.SetColor("", strColorText: strColor); //ButtonExpand.SetColor(strColor, strColor); }
private void OnClickedExpander() { if (_initialHeight == 0) { _initialHeight = Container.Height - 15; _expandedHeight = _initialHeight * 2; } bool isExpanded = ButtonExpand.Rotation == 180; var from = isExpanded ? _expandedHeight : _initialHeight; var to = isExpanded ? _initialHeight : _expandedHeight; Easing easing = Easing.SpringOut; uint length = 500; switch (_counter) { case 0: easing = new Easing(t => 9 * t * t * t - 13.5 * t * t + 5.5 * t); EasingLabel.Text = "Hula Hoop Easing"; break; case 1: easing = new Easing(t => 1 - Math.Cos(10 * Math.PI * t) * Math.Exp(-5 * t)); EasingLabel.Text = "Shaking Easing"; break; case 2: easing = Easing.SpringOut; EasingLabel.Text = "Spring Out Easing"; break; case 3: easing = Easing.SpringIn; EasingLabel.Text = "Spring In Easing"; break; } TaskMonitor.Create( async() => { var easingLabelTask = EasingLabel.RotateTo(isExpanded ? 0 : 360, length, easing); var rotateTask = ButtonExpand.RotateTo(isExpanded ? 0 : 180, length, easing); var heightAnimation = Container.DoubleTo( from, to, h => Container.HeightRequest = h, length, easing); await Task.WhenAll(rotateTask, heightAnimation, easingLabelTask); if (isExpanded) { EasingLabel.Text = "Show more details"; } ButtonExpand.Rotation = isExpanded ? 0 : 180; EasingLabel.Rotation = isExpanded ? 0 : 360; }); }