using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Sci-Fi Ship Controller. Copyright (c) 2018-2023 SCSM Pty Ltd. All rights reserved.
namespace SciFiShipController
{
///
/// Class containing data for a control surface.
///
[System.Serializable]
public class ControlSurface
{
#region Enumerations
public enum ControlSurfaceType
{
Aileron = 10,
Elevator = 11,
Rudder = 12,
AirBrake = 20,
//Custom = 50
}
#endregion
#region Public variables and properties
// IMPORTANT - when changing this section also update SetClassDefault()
// Also update ClassName(ClassName className) Clone Constructor (if there is one)
///
/// The type of control surface this is. This defines the axis it rotates on as well as the inputs it is controlled by.
/// If you modify this, call ReinitialiseInputVariables() on the ship this control surface is attached to.
///
public ControlSurfaceType type;
///
/// The length of the control surface (measured along the axis of rotation).
///
public float span;
///
/// The width of the control surface (measured along the local z-axis).
///
public float chord;
///
/// Position of the pivot of the control surface in local space relative to the pivot point of the ship.
///
public Vector3 relativePosition;
///
/// The local axis about which the control surface rotates. This is only relevant for Custom type (in other types it is defined automatically).
///
public Vector3 rotationAxis;
///
/// The index of the damage region this control surface is associated with. When the damage model of the ship is set to simple, this
/// is irrelevant. A negative value means it is associated with no damage region (so the control surface's performance will not be
/// affected by damage). When the damage model of the ship is set to progressive, a value of zero means it is
/// associated with the main damage region. When the damage model of the ship is set to localised, a zero or positive value
/// indicates which damage region it is associated with (using a zero-based indexing system).
///
public int damageRegionIndex;
///
/// The minimum (i.e. when its health reaches zero) performance level of this control surface. The performance level affects how much
/// aerodynamic effect is produced by this control surface. At a performance level of one it produces the usual value. At a performance level of
/// zero it has no effect.
///
[Range(0f, 1f)] public float minPerformance;
///
/// The current performance level of this control surface (determined by the Health value). The performance level affects how much
/// aerodynamic effect is produced by this control surface. At a performance level of one it produces the usual value. At a performance level of
/// zero it has no effect.
///
public float CurrentPerformance { get; private set; }
///
/// The starting health value of this control surface.
///
public float startingHealth;
private float health;
///
/// The current health value of this control surface.
///
public float Health
{
get { return health; }
set
{
// Update the health value
health = value;
// Update the current performance value
CurrentPerformance = value / startingHealth;
CurrentPerformance = CurrentPerformance > minPerformance ? CurrentPerformance : minPerformance;
CurrentPerformance = CurrentPerformance < 1f ? CurrentPerformance : 1f;
}
}
///
/// Whether the control surface is shown as expanded in the inspector window of the editor.
///
public bool showInEditor;
///
/// Whether the control surface node is shown as selected in the scene view of the editor.
///
public bool selectedInSceneView;
///
/// Whether the gizmos for this control surface are shown in the scene view of the editor
///
public bool showGizmosInSceneView;
#endregion
#region Class constructors
public ControlSurface ()
{
SetClassDefaults();
}
// Copy contructor
public ControlSurface(ControlSurface controlSurface)
{
if (controlSurface == null) { SetClassDefaults(); }
else
{
this.type = controlSurface.type;
this.span = controlSurface.span;
this.chord = controlSurface.chord;
this.relativePosition = controlSurface.relativePosition;
this.rotationAxis = controlSurface.rotationAxis;
this.damageRegionIndex = controlSurface.damageRegionIndex;
this.minPerformance = controlSurface.minPerformance;
this.startingHealth = controlSurface.startingHealth;
this.Health = controlSurface.Health;
this.showInEditor = controlSurface.showInEditor;
this.selectedInSceneView = controlSurface.selectedInSceneView;
this.showGizmosInSceneView = controlSurface.showGizmosInSceneView;
}
}
#endregion
#region Public Non-Static Methods
public void SetClassDefaults()
{
this.type = ControlSurfaceType.Aileron;
this.span = 10f;
this.chord = 1f;
this.relativePosition = Vector3.zero;
this.rotationAxis = Vector3.right;
this.damageRegionIndex = -1;
this.minPerformance = 0.25f;
this.startingHealth = 100f;
this.Health = 100f;
this.showInEditor = true;
this.selectedInSceneView = false;
this.showGizmosInSceneView = true;
}
#endregion
}
}