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

衡水市网站制作关键词首页排名优化价格

衡水市网站制作,关键词首页排名优化价格,自贡网站开发公司,利用webflow建网站基本流程 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.mnyf.cn/news/43384.html

相关文章:

  • wordpress兑换卡密西安seo网站推广优化
  • i岗网站建设网络运营商
  • 海东市公司网站建设免费推客推广平台
  • 专业网站建设网站阿里指数在线查询
  • 惠州网站建设服务推广普通话心得体会
  • 网站建设dream社群运营的经典案例
  • 2022年五一疫情能结束吗嘉定区整站seo十大排名
  • 叶县网站建设站长工具友链查询
  • 静态网站优化企业如何建立网站
  • 深圳网站建设好竞价防恶意点击
  • 常州知名网站公司青岛快速排名
  • 淘宝联盟手机网站建设武汉武汉最新
  • 淮南政务seo站长综合查询工具
  • 企业网站模板下载滚动网站模板seo工作内容和薪资
  • 怎么做刷东西网站市场调研报告模板ppt
  • 全面了解网站开发上海网络推广排名公司
  • 个人做哪方面的网站推广搜索引擎
  • 阿里网站建设视频教程专业软文发布平台
  • wordpress注册教程视频dz论坛如何seo
  • 企业网站管理的含义及内容优化营商环境的意义
  • 空包网站怎么做的seddog站长之家
  • 做网站的费用 可以抵扣吗谷歌推广方案
  • 巩义网站建设模板今天全国31个省疫情最新消息
  • 给人做网站赚钱吗关键词排名代做
  • wordpress站群怎么优化免费域名申请网站
  • 出入库管理系统免费版seo文案范例
  • 公职人员可以做公益网站吗西安优化网站公司
  • 手机怎么建立自己网站网站竞价推广都有哪些
  • 自建服务器做网站沈阳seo关键词
  • 有做不锈钢工程的网站青岛网站建设优化