Wormholes
This commit is contained in:
parent
4b10923448
commit
adfb200a91
38 changed files with 1102 additions and 59 deletions
|
|
@ -169,6 +169,14 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """"
|
||||
},
|
||||
{
|
||||
""name"": ""EnterWormhole"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""c918ac22-b029-4805-9c85-e615a52641f2"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """"
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
|
|
@ -567,6 +575,17 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
""action"": ""Toggle Heatsinks"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""95817d40-4c8d-4660-bd68-a93afe74b6e1"",
|
||||
""path"": ""<Keyboard>/#(V)"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": ""Keyboard&Mouse"",
|
||||
""action"": ""EnterWormhole"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -1152,6 +1171,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
m_Player_TargetNext = m_Player.FindAction("Target Next", throwIfNotFound: true);
|
||||
m_Player_TargetNearest = m_Player.FindAction("Target Nearest", throwIfNotFound: true);
|
||||
m_Player_ToggleHeatsinks = m_Player.FindAction("Toggle Heatsinks", throwIfNotFound: true);
|
||||
m_Player_EnterWormhole = m_Player.FindAction("EnterWormhole", throwIfNotFound: true);
|
||||
// UI
|
||||
m_UI = asset.FindActionMap("UI", throwIfNotFound: true);
|
||||
m_UI_Navigate = m_UI.FindAction("Navigate", throwIfNotFound: true);
|
||||
|
|
@ -1236,6 +1256,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
private readonly InputAction m_Player_TargetNext;
|
||||
private readonly InputAction m_Player_TargetNearest;
|
||||
private readonly InputAction m_Player_ToggleHeatsinks;
|
||||
private readonly InputAction m_Player_EnterWormhole;
|
||||
public struct PlayerActions
|
||||
{
|
||||
private @AetheriaInput m_Wrapper;
|
||||
|
|
@ -1259,6 +1280,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
public InputAction @TargetNext => m_Wrapper.m_Player_TargetNext;
|
||||
public InputAction @TargetNearest => m_Wrapper.m_Player_TargetNearest;
|
||||
public InputAction @ToggleHeatsinks => m_Wrapper.m_Player_ToggleHeatsinks;
|
||||
public InputAction @EnterWormhole => m_Wrapper.m_Player_EnterWormhole;
|
||||
public InputActionMap Get() { return m_Wrapper.m_Player; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
|
|
@ -1325,6 +1347,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
@ToggleHeatsinks.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleHeatsinks;
|
||||
@ToggleHeatsinks.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleHeatsinks;
|
||||
@ToggleHeatsinks.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleHeatsinks;
|
||||
@EnterWormhole.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnEnterWormhole;
|
||||
@EnterWormhole.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnEnterWormhole;
|
||||
@EnterWormhole.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnEnterWormhole;
|
||||
}
|
||||
m_Wrapper.m_PlayerActionsCallbackInterface = instance;
|
||||
if (instance != null)
|
||||
|
|
@ -1386,6 +1411,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
@ToggleHeatsinks.started += instance.OnToggleHeatsinks;
|
||||
@ToggleHeatsinks.performed += instance.OnToggleHeatsinks;
|
||||
@ToggleHeatsinks.canceled += instance.OnToggleHeatsinks;
|
||||
@EnterWormhole.started += instance.OnEnterWormhole;
|
||||
@EnterWormhole.performed += instance.OnEnterWormhole;
|
||||
@EnterWormhole.canceled += instance.OnEnterWormhole;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1584,6 +1612,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
void OnTargetNext(InputAction.CallbackContext context);
|
||||
void OnTargetNearest(InputAction.CallbackContext context);
|
||||
void OnToggleHeatsinks(InputAction.CallbackContext context);
|
||||
void OnEnterWormhole(InputAction.CallbackContext context);
|
||||
}
|
||||
public interface IUIActions
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ using UnityEngine.InputSystem;
|
|||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using quaternion = Unity.Mathematics.quaternion;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class ActionGameManager : MonoBehaviour
|
||||
|
|
@ -85,6 +86,21 @@ public class ActionGameManager : MonoBehaviour
|
|||
File.WriteAllBytes(Path.Combine(_loadoutPath.FullName, $"{pack.Name}.preset"), MessagePackSerializer.Serialize(pack));
|
||||
}
|
||||
|
||||
public void GenerateLevel()
|
||||
{
|
||||
var zonePack = ZoneGenerator.GenerateZone(
|
||||
settings: Settings.ZoneSettings,
|
||||
// mapLayers: Context.MapLayers,
|
||||
// resources: Context.Resources,
|
||||
mass: Settings.DefaultZoneMass,
|
||||
radius: Settings.DefaultZoneRadius
|
||||
);
|
||||
|
||||
Zone = new Zone(Settings.PlanetSettings, zonePack);
|
||||
Zone.Log = s => Debug.Log($"Zone: {s}");
|
||||
SectorRenderer.LoadZone(Zone);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
AkSoundEngine.RegisterGameObj(gameObject);
|
||||
|
|
@ -95,27 +111,14 @@ public class ActionGameManager : MonoBehaviour
|
|||
ItemData = new DatabaseCache();
|
||||
ItemData.Load(_filePath.FullName);
|
||||
ItemManager = new ItemManager(ItemData, Settings.GameplaySettings, Debug.Log);
|
||||
SectorRenderer.ItemManager = ItemManager;
|
||||
|
||||
Loadouts.AddRange(_loadoutPath.EnumerateFiles("*.preset")
|
||||
.Select(fi => MessagePackSerializer.Deserialize<EntityPack>(File.ReadAllBytes(fi.FullName))));
|
||||
|
||||
var zoneFile = Path.Combine(_filePath.FullName, "Home.zone");
|
||||
//var zoneFile = Path.Combine(_filePath.FullName, "Home.zone");
|
||||
|
||||
// If the game has already been run, there will be a Home file containing a ZonePack; if not, generate one
|
||||
var zonePack = File.Exists(zoneFile) ?
|
||||
MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile)):
|
||||
ZoneGenerator.GenerateZone(
|
||||
settings: Settings.ZoneSettings,
|
||||
// mapLayers: Context.MapLayers,
|
||||
// resources: Context.Resources,
|
||||
mass: Settings.DefaultZoneMass,
|
||||
radius: Settings.DefaultZoneRadius
|
||||
);
|
||||
|
||||
Zone = new Zone(Settings.PlanetSettings, zonePack);
|
||||
Zone.Log = s => Debug.Log($"Zone: {s}");
|
||||
SectorRenderer.ItemManager = ItemManager;
|
||||
SectorRenderer.LoadZone(Zone);
|
||||
GenerateLevel();
|
||||
|
||||
_input = new AetheriaInput();
|
||||
_input.Global.Enable();
|
||||
|
|
@ -189,6 +192,23 @@ public class ActionGameManager : MonoBehaviour
|
|||
else Undock();
|
||||
};
|
||||
|
||||
_input.Player.EnterWormhole.performed += context =>
|
||||
{
|
||||
foreach (var wormhole in SectorRenderer.WormholeInstances.Keys)
|
||||
{
|
||||
if (length(wormhole.Position - CurrentShip.Position.xz) < Settings.GameplaySettings.WormholeExitRadius)
|
||||
{
|
||||
CurrentShip.EnterWormhole(wormhole.Position);
|
||||
CurrentShip.OnEnteredWormhole += () =>
|
||||
{
|
||||
GenerateLevel();
|
||||
CurrentShip.ExitWormhole(SectorRenderer.WormholeInstances.Keys.First().Position,
|
||||
Settings.GameplaySettings.WormholeExitVelocity * ItemManager.Random.NextFloat2Direction());
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_input.Player.ToggleHeatsinks.performed += context =>
|
||||
{
|
||||
CurrentShip.HeatsinksEnabled = !CurrentShip.HeatsinksEnabled;
|
||||
|
|
@ -197,13 +217,15 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
_input.Player.TargetReticle.performed += context =>
|
||||
{
|
||||
var underReticle = Zone.Entities.Where(x => x != CurrentShip).MaxBy(x => dot(normalize(x.Position - CurrentShip.Position), CurrentShip.LookDirection));
|
||||
var underReticle = Zone.Entities.Where(x => x != CurrentShip)
|
||||
.MaxBy(x => dot(normalize(x.Position - CurrentShip.Position), CurrentShip.LookDirection));
|
||||
CurrentShip.Target.Value = CurrentShip.Target.Value == underReticle ? null : underReticle;
|
||||
};
|
||||
|
||||
_input.Player.TargetNearest.performed += context =>
|
||||
{
|
||||
CurrentShip.Target.Value = Zone.Entities.Where(x=>x!=CurrentShip).MaxBy(x => length(x.Position - CurrentShip.Position));
|
||||
CurrentShip.Target.Value = Zone.Entities.Where(x=>x!=CurrentShip)
|
||||
.MaxBy(x => length(x.Position - CurrentShip.Position));
|
||||
};
|
||||
|
||||
_input.Player.TargetNext.performed += context =>
|
||||
|
|
@ -599,7 +621,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
foreach(var agent in _shipAgents)
|
||||
agent.Update(Time.deltaTime);
|
||||
Zone.Update(_time, Time.deltaTime);
|
||||
SectorRenderer.Time = _time;
|
||||
SectorRenderer.GameTime = _time;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using UnityEngine;
|
|||
[CreateAssetMenu(fileName = "Sector Display Properties", menuName = "Aetheria/Sector Display Properties")]
|
||||
public class GameSettings : ScriptableObject
|
||||
{
|
||||
public float WormholeDistanceRatio;
|
||||
public float DefaultZoneRadius;
|
||||
public float DefaultZoneMass;
|
||||
public float DefaultViewDistance;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ using float2 = Unity.Mathematics.float2;
|
|||
|
||||
public class SectorRenderer : MonoBehaviour
|
||||
{
|
||||
public Transform WormholePrefab;
|
||||
public float EntityFadeTime;
|
||||
public Transform EffectManagerParent;
|
||||
public Transform FogCameraParent;
|
||||
|
|
@ -76,6 +77,8 @@ public class SectorRenderer : MonoBehaviour
|
|||
private Entity _perspectiveEntity;
|
||||
private IDisposable[] _perspectiveSubscriptions = new IDisposable[2];
|
||||
|
||||
public Dictionary<Wormhole, GameObject> WormholeInstances = new Dictionary<Wormhole, GameObject>();
|
||||
|
||||
public Zone Zone { get; private set; }
|
||||
public ItemManager ItemManager { get; set; }
|
||||
|
||||
|
|
@ -108,7 +111,7 @@ public class SectorRenderer : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
public float Time { get; set; }
|
||||
public float GameTime { get; set; }
|
||||
|
||||
public float ViewDistance
|
||||
{
|
||||
|
|
@ -176,7 +179,7 @@ public class SectorRenderer : MonoBehaviour
|
|||
Debug.Log("WTF!");
|
||||
}
|
||||
}
|
||||
_tourPlanets.Add((x.Value.Body.transform, parent.Body.transform));
|
||||
//_tourPlanets.Add((x.Value.Body.transform, parent.Body.transform));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,10 +187,26 @@ public class SectorRenderer : MonoBehaviour
|
|||
LoadEntity(entity);
|
||||
zone.Entities.ObserveAdd().Subscribe(e => LoadEntity(e.Value));
|
||||
zone.Entities.ObserveRemove().Subscribe(e => UnloadEntity(e.Value));
|
||||
|
||||
var southernWormhole = new Wormhole {Position = float2(0, -Settings.DefaultZoneRadius * Settings.WormholeDistanceRatio)};
|
||||
AddWormhole(southernWormhole);
|
||||
|
||||
var northernWormhole = new Wormhole {Position = float2(0, Settings.DefaultZoneRadius * Settings.WormholeDistanceRatio)};
|
||||
AddWormhole(northernWormhole);
|
||||
}
|
||||
|
||||
public void AddWormhole(Wormhole wormhole)
|
||||
{
|
||||
var instance = Instantiate(WormholePrefab);
|
||||
instance.position = new Vector3(wormhole.Position.x, 0, wormhole.Position.y);
|
||||
WormholeInstances.Add(wormhole, instance.gameObject);
|
||||
}
|
||||
|
||||
public void ClearZone()
|
||||
{
|
||||
foreach (var wormhole in WormholeInstances.Values) Destroy(wormhole);
|
||||
WormholeInstances.Clear();
|
||||
|
||||
if (Planets.Count > 0)
|
||||
{
|
||||
foreach (var planet in Planets.Values)
|
||||
|
|
@ -195,6 +214,11 @@ public class SectorRenderer : MonoBehaviour
|
|||
DestroyImmediate(planet.gameObject);
|
||||
}
|
||||
Planets.Clear();
|
||||
// foreach (var beltObject in _beltObjects.Values)
|
||||
// {
|
||||
// beltObject.
|
||||
// }
|
||||
_beltObjects.Clear();
|
||||
_beltMeshes.Clear();
|
||||
_beltMatrices.Clear();
|
||||
_tourPlanets.Clear();
|
||||
|
|
@ -386,7 +410,7 @@ public class SectorRenderer : MonoBehaviour
|
|||
planet.Value.Body.transform.localPosition = new Vector3(0, Zone.GetHeight(p) + planetInstance.BodyRadius.Value * 2, 0);
|
||||
if(planet.Value is GasGiantObject gasGiantObject)
|
||||
{
|
||||
gasGiantObject.GravityWaves.material.SetFloat("_Phase", Time * ((GasGiant) Zone.PlanetInstances[planet.Key]).GravityWavesSpeed.Value);
|
||||
gasGiantObject.GravityWaves.material.SetFloat("_Phase", GameTime * ((GasGiant) Zone.PlanetInstances[planet.Key]).GravityWavesSpeed.Value);
|
||||
if(!(planet.Value is SunObject))
|
||||
{
|
||||
var toParent = normalize(Zone.GetOrbitPosition(Zone.Orbits[planetInstance.BodyData.Orbit].Data.Parent) - p);
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(6, typeof(ReflectorData)),
|
||||
Union(7, typeof(ShieldData)),
|
||||
Union(8, typeof(ThrusterData)),
|
||||
// Union(9, typeof(TurningData)),
|
||||
Union(9, typeof(WearData)),
|
||||
Union(10, typeof(VelocityConversionData)),
|
||||
Union(11, typeof(VelocityLimitData)),
|
||||
Union(12, typeof(FactoryData)),
|
||||
|
|
@ -113,7 +113,7 @@ public abstract class PersistentBehaviorData
|
|||
// Union(30, typeof(HaulingControllerData)),
|
||||
Union(31, typeof(CapacitorData)),
|
||||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
Union(33, typeof(HeatStorageData)),
|
||||
Union(34, typeof(TurretControllerData)),
|
||||
Union(35, typeof(InstantWeaponData)),
|
||||
Union(36, typeof(ConstantWeaponData)),
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ using Unity.Mathematics;
|
|||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class HeatsinkData : BehaviorData
|
||||
public class HeatStorageData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Heatsink(context, this, entity, item);
|
||||
return new HeatStorage(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Heatsink : IBehavior
|
||||
public class HeatStorage : IBehavior
|
||||
{
|
||||
private HeatsinkData _data;
|
||||
private HeatStorageData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
|
|
@ -27,7 +27,7 @@ public class Heatsink : IBehavior
|
|||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Heatsink(ItemManager context, HeatsinkData data, Entity entity, EquippedItem item)
|
||||
public HeatStorage(ItemManager context, HeatStorageData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
|
|
@ -73,6 +73,6 @@ public class Thruster : IAnalogBehavior
|
|||
var vis = _input * Context.Evaluate(_data.Visibility, Item);
|
||||
if(!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
||||
Entity.VisibilitySources[this] = vis;
|
||||
return true;
|
||||
return _input > .01f;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Union(0, typeof(InstantWeaponData)),
|
||||
Union(1, typeof(LauncherData)),
|
||||
|
|
@ -123,7 +124,10 @@ public abstract class Weapon : IActivatedBehavior
|
|||
Visibility = Context.Evaluate(_data.Visibility, Item);
|
||||
Spread = Context.Evaluate(_data.Spread, Item);
|
||||
Velocity = Context.Evaluate(_data.Velocity, Item);
|
||||
Wear = Context.Evaluate(_itemData.WearDamage, Item);
|
||||
Wear = (1 - pow(_itemData.Performance(Item.Temperature),
|
||||
(1 - pow(Item.EquippableItem.Quality, Context.GameplaySettings.QualityWearExponent)) *
|
||||
Context.GameplaySettings.ThermalWearExponent)
|
||||
) * _itemData.Durability;
|
||||
}
|
||||
|
||||
public virtual bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using static Unity.Mathematics.math;
|
|||
public class WearData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("perSecond"), Key(1)]
|
||||
public bool PerSecond;
|
||||
public bool PerSecond = true;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
|
|
@ -42,7 +42,10 @@ public class Wear : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var wear = Context.Evaluate(_itemData.WearDamage, Item);
|
||||
var wear = (1 - pow(_itemData.Performance(Item.Temperature),
|
||||
(1 - pow(Item.EquippableItem.Quality, Context.GameplaySettings.QualityWearExponent)) *
|
||||
Context.GameplaySettings.ThermalWearExponent)
|
||||
) * _itemData.Durability / _itemData.ThermalResilience;
|
||||
if (_data.PerSecond) wear *= delta;
|
||||
Item.EquippableItem.Durability -= wear;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -297,8 +297,8 @@ public abstract class EquippableItemData : CraftedItemData
|
|||
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(17)]
|
||||
public float4[] HeatPerformanceCurve;
|
||||
|
||||
[InspectableField, JsonProperty("wearDamage"), Key(18)]
|
||||
public PerformanceStat WearDamage = new PerformanceStat();
|
||||
[InspectableField, JsonProperty("resilience"), Key(18)]
|
||||
public float ThermalResilience = 1;
|
||||
|
||||
[IgnoreMember]
|
||||
public abstract HardpointType HardpointType { get; }
|
||||
|
|
|
|||
|
|
@ -88,6 +88,13 @@ public class ZoneGenerationSettings
|
|||
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
|
||||
public class GameplaySettings
|
||||
{
|
||||
public float WormholeDepth = 1000;
|
||||
public float WormholeExitVelocity = 20;
|
||||
public float WormholeExitRadius = 50;
|
||||
public float WormholeAnimationDuration = 4;
|
||||
public float WormholeExitCurveStart = .8f;
|
||||
public float ThermalWearExponent = .01f;
|
||||
public float QualityWearExponent = 2;
|
||||
public int TriggerGroupCount = 6;
|
||||
public float WarpDistance = 25;
|
||||
public float DockingDistance = 25;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,15 @@ public class Ship : Entity
|
|||
private HashSet<Thruster> _leftThrusters;
|
||||
private HashSet<Thruster> _clockwiseThrusters;
|
||||
private HashSet<Thruster> _counterClockwiseThrusters;
|
||||
|
||||
|
||||
private bool _exitingWormhole = false;
|
||||
private bool _enteringWormhole = false;
|
||||
private float _wormholeAnimationProgress;
|
||||
private float2 _wormholeEntryPosition;
|
||||
private float2 _wormholeEntryDirection;
|
||||
private float2 _wormholePosition;
|
||||
private float2 _wormholeExitVelocity;
|
||||
|
||||
public float ForwardThrust { get; private set; }
|
||||
public float ReverseThrust { get; private set; }
|
||||
public float LeftStrafeThrust { get; private set; }
|
||||
|
|
@ -52,9 +60,30 @@ public class Ship : Entity
|
|||
var clockwise = dot(direction, Direction.Rotate(ItemRotation.Clockwise)) > 0;
|
||||
return angleDiff / ((clockwise ? ClockwiseTorque : CounterClockwiseTorque) / Mass);
|
||||
}
|
||||
|
||||
public event Action OnExitedWormhole;
|
||||
public event Action OnEnteredWormhole;
|
||||
|
||||
public quaternion Rotation { get; private set; }
|
||||
|
||||
public void ExitWormhole(float2 wormholePosition, float2 exitVelocity)
|
||||
{
|
||||
_exitingWormhole = true;
|
||||
_wormholeAnimationProgress = 0;
|
||||
_wormholePosition = wormholePosition;
|
||||
_wormholeExitVelocity = exitVelocity;
|
||||
Direction = normalize(exitVelocity);
|
||||
}
|
||||
|
||||
public void EnterWormhole(float2 wormholePosition)
|
||||
{
|
||||
_wormholeAnimationProgress = 0;
|
||||
_enteringWormhole = true;
|
||||
_wormholeEntryPosition = Position.xz;
|
||||
_wormholeEntryDirection = normalize(_wormholeEntryPosition-wormholePosition);
|
||||
_wormholePosition = wormholePosition;
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
base.Activate();
|
||||
|
|
@ -113,6 +142,8 @@ public class Ship : Entity
|
|||
ItemOnline.Subscribe(CheckForThruster);
|
||||
}
|
||||
|
||||
#region ThrustCalculation
|
||||
|
||||
private void RecalculateForwardThrust()
|
||||
{
|
||||
ForwardThrust = 0;
|
||||
|
|
@ -187,10 +218,11 @@ public class Ship : Entity
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
Position.xz += Velocity * delta;
|
||||
if (_active)
|
||||
if (_active && !_exitingWormhole)
|
||||
{
|
||||
foreach (var thruster in _allThrusters) thruster.Axis = 0;
|
||||
var rightThrusterTorqueCompensation = abs(RightStrafeTotalTorque) / RightStrafeTorqueThrusters.Length;
|
||||
|
|
@ -226,6 +258,9 @@ public class Ship : Entity
|
|||
foreach (var thruster in _clockwiseThrusters) thruster.Axis += deltaRot;
|
||||
foreach (var thruster in _counterClockwiseThrusters) thruster.Axis += -deltaRot;
|
||||
}
|
||||
|
||||
Position.xz += Velocity * delta;
|
||||
|
||||
var normal = Zone.GetNormal(Position.xz);
|
||||
var force = new float2(normal.x, normal.z);
|
||||
var forceMagnitude = lengthsq(force);
|
||||
|
|
@ -239,6 +274,69 @@ public class Ship : Entity
|
|||
Rotation = quaternion.LookRotation(forward, normal);
|
||||
|
||||
base.Update(delta);
|
||||
|
||||
if (_exitingWormhole)
|
||||
{
|
||||
_wormholeAnimationProgress += delta / ItemManager.GameplaySettings.WormholeAnimationDuration;
|
||||
if(_wormholeAnimationProgress < 1)
|
||||
{
|
||||
if (_wormholeAnimationProgress < ItemManager.GameplaySettings.WormholeExitCurveStart)
|
||||
{
|
||||
Position.xz = _wormholePosition;
|
||||
Rotation = quaternion.LookRotation(float3(0, 1, 0), float3(-Direction.x, 0, -Direction.y));
|
||||
}
|
||||
else
|
||||
{
|
||||
var exitLerp = _wormholeAnimationProgress - ItemManager.GameplaySettings.WormholeExitCurveStart /
|
||||
(1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
|
||||
exitLerp *= exitLerp; // Square the interpolation variable to produce curve with zero slope at start
|
||||
Position.xz = _wormholePosition + normalize(_wormholeExitVelocity) * exitLerp * ItemManager.GameplaySettings.WormholeExitRadius;
|
||||
Rotation = quaternion.LookRotation(
|
||||
lerp(float3(0, 1, 0), forward, exitLerp),
|
||||
lerp(float3(-Direction.x, 0, -Direction.y), normal, exitLerp));
|
||||
}
|
||||
|
||||
Position.y = Position.y - lerp(ItemManager.GameplaySettings.WormholeDepth, 0, _wormholeAnimationProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
_exitingWormhole = false;
|
||||
OnExitedWormhole?.Invoke();
|
||||
OnExitedWormhole = null;
|
||||
Velocity = _wormholeExitVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
if (_enteringWormhole)
|
||||
{
|
||||
_wormholeAnimationProgress += delta / ItemManager.GameplaySettings.WormholeAnimationDuration;
|
||||
if(_wormholeAnimationProgress < 1)
|
||||
{
|
||||
if (_wormholeAnimationProgress < 1 - ItemManager.GameplaySettings.WormholeExitCurveStart)
|
||||
{
|
||||
var enterLerp = _wormholeAnimationProgress / (1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
|
||||
enterLerp *= enterLerp; // Square the interpolation variable to produce curve with zero slope at vertical
|
||||
Position.xz = lerp(_wormholeEntryPosition, _wormholePosition, enterLerp);
|
||||
Rotation = quaternion.LookRotation(
|
||||
lerp(forward, float3(0, -1, 0), enterLerp),
|
||||
lerp(normal, float3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y), enterLerp));
|
||||
}
|
||||
else
|
||||
{
|
||||
Position.xz = _wormholePosition;
|
||||
Rotation = quaternion.LookRotation(float3(0, -1, 0),
|
||||
float3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y));
|
||||
}
|
||||
|
||||
Position.y = Position.y - lerp(0, ItemManager.GameplaySettings.WormholeDepth, _wormholeAnimationProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
_enteringWormhole = false;
|
||||
OnEnteredWormhole?.Invoke();
|
||||
OnEnteredWormhole = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
6
Assets/Scripts/ServerShared/Wormhole.cs
Normal file
6
Assets/Scripts/ServerShared/Wormhole.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
using Unity.Mathematics;
|
||||
|
||||
public class Wormhole
|
||||
{
|
||||
public float2 Position;
|
||||
}
|
||||
3
Assets/Scripts/ServerShared/Wormhole.cs.meta
Normal file
3
Assets/Scripts/ServerShared/Wormhole.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5a943b5358a47a199ad5e7271c14032
|
||||
timeCreated: 1614907192
|
||||
|
|
@ -6,6 +6,7 @@ using TMPro;
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.Serialization;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class SchematicDisplay : MonoBehaviour
|
||||
|
|
@ -22,7 +23,7 @@ public class SchematicDisplay : MonoBehaviour
|
|||
public TextMeshProUGUI EnergyLabel;
|
||||
public TextMeshProUGUI CockpitTemperatureLabel;
|
||||
public TextMeshProUGUI RadiatorTemperatureLabel;
|
||||
public TextMeshProUGUI HeatsinkTemperatureLabel;
|
||||
[FormerlySerializedAs("HeatsinkTemperatureLabel")] public TextMeshProUGUI HeatStorageTemperatureLabel;
|
||||
public TextMeshProUGUI CargoTemperatureLabel;
|
||||
public TextMeshProUGUI VisibilityLabel;
|
||||
public TextMeshProUGUI HullDurabilityLabel;
|
||||
|
|
@ -45,7 +46,7 @@ public class SchematicDisplay : MonoBehaviour
|
|||
private Cockpit _cockpit;
|
||||
private Reactor _reactor;
|
||||
private Capacitor[] _capacitors;
|
||||
private Heatsink[] _heatsinks;
|
||||
private HeatStorage[] _heatStorages;
|
||||
private EquippedCargoBay[] _cargoBays;
|
||||
private SchematicDisplayItem[] _schematicItems;
|
||||
private Graphic[] _groupGraphics;
|
||||
|
|
@ -115,9 +116,9 @@ public class SchematicDisplay : MonoBehaviour
|
|||
if (_radiators.Length == 0)
|
||||
RadiatorTemperatureLabel.text = "N/A";
|
||||
|
||||
_heatsinks = entity.GetBehaviors<Heatsink>().ToArray();
|
||||
if (_heatsinks.Length == 0)
|
||||
HeatsinkTemperatureLabel.text = "N/A";
|
||||
_heatStorages = entity.GetBehaviors<HeatStorage>().ToArray();
|
||||
if (_heatStorages.Length == 0)
|
||||
HeatStorageTemperatureLabel.text = "N/A";
|
||||
|
||||
_cargoBays = entity.CargoBays.ToArray();
|
||||
if (_cargoBays.Length == 0)
|
||||
|
|
@ -222,12 +223,12 @@ public class SchematicDisplay : MonoBehaviour
|
|||
$"{((int)(_radiators.Max(r => r.Temperature) - 273.15f)).ToString()}°C";
|
||||
HeatsinkBackground.color = _entity.HeatsinksEnabled ? HeaderElementEnabledColor : HeaderElementDisabledColor;
|
||||
|
||||
if (_heatsinks.Length == 1)
|
||||
HeatsinkTemperatureLabel.text = $"{((int)(_heatsinks[0].Item.Temperature - 273.15f)).ToString()}°C";
|
||||
else if (_heatsinks.Length > 1)
|
||||
HeatsinkTemperatureLabel.text =
|
||||
$"{((int)(_heatsinks.Min(r => r.Item.Temperature) - 273.15f)).ToString()}-" +
|
||||
$"{((int)(_heatsinks.Max(r => r.Item.Temperature) - 273.15f)).ToString()}°C";
|
||||
if (_heatStorages.Length == 1)
|
||||
HeatStorageTemperatureLabel.text = $"{((int)(_heatStorages[0].Item.Temperature - 273.15f)).ToString()}°C";
|
||||
else if (_heatStorages.Length > 1)
|
||||
HeatStorageTemperatureLabel.text =
|
||||
$"{((int)(_heatStorages.Min(r => r.Item.Temperature) - 273.15f)).ToString()}-" +
|
||||
$"{((int)(_heatStorages.Max(r => r.Item.Temperature) - 273.15f)).ToString()}°C";
|
||||
|
||||
if (_cargoBays.Length == 1)
|
||||
CargoTemperatureLabel.text = $"{((int)(_cargoBays[0].Temperature - 273.15f)).ToString()}°C";
|
||||
|
|
|
|||
Loading…
Reference in a new issue