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

企业网站优化做法大秀

企业网站优化做法,大秀,wordpress前台登陆验证码,网络营销推广策划案前言 在Unity3D游戏开发中#xff0c;经常需要生成和处理多个房间的场景#xff0c;特别是在地牢生成、房屋布局或迷宫设计等应用中。为了确保生成的房间不会重叠#xff0c;我们需要一种有效的去重叠化算法。以下将详细介绍该算法的原理和代码实现。 对惹#xff0c;这里有…前言 在Unity3D游戏开发中经常需要生成和处理多个房间的场景特别是在地牢生成、房屋布局或迷宫设计等应用中。为了确保生成的房间不会重叠我们需要一种有效的去重叠化算法。以下将详细介绍该算法的原理和代码实现。 对惹这里有一个游戏开发交流小组希望大家可以点击进来一起交流一下开发经验呀 算法原理 房间表示 每个房间可以表示为一个矩形其位置和大小由其在世界坐标系中的位置x, y, z以及宽度和高度决定。在Unity3D中通常使用Rect组件或自定义的DungeonCell类来表示房间。 重叠检测 重叠检测是判断两个房间是否相交的过程。这可以通过比较两个矩形的边界来实现。如果两个矩形的任意一边相交则它们重叠。 移动房间 一旦检测到重叠就需要移动其中一个房间以避免重叠。移动的方向和距离可以根据重叠的严重程度来计算。一种简单的方法是计算两个房间中心点的差值然后移动重叠的房间使其中心点沿这个差值方向移动一定距离。 迭代处理 由于移动一个房间可能会导致它与另一个房间重叠因此需要迭代处理直到所有房间都不重叠为止。 代码实现 以下是一个Unity3D中实现房间去重叠化算法的示例代码。 using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; public class DungeonCell : MonoBehaviour { public Rect CellRect { get; private set; } public Vector3 Position { get; private set; } public int Width { get; private set; } public int Height { get; private set; } public CellType cellType { get; set; } public enum CellType { Normal, Hall } public void CreateCell(int width, int height) { Width width; Height height; Position transform.position; CellRect new Rect(Position.x - Width / 2, Position.z - Height / 2, Width, Height); } public void MoveTo(Vector3 position) { transform.position position; Position position; CellRect new Rect(Position.x - Width / 2, Position.z - Height / 2, Width, Height); } public bool Overlap(DungeonCell comparedCell) { return CellRect.Overlaps(comparedCell.CellRect); } } public class DungeonMaker : MonoBehaviour { public float CellCreationRadius 150; public int NumberOfCells 40; public int NumberOfHalls 12; public ListDungeonCell cellsList new ListDungeonCell(); public int MinWidth 3; public int MaxWidth 8; public int MinLength 3; public int MaxLength 8; public float movementForce 4.0f; public ListDungeonCell importantCells new ListDungeonCell(); void Start() { CreateCells(); SeparateCells(); MarkImportantCell(); } private void CreateCells() { for (int i 0; i NumberOfCells; i) { Vector2 Position2D Random.insideUnitCircle * CellCreationRadius; GameObject gameObjectPointer new GameObject(Cell i); DungeonCell cellPointer gameObjectPointer.AddComponentDungeonCell(); cellPointer.CreateCell(Random.Range(MinWidth, MaxWidth 1), Random.Range(MinLength, MaxLength 1)); cellPointer.MoveTo(new Vector3(Position2D.x, 0, Position2D.y)); cellsList.Add(cellPointer); } } private void SeparateCells() { bool allCellsNotOverlap false; while (!allCellsNotOverlap) { allCellsNotOverlap true; foreach (DungeonCell currentCell in cellsList) { Vector3 movementVector Vector3.zero; int numberOfOverlaps 0; foreach (DungeonCell comparedCell in cellsList) { if (currentCell comparedCell) continue; if (currentCell.Overlap(comparedCell)) { movementVector currentCell.transform.position - comparedCell.transform.position; numberOfOverlaps; } } if (numberOfOverlaps ! 0) { allCellsNotOverlap false; if (movementVector.magnitude 0) { movementVector movementVector.normalized * movementForce; } else { movementVector Random.insideUnitCircle.normalized * movementForce; } currentCell.MoveTo(currentCell.transform.position movementVector); } } } } private void MarkImportantCell() { importantCells cellsList.OrderByDescending(n n.CellRect.width * n.CellRect.height).ToList(); for (int i 0; i NumberOfHalls; i) { importantCells[i].cellType DungeonCell.CellType.Hall; } } } 技术详解 DungeonCell 类 CreateCell 方法用于初始化房间的大小和位置并计算其Rect边界。 MoveTo 方法用于更新房间的位置并重新计算其Rect边界。 Overlap 方法用于检测两个房间是否重叠。 DungeonMaker 类 CreateCells 方法用于随机生成指定数量的房间并将它们添加到cellsList中。 SeparateCells 方法用于迭代处理房间重叠问题。通过计算重叠房间的移动向量并将房间移动到新位置来避免重叠。 MarkImportantCell 方法用于根据房间大小将房间标记为重要房间如大厅以便后续处理。 通过该算法和代码实现可以有效地解决Unity3D中房间重叠的问题并为后续的房间布局和场景生成提供基础。 更多教学视频 Unity3D ​ www.bycwedu.com/promotion_channels/2146264125
http://www.dnsts.com.cn/news/96529.html

相关文章:

  • 泰安网站建设最好网站开发流程分为哪三个阶段
  • 跨平台网站制作wordpress 交友模板
  • 免费网站建设模板网站设置手机版
  • 个人网站备案需要几天建一个下载网站要什么cms系统
  • 福州智能建站WordPress评论调用QQ头像
  • 用博客做网站厦门网络建站公司
  • 网站后台数据库怎么做微网站 好处
  • 网站源码下载教程工业设计和产品设计的区别
  • 做游戏网站定位网站开发怎样手机号验证
  • 在线设计装修的网站宁海县城镇建设局网站
  • 通付盾 建设网站网站规划建设论文
  • 购物网站有哪些平台宁波网站关键词排名推广
  • 网站开发销售提成张家港阿里网站建设
  • 做八年级题目的网站大型门户网站多少钱
  • 哪些人需要建网站怎么做饲料电商网站
  • 上街郑州网站建设网络工程就业岗位有哪些
  • 论述网站建设引言网站移动端是什么问题
  • app制作的网站有些公司做网站比较好的
  • 小程序怎么制作网站电子邮箱免费注册
  • 网站制作的基本步骤动力无限西安网站建设
  • 竞价网站做不做链接龙华网站建设的基本步骤
  • 站长网站素材网易企业邮箱注册流程
  • 有做销售产品的网站有哪些一开始用php做网站
  • 富阳网站定制开发哪家公司好网页制作与网站开发从入门到精通 下载
  • 专业网站建设哪家效果好如何自己做公众号
  • 网站建设的局限性the7 wordpress 汉化
  • 邯郸网站建网站所有页面只显示域名
  • 网站开发项目教程笔记长沙网页设计哪家专业
  • 怎么做网站软件万网域名管理登录
  • 深圳罗湖外贸网站建设手机官方网站