Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/SceneObjectMeshCollider.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

78 lines
2.2 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.SceneObjects.Common
{
using Engine.Core.Implementation;
using Engine.Extensions;
using Rendering.Renderer;
using UnityEngine;
public sealed class SceneObjectMeshCollider : GameEntityScript
{
private BoxCollider _collider;
private Vector3 _meshBoundsSize;
private Vector3 _boundsSizeOffset;
private bool _initialized;
protected override void OnEnableGameEntity()
{
if (!_initialized)
{
UpdateBounds();
}
}
protected override void OnDisableGameEntity()
{
if (_collider != null)
{
_collider.Destroy();
_collider = null;
}
}
/// <summary>
/// Init with a size offset.
/// Note: This method is not required to be called.
/// </summary>
/// <param name="sizeOffset">A size offset to the bounds based on model</param>
public void Init(Vector3 sizeOffset)
{
_boundsSizeOffset = sizeOffset;
UpdateBounds();
_initialized = true;
}
private void UpdateBounds()
{
Bounds bounds;
if (GameEntity.GetComponent<CvdModelRenderer>() is { } cvdModelRenderer)
{
bounds = cvdModelRenderer.GetMeshBounds();
}
else if (GameEntity.GetComponent<PolyModelRenderer>() is { } polyModelRenderer)
{
bounds = polyModelRenderer.GetMeshBounds();
}
else
{
return;
}
if (_collider == null)
{
_collider = GameEntity.AddComponent<BoxCollider>();
}
_meshBoundsSize = bounds.size;
_collider.center = bounds.center;
_collider.size = _meshBoundsSize + _boundsSizeOffset;
}
}
}