资源简介
Unity5.6终于支持NavMesh动态烘培啦!
代码片段和文件信息
using UnityEngine;
using UnityEngine.AI;
using System.Collections;
using System.Collections.Generic;
using NavMeshBuilder = UnityEngine.AI.NavMeshBuilder;
// Build and update a localized navmesh from the sources marked by NavMeshSourceTag
[DefaultExecutionOrder(-102)]
public class My_LocalNavMeshBuilder : MonoBehaviour
{
// The center of the build
public Transform m_Tracked;
// The size of the build bounds
public Vector3 m_Size = new Vector3(80.0f 20.0f 80.0f);
NavMeshData m_NavMesh;
AsyncOperation m_Operation;
NavMeshDataInstance m_Instance;
List m_Sources = new List();
private MeshFilter mf;
private Mesh m;
//IEnumerator Start()
//{
// while (true)
// {
// UpdateNavMesh(true);
// yield return m_Operation;
// }
//}
void Start()
{
mf = GetComponent();
m = mf.mesh;
}
void Update()
{
if(Input.GetKey(KeyCode.A))
{
bake();
}
if(Input.GetKey(KeyCode.D))
{
drawNavMesh();
}
}
private void bake()
{
m_NavMesh = new NavMeshData();
m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
if (m_Tracked == null)
m_Tracked = transform;
UpdateNavMesh(false);
}
private void drawNavMesh()
{
NavMeshTriangulation nt = NavMesh.CalculateTriangulation();
m.vertices = nt.vertices;
m.triangles = nt.indices;
}
//void OnEnable()
//{
// // Construct and add navmesh
// m_NavMesh = new NavMeshData();
// m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
// if (m_Tracked == null)
// m_Tracked = transform;
// UpdateNavMesh(false);
//}
//void OnDisable()
//{
// // Unload navmesh and clear handle
// m_Instance.Remove();
//}
void UpdateNavMesh(bool asyncUpdate = false)
{
NavMeshSourceTag.Collect(ref m_Sources);
var defaultBuildSettings = NavMesh.GetSettingsByID(0);
var bounds = QuantizedBounds();
if (asyncUpdate)
m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh defaultBuildSettings m_Sources bounds);
else
NavMeshBuilder.UpdateNavMeshData(m_NavMesh defaultBuildSettings m_Sources bounds);
}
static Vector3 Quantize(Vector3 v Vector3 quant)
{
float x = quant.x * Mathf.Floor(v.x / quant.x);
float y = quant.y * Mathf.Floor(v.y / quant.y);
float z = quant.z * Mathf.Floor(v.z / quant.z);
return new Vector3(x y z);
}
Bounds QuantizedBounds()
{
// Quantize the bounds to update only when theres a 10% change in size
var center = m_Tracked ? m_Tracked.position : transform.position;
r
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-04-19 14:54 NavMeshComponents\
目录 0 2017-04-19 14:54 NavMeshComponents\Assets\
文件 27353 2017-04-19 14:54 NavMeshComponents\Assets\DemoScene.unity
文件 174 2017-04-19 14:28 NavMeshComponents\Assets\DemoScene.unity.me
目录 0 2017-04-19 13:48 NavMeshComponents\Assets\Examples\
文件 3497 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Cube.prefab
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Cube.prefab.me
目录 0 2017-04-19 13:48 NavMeshComponents\Assets\Examples\Editor\
文件 4425 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Editor\NavMeshPrefabInstanceEditor.cs
文件 262 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Editor\NavMeshPrefabInstanceEditor.cs.me
文件 191 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Editor.me
目录 0 2017-04-19 13:48 NavMeshComponents\Assets\Examples\Materials\
文件 2867 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\brightgreen.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\brightgreen.mat.me
文件 2867 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\brown.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\brown.mat.me
文件 3947 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\crosshair.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\crosshair.mat.me
文件 2865 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\floor.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\floor.mat.me
文件 2867 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\green.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\green.mat.me
文件 2863 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\grey.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\grey.mat.me
文件 1036 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\modify_crosshair.png
文件 1184 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\modify_crosshair.png.me
文件 2863 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\red.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\red.mat.me
文件 2849 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\yellow.mat
文件 179 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials\yellow.mat.me
文件 191 2017-04-03 17:57 NavMeshComponents\Assets\Examples\Materials.me
............此处省略871个文件信息
相关资源
- OpenGL绘制可运动自行车源程序.zip
- opengl室内场景的绘制,包括碰撞检测
- 2019西门子挑战杯初赛获奖程序+方案书
- 勘测测量插件
- CIE色度图绘制软件
- AxGlyph(矢量图绘制软件)v12.25免费安
- 细集料沥青混合料蠕变柔量主曲线绘
- 用Qt绘制柱状图
- 二维点电荷形成的静电场电场线绘制
- STM32单片机控制的自动浇水系统+OLED显
- 入门使用AD绘制PCB两层板的基本操作
- 使用canvas画线,位移,旋转,绘制五
- opengl绘制树
- 操作系统课程设计 绘制资源分配图
- AD14绘制PCB教程_V2.3_20200319.doc
- ATM机数据流图及原型图的绘制
- OpenGL球体绘制与球体贴图
- 使用OpenGL绘制Bezier曲线
- OpenGL卡通人脸绘制
- 实验一 OpenGL 程序设计基础
- 蓝牙接收数据并绘制波形
- OpenGL绘制3D企鹅
- 运用DirectX9绘制太阳系
- Bezier曲面 Coons曲面 B样条曲面绘制(用
- 用opengl绘制的兔子
- QtCharts绘制动态心电图
- 基于OpenGL的描点绘制Bezier曲线
- QPainter绘制雷达图玫瑰图
- OpenGL绘制的鱼轮廓曲线
- 故障树自动绘制软件
评论
共有 条评论