Hit Detection
This commit is contained in:
parent
1992428a14
commit
871c978301
225 changed files with 210834 additions and 237 deletions
|
|
@ -20,6 +20,7 @@ using float2 = Unity.Mathematics.float2;
|
|||
|
||||
public class ActionGameManager : MonoBehaviour
|
||||
{
|
||||
public EventLog EventLog;
|
||||
public GameSettings Settings;
|
||||
public SectorRenderer SectorRenderer;
|
||||
// public MapView MapView;
|
||||
|
|
@ -53,6 +54,12 @@ public class ActionGameManager : MonoBehaviour
|
|||
public ItemManager ItemManager { get; private set; }
|
||||
public Zone Zone { get; private set; }
|
||||
|
||||
private readonly (float2 direction, string name)[] _directions = {
|
||||
(float2(0, 1), "Front"),
|
||||
(float2(1, 0), "Right"),
|
||||
(float2(-1, 0), "Left"),
|
||||
(float2(0, -1), "Rear")
|
||||
};
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
|
@ -102,7 +109,14 @@ public class ActionGameManager : MonoBehaviour
|
|||
Cursor.lockState = CursorLockMode.Locked;
|
||||
_input.Player.Enable();
|
||||
Menu.gameObject.SetActive(false);
|
||||
GameplayUI.SetActive(true);
|
||||
if (_currentShip != null && _currentShip.Parent == null)
|
||||
{
|
||||
GameplayUI.SetActive(true);
|
||||
|
||||
SchematicDisplay.ShowShip(_currentShip);
|
||||
ShipPanel.Display(_currentShip);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +134,13 @@ public class ActionGameManager : MonoBehaviour
|
|||
Cursor.lockState = CursorLockMode.Locked;
|
||||
_input.Player.Enable();
|
||||
Menu.gameObject.SetActive(false);
|
||||
GameplayUI.SetActive(true);
|
||||
if (_currentShip != null && _currentShip.Parent == null)
|
||||
{
|
||||
GameplayUI.SetActive(true);
|
||||
|
||||
SchematicDisplay.ShowShip(_currentShip);
|
||||
ShipPanel.Display(_currentShip);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -398,6 +418,24 @@ public class ActionGameManager : MonoBehaviour
|
|||
var ship = new Ship(ItemManager, Zone, shipHull);
|
||||
PlayerShips.Add(ship);
|
||||
_currentShip = ship;
|
||||
ship.ArmorDamage.Subscribe(hit =>
|
||||
{
|
||||
var direction = _directions.MaxBy(d => dot(d.direction, normalize(hit.pos - hullType.Shape.CenterOfMass)));
|
||||
EventLog.LogMessage(
|
||||
$"{direction.name} armor hit for {hit.damage} damage, currently {((int) (ship.Armor[hit.pos.x, hit.pos.y] / hullType.Armor * 100)).ToString()}%",
|
||||
Settings.ArmorHitColor);
|
||||
});
|
||||
ship.HullDamage.Subscribe(hit => EventLog.LogMessage($"Hull Structure hit for {hit} damage"));
|
||||
ship.ItemDamage.Subscribe(hit =>
|
||||
{
|
||||
var data = ItemManager.GetData(hit.item.EquippableItem);
|
||||
EventLog.LogMessage(
|
||||
$"{hit.item.EquippableItem.Name} hit for {hit.damage} damage, currently {((int) (hit.item.EquippableItem.Durability / data.Durability * 100)).ToString()}%",
|
||||
data.HardpointType == HardpointType.Thermal ? Settings.ThermalHitColor : Settings.GearHitColor);
|
||||
});
|
||||
ship.HardpointDamage.Subscribe(hit => EventLog.LogMessage(
|
||||
$"{Enum.GetName(typeof(HardpointType), hit.hardpoint.Type)} hardpoint hit for {hit.damage} damage, currently {((int) (ship.HardpointArmor[hit.hardpoint] / hit.hardpoint.Armor * 100)).ToString()}%",
|
||||
Settings.HardpointHitColor));
|
||||
|
||||
var thrusterData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Thruster && x.Shape.Height == 1);
|
||||
for (int i = 0; i < 8; i++)
|
||||
|
|
|
|||
45
Assets/Scripts/ArticulationPoint.cs
Normal file
45
Assets/Scripts/ArticulationPoint.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class ArticulationPoint : MonoBehaviour
|
||||
{
|
||||
public Transform Target;
|
||||
|
||||
public float YawMin;
|
||||
public float YawMax;
|
||||
|
||||
public float PitchMin;
|
||||
public float PitchMax;
|
||||
|
||||
public float Speed;
|
||||
|
||||
private float _yaw;
|
||||
private float _pitch;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Target)
|
||||
{
|
||||
var targetLocal = transform.parent.InverseTransformPoint(Target.position);
|
||||
|
||||
var yaw = Vector2.SignedAngle(new Vector2(0, 1), new Vector2(targetLocal.x, targetLocal.z));
|
||||
var pitch = Vector2.SignedAngle(new Vector2(1, 0), new Vector2(targetLocal.z, targetLocal.y));
|
||||
|
||||
var targetYaw = clamp(-yaw, YawMin, YawMax);
|
||||
var targetPitch = clamp(-pitch, PitchMin, PitchMax);
|
||||
|
||||
if (abs(targetYaw - _yaw) < Speed * Time.deltaTime)
|
||||
_yaw = targetYaw;
|
||||
else _yaw = _yaw + sign(targetYaw - _yaw) * Speed * Time.deltaTime;
|
||||
|
||||
if (abs(targetPitch - _pitch) < Speed * Time.deltaTime)
|
||||
_pitch = targetPitch;
|
||||
else _pitch = _pitch + sign(targetPitch - _pitch) * Speed * Time.deltaTime;
|
||||
|
||||
transform.localRotation = Quaternion.Euler(_pitch, _yaw, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ArticulationPoint.cs.meta
Normal file
11
Assets/Scripts/ArticulationPoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a2c831a00e255547b4261897f5c0b81
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -175,11 +175,13 @@ public class DatabaseListView : EditorWindow
|
|||
if (GUILayout.Button("Save"))
|
||||
{
|
||||
_databaseCache.Save(_filePath.FullName);
|
||||
Debug.Log("Local DB Cache Saved!");
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Load"))
|
||||
{
|
||||
_databaseCache.Load(_filePath.FullName);
|
||||
Debug.Log("Loaded DB From Local Cache!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
13
Assets/Scripts/EntityPrefab.cs
Normal file
13
Assets/Scripts/EntityPrefab.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityPrefab : MonoBehaviour
|
||||
{
|
||||
public HullCollider[] HullColliders;
|
||||
|
||||
public ThrusterHardpoint[] ThrusterHardpoints;
|
||||
public WeaponHardpoint[] WeaponHardpoints;
|
||||
public ArticulationPoint[] ArticulationPoints;
|
||||
}
|
||||
11
Assets/Scripts/EntityPrefab.cs.meta
Normal file
11
Assets/Scripts/EntityPrefab.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 170aefb3b5cd0e444826f3561d38a962
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Assets/Scripts/FilterTest.cs
Normal file
71
Assets/Scripts/FilterTest.cs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class FilterTest : MonoBehaviour
|
||||
{
|
||||
enum DownSampleMode { Off, Half, Quarter }
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
private Shader _shader;
|
||||
|
||||
[SerializeField]
|
||||
private DownSampleMode _downSampleMode = DownSampleMode.Quarter;
|
||||
|
||||
[SerializeField, Range(0, 8)]
|
||||
private int _iteration = 4;
|
||||
|
||||
private Material _material;
|
||||
|
||||
private int _width;
|
||||
private int _height;
|
||||
|
||||
private RenderTexture _target;
|
||||
|
||||
void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
Graphics.Blit(source,destination);
|
||||
|
||||
if (_material == null)
|
||||
{
|
||||
_material = new Material(_shader);
|
||||
_material.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
|
||||
if (Screen.width != _width || Screen.height != _height)
|
||||
{
|
||||
_width = Screen.width;
|
||||
_height = Screen.height;
|
||||
if (_downSampleMode == DownSampleMode.Half)
|
||||
_target = new RenderTexture(_width / 2, _height / 2, 0);
|
||||
else if (_downSampleMode == DownSampleMode.Quarter)
|
||||
_target = new RenderTexture(_width / 4, _height / 4, 0);
|
||||
}
|
||||
|
||||
RenderTexture rt2;
|
||||
|
||||
if (_downSampleMode == DownSampleMode.Half)
|
||||
{
|
||||
rt2 = RenderTexture.GetTemporary(source.width / 2, source.height / 2);
|
||||
Graphics.Blit(source, _target);
|
||||
}
|
||||
else if (_downSampleMode == DownSampleMode.Quarter)
|
||||
{
|
||||
rt2 = RenderTexture.GetTemporary(source.width / 4, source.height / 4);
|
||||
Graphics.Blit(source, _target, _material, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt2 = RenderTexture.GetTemporary(source.width, source.height);
|
||||
Graphics.Blit(source, _target);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _iteration; i++)
|
||||
{
|
||||
Graphics.Blit(_target, rt2, _material, 1);
|
||||
Graphics.Blit(rt2, _target, _material, 2);
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(rt2);
|
||||
Shader.SetGlobalTexture("_CameraBlur", _target);
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/FilterTest.cs.meta
Normal file
12
Assets/Scripts/FilterTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0fc98635c5cb28848958c245f681acaf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- _shader: {fileID: 4800000, guid: 2d020ca820b3647479e78b8c3d26e3a6, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/FitToCamera.cs
Normal file
13
Assets/Scripts/FitToCamera.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FitToCamera : MonoBehaviour
|
||||
{
|
||||
public Camera Camera;
|
||||
|
||||
void Update()
|
||||
{
|
||||
transform.localScale = Camera.orthographicSize * 2 * Vector3.one;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/FitToCamera.cs.meta
Normal file
11
Assets/Scripts/FitToCamera.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ab5a36d7c56c02b448b17592b3ab8857
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -24,6 +24,11 @@ public class GameSettings : ScriptableObject
|
|||
public PlanetSettings PlanetSettings;
|
||||
public ZoneGenerationSettings ZoneSettings;
|
||||
public GameplaySettings GameplaySettings;
|
||||
public Color HullHitColor;
|
||||
public Color ArmorHitColor;
|
||||
public Color HardpointHitColor;
|
||||
public Color GearHitColor;
|
||||
public Color ThermalHitColor;
|
||||
[HideInInspector] public Sprite[] ItemIcons;
|
||||
}
|
||||
|
||||
|
|
|
|||
121
Assets/Scripts/GuidedProjectile.cs
Normal file
121
Assets/Scripts/GuidedProjectile.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class GuidedProjectile : MonoBehaviour
|
||||
{
|
||||
public ParticleSystem Particles;
|
||||
public float FadeOutTime;
|
||||
public AnimationCurve ThrustCurve;
|
||||
public AnimationCurve GuidanceCurve;
|
||||
public AnimationCurve LiftCurve;
|
||||
public float Frequency;
|
||||
public float Thrust;
|
||||
public float TopSpeed;
|
||||
public Transform Source;
|
||||
public Transform Target;
|
||||
|
||||
private float _phase;
|
||||
private float _prevDist;
|
||||
private bool _active;
|
||||
private bool _alive;
|
||||
|
||||
public Vector3 Velocity { get; set; }
|
||||
public float Damage { get; set; }
|
||||
public float Penetration { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_active = _alive = true;
|
||||
_phase = Random.value * 100;
|
||||
_prevDist = Single.MaxValue;
|
||||
var main = Particles.main;
|
||||
main.startColor = Color.white;
|
||||
Particles.Clear(true);
|
||||
Particles.Play(true);
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (SourceEntity == null) return;
|
||||
|
||||
var diff = Target.position - transform.position;
|
||||
var targetDist = diff.magnitude;
|
||||
|
||||
if (_prevDist < targetDist)
|
||||
{
|
||||
StartCoroutine(FadeOut());
|
||||
}
|
||||
_prevDist = targetDist;
|
||||
|
||||
var t = transform;
|
||||
|
||||
if (_active)
|
||||
{
|
||||
var position = (float3) t.position;
|
||||
var sourceDist = length((float3) Source.position - position);
|
||||
var curveLerp = 1 - targetDist / (sourceDist + targetDist);
|
||||
var dir = diff.normalized;
|
||||
var right = cross(dir, float3(0, 1, 0));
|
||||
var up = cross(dir, right);
|
||||
var dodge = normalize(lerp(
|
||||
normalize(right * snoise(position * Frequency + float3(1) * _phase) +
|
||||
up * snoise(position * Frequency + float3(1) * (100 + _phase))),
|
||||
Vector3.up, LiftCurve.Evaluate(curveLerp)));
|
||||
var desired = Vector3.Slerp(dodge, dir, GuidanceCurve.Evaluate(curveLerp)).normalized * TopSpeed;
|
||||
var thrust = Thrust * ThrustCurve.Evaluate(curveLerp);
|
||||
Velocity += (desired-Velocity) * (thrust * Time.deltaTime);
|
||||
}
|
||||
|
||||
var ray = new Ray(t.position, Velocity);
|
||||
if (Physics.Raycast(ray, out var hit, Velocity.magnitude, LayerMask.NameToLayer("Combat")))
|
||||
{
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, Velocity.normalized);
|
||||
}
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
if(_alive)
|
||||
t.position += Velocity * Time.deltaTime;
|
||||
}
|
||||
|
||||
IEnumerator FadeOut()
|
||||
{
|
||||
_active = false;
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < FadeOutTime)
|
||||
{
|
||||
var lerp = 1 - (Time.time - startTime) / FadeOutTime;
|
||||
var main = Particles.main;
|
||||
main.startColor = Color.white * lerp;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
|
||||
IEnumerator Kill()
|
||||
{
|
||||
_alive = false;
|
||||
Particles.Stop(true, ParticleSystemStopBehavior.StopEmitting);
|
||||
var startTime = Time.time;
|
||||
var lifetime = Particles.main.startLifetime.constant;
|
||||
while (Time.time - startTime < lifetime)
|
||||
yield return null;
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GuidedProjectile.cs.meta
Normal file
11
Assets/Scripts/GuidedProjectile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 56c973b8f3781c848b6530c2e7efce05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Scripts/GuidedProjectileManager.cs
Normal file
31
Assets/Scripts/GuidedProjectileManager.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GuidedProjectileManager : MonoBehaviour
|
||||
{
|
||||
public Prototype ProjectilePrototype;
|
||||
|
||||
public void Launch(LauncherData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
||||
p.Source = source.Transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Target = target.Transform;
|
||||
p.Frequency = data.DodgeFrequency;
|
||||
p.Thrust = source.Entity.ItemManager.Evaluate(data.Thrust, item.EquippableItem, source.Entity);
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.transform.position = barrel.position;
|
||||
p.Velocity = barrel.forward * source.Entity.ItemManager.Evaluate(data.LaunchSpeed, item.EquippableItem, source.Entity);
|
||||
p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity);
|
||||
p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity);
|
||||
p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
p.GuidanceCurve = data.GuidanceCurve.ToCurve();
|
||||
p.LiftCurve = data.LiftCurve.ToCurve();
|
||||
p.ThrustCurve = data.ThrustCurve.ToCurve();
|
||||
p.Thrust = source.Entity.ItemManager.Evaluate(data.Thrust, item.EquippableItem, source.Entity);
|
||||
p.TopSpeed = source.Entity.ItemManager.Evaluate(data.MissileSpeed, item.EquippableItem, source.Entity);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GuidedProjectileManager.cs.meta
Normal file
11
Assets/Scripts/GuidedProjectileManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee3949bbc28566148b9f661741b6e25d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Scripts/HullCollider.cs
Normal file
39
Assets/Scripts/HullCollider.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class HullCollider : MonoBehaviour
|
||||
{
|
||||
public Subject<HullHitEventArgs> Hit = new Subject<HullHitEventArgs>();
|
||||
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
public void SendHit(float damage, float penetration, float spread, DamageType damageType, Entity source, RaycastHit hit, Vector3 direction)
|
||||
{
|
||||
Hit.OnNext(new HullHitEventArgs
|
||||
{
|
||||
Damage = damage,
|
||||
Penetration = penetration,
|
||||
Spread = spread,
|
||||
DamageType = damageType,
|
||||
Source = source,
|
||||
Hit = hit,
|
||||
Direction = direction
|
||||
});
|
||||
}
|
||||
|
||||
public class HullHitEventArgs
|
||||
{
|
||||
public float Damage;
|
||||
public float Penetration;
|
||||
public float Spread;
|
||||
public DamageType DamageType;
|
||||
public Entity Source;
|
||||
public RaycastHit Hit;
|
||||
public float3 Direction;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HullCollider.cs.meta
Normal file
11
Assets/Scripts/HullCollider.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eff043e6f0a5f834ebfbc7f750260ae0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/InventoryCell.cs
Normal file
24
Assets/Scripts/InventoryCell.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InventoryCell : MonoBehaviour
|
||||
{
|
||||
public Image Background;
|
||||
public Image Icon;
|
||||
public TextMeshProUGUI Label;
|
||||
|
||||
public ObservablePointerClickTrigger PointerClickTrigger;
|
||||
public ObservableBeginDragTrigger BeginDragTrigger;
|
||||
public ObservableDragTrigger DragTrigger;
|
||||
public ObservableEndDragTrigger EndDragTrigger;
|
||||
public ObservablePointerEnterTrigger PointerEnterTrigger;
|
||||
public ObservablePointerExitTrigger PointerExitTrigger;
|
||||
}
|
||||
11
Assets/Scripts/InventoryCell.cs.meta
Normal file
11
Assets/Scripts/InventoryCell.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e28c3f1c546ff7544a127c24a6ee3091
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
290
Assets/Scripts/InventoryMenu.cs
Normal file
290
Assets/Scripts/InventoryMenu.cs
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InventoryMenu : MonoBehaviour
|
||||
{
|
||||
public InventoryPanel[] InventoryPanels;
|
||||
public PropertiesPanel PropertiesPanel;
|
||||
public ActionGameManager GameManager;
|
||||
public RectTransform DragParent;
|
||||
public ConfirmationDialog Dialog;
|
||||
|
||||
private int _currentPanel = -1;
|
||||
|
||||
private int2 _selectedPosition;
|
||||
private InventoryPanel _selectedPanel;
|
||||
private ItemInstance _selectedItem;
|
||||
private ItemData _selectedItemData;
|
||||
|
||||
private ItemInstance _dragItem;
|
||||
private Transform[] _dragCells;
|
||||
private Vector2[] _dragOffsets;
|
||||
private int2 _dragCellOffset;
|
||||
private ItemRotation _originalRotation;
|
||||
//private Shape _previousFakeOccupancy;
|
||||
private Shape _originalOccupancy;
|
||||
private EquippedItem _originalEquippedItem;
|
||||
private InventoryPanel _originalPanel;
|
||||
|
||||
private InventoryPanel _dragTargetPanel;
|
||||
private int2 _dragTargetPosition;
|
||||
private int2 _lastDragPosition;
|
||||
private bool _dragTargetValid;
|
||||
|
||||
public InventoryPanel GetPanel => InventoryPanels[_currentPanel = (_currentPanel + 1) % InventoryPanels.Length];
|
||||
|
||||
void Start()
|
||||
{
|
||||
PropertiesPanel.Context = GameManager.ItemManager;
|
||||
foreach (var panel in InventoryPanels)
|
||||
{
|
||||
panel.OnBeginDragAsObservable().Subscribe(data =>
|
||||
{
|
||||
//Debug.Log($"Begin drag on panel {panel.name}");
|
||||
if (data is InventoryCargoEventData cargoEvent)
|
||||
{
|
||||
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
|
||||
if (item != null)
|
||||
{
|
||||
var itemData = GameManager.ItemManager.GetData(item);
|
||||
|
||||
var itemPosition = cargoEvent.CargoBay.Cargo[item];
|
||||
_originalOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, itemPosition, item.Rotation);
|
||||
_originalRotation = item.Rotation;
|
||||
_originalPanel = panel;
|
||||
_dragItem = item;
|
||||
_dragCellOffset = itemPosition - cargoEvent.Position;
|
||||
_dragCells = _originalOccupancy.Coordinates
|
||||
.Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray();
|
||||
foreach(var cell in _dragCells)
|
||||
{
|
||||
foreach (var component in cell.GetComponentsInChildren<ObservableTriggerBase>())
|
||||
component.enabled = false;
|
||||
cell.GetComponentInChildren<Image>().raycastTarget = false;
|
||||
}
|
||||
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
|
||||
panel.IgnoreOccupancy = _originalOccupancy;
|
||||
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
|
||||
}
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
|
||||
if (item != null)
|
||||
{
|
||||
var itemData = GameManager.ItemManager.GetData(item.EquippableItem);
|
||||
var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull);
|
||||
|
||||
_originalRotation = item.EquippableItem.Rotation;
|
||||
_originalEquippedItem = entityEvent.Entity.GearOccupancy[data.Position.x, data.Position.y];
|
||||
_originalOccupancy = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation);
|
||||
_originalPanel = panel;
|
||||
_dragItem = item.EquippableItem;
|
||||
_dragCellOffset = item.Position - entityEvent.Position;
|
||||
_dragCells = _originalOccupancy.Coordinates
|
||||
.Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray();
|
||||
foreach(var cell in _dragCells)
|
||||
{
|
||||
foreach (var component in cell.GetComponentsInChildren<ObservableTriggerBase>())
|
||||
component.enabled = false;
|
||||
cell.GetComponentInChildren<Image>().raycastTarget = false;
|
||||
}
|
||||
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
|
||||
panel.IgnoreOccupancy = _originalOccupancy;
|
||||
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
panel.OnDragAsObservable().Subscribe(data =>
|
||||
{
|
||||
if (_dragItem == null) return;
|
||||
for (var i = 0; i < _dragCells.Length; i++)
|
||||
_dragCells[i].position = new Vector3(
|
||||
data.PointerEventData.position.x + _dragOffsets[i].x,
|
||||
data.PointerEventData.position.y + _dragOffsets[i].y,
|
||||
_dragCells[i].position.z);
|
||||
});
|
||||
|
||||
|
||||
panel.OnEndDragAsObservable().Subscribe(data =>
|
||||
{
|
||||
if (_dragItem == null) return;
|
||||
if (_dragTargetValid)
|
||||
{
|
||||
if (data is InventoryCargoEventData cargoEvent)
|
||||
{
|
||||
cargoEvent.CargoBay.Remove(_dragItem);
|
||||
_dragTargetPanel.DropItem(_dragItem, _dragTargetPosition);
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
if (entityEvent.Entity.Unequip(_originalEquippedItem) != null)
|
||||
{
|
||||
_dragTargetPanel.DropItem(_dragItem, _dragTargetPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to move item!";
|
||||
Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them.");
|
||||
Dialog.Show();
|
||||
}
|
||||
}
|
||||
|
||||
_dragTargetPanel.FakeOccupancy = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dragItem.Rotation = _originalRotation;
|
||||
}
|
||||
panel.IgnoreOccupancy = null;
|
||||
panel.RefreshCells();
|
||||
if(_dragTargetPanel!=panel)
|
||||
_dragTargetPanel.RefreshCells();
|
||||
|
||||
_dragItem = null;
|
||||
foreach (var cell in _dragCells) Destroy(cell.gameObject);
|
||||
});
|
||||
|
||||
Action floatCells = () =>
|
||||
{
|
||||
foreach (var cell in _dragCells) cell.gameObject.SetActive(true);
|
||||
_dragTargetValid = false;
|
||||
};
|
||||
|
||||
panel.OnPointerEnterAsObservable().Subscribe(data =>
|
||||
{
|
||||
if (_dragItem == null) return;
|
||||
|
||||
// Debug.Log($"Pointer entered {data.Position}");
|
||||
// if(panel != _originalPanel)
|
||||
// _originalPanel.RefreshCells();
|
||||
|
||||
_dragTargetPanel = panel;
|
||||
_lastDragPosition = data.Position;
|
||||
_dragTargetPosition = data.Position + _dragCellOffset;
|
||||
if (data is InventoryCargoEventData cargoEvent)
|
||||
{
|
||||
if (cargoEvent.CargoBay.ItemFits(_dragItem, _dragTargetPosition))
|
||||
{
|
||||
foreach (var cell in _dragCells) cell.gameObject.SetActive(false);
|
||||
var itemData = GameManager.ItemManager.GetData(_dragItem);
|
||||
panel.FakeItem = _dragItem;
|
||||
panel.FakeOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation);
|
||||
_dragTargetValid = true;
|
||||
panel.RefreshCells();
|
||||
}
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
var eqItem = _dragItem as EquippableItem;
|
||||
var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull);
|
||||
if (eqItem != null && entityEvent.Entity.ItemFits(eqItem, _dragTargetPosition))
|
||||
{
|
||||
foreach (var cell in _dragCells) cell.gameObject.SetActive(false);
|
||||
var itemData = GameManager.ItemManager.GetData(_dragItem);
|
||||
panel.FakeEquipment = _originalEquippedItem;
|
||||
panel.FakeOccupancy = hullData.Shape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation);
|
||||
_dragTargetValid = true;
|
||||
panel.RefreshCells();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
panel.OnPointerExitAsObservable().Subscribe(data =>
|
||||
{
|
||||
if (_dragItem == null) return;
|
||||
|
||||
if (data.Position.Equals(_lastDragPosition) || !_dragTargetValid)
|
||||
{
|
||||
panel.FakeItem = null;
|
||||
panel.FakeOccupancy = null;
|
||||
panel.RefreshCells();
|
||||
// if (_originalPanel != panel)
|
||||
// {
|
||||
// _originalPanel.FakeItem = null;
|
||||
// _originalPanel.FakeOccupancy = null;
|
||||
// _originalPanel.RefreshCells();
|
||||
// }
|
||||
floatCells();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
panel.OnClickAsObservable().Subscribe(data =>
|
||||
{
|
||||
if (data is InventoryCargoEventData cargoEvent)
|
||||
{
|
||||
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
|
||||
if(item!=null)
|
||||
{
|
||||
if (_selectedPanel != null)
|
||||
{
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
|
||||
}
|
||||
}
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = cargoEvent.Position;
|
||||
PropertiesPanel.Clear();
|
||||
PropertiesPanel.AddItemProperties(item);
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = cargoEvent.CargoBay.Cargo[item];
|
||||
_selectedItem = item;
|
||||
_selectedItemData = GameManager.ItemManager.GetData(item);
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
|
||||
if (item != null)
|
||||
{
|
||||
if (_selectedPanel != null)
|
||||
{
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
|
||||
}
|
||||
}
|
||||
PropertiesPanel.Inspect(entityEvent.Entity, item);
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = item.Position;
|
||||
_selectedItem = item.EquippableItem;
|
||||
_selectedItemData = GameManager.ItemManager.GetData(item.EquippableItem);
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InventoryMenu.cs.meta
Normal file
11
Assets/Scripts/InventoryMenu.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 238f19b944b59394481b32a38d68dc0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Scripts/MapMenuInput.cs
Normal file
47
Assets/Scripts/MapMenuInput.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MapMenuInput : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
|
||||
{
|
||||
public MapRenderer Map;
|
||||
public float ZoomSpeed;
|
||||
|
||||
private Vector2 _startMousePosition;
|
||||
|
||||
private Vector2 _startMapPosition;
|
||||
private RectTransform _mapRect;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_mapRect = Map.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
_startMousePosition = eventData.position;
|
||||
_startMapPosition = Map.Position;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
Map.Position = _startMapPosition - (eventData.position - _startMousePosition) * Map.Scale;
|
||||
}
|
||||
|
||||
public void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
Vector3[] mapCorners = new Vector3[4];
|
||||
_mapRect.GetWorldCorners(mapCorners);
|
||||
var mapCenter = ((float3)(mapCorners[2] + mapCorners[0]) / 2).xy;
|
||||
var oldPointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
|
||||
Map.Scale *= 1 - eventData.scrollDelta.y * ZoomSpeed;
|
||||
var pointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
|
||||
Map.Position += oldPointerPosition - pointerPosition;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MapMenuInput.cs.meta
Normal file
11
Assets/Scripts/MapMenuInput.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d49dbb702a53a4e4196a99b448958958
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
103
Assets/Scripts/MapRenderer.cs
Normal file
103
Assets/Scripts/MapRenderer.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
using int2 = Unity.Mathematics.int2;
|
||||
|
||||
public class MapRenderer : MonoBehaviour
|
||||
{
|
||||
public Canvas Canvas;
|
||||
public Camera MapOverlayCamera;
|
||||
public Camera GravityCamera;
|
||||
public Camera TintCamera;
|
||||
public Image OverlayDisplay;
|
||||
public Image GravityDisplay;
|
||||
public Image TintDisplay;
|
||||
public float Scale;
|
||||
public float2 Position;
|
||||
|
||||
private RectTransform _rect;
|
||||
private RenderTexture _mapTexture;
|
||||
private RenderTexture _gravityTexture;
|
||||
private RenderTexture _tintTexture;
|
||||
private int2 _size;
|
||||
private bool _init;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_rect = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_init = true;
|
||||
MapOverlayCamera.gameObject.SetActive(true);
|
||||
GravityCamera.gameObject.SetActive(true);
|
||||
TintCamera.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_mapTexture != null)
|
||||
{
|
||||
_mapTexture.Release();
|
||||
_mapTexture = null;
|
||||
_gravityTexture.Release();
|
||||
_gravityTexture = null;
|
||||
_tintTexture.Release();
|
||||
_tintTexture = null;
|
||||
}
|
||||
MapOverlayCamera.gameObject.SetActive(false);
|
||||
GravityCamera.gameObject.SetActive(false);
|
||||
TintCamera.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
var size = int2(Screen.width, Screen.height);
|
||||
if (_init || size.x != _size.x || size.y != _size.y)
|
||||
{
|
||||
_init = false;
|
||||
_size = size;
|
||||
if (_mapTexture != null)
|
||||
{
|
||||
_mapTexture.Release();
|
||||
_mapTexture = null;
|
||||
_gravityTexture.Release();
|
||||
_gravityTexture = null;
|
||||
_tintTexture.Release();
|
||||
_tintTexture = null;
|
||||
}
|
||||
var canvasCorners = new Vector3[4];
|
||||
Canvas.GetComponent<RectTransform>().GetWorldCorners(canvasCorners);
|
||||
_mapTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.Default);
|
||||
MapOverlayCamera.targetTexture = _mapTexture;
|
||||
OverlayDisplay.material.SetTexture("_DetailTex", _mapTexture);
|
||||
_gravityTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat);
|
||||
GravityCamera.targetTexture = _gravityTexture;
|
||||
GravityDisplay.material.SetTexture("_DetailTex", _gravityTexture);
|
||||
_tintTexture = new RenderTexture(_size.x / 2, _size.y / 2, 0, RenderTextureFormat.RGB111110Float);
|
||||
TintCamera.targetTexture = _tintTexture;
|
||||
TintDisplay.material.SetTexture("_DetailTex", _tintTexture);
|
||||
}
|
||||
|
||||
var pos = ((Vector2) Position).Flatland(1);
|
||||
|
||||
MapOverlayCamera.transform.position = pos;
|
||||
MapOverlayCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
|
||||
GravityCamera.transform.position = pos;
|
||||
GravityCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
GravityDisplay.material.SetFloat("_Scale", Scale / 2);
|
||||
|
||||
TintCamera.transform.position = pos;
|
||||
TintCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MapRenderer.cs.meta
Normal file
11
Assets/Scripts/MapRenderer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95307b613a054bc4a9bb1f9db0a2e3d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Scripts/MenuPanel.cs
Normal file
61
Assets/Scripts/MenuPanel.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MenuPanel : MonoBehaviour
|
||||
{
|
||||
public RectTransform TabButtons;
|
||||
public Color ActiveTabColor;
|
||||
public Color InactiveTabColor;
|
||||
|
||||
public event Action<MenuTab> TabChanged;
|
||||
|
||||
private Dictionary<MenuTab, MenuTabButton> _tabs = new Dictionary<MenuTab, MenuTabButton>();
|
||||
private MenuTabButton _current;
|
||||
|
||||
public MenuTab CurrentTab { get; private set; }
|
||||
|
||||
public void ShowTab(MenuTab tab)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
if (_current == _tabs[tab]) return;
|
||||
|
||||
if(_current != null)
|
||||
{
|
||||
_current.TabContents.SetActive(false);
|
||||
_current.Text.color = InactiveTabColor;
|
||||
}
|
||||
|
||||
CurrentTab = tab;
|
||||
_current = _tabs[tab];
|
||||
|
||||
_current.TabContents.SetActive(true);
|
||||
_current.Text.color = ActiveTabColor;
|
||||
|
||||
TabChanged?.Invoke(tab);
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
foreach (var tabButton in TabButtons.GetComponentsInChildren<MenuTabButton>())
|
||||
{
|
||||
tabButton.TabContents.SetActive(false);
|
||||
tabButton.Text.color = InactiveTabColor;
|
||||
_tabs.Add(tabButton.Tab, tabButton);
|
||||
tabButton.Button.onClick.AddListener(() => ShowTab(tabButton.Tab));
|
||||
}
|
||||
ShowTab(MenuTab.Inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public enum MenuTab
|
||||
{
|
||||
Map,
|
||||
Inventory
|
||||
}
|
||||
11
Assets/Scripts/MenuPanel.cs.meta
Normal file
11
Assets/Scripts/MenuPanel.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebae71ac39c2d9a42b3cfbaa0d1ae7a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/MenuTabButton.cs
Normal file
18
Assets/Scripts/MenuTabButton.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MenuTabButton : MonoBehaviour
|
||||
{
|
||||
public GameObject TabContents;
|
||||
public Button Button;
|
||||
public MenuTab Tab;
|
||||
public TextMeshProUGUI Text;
|
||||
}
|
||||
11
Assets/Scripts/MenuTabButton.cs.meta
Normal file
11
Assets/Scripts/MenuTabButton.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d90317f6ecd38754fad9aee92f46b126
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/Scripts/NIH/SizedQueue.cs
Normal file
27
Assets/Scripts/NIH/SizedQueue.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Thanks, https://stackoverflow.com/a/49924960
|
||||
public sealed class SizedQueue<T> : Queue<T>
|
||||
{
|
||||
public int FixedCapacity { get; }
|
||||
|
||||
public SizedQueue(int fixedCapacity)
|
||||
{
|
||||
FixedCapacity = fixedCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the total number of item exceed the capacity, the oldest ones automatically dequeues.
|
||||
/// </summary>
|
||||
/// <returns>The dequeued value, if any.</returns>
|
||||
public new T Enqueue(T item)
|
||||
{
|
||||
base.Enqueue(item);
|
||||
if (Count > FixedCapacity)
|
||||
{
|
||||
return Dequeue();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/NIH/SizedQueue.cs.meta
Normal file
11
Assets/Scripts/NIH/SizedQueue.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af71613b1f4e5484fa9be3717186b3fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/Scripts/Projectile.cs
Normal file
84
Assets/Scripts/Projectile.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
public TrailRenderer Trail;
|
||||
public float Gravity;
|
||||
public Prototype HitEffect;
|
||||
|
||||
private bool _alive;
|
||||
|
||||
public Zone Zone { get; set; }
|
||||
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 Velocity { get; set; }
|
||||
public float Damage { get; set; }
|
||||
public float Penetration { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_alive = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (SourceEntity == null) return;
|
||||
|
||||
if(_alive)
|
||||
{
|
||||
var position = transform.position;
|
||||
Velocity += Vector3.up * (Gravity * Time.deltaTime);
|
||||
var ray = new Ray(position, Velocity);
|
||||
if (Physics.Raycast(ray, out var hit, Velocity.magnitude * Time.deltaTime))
|
||||
{
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
if(hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, Velocity.normalized);
|
||||
transform.position = hit.point;
|
||||
StartCoroutine(Kill());
|
||||
if(HitEffect!=null)
|
||||
{
|
||||
var t = HitEffect.Instantiate<Transform>();
|
||||
t.SetParent(hit.collider.transform);
|
||||
t.position = hit.point;
|
||||
}
|
||||
}
|
||||
}
|
||||
else StartCoroutine(Kill());
|
||||
}
|
||||
|
||||
transform.position += Velocity * Time.deltaTime;
|
||||
if((transform.position - StartPosition).magnitude > Range)
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Kill()
|
||||
{
|
||||
_alive = false;
|
||||
var startTime = Time.time;
|
||||
var lifetime = Trail.time;
|
||||
while (Time.time - startTime < lifetime)
|
||||
yield return null;
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Projectile.cs.meta
Normal file
11
Assets/Scripts/Projectile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4528540a139424748a7b6c47bfecc7fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/ProjectileManager.cs
Normal file
25
Assets/Scripts/ProjectileManager.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProjectileManager : MonoBehaviour
|
||||
{
|
||||
public Prototype ProjectilePrototype;
|
||||
|
||||
public void Launch(ProjectileWeaponData data, EquippedItem item, EntityInstance source)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Projectile>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Range = source.Entity.ItemManager.Evaluate(data.Range, item.EquippableItem, source.Entity);
|
||||
p.StartPosition = p.transform.position = barrel.position;
|
||||
p.Velocity = barrel.forward * source.Entity.ItemManager.Evaluate(data.Velocity, item.EquippableItem, source.Entity);
|
||||
p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity);
|
||||
p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity);
|
||||
p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
p.Zone = source.Entity.Zone;
|
||||
p.Trail.Clear();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ProjectileManager.cs.meta
Normal file
11
Assets/Scripts/ProjectileManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 49c173e3c2313ca4d9d04d0d87ec0f06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -84,7 +84,8 @@ public class Prototype : MonoBehaviour {
|
|||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
transform.SetParent(_originalPrototype.transform.parent);
|
||||
_originalPrototype.AddToPool(this);
|
||||
OnReturnToPool = null;
|
||||
}
|
||||
|
|
|
|||
15
Assets/Scripts/Rotate.cs
Normal file
15
Assets/Scripts/Rotate.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Rotate : MonoBehaviour
|
||||
{
|
||||
public Vector3 Axis;
|
||||
|
||||
public float Speed;
|
||||
|
||||
void Update()
|
||||
{
|
||||
transform.localRotation *= Quaternion.AngleAxis(Speed * Time.deltaTime, Axis);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Rotate.cs.meta
Normal file
11
Assets/Scripts/Rotate.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd72410ad11370d478bf52dc4afddc0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
261
Assets/Scripts/SchematicDisplay.cs
Normal file
261
Assets/Scripts/SchematicDisplay.cs
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class SchematicDisplay : MonoBehaviour
|
||||
{
|
||||
public GameSettings Settings;
|
||||
public Prototype ListElementPrototype;
|
||||
public Prototype TriggerGroupPrototype;
|
||||
|
||||
public TextMeshProUGUI EnergyLabel;
|
||||
public TextMeshProUGUI CockpitTemperatureLabel;
|
||||
public TextMeshProUGUI RadiatorTemperatureLabel;
|
||||
public TextMeshProUGUI HeatsinkTemperatureLabel;
|
||||
public TextMeshProUGUI CargoTemperatureLabel;
|
||||
public TextMeshProUGUI VisibilityLabel;
|
||||
public TextMeshProUGUI HullDurabilityLabel;
|
||||
|
||||
public RectTransform EnergyFill;
|
||||
public RectTransform HullDurabilityFill;
|
||||
public RectTransform HeatstrokeMeterFill;
|
||||
public RectTransform HeatstrokeLimitFill;
|
||||
|
||||
public CanvasGroup TriggerGroups;
|
||||
public float TriggerGroupsFadeDuration = .5f;
|
||||
public float TriggerGroupsPersistDuration = 5f;
|
||||
|
||||
public Color TriggerGroupColor;
|
||||
|
||||
private Ship _ship;
|
||||
private EquippableItem _hull;
|
||||
private Radiator[] _radiators;
|
||||
private Cockpit _cockpit;
|
||||
private Reactor _reactor;
|
||||
private Capacitor[] _capacitors;
|
||||
private Heatsink[] _heatsinks;
|
||||
private EquippedCargoBay[] _cargoBays;
|
||||
private SchematicDisplayItem[] _schematicItems;
|
||||
private Graphic[] _groupGraphics;
|
||||
|
||||
private int _selectedGroupIndex;
|
||||
private int _selectedItemIndex;
|
||||
private bool _triggerGroupsVisible;
|
||||
private float _triggerGroupsFadeOutTime;
|
||||
|
||||
public SchematicDisplayItem[] SchematicItems
|
||||
{
|
||||
get { return _schematicItems; }
|
||||
}
|
||||
|
||||
public int SelectedItemIndex
|
||||
{
|
||||
get => _selectedItemIndex;
|
||||
set
|
||||
{
|
||||
_selectedItemIndex = (value + _schematicItems.Length) % _schematicItems.Length;
|
||||
UpdateTriggerGroups();
|
||||
}
|
||||
}
|
||||
|
||||
public int SelectedGroupIndex
|
||||
{
|
||||
get => _selectedGroupIndex;
|
||||
set
|
||||
{
|
||||
_selectedGroupIndex = (value + Settings.GameplaySettings.TriggerGroupCount) % Settings.GameplaySettings.TriggerGroupCount;
|
||||
UpdateTriggerGroups();
|
||||
}
|
||||
}
|
||||
|
||||
public class SchematicDisplayItem
|
||||
{
|
||||
public EquippedItem Item;
|
||||
public SchematicListElement ListElement;
|
||||
public SchematicTriggerGroupElement TriggerGroupElement;
|
||||
public IProgressBehavior Cooldown;
|
||||
public ItemUsage ItemUsage;
|
||||
public WeaponData WeaponData;
|
||||
}
|
||||
|
||||
public void ShowShip(Ship ship)
|
||||
{
|
||||
if (_schematicItems != null)
|
||||
foreach (var item in _schematicItems)
|
||||
{
|
||||
item.ListElement.GetComponent<Prototype>().ReturnToPool();
|
||||
item.TriggerGroupElement?.GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
_ship = ship;
|
||||
_cockpit = ship.GetBehavior<Cockpit>();
|
||||
_reactor = ship.GetBehavior<Reactor>();
|
||||
_capacitors = ship.GetBehaviors<Capacitor>().ToArray();
|
||||
|
||||
_radiators = ship.GetBehaviors<Radiator>().ToArray();
|
||||
if (_radiators.Length == 0)
|
||||
RadiatorTemperatureLabel.text = "N/A";
|
||||
|
||||
_heatsinks = ship.GetBehaviors<Heatsink>().ToArray();
|
||||
if (_heatsinks.Length == 0)
|
||||
HeatsinkTemperatureLabel.text = "N/A";
|
||||
|
||||
_cargoBays = ship.CargoBays.ToArray();
|
||||
if (_cargoBays.Length == 0)
|
||||
CargoTemperatureLabel.text = "N/A";
|
||||
|
||||
_schematicItems = ship.Equipment
|
||||
.Where(x => x.Behaviors.Any(b => b.Data is WeaponData))
|
||||
.Select(x => new SchematicDisplayItem
|
||||
{
|
||||
Item = x,
|
||||
ListElement = ListElementPrototype.Instantiate<SchematicListElement>(),
|
||||
TriggerGroupElement = TriggerGroupPrototype.Instantiate<SchematicTriggerGroupElement>(),
|
||||
Cooldown = (IProgressBehavior) x.Behaviors.FirstOrDefault(b=> b is IProgressBehavior),
|
||||
ItemUsage = (ItemUsage) x.Behaviors.FirstOrDefault(b=> b is ItemUsage),
|
||||
WeaponData = (WeaponData) x.Behaviors.FirstOrDefault(b=>b.Data is WeaponData)?.Data
|
||||
})
|
||||
.ToArray();
|
||||
foreach (var x in _schematicItems)
|
||||
{
|
||||
x.ListElement.Icon.sprite = Settings.ItemIcons[(int) ship.Hardpoints[x.Item.Position.x, x.Item.Position.y].Type];
|
||||
x.ListElement.Label.text = x.Item.EquippableItem.Name;
|
||||
x.ListElement.InfiniteAmmoIcon.gameObject.SetActive(x.ItemUsage == null);
|
||||
x.ListElement.AmmoLabel.gameObject.SetActive(x.ItemUsage != null);
|
||||
foreach (var group in x.TriggerGroupElement.GroupBackgrounds)
|
||||
group.color = TriggerGroupColor;
|
||||
}
|
||||
UpdateTriggerGroups();
|
||||
}
|
||||
|
||||
public void UpdateTriggerGroups()
|
||||
{
|
||||
if (!_triggerGroupsVisible)
|
||||
{
|
||||
StartCoroutine(FadeInTriggerGroups());
|
||||
_triggerGroupsVisible = true;
|
||||
}
|
||||
_triggerGroupsFadeOutTime = Time.time + TriggerGroupsPersistDuration;
|
||||
for (var itemIndex = 0; itemIndex < _schematicItems.Length; itemIndex++)
|
||||
{
|
||||
var item = _schematicItems[itemIndex];
|
||||
for (var groupIndex = 0; groupIndex < item.TriggerGroupElement.GroupBackgrounds.Length; groupIndex++)
|
||||
{
|
||||
var backgroundColor = TriggerGroupColor;
|
||||
if (_selectedGroupIndex == groupIndex)
|
||||
backgroundColor.a *= 2;
|
||||
if (_selectedItemIndex == itemIndex)
|
||||
backgroundColor.a *= 2;
|
||||
item.TriggerGroupElement.GroupBackgrounds[groupIndex].color = backgroundColor;
|
||||
item.TriggerGroupElement.GroupLabel[groupIndex].color =
|
||||
_ship.TriggerGroups[groupIndex].Contains(item.Item) ? Color.white : Color.gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator FadeInTriggerGroups()
|
||||
{
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < TriggerGroupsFadeDuration)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / TriggerGroupsFadeDuration;
|
||||
TriggerGroups.alpha = lerp;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
TriggerGroups.alpha = 1;
|
||||
}
|
||||
|
||||
IEnumerator FadeOutTriggerGroups()
|
||||
{
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < TriggerGroupsFadeDuration)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / TriggerGroupsFadeDuration;
|
||||
TriggerGroups.alpha = 1-lerp;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
TriggerGroups.alpha = 0;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_triggerGroupsVisible && _triggerGroupsFadeOutTime < Time.time)
|
||||
{
|
||||
_triggerGroupsVisible = false;
|
||||
StartCoroutine(FadeOutTriggerGroups());
|
||||
}
|
||||
if (_ship != null)
|
||||
{
|
||||
VisibilityLabel.text = ((int) _ship.Visibility).ToString();
|
||||
|
||||
if(_radiators.Length == 1)
|
||||
RadiatorTemperatureLabel.text = $"{(_radiators[0].Item.Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
else if(_radiators.Length > 1)
|
||||
RadiatorTemperatureLabel.text =
|
||||
$"{(_radiators.Min(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}-" +
|
||||
$"{(_radiators.Max(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
if(_heatsinks.Length == 1)
|
||||
HeatsinkTemperatureLabel.text = $"{(_heatsinks[0].Item.Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
else if(_heatsinks.Length > 1)
|
||||
HeatsinkTemperatureLabel.text =
|
||||
$"{(_heatsinks.Min(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}-" +
|
||||
$"{(_heatsinks.Max(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
if(_cargoBays.Length == 1)
|
||||
CargoTemperatureLabel.text = $"{(_cargoBays[0].Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
else if(_cargoBays.Length > 1)
|
||||
CargoTemperatureLabel.text =
|
||||
$"{(_cargoBays.Min(r => r.Temperature) - 273.15f).SignificantDigits(3)}-" +
|
||||
$"{(_cargoBays.Max(r => r.Temperature) - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
CockpitTemperatureLabel.text = $"{(_cockpit.Item.Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
HeatstrokeMeterFill.anchorMax = new Vector2(_cockpit.Heatstroke, 1);
|
||||
HeatstrokeLimitFill.anchorMax = new Vector2(_cockpit.Item.Temperature / Settings.GameplaySettings.HeatstrokeTemperature, 1);
|
||||
|
||||
_hull = _ship.Hull;
|
||||
var hullData = _ship.ItemManager.GetData(_hull);
|
||||
var dur = _hull.Durability / hullData.Durability;
|
||||
HullDurabilityFill.anchorMax = new Vector2(dur, 1);
|
||||
HullDurabilityLabel.text = $"{(dur*100).SignificantDigits(3)}%";
|
||||
|
||||
if (_capacitors.Length == 0)
|
||||
{
|
||||
EnergyFill.anchorMax = Vector2.up;
|
||||
EnergyLabel.text = _reactor.Surplus.SignificantDigits(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
var charge = _capacitors.Sum(x => x.Charge);
|
||||
var maxCharge = _capacitors.Sum(x => x.Capacity);
|
||||
EnergyFill.anchorMax = new Vector2(charge / maxCharge, 1);
|
||||
EnergyLabel.text = $"{charge.SignificantDigits(3)}/{maxCharge.SignificantDigits(3)} ({_reactor.Surplus.SignificantDigits(3)})";
|
||||
}
|
||||
|
||||
foreach (var x in _schematicItems)
|
||||
{
|
||||
var itemData = _ship.ItemManager.GetData(x.Item.EquippableItem);
|
||||
x.ListElement.HeatFill.anchorMax = new Vector2(unlerp(itemData.MinimumTemperature,itemData.MaximumTemperature, x.Item.Temperature), 0);
|
||||
if(x.Cooldown!=null)
|
||||
x.ListElement.CooldownFill.anchorMax = new Vector2(x.Cooldown.Progress,1);
|
||||
x.ListElement.DurabilityLabel.text = $"{(int)(x.Item.EquippableItem.Durability / itemData.Durability * 100)}%";
|
||||
if (x.ItemUsage != null)
|
||||
{
|
||||
x.ListElement.AmmoLabel.text = _ship.CountItemsInCargo(((ItemUsageData) x.ItemUsage.Data).Item).ToString();
|
||||
}
|
||||
|
||||
if (x.WeaponData != null)
|
||||
{
|
||||
x.ListElement.RangeLabel.text = ((int) _ship.ItemManager.Evaluate(x.WeaponData.Range, x.Item.EquippableItem, _ship)).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/SchematicDisplay.cs.meta
Normal file
11
Assets/Scripts/SchematicDisplay.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 296faceaa1771414f8744840ecaa026c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/SchematicListElement.cs
Normal file
17
Assets/Scripts/SchematicListElement.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SchematicListElement : MonoBehaviour
|
||||
{
|
||||
public Image Icon;
|
||||
public TextMeshProUGUI Label;
|
||||
public TextMeshProUGUI DurabilityLabel;
|
||||
public TextMeshProUGUI RangeLabel;
|
||||
public TextMeshProUGUI AmmoLabel;
|
||||
public Image InfiniteAmmoIcon;
|
||||
public RectTransform CooldownFill;
|
||||
public RectTransform HeatFill;
|
||||
}
|
||||
11
Assets/Scripts/SchematicListElement.cs.meta
Normal file
11
Assets/Scripts/SchematicListElement.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6755ecd82e50a5d4bada4d900b47eeb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Scripts/SchematicTriggerGroupElement.cs
Normal file
10
Assets/Scripts/SchematicTriggerGroupElement.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SchematicTriggerGroupElement : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI[] GroupLabel;
|
||||
public Image[] GroupBackgrounds;
|
||||
}
|
||||
3
Assets/Scripts/SchematicTriggerGroupElement.cs.meta
Normal file
3
Assets/Scripts/SchematicTriggerGroupElement.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f090c2738224f698bdfa545978f4d5a
|
||||
timeCreated: 1609423819
|
||||
|
|
@ -253,7 +253,204 @@ public class SectorRenderer : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
instance.LookAtPoint = new GameObject().transform;
|
||||
void DamageSchematic(float damage, float spread, Shape hitShape)
|
||||
{
|
||||
// Spread indicates proportion of penetrating damage which is divided among neighboring schematic cells
|
||||
var directDamage = damage * (1 - spread);
|
||||
|
||||
// Search all cells occupied by target cells for equipped gear
|
||||
EquippedItem equippedGear = null;
|
||||
foreach (var hullCoord in hitShape.Coordinates)
|
||||
{
|
||||
if (entity.GearOccupancy[hullCoord.x, hullCoord.y] != null)
|
||||
{
|
||||
equippedGear = entity.GearOccupancy[hullCoord.x, hullCoord.y];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Search all cells occupied by target cells for any thermal equipment
|
||||
var equippedThermals = new List<EquippedItem>();
|
||||
foreach (var hullCoord in hitShape.Coordinates)
|
||||
{
|
||||
if (entity.ThermalOccupancy[hullCoord.x, hullCoord.y] != null)
|
||||
{
|
||||
equippedThermals.Add(entity.ThermalOccupancy[hullCoord.x, hullCoord.y]);
|
||||
}
|
||||
}
|
||||
|
||||
float remainder = 0;
|
||||
|
||||
// Direct damage is divided between gear and thermal equipment (if present)
|
||||
if (equippedGear != null && equippedThermals.Count > 0)
|
||||
{
|
||||
remainder = max(directDamage / 2 - equippedGear.EquippableItem.Durability, 0);
|
||||
equippedGear.EquippableItem.Durability = max(equippedGear.EquippableItem.Durability - directDamage / 2, 0);
|
||||
entity.ItemDamage.OnNext((equippedGear, directDamage / 2));
|
||||
foreach (var t in equippedThermals)
|
||||
{
|
||||
remainder += max(directDamage / (2 * equippedThermals.Count) - t.EquippableItem.Durability, 0);
|
||||
t.EquippableItem.Durability = max(equippedGear.EquippableItem.Durability - directDamage / (2 * equippedThermals.Count), 0);
|
||||
entity.ItemDamage.OnNext((t, directDamage / (2 * equippedThermals.Count)));
|
||||
}
|
||||
}
|
||||
else if (equippedGear != null)
|
||||
{
|
||||
remainder = max(directDamage - equippedGear.EquippableItem.Durability, 0);
|
||||
equippedGear.EquippableItem.Durability = max(equippedGear.EquippableItem.Durability - directDamage, 0);
|
||||
entity.ItemDamage.OnNext((equippedGear, directDamage));
|
||||
}
|
||||
else if (equippedThermals.Count > 0)
|
||||
{
|
||||
foreach (var t in equippedThermals)
|
||||
{
|
||||
remainder += max(directDamage / (equippedThermals.Count) - t.EquippableItem.Durability, 0);
|
||||
t.EquippableItem.Durability = max(equippedGear.EquippableItem.Durability - directDamage / equippedThermals.Count, 0);
|
||||
entity.ItemDamage.OnNext((t, directDamage / equippedThermals.Count));
|
||||
}
|
||||
}
|
||||
else remainder = directDamage;
|
||||
|
||||
// Direct damage remaining after all items are destroyed damages the hull
|
||||
var hullDamage = remainder;
|
||||
|
||||
// Spread damage is divided among components surrounding the hardpoint which has been hit
|
||||
var spreadDamage = damage * spread;
|
||||
|
||||
// Find the cells surrounding the target cells
|
||||
var surroundingCells = hitShape.Expand();
|
||||
|
||||
// Exclude cells contained by the original shape or not within the ship interior
|
||||
foreach (var cell in surroundingCells.Coordinates.ToArray())
|
||||
if (hitShape[cell] || !hullData.InteriorCells[cell])
|
||||
surroundingCells[cell] = false;
|
||||
|
||||
// Find all equipment occupying surrounding cells
|
||||
var surroundingEquipment = new List<EquippedItem>();
|
||||
foreach (var hullCoord in surroundingCells.Coordinates)
|
||||
{
|
||||
if (entity.GearOccupancy[hullCoord.x, hullCoord.y] != null)
|
||||
surroundingEquipment.Add(entity.GearOccupancy[hullCoord.x, hullCoord.y]);
|
||||
if (entity.ThermalOccupancy[hullCoord.x, hullCoord.y] != null)
|
||||
surroundingEquipment.Add(entity.ThermalOccupancy[hullCoord.x, hullCoord.y]);
|
||||
}
|
||||
|
||||
// Divide spread damage among all surrounding cells
|
||||
remainder = 0;
|
||||
foreach (var e in surroundingEquipment)
|
||||
{
|
||||
remainder += max(spreadDamage / surroundingCells.Coordinates.Length - e.EquippableItem.Durability, 0);
|
||||
e.EquippableItem.Durability = max(e.EquippableItem.Durability - spreadDamage / surroundingCells.Coordinates.Length, 0);
|
||||
entity.ItemDamage.OnNext((e, spreadDamage / surroundingCells.Coordinates.Length));
|
||||
}
|
||||
|
||||
// Remaining damage plus spread damage for empty cells is dealt to the hull
|
||||
hullDamage += remainder + spreadDamage / surroundingCells.Coordinates.Length *
|
||||
(surroundingCells.Coordinates.Length - surroundingEquipment.Count);
|
||||
|
||||
entity.Hull.Durability -= hullDamage;
|
||||
entity.HullDamage.OnNext(hullDamage);
|
||||
}
|
||||
|
||||
foreach (var collider in instance.Prefab.HullColliders)
|
||||
{
|
||||
collider.Hit.Subscribe(hit =>
|
||||
{
|
||||
var hardpointIndex = (int) hit.Hit.textureCoord.x;
|
||||
|
||||
// U coordinate between 0-1 indicates a hit that didn't land directly on a hardpoint
|
||||
if (hardpointIndex <= 0)
|
||||
{
|
||||
// Penetration indicates proportion of damage which passes through the hull armor
|
||||
var surfaceDamage = hit.Damage * (1 - hit.Penetration);
|
||||
|
||||
// Find the 2D position of the hit relative to the entity's pivot point
|
||||
var hitPos3 = instance.Transform.InverseTransformPoint(hit.Hit.point);
|
||||
var hitDirection = normalize(float2(hitPos3.x, hitPos3.z));
|
||||
|
||||
// Search all schematic border cells for the cell which is closest to the hit position
|
||||
var hitCell = int2(-1);
|
||||
var maxDot = -1f;
|
||||
foreach (var v in hullData.Shape.Coordinates)
|
||||
{
|
||||
if (!hullData.InteriorCells[v])
|
||||
{
|
||||
// Take the dot product of the vector from the center to each border cell,
|
||||
// and the vector from the center to the impact point
|
||||
var cellDot = dot(normalize(v - hullData.Shape.CenterOfMass), hitDirection);
|
||||
if (cellDot > maxDot)
|
||||
{
|
||||
maxDot = cellDot;
|
||||
hitCell = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extra damage remaining after depleting hull armor is added to penetrating damage
|
||||
var remainder = max(surfaceDamage - entity.Armor[hitCell.x,hitCell.y], 0);
|
||||
var penetratingDamage = remainder + hit.Damage * hit.Penetration;
|
||||
|
||||
// Subtract surface damage from hull armor
|
||||
entity.Armor[hitCell.x,hitCell.y] = max(entity.Armor[hitCell.x,hitCell.y] - surfaceDamage, 0);
|
||||
entity.ArmorDamage.OnNext((hitCell, surfaceDamage));
|
||||
|
||||
// Find the local 2D vector corresponding to the direction of the incoming hit
|
||||
var localHitDirection = instance.Prefab.transform.InverseTransformDirection(hit.Direction);
|
||||
var penetrationVector = normalize(float2(localHitDirection.x, localHitDirection.z));
|
||||
|
||||
// March a ray through the ship from the hit position until we reach an item or pass all the way through
|
||||
var penetrationPoint = float2(hitCell);
|
||||
var penetrationCell = hitCell;
|
||||
while (hullData.Shape[penetrationCell] &&
|
||||
entity.GearOccupancy[penetrationCell.x, penetrationCell.y] == null &&
|
||||
entity.ThermalOccupancy[penetrationCell.x, penetrationCell.y] == null)
|
||||
{
|
||||
penetrationPoint += penetrationVector * .5f;
|
||||
penetrationCell = int2(penetrationPoint);
|
||||
}
|
||||
|
||||
// If we have passed all the way through the ship without touching an item, just damage the hull
|
||||
if (!hullData.Shape[penetrationCell])
|
||||
{
|
||||
entity.Hull.Durability -= penetratingDamage;
|
||||
entity.HullDamage.OnNext(penetratingDamage);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a shape containing only the cell which the hit penetrated to
|
||||
var hitShape = new Shape(hullData.Shape.Width, hullData.Shape.Height);
|
||||
hitShape[penetrationCell] = true;
|
||||
|
||||
// Continue with the damage calculation, damaging the item and spreading some damage to the cells around it
|
||||
DamageSchematic(penetratingDamage, hit.Spread, hitShape);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Collider UV coordinates starting with 1 correspond to hardpoint index
|
||||
var hardpoint = hullData.Hardpoints[hardpointIndex - 1];
|
||||
|
||||
// Penetration indicates proportion of damage which passes directly to the item
|
||||
var surfaceDamage = hit.Damage * (1 - hit.Penetration);
|
||||
|
||||
// Extra damage remaining after depleting hardpoint armor is added to penetrating damage
|
||||
var remainder = max(surfaceDamage - entity.HardpointArmor[hardpoint], 0);
|
||||
|
||||
// Subtract surface damage from hardpoint armor
|
||||
entity.HardpointArmor[hardpoint] = max(entity.HardpointArmor[hardpoint] - surfaceDamage, 0);
|
||||
|
||||
var penetratingDamage = remainder + hit.Damage * hit.Penetration;
|
||||
|
||||
// Obtain the hull coordinates of all cells occupied by the hardpoint
|
||||
var hardpointCells = hullData.Shape.Inset(hardpoint.Shape, hardpoint.Position);
|
||||
|
||||
// Continue with the damage calculation, damaging the hardpoint and spreading some damage to the cells around it
|
||||
DamageSchematic(penetratingDamage, hit.Spread, hardpointCells);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
instance.LookAtPoint = new GameObject($"{entity.Name} Look Point").transform;
|
||||
|
||||
foreach (var articulationPoint in instance.Prefab.ArticulationPoints)
|
||||
{
|
||||
|
|
@ -442,6 +639,8 @@ public class SectorRenderer : MonoBehaviour
|
|||
entity.Key.HardpointTransforms[x.Key] = (x.Value[0].position, x.Value[0].forward);
|
||||
}
|
||||
|
||||
if (entity.Key.Target != null && !EntityInstances.ContainsKey(entity.Key.Target))
|
||||
entity.Key.Target = null;
|
||||
entity.Value.LookAtPoint.position = entity.Value.Transform.position + (Vector3) entity.Key.LookDirection * (entity.Key.Target != null
|
||||
? (EntityInstances[entity.Key.Target].Transform.position - entity.Value.Transform.position).magnitude : 100);
|
||||
entity.Value.Transform.position = entity.Key.Position;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@ public class ConstantWeaponData : WeaponData
|
|||
public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private ConstantWeaponData _data;
|
||||
|
||||
public int _burstCount;
|
||||
public float _burstTimer;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
|
|
|
|||
|
|
@ -9,31 +9,31 @@ using Unity.Mathematics;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class LauncherData : InstantWeaponData
|
||||
{
|
||||
[InspectableAnimationCurve, JsonProperty("guidance"), Key(7)]
|
||||
[InspectableAnimationCurve, JsonProperty("guidance"), Key(9)]
|
||||
public float4[] GuidanceCurve;
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(8)]
|
||||
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(10)]
|
||||
public float4[] ThrustCurve;
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(9)]
|
||||
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(11)]
|
||||
public float4[] LiftCurve;
|
||||
|
||||
[InspectableField, JsonProperty("thrust"), Key(10)]
|
||||
[InspectableField, JsonProperty("thrust"), Key(12)]
|
||||
public PerformanceStat Thrust = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("lockAngle"), Key(11)]
|
||||
[InspectableField, JsonProperty("lockAngle"), Key(13)]
|
||||
public float LockAngle;
|
||||
|
||||
[InspectableField, JsonProperty("frequency"), Key(12)]
|
||||
[InspectableField, JsonProperty("frequency"), Key(14)]
|
||||
public float DodgeFrequency;
|
||||
|
||||
[InspectableField, JsonProperty("launchSpeed"), Key(13)]
|
||||
[InspectableField, JsonProperty("launchSpeed"), Key(15)]
|
||||
public PerformanceStat LaunchSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("missileSpeed"), Key(14)]
|
||||
[InspectableField, JsonProperty("missileSpeed"), Key(16)]
|
||||
public PerformanceStat MissileSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("lockOnTime"), Key(15)]
|
||||
[InspectableField, JsonProperty("lockOnTime"), Key(17)]
|
||||
public PerformanceStat LockOnTime = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ using Newtonsoft.Json;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ProjectileWeaponData : InstantWeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("spread"), Key(7)]
|
||||
[InspectableField, JsonProperty("spread"), Key(9)]
|
||||
public PerformanceStat Spread = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("bulletInherit"), Key(8)]
|
||||
[InspectableField, JsonProperty("bulletInherit"), Key(10)]
|
||||
public float Inherit;
|
||||
|
||||
[InspectableField, JsonProperty("bulletVelocity"), Key(9)]
|
||||
[InspectableField, JsonProperty("bulletVelocity"), Key(11)]
|
||||
public PerformanceStat Velocity = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
|
|
|
|||
|
|
@ -17,20 +17,26 @@ public abstract class WeaponData : BehaviorData
|
|||
[InspectableField, JsonProperty("damage"), Key(2)]
|
||||
public PerformanceStat Damage = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("range"), Key(3)]
|
||||
[RangedFloatInspectable(0,1), JsonProperty("penetration"), Key(3)]
|
||||
public PerformanceStat Penetration = new PerformanceStat();
|
||||
|
||||
[RangedFloatInspectable(0,1), JsonProperty("damageSpread"), Key(4)]
|
||||
public PerformanceStat DamageSpread = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("range"), Key(5)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
[InspectablePrefab, JsonProperty("effect"), Key(4)]
|
||||
[InspectablePrefab, JsonProperty("effect"), Key(6)]
|
||||
public string EffectPrefab;
|
||||
}
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class InstantWeaponData : WeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("burstCount"), Key(5)]
|
||||
[InspectableField, JsonProperty("burstCount"), Key(7)]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField, JsonProperty("burstTime"), Key(6)]
|
||||
[InspectableField, JsonProperty("burstTime"), Key(8)]
|
||||
public PerformanceStat BurstTime = new PerformanceStat();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ public abstract class Entity
|
|||
|
||||
public readonly Dictionary<string, float> Messages = new Dictionary<string, float>();
|
||||
public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
|
||||
public readonly Dictionary<HardpointData, (float3 position, float3 direction)> HardpointTransforms = new Dictionary<HardpointData, (float3 position, float3 direction)>();
|
||||
public readonly Dictionary<HardpointData, (float3 position, float3 direction)> HardpointTransforms =
|
||||
new Dictionary<HardpointData, (float3 position, float3 direction)>();
|
||||
public Dictionary<HardpointData, float> HardpointArmor;
|
||||
|
||||
public readonly List<EquippedItem>[] TriggerGroups;
|
||||
|
||||
|
|
@ -58,6 +60,7 @@ public abstract class Entity
|
|||
public EquippedItem[,] GearOccupancy;
|
||||
public EquippedItem[,] ThermalOccupancy;
|
||||
public HardpointData[,] Hardpoints;
|
||||
public float[,] Armor;
|
||||
|
||||
private EquippedItem[] _orderedEquipment;
|
||||
protected bool _active;
|
||||
|
|
@ -67,6 +70,11 @@ public abstract class Entity
|
|||
public float Mass { get; private set; }
|
||||
public float Visibility => VisibilitySources.Values.Sum();
|
||||
|
||||
public Subject<(HardpointData hardpoint, float damage)> HardpointDamage = new Subject<(HardpointData, float)>();
|
||||
public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>();
|
||||
public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>();
|
||||
public Subject<float> HullDamage = new Subject<float>();
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _active;
|
||||
|
|
@ -94,23 +102,27 @@ public abstract class Entity
|
|||
Zone = zone;
|
||||
Hull = hull;
|
||||
Name = hull.Name;
|
||||
MapShip();
|
||||
MapEntity();
|
||||
TriggerGroups = new List<EquippedItem>[itemManager.GameplaySettings.TriggerGroupCount];
|
||||
for(int i=0; i<itemManager.GameplaySettings.TriggerGroupCount; i++)
|
||||
TriggerGroups[i] = new List<EquippedItem>();
|
||||
}
|
||||
|
||||
private void MapShip()
|
||||
private void MapEntity()
|
||||
{
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
HardpointArmor = hullData.Hardpoints.ToDictionary(hp => hp, hp => hp.Armor);
|
||||
Equipment.Add(new EquippedItem(ItemManager, Hull, int2.zero, this));
|
||||
Mass = hullData.Mass;
|
||||
Temperature = new float[hullData.Shape.Width, hullData.Shape.Height];
|
||||
Conductivity = new float4[hullData.Shape.Width, hullData.Shape.Height];
|
||||
ThermalMass = new float[hullData.Shape.Width, hullData.Shape.Height];
|
||||
Armor = new float[hullData.Shape.Width, hullData.Shape.Height];
|
||||
var cellCount = hullData.Shape.Coordinates.Length;
|
||||
foreach (var v in hullData.Shape.Coordinates)
|
||||
{
|
||||
if (!hullData.InteriorCells[v])
|
||||
Armor[v.x, v.y] = hullData.Armor;
|
||||
Temperature[v.x, v.y] = 280;
|
||||
Conductivity[v.x, v.y] = hullData.Conductivity;
|
||||
ThermalMass[v.x, v.y] = hullData.Mass * hullData.SpecificHeat / cellCount;
|
||||
|
|
@ -261,6 +273,11 @@ public abstract class Entity
|
|||
var itemShapeInset = hullData.Shape.Inset(itemData.Shape, hullCoord, item.Rotation);
|
||||
var hardpointShapeInset = hullData.Shape.Inset(hardpoint.Shape, hardpoint.Position);
|
||||
|
||||
// Check every cell of the hardpoint shape
|
||||
foreach(var v in hardpointShapeInset.Coordinates)
|
||||
if (GearOccupancy[v.x, v.y] != null)
|
||||
return false;
|
||||
|
||||
// Check every cell of the item's shape
|
||||
foreach (var i in itemShapeInset.Coordinates)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ public enum ItemRotation
|
|||
Clockwise = 3
|
||||
}
|
||||
|
||||
public enum HitType
|
||||
{
|
||||
Armor,
|
||||
Hardpoint,
|
||||
Gear,
|
||||
Thermal
|
||||
}
|
||||
|
||||
public enum LauncherCaliber
|
||||
{
|
||||
Micro,
|
||||
|
|
|
|||
|
|
@ -333,6 +333,9 @@ public class HullData : EquippableItemData
|
|||
[InspectableField, JsonProperty("gridOffset"), Key(17)]
|
||||
public float GridOffset;
|
||||
|
||||
[InspectableField, JsonProperty("armor"), Key(18)]
|
||||
public float Armor;
|
||||
|
||||
[IgnoreMember]
|
||||
public Shape InteriorCells
|
||||
{
|
||||
|
|
@ -360,6 +363,7 @@ public class HardpointData : ITintInspector
|
|||
[InspectableField, JsonProperty("shape"), Key(2)] public Shape Shape = new Shape();
|
||||
[InspectableField, JsonProperty("transform"), Key(3)] public string Transform;
|
||||
[InspectableField, JsonProperty("rotation"), Key(4)] public ItemRotation Rotation;
|
||||
[InspectableField, JsonProperty("armor"), Key(5)] public float Armor;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
|
|||
8
Assets/Scripts/ThrusterHardpoint.cs
Normal file
8
Assets/Scripts/ThrusterHardpoint.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ThrusterHardpoint : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Emitter;
|
||||
}
|
||||
11
Assets/Scripts/ThrusterHardpoint.cs.meta
Normal file
11
Assets/Scripts/ThrusterHardpoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 50d4c3a9c5db3ce40b91caf2ae88dabe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -19,6 +19,7 @@ using int2 = Unity.Mathematics.int2;
|
|||
|
||||
public class InventoryPanel : MonoBehaviour
|
||||
{
|
||||
public GameSettings Settings;
|
||||
public ActionGameManager GameManager;
|
||||
public ContextMenu ContextMenu;
|
||||
public TextMeshProUGUI Title;
|
||||
|
|
@ -33,6 +34,8 @@ public class InventoryPanel : MonoBehaviour
|
|||
public ExponentialLerp TemperatureAlphaCurve;
|
||||
public float MaxTemperature;
|
||||
public bool FitToContent;
|
||||
public float CellHealthPersistDuration;
|
||||
public float CellHealthFadeTime;
|
||||
|
||||
Subject<InventoryEventData> _onBeginDrag;
|
||||
Subject<InventoryEventData> _onDrag;
|
||||
|
|
@ -53,6 +56,10 @@ public class InventoryPanel : MonoBehaviour
|
|||
public List<GameObject> EmptyCells = new List<GameObject>();
|
||||
public Dictionary<int2, InventoryCell> CellInstances = new Dictionary<int2, InventoryCell>();
|
||||
|
||||
private List<IDisposable> _subscriptions = new List<IDisposable>();
|
||||
private Dictionary<int2, float> _cellHealthFadeoutTime = new Dictionary<int2, float>();
|
||||
private Dictionary<int2, Dictionary<HitType, string>> _cellQueuedLabels = new Dictionary<int2, Dictionary<HitType, string>>();
|
||||
|
||||
private int2[] _offsets = {
|
||||
int2(0, 1),
|
||||
int2(1, 0),
|
||||
|
|
@ -116,9 +123,41 @@ public class InventoryPanel : MonoBehaviour
|
|||
}
|
||||
_temperatureTexture.Apply();
|
||||
TemperatureDisplay.rectTransform.anchoredPosition = _firstRect.anchoredPosition - Vector2.one * Grid.cellSize * 1.5f;
|
||||
|
||||
foreach (var damagedCell in _cellHealthFadeoutTime.Keys.ToArray())
|
||||
{
|
||||
var fadeoutTime = _cellHealthFadeoutTime[damagedCell];
|
||||
if (fadeoutTime < Time.time)
|
||||
{
|
||||
StartCoroutine(FadeOutLabel(CellInstances[damagedCell]));
|
||||
_cellHealthFadeoutTime.Remove(damagedCell);
|
||||
_cellQueuedLabels[damagedCell].Clear();
|
||||
continue;
|
||||
}
|
||||
var queuedLabels = _cellQueuedLabels[damagedCell];
|
||||
var currentLabel = queuedLabels.ElementAt((int) ((fadeoutTime - Time.time) / CellHealthPersistDuration * queuedLabels.Count));
|
||||
if (CellInstances[damagedCell].Label.text != currentLabel.Value)
|
||||
{
|
||||
CellInstances[damagedCell].Label.text = currentLabel.Value;
|
||||
CellInstances[damagedCell].Label.color = currentLabel.Key switch
|
||||
{
|
||||
HitType.Armor => Settings.ArmorHitColor,
|
||||
HitType.Hardpoint => Settings.HardpointHitColor,
|
||||
HitType.Gear => Settings.GearHitColor,
|
||||
HitType.Thermal => Settings.ThermalHitColor,
|
||||
_ => Color.white
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_displayedCargo = null;
|
||||
|
|
@ -128,10 +167,17 @@ public class InventoryPanel : MonoBehaviour
|
|||
Destroy(empty);
|
||||
EmptyCells.Clear();
|
||||
|
||||
_cellQueuedLabels.Clear();
|
||||
|
||||
foreach(var node in CellInstances.Values)
|
||||
node.GetComponent<Prototype>().ReturnToPool();
|
||||
CellInstances.Clear();
|
||||
|
||||
foreach(var s in _subscriptions)
|
||||
s.Dispose();
|
||||
|
||||
_subscriptions.Clear();
|
||||
|
||||
if(Title)
|
||||
Title.text = "None";
|
||||
}
|
||||
|
|
@ -178,6 +224,7 @@ public class InventoryPanel : MonoBehaviour
|
|||
}
|
||||
else
|
||||
{
|
||||
_cellQueuedLabels.Add(v, new Dictionary<HitType, string>(4));
|
||||
var cell = NodePrototype.Instantiate<InventoryCell>();
|
||||
if (!_firstRect)
|
||||
_firstRect = cell.GetComponent<RectTransform>();
|
||||
|
|
@ -197,6 +244,61 @@ public class InventoryPanel : MonoBehaviour
|
|||
}
|
||||
}
|
||||
RefreshCells(CellInstances.Keys);
|
||||
|
||||
_subscriptions.Add(entity.ArmorDamage.Subscribe(hit =>
|
||||
{
|
||||
var labelText = $"{((int) (entity.Armor[hit.pos.x, hit.pos.y] / hullData.Armor * 100)).ToString()}%";
|
||||
// If there is no set fadeout time, that means this is the first hit and the cell label isn't visible yet
|
||||
if (!_cellHealthFadeoutTime.ContainsKey(hit.pos)) StartCoroutine(FadeInLabel(CellInstances[hit.pos]));
|
||||
// Color and label text will be set according to remaining time until fadeout
|
||||
_cellQueuedLabels[hit.pos][HitType.Armor] = labelText;
|
||||
// Set the fadeout time to some time in the future
|
||||
_cellHealthFadeoutTime[hit.pos] = Time.time + CellHealthPersistDuration;
|
||||
//RefreshCells(new []{int2(hit.pos)});
|
||||
}));
|
||||
|
||||
_subscriptions.Add(entity.ItemDamage.Subscribe(hit =>
|
||||
{
|
||||
var data = entity.ItemManager.GetData(hit.item.EquippableItem);
|
||||
var labelText = $"{((int) (hit.item.EquippableItem.Durability / data.Durability * 100)).ToString()}%";
|
||||
if (!_cellHealthFadeoutTime.ContainsKey(hit.item.Position)) StartCoroutine(FadeInLabel(CellInstances[hit.item.Position]));
|
||||
_cellQueuedLabels[hit.item.Position][data.HardpointType == HardpointType.Thermal ? HitType.Thermal : HitType.Gear] = labelText;
|
||||
_cellHealthFadeoutTime[hit.item.Position] = Time.time + CellHealthPersistDuration;
|
||||
}));
|
||||
|
||||
_subscriptions.Add(entity.HardpointDamage.Subscribe(hit =>
|
||||
{
|
||||
var labelText = $"{((int) (entity.HardpointArmor[hit.hardpoint] / hit.hardpoint.Armor * 100)).ToString()}%";
|
||||
if (!_cellHealthFadeoutTime.ContainsKey(hit.hardpoint.Position)) StartCoroutine(FadeInLabel(CellInstances[hit.hardpoint.Position]));
|
||||
_cellQueuedLabels[hit.hardpoint.Position][HitType.Hardpoint] = labelText;
|
||||
_cellHealthFadeoutTime[hit.hardpoint.Position] = Time.time + CellHealthPersistDuration;
|
||||
}));
|
||||
}
|
||||
|
||||
private IEnumerator FadeInLabel(InventoryCell cell)
|
||||
{
|
||||
cell.Label.gameObject.SetActive(true);
|
||||
float startTime = Time.time;
|
||||
while (Time.time - startTime < CellHealthFadeTime)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / CellHealthFadeTime;
|
||||
cell.Label.alpha = lerp;
|
||||
yield return null;
|
||||
}
|
||||
cell.Label.alpha = 1;
|
||||
}
|
||||
|
||||
private IEnumerator FadeOutLabel(InventoryCell cell)
|
||||
{
|
||||
float startTime = Time.time;
|
||||
while (Time.time - startTime < CellHealthFadeTime)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / CellHealthFadeTime;
|
||||
cell.Label.alpha = 1 - lerp;
|
||||
yield return null;
|
||||
}
|
||||
cell.Label.alpha = 0;
|
||||
cell.Label.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Display(EquippedCargoBay cargo)
|
||||
|
|
|
|||
11
Assets/Scripts/UnityHelpers.cs
Normal file
11
Assets/Scripts/UnityHelpers.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UnityHelpers
|
||||
{
|
||||
public static T LoadAsset<T>(string path) where T : Object
|
||||
{
|
||||
return Resources.Load<T>(path.Substring("Assets/Resources/".Length).Split('.')[0]);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UnityHelpers.cs.meta
Normal file
11
Assets/Scripts/UnityHelpers.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7b4543cc6e0fec6498202ce0387b911d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/WeaponHardpoint.cs
Normal file
8
Assets/Scripts/WeaponHardpoint.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponHardpoint : MonoBehaviour
|
||||
{
|
||||
public Transform[] FiringPoint;
|
||||
}
|
||||
11
Assets/Scripts/WeaponHardpoint.cs.meta
Normal file
11
Assets/Scripts/WeaponHardpoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b6f57d9fe9e78c438112332511e7b07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue