using UnityEngine; namespace ECM2 { /// /// The slope behaviour for attached collider. /// public enum SlopeBehaviour { Default, /// /// Sets the collider as walkable. /// Walkable, /// /// Sets the collider as not walkable. /// NotWalkable, /// /// Let you specify a custom slope limit value for collider. /// Override } /// /// Overrides a CharacterMovement SlopeLimit property allowing to define per-object behaviour instead of per face. /// This enable you to tweak what surfaces Characters can walk up. Perhaps a stair case is too steep or /// maybe you want to enforce the "no walking on the grass" signs, these settings will enable you to do so. /// public sealed class SlopeLimitBehaviour : MonoBehaviour { #region EDITOR EXPOSED FIELDS [Tooltip("The desired behaviour.")] [SerializeField] private SlopeBehaviour _slopeBehaviour = SlopeBehaviour.Default; [SerializeField] private float _slopeLimit; #endregion #region FIELDS [SerializeField, HideInInspector] private float _slopeLimitCos; #endregion #region PROPERTIES /// /// The current behaviour. /// public SlopeBehaviour walkableSlopeBehaviour { get => _slopeBehaviour; set => _slopeBehaviour = value; } /// /// The slope limit angle in degrees. /// public float slopeLimit { get => _slopeLimit; set { _slopeLimit = Mathf.Clamp(value, 0.0f, 89.0f); _slopeLimitCos = Mathf.Cos(_slopeLimit * Mathf.Deg2Rad); } } /// /// The cosine of slope angle (in radians), this is used to faster angle tests (e.g. dotProduct > slopeLimitCos) /// public float slopeLimitCos { get => _slopeLimitCos; set { _slopeLimitCos = Mathf.Clamp01(value); _slopeLimit = Mathf.Clamp(Mathf.Acos(_slopeLimitCos) * Mathf.Rad2Deg, 0.0f, 89.0f); } } #endregion #region MONOBEHAVIOUR private void OnValidate() { slopeLimit = _slopeLimit; } #endregion } }