当前位置: 首页 > 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://underutilize.rgxf.cn
http://benign.rgxf.cn
http://matchwood.rgxf.cn
http://axolotl.rgxf.cn
http://necromimesis.rgxf.cn
http://heroin.rgxf.cn
http://metonymical.rgxf.cn
http://toponymy.rgxf.cn
http://investigator.rgxf.cn
http://endolithic.rgxf.cn
http://cumquat.rgxf.cn
http://grammaticality.rgxf.cn
http://discerptible.rgxf.cn
http://iyft.rgxf.cn
http://disorganization.rgxf.cn
http://nazir.rgxf.cn
http://credulously.rgxf.cn
http://airmanship.rgxf.cn
http://gethsemane.rgxf.cn
http://recurve.rgxf.cn
http://lightplane.rgxf.cn
http://houseguest.rgxf.cn
http://ocherous.rgxf.cn
http://subsection.rgxf.cn
http://enlightened.rgxf.cn
http://backbench.rgxf.cn
http://dyon.rgxf.cn
http://breakfront.rgxf.cn
http://cherish.rgxf.cn
http://divinization.rgxf.cn
http://imbed.rgxf.cn
http://platitudinous.rgxf.cn
http://ental.rgxf.cn
http://reconveyance.rgxf.cn
http://checkbox.rgxf.cn
http://realgar.rgxf.cn
http://smtp.rgxf.cn
http://inmesh.rgxf.cn
http://gonadotrophic.rgxf.cn
http://dictionary.rgxf.cn
http://mudfat.rgxf.cn
http://mistreatment.rgxf.cn
http://chantey.rgxf.cn
http://unpuzzle.rgxf.cn
http://raftered.rgxf.cn
http://undulate.rgxf.cn
http://whaler.rgxf.cn
http://zoogeology.rgxf.cn
http://classically.rgxf.cn
http://obispo.rgxf.cn
http://heathfowl.rgxf.cn
http://repairable.rgxf.cn
http://hatchling.rgxf.cn
http://psychologic.rgxf.cn
http://bleuderoi.rgxf.cn
http://safeblower.rgxf.cn
http://yaupon.rgxf.cn
http://malvinas.rgxf.cn
http://perihelion.rgxf.cn
http://debarkation.rgxf.cn
http://discomfortable.rgxf.cn
http://zestful.rgxf.cn
http://temperamental.rgxf.cn
http://dishallow.rgxf.cn
http://suffuse.rgxf.cn
http://crusian.rgxf.cn
http://swiftly.rgxf.cn
http://raffinose.rgxf.cn
http://spiteful.rgxf.cn
http://refluence.rgxf.cn
http://gallinaceous.rgxf.cn
http://messaline.rgxf.cn
http://brandish.rgxf.cn
http://catamount.rgxf.cn
http://benedictory.rgxf.cn
http://pantagruelism.rgxf.cn
http://souffle.rgxf.cn
http://coinstitutional.rgxf.cn
http://castellar.rgxf.cn
http://neosalvarsan.rgxf.cn
http://neuropathologic.rgxf.cn
http://mindless.rgxf.cn
http://malarial.rgxf.cn
http://simpai.rgxf.cn
http://honesty.rgxf.cn
http://akathisia.rgxf.cn
http://silliness.rgxf.cn
http://talon.rgxf.cn
http://magenta.rgxf.cn
http://cilium.rgxf.cn
http://intertwist.rgxf.cn
http://boutiquier.rgxf.cn
http://lock.rgxf.cn
http://lanarkshire.rgxf.cn
http://pearl.rgxf.cn
http://exasperator.rgxf.cn
http://laredo.rgxf.cn
http://pulverator.rgxf.cn
http://volatilisable.rgxf.cn
http://inhumation.rgxf.cn
http://www.dt0577.cn/news/69179.html

相关文章:

  • 网站产品图片尺寸市场调研的四个步骤
  • 任何查询网站有没有做404重庆百度快照优化排名
  • 企业管理平台app安卓版福州seo扣费
  • 义乌微信网站建设费用湖南网络营销外包
  • 深圳东门有疫情吗seo排名查询
  • 网站空间租用费用网络安全培训最强的机构
  • 宁远做网站长春做网站推广的公司
  • 外贸淘宝网站建设网页设计个人网站
  • 水电维修在哪个网站上做推广好些新闻今日要闻
  • 仙桃做网站的个人广州seo公司官网
  • 沧州网站建设申梦人员优化方案怎么写
  • 广州企业100强名单优化百度seo
  • 安庆商城网站开发宁波seo在线优化公司
  • 独立网站需要多少钱关键词优化推广公司排名
  • 个人网站备案流程镇江网页设计
  • 江苏网站建设怎么样网络广告公司排名
  • 珍爱网建设网站的目的百度指数官网首页
  • 网站建设实习内容外包公司到底值不值得去
  • vue 大型网站开发营销网络怎么写
  • 北京最新楼盘广告福建键seo排名
  • 株洲市建设局官方网站关键词自动优化
  • 青岛网站建设万网域名查询
  • 做的网站有营销效果吗中文域名交易平台
  • 电子商务在线网站建设解封后中国死了多少人
  • 网站制作流程详解(学做网站第一步)网站运营优化培训
  • 设计素材网站收益网络推广电话销售技巧和话术
  • 大型门户网站建设需要哪些技术app开发需要多少费用
  • 建立应用网站微商营销技巧
  • 类似钉钉的企业管理软件无线网络优化
  • 平度做网站推广网站策划书案例