Better navmesh, Added icons, Added PSXPlayer component
This commit is contained in:
@@ -3,7 +3,6 @@ using Unity.AI.Navigation;
|
||||
using UnityEngine.AI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
public struct PSXNavMeshTri
|
||||
@@ -20,23 +19,35 @@ namespace SplashEdit.RuntimeCode
|
||||
public class PSXNavMesh : MonoBehaviour
|
||||
{
|
||||
|
||||
Mesh mesh;
|
||||
|
||||
[HideInInspector]
|
||||
public List<PSXNavMeshTri> Navmesh { get; set; }
|
||||
|
||||
public void CreateNavmesh(float GTEScaling)
|
||||
{
|
||||
mesh = new Mesh();
|
||||
Navmesh = new List<PSXNavMeshTri>();
|
||||
NavMeshSurface navMeshSurface = GetComponent<NavMeshSurface>();
|
||||
navMeshSurface.overrideTileSize = true;
|
||||
navMeshSurface.tileSize = 16;
|
||||
navMeshSurface.overrideVoxelSize = true;
|
||||
navMeshSurface.voxelSize = 0.1f;
|
||||
navMeshSurface.BuildNavMesh();
|
||||
NavMeshTriangulation triangulation = NavMesh.CalculateTriangulation();
|
||||
navMeshSurface.overrideTileSize = false;
|
||||
navMeshSurface.overrideVoxelSize = false;
|
||||
|
||||
int[] triangles = triangulation.indices;
|
||||
Vector3[] vertices = triangulation.vertices;
|
||||
|
||||
mesh.vertices = vertices;
|
||||
mesh.triangles = triangles;
|
||||
|
||||
mesh.RecalculateNormals();
|
||||
|
||||
for (int i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
|
||||
|
||||
int vid0 = triangles[i];
|
||||
int vid1 = triangles[i + 1];
|
||||
int vid2 = triangles[i + 2];
|
||||
@@ -58,5 +69,27 @@ namespace SplashEdit.RuntimeCode
|
||||
Navmesh.Add(tri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnDrawGizmos()
|
||||
{
|
||||
if (mesh == null) return;
|
||||
Gizmos.DrawMesh(mesh);
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
var vertices = mesh.vertices;
|
||||
var triangles = mesh.triangles;
|
||||
|
||||
for (int i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
Vector3 v0 = vertices[triangles[i]];
|
||||
Vector3 v1 = vertices[triangles[i + 1]];
|
||||
Vector3 v2 = vertices[triangles[i + 2]];
|
||||
|
||||
Gizmos.DrawLine(v0, v1);
|
||||
Gizmos.DrawLine(v1, v2);
|
||||
Gizmos.DrawLine(v2, v0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user