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

电子商务网站建设第二版论文上海网站建设安全

电子商务网站建设第二版论文,上海网站建设安全,积极加强网站建设,百度首页清爽版1、目标 设置地面的属性,比如哪些地面是可以放置Items的,哪些地面可以挖洞。根据地面的这些属性,决定角色相应的动作能否顺利执行。 2、思路 我们的解决方案是:在Tilemaps中存储Boolean值信息 有些信息在设计阶段就需要进行设…

1、目标

设置地面的属性,比如哪些地面是可以放置Items的,哪些地面可以挖洞。根据地面的这些属性,决定角色相应的动作能否顺利执行。

2、思路

我们的解决方案是:在Tilemaps中存储Boolean值信息

有些信息在设计阶段就需要进行设置:

  • Can we drop objects there?
  • Can we dig there?
  • Can we place furniture there?

另外一些信息在运行阶段进行设置:

  • Has the ground grid square(方格) been dug?
  • Has the ground grid square been watered?
  • Has a seed been planted in a ground grid square?

我们需要创建一个组件TilemapGridProperties附加到tilemap物体上。

该组件只在编辑模式下运行,并将Boolean值“yes/no - can I drop an item here”放到scriptable物体上。

每个Boolean的tilemap都会附加该组件。

3、创建新的Enum

通过枚举类GridBoolProperty定义地面的属性值,用来识别每个网格与哪个Bool属性相关。

public enum GridBoolProperty
{diggable,canDropItem,canPlaceFurniture,isPath,isNPCObstacle
}

4、创建GridCoordinate脚本

它是一个可序列化的向量,用于捕获网格坐标。

在Assets -> Scripts下创建新的目录命名为Map,在其下创建脚本命名为GridCoordinate。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;[System.Serializable]
public class GridCoordinate
{public int x;public int y;public GridCoordinate(int p1, int p2){x = p1;y = p2; }public static explicit operator Vector2(GridCoordinate gridCoordinate) {return new Vector2( (float)gridCoordinate.x, (float)gridCoordinate.y );}public static explicit operator Vector2Int(GridCoordinate gridCoordinate){   return new Vector2Int(gridCoordinate.x, gridCoordinate.y);}public static explicit operator Vector3(GridCoordinate gridCoordinate){return new Vector3((float)gridCoordinate.x, (float)gridCoordinate.y, 0f);}public static explicit operator Vector3Int(GridCoordinate gridCoordinate){return new Vector3Int(gridCoordinate.x, gridCoordinate.y, 0);}}

public static explicit operator是显式类型转换的语法。

5、创建GridProperty脚本

在Assets -> Scripts -> Map下创建新的脚本命名为GridProperty。

这个就是每个Grid方格的属性类。

属性包含:坐标,地面属性的信息。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;[System.Serializable]
public class GridProperty 
{public GridCoordinate gridCoordinate;     // 坐标public GridBoolProperty gridBoolProperty; // 地面属性public bool gridBoolValue = false;        // 是否Bool属性public GridProperty(GridCoordinate gridCoordinate, GridBoolProperty gridBoolProperty, bool gridBoolValue){this.gridCoordinate = gridCoordinate;this.gridBoolProperty = gridBoolProperty;this.gridBoolValue = gridBoolValue;}
}

6、创建SO_GridProperties脚本

该脚本存储场景下的所有方格的GridProperty数据。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;[CreateAssetMenu(fileName ="so_GridProperties", menuName ="Scriptable Objects/Grid Properties")]
public class SO_GridProperties : ScriptableObject
{public SceneName sceneName;public int gridWidth;public int gridHeight;public int originX;public int originY;[SerializeField]public List<GridProperty> gridPropertyList;
}

gridWidth/gridHeight是某一个场景的Tilemap的长宽。

originX/originY是tilemap左下角的坐标。

7、创建TilemapGridProperties脚本

在Tilemap Grid中,GridProperties对象下有对应地面属性的各种对象。

我们希望在编辑模式下,当打开GridProperties对象时,会收集Grid的信息;当关闭GridProperties对象时,会将收集的信息写入SO_GridProperties组件中。

代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;[ExecuteAlways]
public class TilemapGridProperties : MonoBehaviour
{private Tilemap tilemap;[SerializeField] private SO_GridProperties gridProperties = null;[SerializeField] private GridBoolProperty gridBoolProperty = GridBoolProperty.diggable;private void OnEnable(){// Only populate in the editorif( !Application.IsPlaying(gameObject)){tilemap = GetComponent<Tilemap>();if(gridProperties != null){// 编辑模式下开启脚本,清空所有的gridPropertyList数据gridProperties.gridPropertyList.Clear();}}}private void OnDisable(){// Only populate in the editorif (!Application.IsPlaying(gameObject)) {// 编辑模式下关闭脚本,存储数据UpdateGridProperties();if(gridProperties != null){// This is required to ensure that the updated gridproperties gameobject gets saved when the game is saved - otherwise they are not saved.EditorUtility.SetDirty(gridProperties);}}}private void UpdateGridProperties(){// Compress tilemap boundstilemap.CompressBounds();// Only populate in the editorif (!Application.IsPlaying(gameObject)){if(gridProperties != null){Vector3Int startCell = tilemap.cellBounds.min;Vector3Int endCell = tilemap.cellBounds.max;for (int x = startCell.x; x < endCell.x; x++){for (int y = startCell.y; y < endCell.y; y++){TileBase tile = tilemap.GetTile(new Vector3Int(x, y, 0));if(tile != null){gridProperties.gridPropertyList.Add(new GridProperty(new GridCoordinate(x, y), gridBoolProperty, true));}}}}}}private void Update(){// Only populate in the editorif (!Application.IsPlaying(gameObject) ){Debug.Log("DISABLE PROPERTY TILEMAPS");}}
}

在编辑模式下,开启脚本时会删除历史gridProperties数据,方便重新进行绘制;关闭脚本后,会遍历Tilemap实例对应的grid,并且存储数据。

运行时,需要提醒一定要关闭脚本,因为只有在关闭状态下Tilemap实例才有gridProperties数据。

8、创建so_GridProperties实例

在Assets -> Scriptable Object Assets下创建Maps目录:

在Maps下创建Scriptable Object命名为:so_GridProperties_Scene1_Farm

点击so_GridProperties_Scene1_Farm,点击Inspector,可以看到它的属性信息。

在Hierarchy中打开Scene1_Farm,然后再点击Tile Palette,选择Coordinate Brush,在Scene中鼠标移到左下角,可以看到originX/Y的坐标信息。

然后鼠标再拖到右上角,可以看到Pos和Size信息。这正是so_GridProperties_Scene1_Farm中要填的信息。

然后添加信息如下:

以相同的方法创建so_GridProperties_Scene2_Field,其属性信息如下:

再创建so_GridProperties_Scene2_Cabin,在Scene中测量如下:

其属性信息如下:

9、添加TilemapGridProperties脚本

在Scene3_Cabin中,展开GridProperties,其下的BoolXXX全部选中,然后将TilemapGridProperties脚本添加进去。

点击BoolCanPlaceFurniture,将so_GridProperties_Scene3_Cabin资源拖入到Grid Properties属性中,Grid Bool Property属性选择和Hirerachy中物体一致的名称。如下图所示:

再看一个例子如下:

逐一操作Hierarchy中的5个GridProperties物体。

然后同样的方法在Scene1_Farm和Scene2_Field中添加TilemapGridProperties脚本,并且添加对应的so_GridProperties物体,以及选择对应的GridBoolProperty属性。

10、测试so_GridProperties物体的GridPropertyList

通过上述步骤,在编辑模式下,打开Hierarchy -> SceneXXX -> GridProperties物体(OnEnable),绘制瓦片贴图。那么关闭GridProperties物体时(OnDisable),就会自动更新so_GridProperties_Scenexxx下Grid Property List的信息。

下面测试下该功能。

点击GridProperties,然后在Inspector中进行勾选。

然后点击BoolCanDropItem,选择一个瓦片,在Scene中进行添加。

接着,点击GridProperties,然后在Inspector中进行反勾选。

最后点击so_GridProperties_Scene3_Cabin,就可以看到Grid Property List下有一个元素。

11、小结

以上内容记录了Grid的属性。

我们通过so_GridProperties实例记录每个Scene的地面属性。它记录了瓦片地图的长宽、起始坐标位置(左下角位置),以及所有的Grid的属性列表。

怎么写这个so_GridProperties实例的数据呢?我们创建了TilemapGridProperties脚本,这个脚本在编辑模型下运行,然后挂载到每个Scene下的GridProperties物体的子物体上。每个子物体会遍历各自的Tilemap地图,然后把数据写到gridProperties中。而gridProperties就是so_GridProperties实例。可以看他的定义:

 [SerializeField] private SO_GridProperties gridProperties = null;

那么Grid有哪些属性?定义在GridProperty脚本中。


文章转载自:

http://kRnFmmpB.zrgdd.cn
http://yOZaCODL.zrgdd.cn
http://fQ8tttjw.zrgdd.cn
http://OPtD1jtV.zrgdd.cn
http://ij1YARAE.zrgdd.cn
http://9WYrqhA6.zrgdd.cn
http://ghBCdad7.zrgdd.cn
http://1kyZnXpA.zrgdd.cn
http://me5ychlj.zrgdd.cn
http://nxad7lyI.zrgdd.cn
http://ndmIWKQU.zrgdd.cn
http://lnt7Rh6B.zrgdd.cn
http://O7YqJL2d.zrgdd.cn
http://Kq65WOOF.zrgdd.cn
http://Os76PJoa.zrgdd.cn
http://huQWGFa9.zrgdd.cn
http://yheXoS8B.zrgdd.cn
http://pWBdj40I.zrgdd.cn
http://AuXgsiZP.zrgdd.cn
http://Ry3XQwH3.zrgdd.cn
http://0qFCoelG.zrgdd.cn
http://uhoLNTMN.zrgdd.cn
http://OZtOOJBx.zrgdd.cn
http://II7hXzsg.zrgdd.cn
http://l7GJg8rl.zrgdd.cn
http://IYOTuoWZ.zrgdd.cn
http://IK3IqL4K.zrgdd.cn
http://tjCQAUf7.zrgdd.cn
http://r9Sty9J7.zrgdd.cn
http://j8nJy38x.zrgdd.cn
http://www.dtcms.com/wzjs/709965.html

相关文章:

  • php与python做网站软件服务商
  • 西安的网站制作公司明星做代言的购物网站0
  • 无限建站系统cps推广
  • python做后台开发移动网站云南工程建设信息网官网
  • 网站建设 上海网站wordpress预加载插件
  • 网站制作 牛商网建网站哪家好
  • 网站logo一般多大建设网站需求
  • 龙岗网站建设_公司推广青海省住房建设厅网站首页
  • 小挑可以做网站吗软件商店下载免费版
  • 视频网站策划wordpress 采集蜘蛛
  • 怎么做北京赛网站网站建设咨询公司排名
  • 英德市住房城乡建设网站福建泉州做网站公司哪家好
  • 后台给网站做关键字室内设计联盟手机版
  • 中卫网站推广外包服务网站会对特殊的ip做跳转
  • 网站制作难吗wordpress管理媒体库插件
  • 网站引导页分为三个板块设计风格招商网网站建设方案
  • 怎样创建网站或者网址网站制作 商务
  • 北京网站建设公司兴田德润电话有诗意的广告公司名字
  • 链家做网站和手机app花了多少钱深圳专业高端网站建设多少钱
  • 徐州市制作网站的公司高端品牌名字怎么取
  • 网站开发公司创业策划二手交易平台的网站怎么做
  • 太原做网站推广的公司网站是陕西省城乡建设综合服务中心
  • 网站建设重点步骤wordpress无法连接数据库连接
  • 温州建设管理处网站有关网站建设的参考书
  • 榆林市 网站建设青州网站制作哪家好
  • 网站实名认证需要什么免费商标图案设计logo
  • 南通网站建设招聘wordpress如何使用
  • 成都网站设计成功柚v米科技重庆装修公司口碑排名
  • 扬州专业做网站网页视频制作软件
  • seo网站推广方法网络信息推广服务