/// <summary> /// 交换道具-容器 /// </summary> /// <param name="viewItemContainer"></param> public bool ExchangeItemForContainer(UIViewItemContainer viewItemContainer) { UIViewItem tempViewItem = viewItemContainer.GetViewItem(); if (tempViewItem == null) { //检测容器是否能放置当前物品 bool canSetItem = viewItemContainer.CheckCanSetItem(itemsInfo.GetItemsType()); //如果能放置 if (canSetItem) { //如果容器里没有道具 则直接设置容器的道具为当前道具 //首先清空原容器里的数据 originalParent.ClearViewItem(); //设置新的容器 viewItemContainer.SetViewItem(this); AnimForPositionChange(timeForMove, null); } else { //如果没有设置成功(不能放置该类型),则返回原容器 HandleForBackOriginalContainer(); } return(true); } else { //如果容器里有道具 则返回原容器 HandleForBackOriginalContainer(); return(true); } }
/// <summary> /// 设置容器道具 用于初始化 /// </summary> /// <param name="itemsData"></param> public void SetViewItem(ItemsBean itemsData) { //设置展示信息 ui_ViewItemContainer.SetItemId(itemsData.itemId); //如果没有东西,则删除原来存在的 if (itemsData == null || itemsData.itemId == 0) { if (currentViewItem != null) { Destroy(currentViewItem.gameObject); } currentViewItem = null; return; } //如果有东西,则先实例化再设置数据 if (currentViewItem == null) { GameObject obj = Instantiate(gameObject, ui_ViewItemModel.gameObject); obj.name = "ViewItem"; currentViewItem = obj.GetComponent <UIViewItem>(); currentViewItem.originalParent = this; currentViewItem.transform.position = ui_ViewItemModel.transform.position; currentViewItem.transform.localScale = ui_ViewItemModel.transform.localScale; currentViewItem.transform.rotation = ui_ViewItemModel.transform.rotation; } currentViewItem.SetData(itemsData.itemId, itemsData.number, itemsData.meta); callBackForSetViewItem?.Invoke(this, itemsData.itemId); this.TriggerEvent(EventsInfo.UIViewItemContainer_ItemChange, this, itemsData.itemId); }
/// <summary> /// 增加道具 /// </summary> /// <param name="uiViewItem"></param> public bool AddItems(UIViewItem uiViewItem) { //首先直接在显示的list中搜索空位 List <GameObject> listCellObj = ui_ItemList.GetAllCellObj(); for (int i = 0; i < listCellObj.Count; i++) { GameObject itemObj = listCellObj[i]; UIViewItemContainer itemContainer = itemObj.GetComponent <UIViewItemContainer>(); //如果有容器VIEW 并且里面没有东西 if (itemContainer != null && itemContainer.GetViewItem() == null) { uiViewItem.ExchangeItemForContainer(itemContainer); return(true); } } //如果不成功则直接查询整个listBackpack for (int i = 0; i < listBackpack.Length; i++) { ItemsBean itemData = listBackpack[i]; if (itemData == null || itemData.itemId == 0) { itemData.itemId = uiViewItem.itemId; itemData.number = uiViewItem.itemNumber; itemData.meta = uiViewItem.meta; Destroy(uiViewItem.gameObject); return(true); } } return(false); }
public override BUSViewItem UIToBusiness(UIViewItem UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord) { BUSViewItem businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord); View view = context.Views .AsNoTracking() .Select(v => new { id = v.Id, name = v.Name, viewItems = v.ViewItems.Select(viewItem => new { id = viewItem.Id, name = viewItem.Name, }) }) .Select(v => new View { Id = v.id, Name = v.name, ViewItems = v.viewItems.Select(viewItem => new ViewItem { Id = viewItem.id, Name = viewItem.name }).ToList() }) .FirstOrDefault(n => n.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("View")); if (view == null) { businessEntity.ErrorMessage = "First you need create view."; } else { // Если запись новая и она не уникальна, записывается ошибка ViewItem viewItem = view.ViewItems?.FirstOrDefault(n => n.Name == UIEntity.Name); if (viewInfo.ViewItems != null && viewItem != null && viewItem.Id != UIEntity.Id) { businessEntity.ErrorMessage = $"View item with this name is already exists in view {view.Name}."; } else { businessEntity.View = view; businessEntity.ViewId = view.Id; Applet applet = context.Applets.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.AppletName); if (applet != null) { businessEntity.Applet = applet; businessEntity.AppletId = applet.Id; businessEntity.AppletName = applet.Name; } businessEntity.Autofocus = UIEntity.Autofocus.ToString() == string.Empty || UIEntity.Autofocus; businessEntity.AutofocusRecord = UIEntity.AutofocusRecord.ToString() == string.Empty ? 0 : UIEntity.AutofocusRecord; } } return(businessEntity); }
public override UIViewItem BusinessToUI(BUSViewItem businessEntity) { UIViewItem UIEntity = base.BusinessToUI(businessEntity); UIEntity.AppletName = businessEntity.AppletName; UIEntity.Autofocus = businessEntity.Autofocus; UIEntity.AutofocusRecord = businessEntity.AutofocusRecord; UIEntity.Type = businessEntity.Applet?.Type; return(UIEntity); }
/// <summary> /// 在原位置复制一个道具 并且数量为该道具的最大 /// </summary> protected void CopyItemInOriginal() { GameObject objOriginal = Instantiate(originalParent.gameObject, gameObject); objOriginal.name = "ViewItem"; UIViewItem viewItem = objOriginal.GetComponent <UIViewItem>(); objOriginal.transform.position = gameObject.transform.position; originalParent.SetViewItem(viewItem); //设置拿出的物体数量为该物体的最大数量 itemNumber = itemsInfo.max_number; //刷新一下UI RefreshUI(); }
/// <summary> /// 设置容器道具 /// </summary> /// <param name="uiView"></param> public bool SetViewItem(UIViewItem uiView) { this.currentViewItem = uiView; this.currentViewItem.originalParent = this; this.currentViewItem.transform.SetParent(rectTransform); itemsData.itemId = uiView.itemId; itemsData.number = uiView.itemNumber; itemsData.meta = uiView.meta; callBackForSetViewItem?.Invoke(this, itemsData.itemId); this.TriggerEvent(EventsInfo.UIViewItemContainer_ItemChange, this, itemsData.itemId); //设置展示信息 ui_ViewItemContainer.SetItemId(itemsData.itemId); return(true); }
/// <summary> /// 移出道具 /// </summary> /// <returns></returns> public bool RemoveViewItem() { //如果已经有一个了 则不能删除 UIViewItem viewItem = GetViewItem(); if (viewItem == null) { return(false); } GameObject objViewItem = viewItem.gameObject; viewItem.transform .DOScale(0, timeForRemoveViewItem) .OnComplete(() => { DestroyImmediate(objViewItem); }); ClearViewItem(); return(true); }
/// <summary> /// 结束拖拽 /// </summary> /// <param name="eventData"></param> public void OnEndDrag(PointerEventData eventData) { if (isAnim || !isBeginDrag) { return; } isBeginDrag = false; GameObject objTarget = eventData.pointerCurrentRaycast.gameObject; if (objTarget != null) { UIViewItemContainer viewItemContainer = objTarget.GetComponent <UIViewItemContainer>(); //如果检测到容器 说明只有容器 里面没有道具 if (viewItemContainer != null) { ExchangeItemForContainer(viewItemContainer); return; } UIViewItem viewItem = objTarget.GetComponent <UIViewItem>(); //如果检测到道具 说明容器里有道具 if (viewItem != null) { ExchangeItemForItem(viewItem); return; } else { HandleForBackOriginalContainer(); return; } } else { //如果什么都没有检测到,说明是把物体丢到场景中 DropItem(); return; } }
/// <summary> /// 道具和道具交换 /// </summary> /// <param name="viewItem"></param> /// <returns></returns> protected bool ExchangeItemForItem(UIViewItem viewItem) { //如果目标是同一物品 if (viewItem.itemsInfo.id == itemsInfo.id) { //如果目标是无限物品 则删除现有物品 if (viewItem.itemNumber == int.MaxValue) { transform.SetParent(viewItem.transform.parent); transform.localScale = Vector3.one; AnimForPositionChange(timeForMove, () => { DestroyImmediate(gameObject); }); return(true); } //如果目标不是无限物品,则先将目标叠加到最大,自己再返回原位置 else { //目标数量叠加 viewItem.itemNumber += itemNumber; if (viewItem.itemNumber > viewItem.itemsInfo.max_number) { //如果目标数量超出最大了 itemNumber = viewItem.itemNumber - viewItem.itemsInfo.max_number; viewItem.itemNumber = viewItem.itemsInfo.max_number; } else { //如果没有 则自己的数量为0 itemNumber = 0; } //刷新一下UI viewItem.RefreshUI(); RefreshUI(); if (itemNumber == 0) { //如果自己没有数量了,则删除 DestroyImmediate(gameObject); return(true); } else { //如果自己还有数量,则返回原容器 HandleForBackOriginalContainer(); return(true); } } } //如果目标不是同一类物品 else { //如果目标是无限物品 则回到原来位置 if (viewItem.itemNumber == int.MaxValue) { HandleForBackOriginalContainer(); return(true); } //如果是目标不是无限物品,则交换物品位置 else { //检测容器是否能放置当前物品 bool canSetItem = viewItem.originalParent.CheckCanSetItem(itemsInfo.GetItemsType()); if (canSetItem) { //交换位置 UIViewItemContainer dargContainer = this.originalParent; UIViewItemContainer targetContainer = viewItem.originalParent; //交换父级 if (dargContainer.GetViewItem() != null && dargContainer.GetViewItem().itemNumber == int.MaxValue) { //如果原父级有东西 则把目标容器里的物品丢出来 viewItem.DropItem(); } else { //如果原父级没有东西 则交换父级 dargContainer.SetViewItem(viewItem); //设置位置 viewItem.rectTransform.anchoredPosition = Vector2.zero; viewItem.transform.localScale = Vector3.one; } targetContainer.SetViewItem(this); //设置位置 transform.localScale = Vector3.one; AnimForPositionChange(timeForMove, () => { }); return(true); } else { //如果不能设置该物品(容器不能装该类型) 则返回 HandleForBackOriginalContainer(); return(true); } } } }
public override IEnumerable <ValidationResult> UIValidate(TContext context, IViewInfo viewInfo, UIViewItem UIEntity, bool isNewRecord) { List <ValidationResult> result = base.UIValidate(context, viewInfo, UIEntity, isNewRecord).ToList(); if (string.IsNullOrWhiteSpace(UIEntity.AppletName)) { result.Add(new ValidationResult( "Applet name is a required field.", new List <string>() { "AppletName" })); } return(result); }
public override IEnumerable <ValidationResult> BUSUIValidate(TContext context, BUSViewItem businessComponent, UIViewItem UIEntity) { List <ValidationResult> result = base.BUSUIValidate(context, businessComponent, UIEntity).ToList(); if (string.IsNullOrWhiteSpace(businessComponent.ErrorMessage)) { if (businessComponent.Applet == null) { result.Add(new ValidationResult( "Applet with this name not found.", new List <string>() { "AppletName" })); } } return(result); }
/// <summary> /// 清空容器 /// </summary> public void ClearViewItem() { this.currentViewItem = null; ClearItemsData(); }