// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#if UNITY_EDITOR
using NWH.NUI;
using UnityEditor;
#endif
#endregion
namespace NWH.Common.CoM
{
///
/// Simple mass affector implementation that contributes a fixed mass at its transform position
/// to the vehicle's center of mass calculations.
///
///
/// Use this component for static mass contributions like passengers, cargo, or equipment.
/// For dynamic masses like fuel tanks, create a custom IMassAffector implementation that
/// returns varying mass values.
///
public class MassAffector : MonoBehaviour, IMassAffector
{
///
/// Mass contribution of this affector in kilograms.
///
public float mass = 100.0f;
///
/// Returns the mass of this affector.
///
/// Mass in kilograms.
public float GetMass()
{
return mass;
}
///
/// Returns the transform of this mass affector.
///
public Transform GetTransform()
{
return transform;
}
///
/// Returns the world position of this mass affector's center of mass.
///
public Vector3 GetWorldCenterOfMass()
{
return transform.position;
}
}
}
#if UNITY_EDITOR
namespace NWH.Common.CoM
{
[CustomEditor(typeof(MassAffector))]
[CanEditMultipleObjects]
public class MassAffectorEditor : NUIEditor
{
public override bool OnInspectorNUI()
{
if (!base.OnInspectorNUI())
{
return false;
}
drawer.Field("mass", true, "kg");
drawer.EndEditor(this);
return true;
}
}
}
#endif