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

电商网站设计文档长沙官网优化公司

电商网站设计文档,长沙官网优化公司,佛山网站到首页排名,网站开发电脑设置1、目标 当角色锄地之后,地面会显示开垦后的样貌。 2、思路 上一篇中,虽然角色dig了hoe,同时grid属性也改变了,但是没有任何可视化的反馈。我们现在将添加新的功能,动态地将"dug ground"瓷砖添加到"…

1、目标

当角色锄地之后,地面会显示开垦后的样貌。

2、思路

上一篇中,虽然角色dig了hoe,同时grid属性也改变了,但是没有任何可视化的反馈。我们现在将添加新的功能,动态地将"dug ground"瓷砖添加到"GroundDecoration1"的tilemap上。

将使用如下的tileset进行绘制。

为了设置正确的dug ground tile,我们需要检查下周边的tiles是否被dug,此时存在16种组合方式。

第1、2种组合方式:

第3、4种组合方式:

第5、6种组合方式:

第7、8种组合方式:

第9、10种组合方式:

第11、12种组合方式:

第13、14种组合方式:

第15、16种组合方式:

连接周边grid的情况:

我们将增加"dug ground" tiles到GroundDecoration1 tilemaps。我们将标记GroundDecoration1和GroundDecoration2 tilemap层,以便可以快速定位到他们,这些标记放到Tag.cs脚本中。

修改GridPropertiesManager.cs脚本如下:

修改Player.cs脚本

3、修改Tag.cs脚本

public static class Tags
{public const string BoundsConfiner = "BoundsConfiner";public const string ItemsParentTransform = "ItemsParentTransform";public const string GroundDecoration1 = "GroundDecoration1";public const string GroundDecoration2 = "GroundDecoration2";
}

添加了下面的2个静态变量。

4、修改GridPropertiesManager.cs脚本

// 修改public为private
private Grid grid;// 添加变量
private Tilemap groundDecoration1;
private Tilemap groundDecoration2;
[SerializeField] private Tile[] dugGround = null;// 添加函数private void ClearDisplayGroundDecorations(){// Remove ground decorationsgroundDecoration1.ClearAllTiles();groundDecoration2.ClearAllTiles();}private void ClearDisplayGridPropertyDetails(){ClearDisplayGroundDecorations();}private void ConnectDugGround(GridPropertyDetails gridPropertyDetails)
{// Select tile based on surrounding dug tilesTile dugTile0 = SetDugTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY, 0), dugTile0);// Set 4 tiles if dug surrounding current tile - up, down, left, right now that this central tile has been dugGridPropertyDetails adjacentGridPropertyDetails;adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1);if(adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile1 = SetDugTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1, 0), dugTile1);}adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1);if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile2 = SetDugTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1, 0), dugTile2);}adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY);if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile3 = SetDugTile(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY, 0), dugTile3);}adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY);if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile4 = SetDugTile(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY, 0), dugTile4);}
}private Tile SetDugTile(int xGrid, int yGrid)
{// Get whether surrounding tiles(up,down,left,right) are dug or notbool upDug = IsGridSquareDug(xGrid, yGrid + 1);bool downDug = IsGridSquareDug(xGrid, yGrid - 1);bool leftDug = IsGridSquareDug(xGrid - 1, yGrid);bool rightDug = IsGridSquareDug(xGrid + 1, yGrid);#region Set appropriate tile based on whether surrounding tiles are dug or notif(!upDug && !downDug &&  !rightDug && !leftDug){return dugGround[0];}else if(!upDug && downDug && rightDug && !leftDug){return dugGround[1];}else if(!upDug && downDug && rightDug && leftDug){return dugGround[2];}else if(!upDug && downDug && !rightDug && leftDug){return dugGround[3];}else if(!upDug && downDug && !rightDug && !leftDug){return dugGround[4];}else if(upDug && downDug && rightDug && !leftDug){return dugGround[5];}else if(upDug && downDug && rightDug && leftDug){return dugGround[6];}else if(upDug && downDug && !rightDug && leftDug){return dugGround[7];}else if(upDug && downDug && !rightDug && !leftDug){return dugGround[8];}else if(upDug && !downDug && rightDug && !leftDug){return dugGround[9];}else if(upDug && !downDug && rightDug && leftDug){return dugGround[10];}else if(upDug && !downDug && !rightDug && leftDug){return dugGround[11];}else if(upDug && !downDug && !rightDug && !leftDug){return dugGround[12];}else if(!upDug && !downDug && rightDug && !leftDug){return dugGround[13];}else if(!upDug && !downDug && rightDug && leftDug){return dugGround[14];}else if(!upDug && !downDug && !rightDug && leftDug){return dugGround[15];}return null;#endregion Set appropriate tile based on whether surrounding tiles are dug or not}private bool IsGridSquareDug(int xGrid, int yGrid)
{GridPropertyDetails gridPropertyDetails = GetGridPropertyDetails(xGrid, yGrid);if(gridPropertyDetails == null){return false;}else if(gridPropertyDetails.daysSinceDug > -1){return true;}else{return false;}
}private void DisplayGridPropertyDetails()
{// Loop throught all grid itemsforeach(KeyValuePair<string, GridPropertyDetails> item in gridPropertyDictionary){GridPropertyDetails gridPropertyDetails = item.Value;DisplayDugGround(gridPropertyDetails);}
}// 优化ISaveableRestoreScene函数public void ISaveableRestoreScene(string sceneName){// Get sceneSave for scene - it exists since we created it in initialiseif(GameObjectSave.sceneData.TryGetValue(sceneName, out SceneSave sceneSave)){// get grid property details dictionary - it exists since we created it in initialiseif(sceneSave.gridPropertyDetailsDictionary != null){gridPropertyDictionary = sceneSave.gridPropertyDetailsDictionary;}// If grid properties existif(gridPropertyDictionary.Count > 0){// grid property details found for the current scene destroy existing ground decorationClearDisplayGridPropertyDetails();// Instantiate grid property details for current sceneDisplayGridPropertyDetails();}}}// 优化AfterSceneLoaded函数
private void AfterSceneLoaded()
{// Get Gridgrid = GameObject.FindObjectOfType<Grid>();// Get tilemapsgroundDecoration1 = GameObject.FindGameObjectWithTag(Tags.GroundDecoration1).GetComponent<Tilemap>();groundDecoration2 = GameObject.FindGameObjectWithTag(Tags.GroundDecoration2).GetComponent<Tilemap>();
}

完整的代码如下:

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Tilemaps;[RequireComponent(typeof(GenerateGUID))]
public class GridPropertiesManager : SingletonMonobehaviour<GridPropertiesManager>, ISaveable
{private Tilemap groundDecoration1;private Tilemap groundDecoration2;private Grid grid;private Dictionary<string, GridPropertyDetails> gridPropertyDictionary;[SerializeField] private SO_GridProperties[] so_gridPropertiesArray = null;[SerializeField] private Tile[] dugGround = null;private string _iSaveableUniqueID;private GameObjectSave _gameObjectSave;public string ISaveableUniqueID { get { return _iSaveableUniqueID; } set { _iSaveableUniqueID = value; } }public GameObjectSave GameObjectSave { get { return _gameObjectSave; } set { _gameObjectSave = value; } }protected override void Awake(){base.Awake();ISaveableUniqueID = GetComponent<GenerateGUID>().GUID;GameObjectSave = new GameObjectSave();}private void OnEnable(){ISaveableRegister();EventHandler.AfterSceneLoadEvent += AfterSceneLoaded;}private void OnDisable() {ISaveableDeregister();EventHandler.AfterSceneLoadEvent -= AfterSceneLoaded;}private void AfterSceneLoaded(){// Get Gridgrid = GameObject.FindObjectOfType<Grid>();// Get tilemapsgroundDecoration1 = GameObject.FindGameObjectWithTag(Tags.GroundDecoration1).GetComponent<Tilemap>();groundDecoration2 = GameObject.FindGameObjectWithTag(Tags.GroundDecoration2).GetComponent<Tilemap>();}public void ISaveableDeregister(){SaveLoadManager.Instance.iSaveableObjectList.Remove(this);}public void ISaveableRegister(){SaveLoadManager.Instance.iSaveableObjectList.Add(this);}public void ISaveableRestoreScene(string sceneName){// Get sceneSave for scene - it exists since we created it in initialiseif(GameObjectSave.sceneData.TryGetValue(sceneName, out SceneSave sceneSave)){// get grid property details dictionary - it exists since we created it in initialiseif(sceneSave.gridPropertyDetailsDictionary != null){gridPropertyDictionary = sceneSave.gridPropertyDetailsDictionary;}// If grid properties existif(gridPropertyDictionary.Count > 0){// grid property details found for the current scene destroy existing ground decorationClearDisplayGridPropertyDetails();// Instantiate grid property details for current sceneDisplayGridPropertyDetails();}}}public void ISaveableStoreScene(string sceneName){// Remove sceneSave for sceneGameObjectSave.sceneData.Remove(sceneName);// Create sceneSave for sceneSceneSave sceneSave = new SceneSave();// create & add dict grid property details dictionarysceneSave.gridPropertyDetailsDictionary = gridPropertyDictionary;// Add scene save to game object scene dataGameObjectSave.sceneData.Add(sceneName, sceneSave);}private void Start(){InitialiseGridProperties();}private void ClearDisplayGroundDecorations(){// Remove ground decorationsgroundDecoration1.ClearAllTiles();groundDecoration2.ClearAllTiles();}private void ClearDisplayGridPropertyDetails(){ClearDisplayGroundDecorations();}public void DisplayDugGround(GridPropertyDetails gridPropertyDetails){// Dugif(gridPropertyDetails.daysSinceDug > -1){ConnectDugGround(gridPropertyDetails);}}private void ConnectDugGround(GridPropertyDetails gridPropertyDetails){// Select tile based on surrounding dug tilesTile dugTile0 = SetDugTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY, 0), dugTile0);// Set 4 tiles if dug surrounding current tile - up, down, left, right now that this central tile has been dugGridPropertyDetails adjacentGridPropertyDetails;adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1);if(adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile1 = SetDugTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1, 0), dugTile1);}adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1);if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile2 = SetDugTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1, 0), dugTile2);}adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY);if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile3 = SetDugTile(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY, 0), dugTile3);}adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY);if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceDug > -1){Tile dugTile4 = SetDugTile(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY);groundDecoration1.SetTile(new Vector3Int(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY, 0), dugTile4);}}private Tile SetDugTile(int xGrid, int yGrid){// Get whether surrounding tiles(up,down,left,right) are dug or notbool upDug = IsGridSquareDug(xGrid, yGrid + 1);bool downDug = IsGridSquareDug(xGrid, yGrid - 1);bool leftDug = IsGridSquareDug(xGrid - 1, yGrid);bool rightDug = IsGridSquareDug(xGrid + 1, yGrid);#region Set appropriate tile based on whether surrounding tiles are dug or notif(!upDug && !downDug &&  !rightDug && !leftDug){return dugGround[0];}else if(!upDug && downDug && rightDug && !leftDug){return dugGround[1];}else if(!upDug && downDug && rightDug && leftDug){return dugGround[2];}else if(!upDug && downDug && !rightDug && leftDug){return dugGround[3];}else if(!upDug && downDug && !rightDug && !leftDug){return dugGround[4];}else if(upDug && downDug && rightDug && !leftDug){return dugGround[5];}else if(upDug && downDug && rightDug && leftDug){return dugGround[6];}else if(upDug && downDug && !rightDug && leftDug){return dugGround[7];}else if(upDug && downDug && !rightDug && !leftDug){return dugGround[8];}else if(upDug && !downDug && rightDug && !leftDug){return dugGround[9];}else if(upDug && !downDug && rightDug && leftDug){return dugGround[10];}else if(upDug && !downDug && !rightDug && leftDug){return dugGround[11];}else if(upDug && !downDug && !rightDug && !leftDug){return dugGround[12];}else if(!upDug && !downDug && rightDug && !leftDug){return dugGround[13];}else if(!upDug && !downDug && rightDug && leftDug){return dugGround[14];}else if(!upDug && !downDug && !rightDug && leftDug){return dugGround[15];}return null;#endregion Set appropriate tile based on whether surrounding tiles are dug or not}private bool IsGridSquareDug(int xGrid, int yGrid){GridPropertyDetails gridPropertyDetails = GetGridPropertyDetails(xGrid, yGrid);if(gridPropertyDetails == null){return false;}else if(gridPropertyDetails.daysSinceDug > -1){return true;}else{return false;}}private void DisplayGridPropertyDetails(){// Loop throught all grid itemsforeach(KeyValuePair<string, GridPropertyDetails> item in gridPropertyDictionary){GridPropertyDetails gridPropertyDetails = item.Value;DisplayDugGround(gridPropertyDetails);}}/// <summary>/// This initialises the grid property dictionary with the values from the SO_GridProperties assets and stores the values for each scene in/// GameObjectSave sceneData/// </summary>private void InitialiseGridProperties(){// loop through all gridproperties in the arrayforeach(SO_GridProperties so_GridProperties in so_gridPropertiesArray){// Create dictionary of grid property detailsDictionary<string, GridPropertyDetails> gridPropertyDictionary = new Dictionary<string, GridPropertyDetails>();// Populate grid property dictionary - Iterate through all the grid properties in the so gridproperties listforeach(GridProperty gridProperty in so_GridProperties.gridPropertyList){GridPropertyDetails gridPropertyDetails;gridPropertyDetails = GetGridPropertyDetails(gridProperty.gridCoordinate.x, gridProperty.gridCoordinate.y, gridPropertyDictionary);if(gridPropertyDetails == null){gridPropertyDetails = new GridPropertyDetails();}switch (gridProperty.gridBoolProperty){case GridBoolProperty.diggable:gridPropertyDetails.isDiggable = gridProperty.gridBoolValue;break;case GridBoolProperty.canDropItem:gridPropertyDetails.canDropItem = gridProperty.gridBoolValue;break;case GridBoolProperty.canPlaceFurniture:gridPropertyDetails.canPlaceFurniture = gridProperty.gridBoolValue;break;case GridBoolProperty.isPath:gridPropertyDetails.isPath = gridProperty.gridBoolValue;break;case GridBoolProperty.isNPCObstacle:gridPropertyDetails.isNPCObstacle = gridProperty.gridBoolValue;break;default:break; }SetGridPropertyDetails(gridProperty.gridCoordinate.x, gridProperty.gridCoordinate.y, gridPropertyDetails, gridPropertyDictionary);}// Create scene save for this gameobjectSceneSave sceneSave = new SceneSave();// Add grid property dictionary to scene save datasceneSave.gridPropertyDetailsDictionary = gridPropertyDictionary;// If starting scene set the griProertyDictionary member variable to the current iterationif(so_GridProperties.sceneName.ToString() == SceneControllerManager.Instance.startingSceneName.ToString()){this.gridPropertyDictionary = gridPropertyDictionary;}// Add scene save to game object scene dataGameObjectSave.sceneData.Add(so_GridProperties.sceneName.ToString(), sceneSave);}}/// <summary>/// Returns the gridPropertyDetails at the gridlocation fro the supplied dictionary,/// or null if no properties exist at that location/// </summary>/// <param name="gridX"></param>/// <param name="gridY"></param>/// <param name="gridPropertyDictionary"></param>/// <returns></returns>public GridPropertyDetails GetGridPropertyDetails(int gridX, int gridY, Dictionary<string, GridPropertyDetails> gridPropertyDictionary){// Construct key from coordinatestring key = "x" + gridX + "y" + gridY;GridPropertyDetails gridPropertyDetails;// Check if grid property details exist for coordinate and retrieveif (!gridPropertyDictionary.TryGetValue(key, out gridPropertyDetails)){// if not foundreturn null;}else{return gridPropertyDetails;}}public GridPropertyDetails GetGridPropertyDetails(int gridX, int gridY){return GetGridPropertyDetails(gridX, gridY, gridPropertyDictionary);}/// <summary>/// Set the grid property details to gridPropertyDetails fro the tile at (gridX, gridY) for current scene/// </summary>/// <param name="gridX"></param>/// <param name="gridY"></param>/// <param name="gridPropertyDetails"></param>public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails){SetGridPropertyDetails(gridX, gridY, gridPropertyDetails, gridPropertyDictionary);}/// <summary>/// Set the grid property details to gridPropertyDetails for the title at (gridX, gridY) for the gridPropertyDictionary./// </summary>/// <param name="gridX"></param>/// <param name="gridY"></param>/// <param name="gridPropertyDetails"></param>/// <param name="gridPropertyDictionary"></param>public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails, Dictionary<string, GridPropertyDetails> gridPropertyDictionary){// Construct key from coordinatestring key = "x" + gridX + "y" + gridY;gridPropertyDetails.gridX = gridX;gridPropertyDetails.gridY = gridY;// Set value gridPropertyDictionary[key] = gridPropertyDetails;}}

5、修改Player.cs脚本

在HoeGroundAtCursorRoutine函数中添加如下代码:

6、设置绘图

(1)创建新的Palette

Create New Palette,并且命名为DugGround,保存到Assets -> Tilemap -> Tile Palettes下。

(2)创建新的Tiles

在Assets -> Sprites -> Sprite Textures -> Tile Sprites 下找到DugGround.

将DugGround拖到右边的Palette中,弹出的目录选择Assets -> Tilemap -> Tiles,创建新的目录Dug Ground,保存到该目录下。

左边灰色为Dug后的grid图案,右边银色为Water之后的grid图案。

7、配置Tile信息

点击Assets -> Tilemap -> Tiles -> Dug Ground,然后点击Open。

点击PersistentScene -> GridPropertiesManager,将Dug Ground中灰色的图片拖入到Dug Ground的List中。

8、添加Tag

点击GridPropertiesManager,点击Add Tag。

添加GroundDecoration1和GroundDecoration2两个Tag。

然后依次给Scene1/Scene2/Scene3场景Tilemap Grid下的GroundDecoration1和GroundDecoration2对象设置GroundDecoration1和GroundDecoration2两个Tag。

设置Prefabs -> Maps -> Tilemap Grid下的GroundDecoration1和GroundDecoration2对象设置GroundDecoration1和GroundDecoration2两个Tag。

9、运行游戏

http://www.dtcms.com/wzjs/543494.html

相关文章:

  • 无障碍浏览网站怎么做网站建设交印花税吗
  • 网站建设策划书建立平台网站要多久
  • 百度智能建站系统网站建设后的团队总结
  • 网站建设应该学什么软件九创 wordpress
  • 海洋cms怎么做电影网站做网站有多赚钱
  • 做健康食品的网站网站群信息管理系统
  • 广州设计网站建设网站建设工作室是干嘛的
  • 网站名称和备案室内设计公司招聘
  • 网站建设需要版块seo网站排名优化
  • 顺营销官方网站用php做的网站怎么上传
  • 工程建设标准网官方网站python培训价格
  • 视频网站建设报价单网站数据库模板
  • 免费建造网站系统企业网站做电脑营销
  • 建立网络平台要多少钱如何申请网站优化工作
  • 合肥住房和建设厅网站首页网站建设管理典型经验材料
  • 制作企业网站电子商务网站的建设目标是什么
  • 电子商务网站建设的主要风险wordpress多人会议插件
  • 做电影网站会不会侵权wordpress怎么连接主机名
  • 那个网站可以做恒指 买涨买跌叫别人做网站权重被转移了
  • 网上建设银行网站网站开发国内外研究状况
  • 南京网站优化报价滨海网站建设服务商
  • 永康网站推广电商平台取名字大全
  • 给公司做网站液压电机东莞网站建设
  • 克隆网站首页做单页站几个文件pc网站增加手机站
  • 网站想换一个空间怎么办外贸网站logo
  • 站库设计网站官网网站内的搜索怎么做
  • 越南的网站建设可以做公司宣传的网站有哪些
  • 青海做网站网站建设及管理制度文章
  • 最好的网站建设团队wordpress网站如何添加栏目
  • 网站开发的后期支持网络服务商在哪咨询