Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs
Jiaqi (0x7c13) Liu e870cf487a Add core protocol regression tests and copyright checks
Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation.

Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries.
2026-11-12 13:37:27 +08:00

53 lines
1.8 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.Scene
{
using Core.DataReader.Nav;
using Engine.Core.Implementation;
using Engine.Extensions;
using UnityEngine;
/// <summary>
/// Represents a navigation mesh used for pathfinding in a game scene.
/// </summary>
public sealed class NavMesh : GameEntityScript
{
public int NavLayerIndex { get; private set; }
private MeshCollider _meshCollider;
protected override void OnEnableGameEntity()
{
// Set layer to NavMeshes for the attached GameEntity
// Because NavMeshes should not collide with anything else, it is only used for raycast.
// This behaviour is configured in Physics settings (Edit -> Project Settings -> Physics)
GameEntity.Layer = LayerMask.NameToLayer("NavMeshes");
}
protected override void OnDisableGameEntity()
{
if (_meshCollider != null)
{
_meshCollider.sharedMesh.Destroy();
_meshCollider.Destroy();
_meshCollider = null;
}
}
public void Init(int layerIndex, NavMeshData navMeshData)
{
NavLayerIndex = layerIndex;
_meshCollider = GameEntity.AddComponent<MeshCollider>();
_meshCollider.convex = false;
_meshCollider.sharedMesh = new Mesh()
{
vertices = navMeshData.GameBoxVertices.ToUnityPositions(),
triangles = navMeshData.GameBoxTriangles.ToUnityTriangles(),
};
}
}
}