Combat & Visibility & Collisions
Converted entity materials to new fade shader Implemented visibility system Refactored per-instance entity code to run inside monobehavior on entity instances Created state machine AI for enemy ships with basic patrol and combat routines Removed legacy AI code (controller item behaviors) Added automatic trigger group assignment for matched weapons Created ship collision system Created shield VFX and colliders
This commit is contained in:
parent
8d4bd04891
commit
b53e4aec8c
204 changed files with 8182 additions and 1919 deletions
72
Assets/Scripts/Gameplay/ShipInstance.cs
Normal file
72
Assets/Scripts/Gameplay/ShipInstance.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShipInstance : EntityInstance
|
||||
{
|
||||
public (Thruster effect, ParticleSystem system, float baseEmission)[] Particles;
|
||||
|
||||
public Ship Ship { get; private set; }
|
||||
|
||||
public override void SetEntity(SectorRenderer sectorRenderer, Entity entity)
|
||||
{
|
||||
base.SetEntity(sectorRenderer, entity);
|
||||
var ship = entity as Ship;
|
||||
if (ship == null)
|
||||
{
|
||||
Debug.LogError($"Attempted to assign non-ship entity to {gameObject.name} ship instance prefab!");
|
||||
return;
|
||||
}
|
||||
Ship = ship;
|
||||
Particles = ship.GetBehaviors<Thruster>()
|
||||
.Select<Thruster, (Thruster effect, ParticleSystem system, float baseEmission)>(x =>
|
||||
{
|
||||
var effectData = (ThrusterData) x.Data;
|
||||
var particles = Instantiate(UnityHelpers.LoadAsset<ParticleSystem>(effectData.ParticlesPrefab), transform, false);
|
||||
var particlesShape = particles.shape;
|
||||
particlesShape.meshRenderer = ThrusterHardpoints
|
||||
.FirstOrDefault(t => t.name == x.Entity.Hardpoints[x.Item.Position.x, x.Item.Position.y].Transform)
|
||||
?.Emitter;
|
||||
return (x, particles, particles.emission.rateOverTimeMultiplier);
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var particle in Particles)
|
||||
{
|
||||
particle.system.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ShowUnfadedElements()
|
||||
{
|
||||
base.ShowUnfadedElements();
|
||||
foreach (var particle in Particles)
|
||||
{
|
||||
particle.system.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void HideUnfadedElements()
|
||||
{
|
||||
base.HideUnfadedElements();
|
||||
foreach (var particle in Particles)
|
||||
{
|
||||
particle.system.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
foreach (var (effect, system, baseEmission) in Particles)
|
||||
{
|
||||
var emissionModule = system.emission;
|
||||
var item = effect.Item.EquippableItem;
|
||||
var data = Entity.ItemManager.GetData(item);
|
||||
emissionModule.rateOverTimeMultiplier = baseEmission * effect.Axis * (item.Durability / data.Durability);
|
||||
}
|
||||
|
||||
transform.rotation = Ship.Rotation;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue