当前位置: 首页 > news >正文

网站建设咨询有客诚信网站建设咨询企业信息化管理软件有哪些

网站建设咨询有客诚信网站建设咨询,企业信息化管理软件有哪些,广西房管局官网,计算机前端工资多少基本流程 1.代码思路 (1)InventoryUI的PlayerSlots与PlayerBag里一一对应,所以想要实现交换数据实际上是,先拿到被拖拽的物体所对的Slot的序号和目标的Slot序号,然后将这两个序号对调一下 (2)物品交换的数据逻辑应该在InventoryManager里去调用,因为InventoryManager里管理了p…

基本流程

1.代码思路

        (1)InventoryUI的PlayerSlots与PlayerBag里一一对应,所以想要实现交换数据实际上是,先拿到被拖拽的物体所对的Slot的序号和目标的Slot序号,然后将这两个序号对调一下

        (2)物品交换的数据逻辑应该在InventoryManager里去调用,因为InventoryManager里管理了playerBag所有的数据

        (3)交换数据时需要考虑库存的类型以及交换的目的,现有三个类型(slotType),有Bag,Box,Shop,依次对应的是同背包转换,跨库存数据进行转换,买卖交易;

        (4)对于在地图上生成物品,首先要在SlotUI中获取拖拽结束时的世界坐标(因为Slot_Bag和已经创建好的背景不在一个层级上)

        (5)新建一个ItemManager.cs,这个脚本用于管理场景中的所有物品,在切换场景的时候,保存场景当中现在有的物品,在切换回来的时候可以再次读取

        (6)基于已经制作好的ItemBase的预制体,拿到这个预制体,在指定的位置进行生成,那么就需要让StotUI告诉ItemManager在哪生成,这时候就需要通过EventHandler来执行

        (7)因为对事件这个知识点不是很熟,所以我会详写,在EventHandler里去实现在场景中生成物品的事件定义以及调用事件的方法,然后就可以去SlotUI里去调用了

        (8)事件的详细描述:

        先在事件中心EventHandler里实现对事件的定义

//在场景中生成物品的事件
//需要的参数有(ItemID,position)
public static event Action<int, Vector3> instantiateItemInScene;

        再写事件的调用方法

public static void CallInstantiateItemInScene(int ID, Vector3 pos)
{InstantiateItemInScene?.Invoke(ID, pos);
}

         去SlotUI中调用事件

//调用事件
EventHandler.CallInstantiateItemInScene(itemDetails.itemID,pos);

        然后去ItemManager里接收数据,就需要添加注册的函数方法

private void OnEnable()
{EventHandler.InstantiateItemInScene += OnInstantiateItemInScene;
}private void OnDisable()
{EventHandler.InstantiateItemInScene -= OnInstantiateItemInScene;
}

         编写方法的实现

private void OnInstantiateItemInScene(int ID, Vector3 pos)
{var item = Instantiate(itemPrefab,pos, Quaternion.identity, itemParent);item.itemID = ID;
}

2.代码实现

        SlotUI中的

public void OnEndDrag(PointerEventData eventData)
{inventoryUI.dragItem.enabled = false;//Debug.Log(eventData.pointerCurrentRaycast.gameObject);//判断非空,只有非空才代表最后碰撞到的是UI物体//再判断碰撞的是否为SlotUI,不是就返回//为真就拿到双方的序号if (eventData.pointerCurrentRaycast.gameObject != null){if (eventData.pointerCurrentRaycast.gameObject.GetComponent<SlotUI>() != null){//目标点的SlotUIvar targetSlot = eventData.pointerCurrentRaycast.gameObject.GetComponent<SlotUI>();int targetIndex = targetSlot.slotIndex;//在Player自身背包范围内转换(同库存转换)if (targetSlot.slotType == SlotType.Bag && slotType == SlotType.Bag){InventoryManager.Instance.SwapItem(slotIndex, targetIndex);}//清空所有高亮 inventoryUI.UpdateSlotHightlight(-1);}}else {if (itemDetails.canDropped){//鼠标对应的世界地图坐标var pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z));//调用事件EventHandler.CallInstantiateItemInScene(itemDetails.itemID, pos);}}
}

        InventoryManager中的

/// <summary>
/// Player背包范围内的交换物品
/// </summary>
/// <param name="fromIndex">起始序号</param>
/// <param name="toIndex">目标数据序号</param>
public void SwapItem(int fromIndex,int toIndex)
{ //需要考虑的是,当前的格子一定是非空的,但是目标格子不一定是空InventoryItem currentItem = playerBag.itemList[fromIndex];InventoryItem targetItem = playerBag.itemList[ toIndex ];if (targetItem.itemID != 0){playerBag.itemList[fromIndex] = targetItem;playerBag.itemList[toIndex] = currentItem;}else{playerBag.itemList[fromIndex] = new InventoryItem();//这里new一个其实就是给它置空playerBag.itemList[toIndex] = currentItem;}EventHandler.CallUpdateInventoryUI(InventoryLocation.Player,playerBag.itemList);
}

        EventHandler中的

//在场景中生成物品的事件
//需要的参数有(ItemID,position)
public static event Action<int, Vector3> InstantiateItemInScene;
public static void CallInstantiateItemInScene(int ID, Vector3 pos)
{InstantiateItemInScene?.Invoke(ID, pos);
}

         ItemManager中的

namespace FuliFarm.Inventory
{public class ItemManager : MonoBehaviour{public Item itemPrefab;private Transform itemParent;private void OnEnable(){EventHandler.InstantiateItemInScene += OnInstantiateItemInScene;}private void OnDisable(){EventHandler.InstantiateItemInScene -= OnInstantiateItemInScene;}private void Start(){itemParent = GameObject.FindWithTag("ItemParent").transform;}private void OnInstantiateItemInScene(int ID, Vector3 pos){var item = Instantiate(itemPrefab, pos, Quaternion.identity, itemParent);item.itemID = ID;}}
}

最终效果

        同库存交换

 

         地图上拾取(就不多展示了,字面意思)

出现的问题

        物品丢在地上后捡不起来,检查canPickUp没有问题,最后发现在生成itemBase的prefab时,碰撞盒的offset的y值不为零,导致碰撞盒与图片不在同一位置

        相关代码是Item.cs中的这一句

 将coll.offset = new Vector2(0,spriteRenderer.bounds.center.y);改为

coll.offset = new Vector2(0, spriteRenderer.transform.localPosition.y);就行了

         但我实在不明白coll.offset = new Vector2(0,spriteRenderer.bounds.center.y);有什么错误,我觉得思路上是没错的

http://www.yayakq.cn/news/926185/

相关文章:

  • 潮州住房和城乡建设局网站如何将自己做的网站
  • 如何做网站优化的内容青岛做门户网站的
  • 啤酒网站建设嘉兴市城市建设门户网站
  • 做轴承生意的网站发卡网站建设方案
  • 网站开发费是无形资产吗react做网站
  • 快递网站建设代码贵阳制作
  • 佛山市seo网站设计哪家好优的网站建设明细报价表
  • 大兴区网站建设公司大连微网站制作
  • 淘宝做网站推广怎么把电脑当服务器做网站
  • 武夷山住房和城乡建设局网站wordpress 域名映射
  • 做网站第一步做什么合肥互联网公司
  • 网站域名不想实名认证网页设计软件app
  • 如何修改网站备案北京东方华美建设集团有限公司网站
  • 自助广告位网站源码电力网站怎么做
  • 大学网站建设包括哪些课程做外贸怎么上国外网站
  • 商务网站建设实践实训心得网站如何做访客统计
  • 公司网站建设目标wordpress xml生成
  • 怎么网站代备案企业网站建设计划表
  • 成都专业网站建设价格低建设网站的叫什么职位
  • 太原网站seo顾问wordpress首页手机版
  • 网站建设佰首选金手指二六鑫鼎信长春网站建设
  • 黑龙江建设人员证件查询网站wordpress怎么改页面底部
  • 网站诊断seo当前数据是指申请网站建设的报告
  • 做医院的系统网站怎么做ftp网站上传之后怎么办
  • 天津做企业网站公司wordpress 不检查更新
  • 企业网站建设要求标准说明秀米网站怎么做推文
  • 深圳网络营销网站设计装饰公司网站制作
  • 建设公寓租房信息网站pc网站建设方案有哪些
  • 手机网站单页军事最新消息新闻
  • 机械模板网站网站开发要学的课程