2020-04-09 07:48:45 +01:00
|
|
|
using MessagePack;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
2020-05-06 04:56:36 +01:00
|
|
|
public class TurningData : BehaviorData
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2020-05-31 03:10:11 +01:00
|
|
|
[InspectableField, JsonProperty("torque"), Key(1), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Torque = new PerformanceStat();
|
|
|
|
|
|
2020-05-11 01:17:10 +01:00
|
|
|
[InspectableField, JsonProperty("visibility"), Key(2)]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Visibility = new PerformanceStat();
|
|
|
|
|
|
2020-05-11 01:17:10 +01:00
|
|
|
[InspectableField, JsonProperty("heat"), Key(3)]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Heat = new PerformanceStat();
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2020-04-09 10:33:16 +01:00
|
|
|
return new Turning(context, this, entity, item);
|
2020-04-09 07:48:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
public class Turning : IAnalogBehavior
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2020-04-09 10:33:16 +01:00
|
|
|
public Entity Entity { get; }
|
2020-12-10 23:20:38 +00:00
|
|
|
public EquippedItem Item { get; }
|
|
|
|
|
public ItemManager Context { get; }
|
2020-05-07 03:53:54 +01:00
|
|
|
|
|
|
|
|
public float Torque { get; private set; }
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2020-06-05 04:16:33 +01:00
|
|
|
public float Axis
|
|
|
|
|
{
|
|
|
|
|
get => _input;
|
|
|
|
|
set => _input = clamp(value, -1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 04:56:36 +01:00
|
|
|
public BehaviorData Data => _data;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
private TurningData _data;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2020-05-07 03:53:54 +01:00
|
|
|
private float _input;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public Turning(ItemManager context, TurningData data, Entity entity, EquippedItem item)
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
|
|
|
|
Context = context;
|
|
|
|
|
_data = data;
|
2020-04-09 10:33:16 +01:00
|
|
|
Entity = entity;
|
2020-04-09 07:48:45 +01:00
|
|
|
Item = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 01:17:10 +01:00
|
|
|
public bool Update(float delta)
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
Torque = Context.Evaluate(_data.Torque, Item.EquippableItem, Entity);
|
2020-05-07 03:53:54 +01:00
|
|
|
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque / Entity.Mass * delta));
|
2020-12-10 23:20:38 +00:00
|
|
|
Item.Temperature += (abs(_input) * Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta) / Context.GetThermalMass(Item.EquippableItem);
|
|
|
|
|
Entity.VisibilitySources[this] = abs(_input) * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Remove()
|
|
|
|
|
{
|
2020-04-09 07:48:45 +01:00
|
|
|
}
|
|
|
|
|
}
|