Merge origin/master into mining: resolve five conflicts by owner, delete the belt-task machine
Mining owns belts, chunks and target picking; scenarios owns admission and run staging; master owns ships and fire control (rule scenarios-cut.md S4). - AetheriaStores.CatalogTypes: nine-type union, master's list plus FieldKindData, no Scenario. - tools/AetherDb/Program.cs: both cases (ship-authoring, field-kinds), one usage string. - Zone.cs: master's MineAsteroid dropped (mining deleted its inputs); scenarios' SettleBelts and its three calls deleted. - RunStartTests: the two belt-task tests deleted (they read belt.Transforms and MineAsteroid). - FireControlCut124Tests: master's strict Exact assertions; mining's CompatibleDrift allowance and its comment dropped. - GameData/Aetheria.cc: master's pointer 70a7b0a9. This commit lacks the Asteroid field kind in the catalog, so TheShippedCatalogHasAPickableFieldKind fails here by design; the next commit rebuilds it. Builds: this commit builds (verified at the end with commit 2); the catalog pin test fails at this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
d9f85dc639
154 changed files with 8764 additions and 4522 deletions
|
|
@ -42,7 +42,13 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
private static CultCache _cultCache;
|
||||
|
||||
// Mod packages left out of this boot (a bad package, or a name collision), for the main menu to name.
|
||||
public static ShipModCatalog.Exclusion[] ModExclusions { get; private set; } = Array.Empty<ShipModCatalog.Exclusion>();
|
||||
|
||||
private static string CatalogPath => Path.Combine(GameDataDirectory.FullName, "Aetheria.cc");
|
||||
private static string ModsPath => Path.Combine(GameDataDirectory.FullName, "Mods");
|
||||
// Disposable: composed at every boot from the shipped catalog and the mod packages, never authored.
|
||||
private static string DerivedCatalogPath => Path.Combine(Application.persistentDataPath, "Aetheria.modded.cc");
|
||||
|
||||
public static CultCache CultCache
|
||||
{
|
||||
|
|
@ -52,12 +58,18 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
// All three stores attach once and stay attached until the process exits. The run lifecycle is record-level
|
||||
// inside this cache; reopening would replace the catalog instances the galaxy and live entities hold.
|
||||
// The catalog is read-only in every build; capturepreset writes through its own cache (Loadouts.Commit).
|
||||
// The catalog is read-only in every build; capturepreset writes through its own cache (Loadouts.Commit) to the
|
||||
// shipped file. With mod packages installed the game reads the derived catalog instead.
|
||||
var (catalog, excluded) = ShipModCatalog.ResolveCatalog(CatalogPath, DerivedCatalogPath, ModsPath);
|
||||
ModExclusions = excluded;
|
||||
_cultCache = AetheriaStores.Open(
|
||||
CatalogPath,
|
||||
catalog,
|
||||
runPath: Path.Combine(GameDataDirectory.FullName, "run.cc"),
|
||||
playerPath: Path.Combine(GameDataDirectory.FullName, "player.cc"));
|
||||
|
||||
// Mod ship prototypes import asynchronously from here; entering a game waits on ShipModShips.Loading.
|
||||
ShipModShips.Preload(_cultCache, ModsPath);
|
||||
|
||||
return _cultCache;
|
||||
}
|
||||
}
|
||||
|
|
@ -94,7 +106,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
|
||||
public static Galaxy CurrentGalaxy;
|
||||
public static bool IsTutorial;
|
||||
// The scenario a new run starts from: MainMenu.Launch sets it, and StartGame's new-run branch consumes it once.
|
||||
public static Scenario PendingScenario;
|
||||
|
||||
public GameSettings Settings;
|
||||
//public string StarterShipTemplate = "Longinus";
|
||||
|
|
@ -238,7 +251,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
if (CurrentGalaxy != null)
|
||||
{
|
||||
var (game, zones) = RunSave.Capture(CultCache, CurrentGalaxy, Zone, DockedEntity ?? CurrentEntity, IsTutorial,
|
||||
var (game, zones) = RunSave.Capture(CultCache, CurrentGalaxy, Zone, DockedEntity ?? CurrentEntity,
|
||||
_actionBarSlots.Select(s => s.Save()).ToArray());
|
||||
RunSave.Commit(CultCache, game, zones, ItemManager.Lots);
|
||||
}
|
||||
|
|
@ -257,7 +270,9 @@ public class ActionGameManager : MonoBehaviour
|
|||
EntityInstance.EffectManagerParent = EffectManagerParent;
|
||||
ConsoleController.MessageReceiver = this;
|
||||
|
||||
ItemManager = new ItemManager(CultCache, RunSave.Lots(CultCache), Settings.GameplaySettings, Debug.Log);
|
||||
// A new run mints into an empty ledger; the saved run's stays in the store until the new run has started.
|
||||
ItemManager = new ItemManager(CultCache, PendingScenario != null ? new ProvenanceLedger() : RunSave.Lots(CultCache),
|
||||
Settings.GameplaySettings, Debug.Log);
|
||||
ZoneRenderer.ItemManager = ItemManager;
|
||||
|
||||
// If hiding minimap asteroids, turn them off to start with
|
||||
|
|
@ -539,26 +554,12 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
var nearestFaction = CurrentGalaxy.Factions.MinBy(f => CurrentGalaxy.HomeZones[f].Distance[Zone.GalaxyZone]);
|
||||
|
||||
var loadoutGenerator = IsTutorial ? new LoadoutGenerator(
|
||||
ref ItemManager.Random,
|
||||
ItemManager,
|
||||
CurrentGalaxy,
|
||||
Zone.GalaxyZone,
|
||||
nearestFaction,
|
||||
.5f) : new LoadoutGenerator(
|
||||
ref ItemManager.Random,
|
||||
ItemManager,
|
||||
CurrentGalaxy,
|
||||
Zone.GalaxyZone,
|
||||
nearestFaction,
|
||||
.5f);
|
||||
var loadoutGenerator = new LoadoutGenerator(ref ItemManager.Random, ItemManager, CurrentGalaxy, Zone.GalaxyZone, nearestFaction, .5f);
|
||||
|
||||
var turret = EntitySerializer.Unpack(ItemManager, Zone, loadoutGenerator.GenerateTurretLoadout());
|
||||
turret.Position.xz = _currentEntity.Position.xz +
|
||||
ItemManager.Random.NextFloat2Direction() * ItemManager.Random.NextFloat(50, 500);
|
||||
turret.Zone = Zone;
|
||||
Zone.Entities.Add(turret);
|
||||
turret.Activate();
|
||||
Zone.Admit(turret, piloted: false);
|
||||
});
|
||||
//Temporary, or not
|
||||
ConsoleController.AddCommand("tow", _ => TowShip());
|
||||
|
|
@ -691,7 +692,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
Settings.ZoneSettings,
|
||||
CurrentGalaxy,
|
||||
galaxyZone,
|
||||
IsTutorial
|
||||
CurrentGalaxy.IsPrelude
|
||||
);
|
||||
galaxyZone.Contents = new Zone(ItemManager, Settings.PlanetSettings, galaxyZone.PackedContents, galaxyZone, CurrentGalaxy);
|
||||
}
|
||||
|
|
@ -705,8 +706,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
CurrentEntity.Deactivate();
|
||||
CurrentEntity.Zone.Entities.Remove(CurrentEntity);
|
||||
CurrentEntity.Zone = Zone;
|
||||
Zone.Entities.Add(CurrentEntity);
|
||||
CurrentEntity.Activate();
|
||||
Zone.Admit(CurrentEntity, piloted: false);
|
||||
}
|
||||
|
||||
ZoneRenderer.LoadZone(Zone);
|
||||
|
|
@ -770,25 +770,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
if (CurrentGalaxy != null)
|
||||
{
|
||||
var saved = CultCache.GetGlobal<SavedGame>();
|
||||
if (saved == null)
|
||||
{
|
||||
SectorMap.QueueZoneReveal(CurrentGalaxy.Entrance.AdjacentZones.Prepend(CurrentGalaxy.Entrance));
|
||||
PopulateLevel(CurrentGalaxy.Entrance);
|
||||
var loadoutGenerator = new LoadoutGenerator(ref ItemManager.Random, ItemManager, CurrentGalaxy, Zone.GalaxyZone, IsTutorial ? CurrentGalaxy.ResolveFaction(Settings.TutorialGenerationSettings.ProtagonistFaction) : null, 2);
|
||||
var ship = EntitySerializer.Unpack(
|
||||
ItemManager,
|
||||
Zone,
|
||||
loadoutGenerator.GenerateShipLoadout(data => string.IsNullOrEmpty(Settings.StartingHullName) || data.Name==Settings.StartingHullName ));
|
||||
((Ship) ship).IsPlayerShip = true;
|
||||
ship.Position = float3.zero;
|
||||
ship.Zone = Zone;
|
||||
Zone.Entities.Add(ship);
|
||||
ship.Activate();
|
||||
BindToEntity(ship);
|
||||
}
|
||||
if (PendingScenario != null) StartScenario();
|
||||
else
|
||||
{
|
||||
var saved = CultCache.GetGlobal<SavedGame>();
|
||||
foreach(var group in CurrentGalaxy.DiscoveredZones
|
||||
.GroupBy(dz=>dz.Distance[CurrentGalaxy.Entrance]))
|
||||
SectorMap.QueueZoneReveal(group);
|
||||
|
|
@ -813,6 +798,41 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
// RunStart owns what a new run starts with (docs/scenarios-cut.md, R.4); this enters and binds. The saved run is
|
||||
// replaced only once the scenario has staged. A start that fails leaves the saved run as it was and says why on
|
||||
// the main menu, where Continue still resumes the saved run.
|
||||
private void StartScenario()
|
||||
{
|
||||
var scenario = PendingScenario;
|
||||
PendingScenario = null;
|
||||
var failures = new List<string>();
|
||||
RunStart.Staged staged = null;
|
||||
try
|
||||
{
|
||||
staged = RunSave.Replace(CultCache, () =>
|
||||
{
|
||||
RunStart.GenerateArena(ItemManager, Settings.ZoneSettings, CurrentGalaxy, scenario);
|
||||
PopulateLevel(CurrentGalaxy.Entrance);
|
||||
return RunStart.Stage(ItemManager, Zone, scenario, Settings.StartingHullName, Settings.TutorialGenerationSettings, failures);
|
||||
});
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogException(exception);
|
||||
failures.Add(exception.Message);
|
||||
}
|
||||
|
||||
if (staged == null)
|
||||
{
|
||||
CurrentGalaxy = null;
|
||||
MainMenu.gameObject.SetActive(true);
|
||||
MainMenu.Refuse($"{scenario.Name} could not start", string.Join("\n", failures));
|
||||
return;
|
||||
}
|
||||
SectorMap.QueueZoneReveal(CurrentGalaxy.Entrance.AdjacentZones.Prepend(CurrentGalaxy.Entrance));
|
||||
BindToEntity(staged.Player);
|
||||
}
|
||||
|
||||
private IEnumerator IntroCutscene(Ship ship)
|
||||
{
|
||||
ZoneRenderer.PerspectiveEntity = ship;
|
||||
|
|
@ -1021,12 +1041,12 @@ public class ActionGameManager : MonoBehaviour
|
|||
_articulationGroups = CurrentEntity.Equipment
|
||||
.Where(item => item.Behaviors.Any(x => x.Data is WeaponData && !(x.Data is LauncherData)))
|
||||
.GroupBy(item => ZoneRenderer.EntityInstances[CurrentEntity]
|
||||
.GetBarrel(CurrentEntity.Hardpoints[item.Position.x, item.Position.y])
|
||||
.GetBarrel(item.Hardpoint)
|
||||
.GetComponentInParent<ArticulationPoint>()?.Group ?? -1)
|
||||
.Select((group, index) => {
|
||||
return (
|
||||
group.Select(item => CurrentEntity.Hardpoints[item.Position.x, item.Position.y]).ToArray(),
|
||||
group.Select(item => ZoneRenderer.EntityInstances[CurrentEntity].GetBarrel(CurrentEntity.Hardpoints[item.Position.x, item.Position.y])).ToArray(),
|
||||
group.Select(item => item.Hardpoint).ToArray(),
|
||||
group.Select(item => ZoneRenderer.EntityInstances[CurrentEntity].GetBarrel(item.Hardpoint)).ToArray(),
|
||||
Crosshairs[index]
|
||||
);
|
||||
}).ToArray();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ public class EntityInstance : MonoBehaviour
|
|||
public ShieldManager Shield;
|
||||
public HullCollider[] HullColliders;
|
||||
|
||||
public Transform[] EquipmentHardpoints;
|
||||
public RadiatorHardpoint[] RadiatorHardpoints;
|
||||
public ThrusterHardpoint[] ThrusterHardpoints;
|
||||
public WeaponHardpoint[] WeaponHardpoints;
|
||||
|
|
@ -241,23 +240,13 @@ public class EntityInstance : MonoBehaviour
|
|||
_constantWeaponManagers[data].StopFiring(item);
|
||||
}
|
||||
}
|
||||
|
||||
var hp = Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
if (hp != null && item.Data.SoundBank != 0)
|
||||
{
|
||||
var hardpointTransform = EquipmentHardpoints.FirstOrDefault(x => x.name == hp.Transform);
|
||||
if (hardpointTransform != null)
|
||||
{
|
||||
var hardpointGameObject = hardpointTransform.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
RadiatorMeshes = new Dictionary<Radiator, MeshRenderer>();
|
||||
Barrels = new Dictionary<HardpointData, Transform[]>();
|
||||
BarrelIndices = new Dictionary<HardpointData, int>();
|
||||
foreach (var radiator in entity.GetBehaviors<Radiator>())
|
||||
{
|
||||
var hp = Entity.Hardpoints[radiator.Item.Position.x, radiator.Item.Position.y];
|
||||
var hp = radiator.Item.Hardpoint;
|
||||
if (hp != null && hp.Type == HardpointType.Radiator)
|
||||
{
|
||||
var mesh = RadiatorHardpoints.FirstOrDefault(x => x.name == hp.Transform);
|
||||
|
|
|
|||
|
|
@ -65,10 +65,9 @@ public class ShipInstance : EntityInstance
|
|||
{
|
||||
var effectData = (ThrusterData) thruster.Data;
|
||||
var particles = Instantiate(EngineAssets.Load<ParticleSystem>(effectData.ParticlesPrefab), transform, false);
|
||||
var particlesShape = particles.shape;
|
||||
var thrusterHardpoint = ThrusterHardpoints
|
||||
.FirstOrDefault(t => t.name == ship.Hardpoints[thruster.Item.Position.x, thruster.Item.Position.y].Transform);
|
||||
particlesShape.meshRenderer = thrusterHardpoint?.Emitter;
|
||||
.FirstOrDefault(t => t.name == thruster.Item.Hardpoint.Transform);
|
||||
ThrusterHardpoint.WireExhaust(particles, thrusterHardpoint);
|
||||
// if (!string.IsNullOrEmpty(thruster.Item.Data.SoundEffectTrigger) && thrusterHardpoint != null)
|
||||
// {
|
||||
// AkSoundEngine.RegisterGameObj(thrusterHardpoint.gameObject);
|
||||
|
|
|
|||
182
Assets/Scripts/Gameplay/ShipModShips.cs
Normal file
182
Assets/Scripts/Gameplay/ShipModShips.cs
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GameCult.Caching;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
// Mod ships in the running game. Preload imports each catalog hull's GLB once, at boot, into an inactive assembled
|
||||
// prototype keyed by the hull's record key; Instantiate then clones it synchronously, so LoadEntity never loads async.
|
||||
// The prototypes are cache-only: rebuilt every boot from the catalog, the mod GLBs and the template.
|
||||
public static class ShipModShips
|
||||
{
|
||||
private static readonly Dictionary<CultRecordKey, GameObject> Prototypes = new Dictionary<CultRecordKey, GameObject>();
|
||||
private static CultCache _catalog;
|
||||
|
||||
// Set by Preload; complete when every hull that could be built has its prototype. A mod ship that fails to import or
|
||||
// assemble is skipped and logged, as Compose skips a bad package, so it never stops the rest; Loading faults only
|
||||
// when the preload itself cannot run.
|
||||
public static Task Loading { get; private set; } = Task.CompletedTask;
|
||||
|
||||
public static Task Preload(CultCache catalog, string modsRoot)
|
||||
{
|
||||
Loading = PreloadAsync(catalog, modsRoot);
|
||||
Loading.ContinueWith(task => Debug.LogException(task.Exception), TaskContinuationOptions.OnlyOnFaulted);
|
||||
return Loading;
|
||||
}
|
||||
|
||||
private static async Task PreloadAsync(CultCache catalog, string modsRoot)
|
||||
{
|
||||
_catalog = catalog;
|
||||
var hulls = catalog.GetAll<HullData>().Where(hull => hull.Visual.IsSet()).ToArray();
|
||||
if (hulls.Length == 0) return;
|
||||
var template = EngineAssets.Load<ShipModTemplate>(ShipModTemplate.Key);
|
||||
if (template == null)
|
||||
throw new InvalidOperationException($"The ship mod template prefab ({ShipModTemplate.Key}) is not loadable.");
|
||||
var root = new GameObject("Mod Ship Prototypes");
|
||||
root.SetActive(false);
|
||||
// DontDestroyOnLoad is play-mode only; the edit-mode play smoke builds the same prototypes
|
||||
// without it, and nothing there loads scenes.
|
||||
if (Application.isPlaying) Object.DontDestroyOnLoad(root);
|
||||
foreach (var hull in hulls)
|
||||
{
|
||||
ShipModVisual.Instance visual = null;
|
||||
try
|
||||
{
|
||||
var package = ShipModCatalog.PackageOf(catalog, hull, modsRoot);
|
||||
visual = await ShipModVisual.LoadAsync(package, root.transform);
|
||||
visual.Root.SetActive(false);
|
||||
Assemble(visual, package.Hull, package.Visual, template);
|
||||
Prototypes[catalog.RefOf(hull).Key] = visual.Root;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
visual?.Destroy();
|
||||
Debug.LogError($"Mod ship {hull.Name} skipped: {error.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A live ship body for a mod hull. Refuses loudly when the prototype is missing: nothing is loaded here.
|
||||
public static GameObject Instantiate(HullData hull, Transform parent)
|
||||
{
|
||||
if (!Loading.IsCompletedSuccessfully)
|
||||
throw new InvalidOperationException($"{hull.Name}: mod ships are not preloaded ({Loading.Status}).");
|
||||
if (!Prototypes.TryGetValue(_catalog.RefOf(hull).Key, out var prototype))
|
||||
throw new InvalidOperationException($"{hull.Name}: no mod ship prototype for this hull.");
|
||||
var body = Object.Instantiate(prototype, parent, false);
|
||||
body.SetActive(true);
|
||||
return body;
|
||||
}
|
||||
|
||||
// Fills a ShipInstance on the visual's root from its anchors, as ShipModPlan says; the shared effects come from the
|
||||
// template. Nothing here decides a slot: the plan does. The schematic lines stay in the prototype but are hidden in
|
||||
// world; the in-world ship is the GLB.
|
||||
public static ShipInstance Assemble(ShipModVisual.Instance visual, HullData hull, ShipAuthoring ship, ShipModTemplate template)
|
||||
{
|
||||
var plan = ShipModPlan.Build(hull, ship);
|
||||
var minimap = LayerMask.NameToLayer("Minimap");
|
||||
var combat = LayerMask.NameToLayer("Combat");
|
||||
if (minimap < 0 || combat < 0) throw new InvalidOperationException("Minimap or Combat layer is missing");
|
||||
|
||||
// The name a catalog hardpoint matches at runtime is its anchor id.
|
||||
Transform Node(string id)
|
||||
{
|
||||
var node = visual.Anchors[id];
|
||||
node.name = id;
|
||||
return node;
|
||||
}
|
||||
MeshRenderer Renderer(string id)
|
||||
{
|
||||
var found = Node(id).GetComponentInChildren<MeshRenderer>(true);
|
||||
if (found == null) throw new InvalidOperationException($"{ship.Id}: anchor {id} needs a mesh in its GLB node.");
|
||||
return found;
|
||||
}
|
||||
|
||||
var mapIcon = Renderer(plan.MapIcon);
|
||||
mapIcon.sharedMaterial = template.MapIcon;
|
||||
mapIcon.gameObject.layer = minimap;
|
||||
|
||||
var hullNode = Node(plan.HullCollider);
|
||||
var hullFilter = hullNode.GetComponent<MeshFilter>();
|
||||
var hullMesh = hullFilter != null ? hullFilter.sharedMesh : null;
|
||||
if (hullMesh == null)
|
||||
throw new InvalidOperationException($"{ship.Id}: hull-collider anchor {plan.HullCollider} needs a mesh in its GLB node.");
|
||||
if (!hullMesh.isReadable)
|
||||
throw new InvalidOperationException($"{ship.Id}: the hull-collider mesh imported unreadable, so it cannot back a MeshCollider.");
|
||||
hullNode.gameObject.layer = combat;
|
||||
// The collision hull is never drawn. Its renderer takes the invisible material, which is serialized and so survives
|
||||
// the prototype's clone; forceRenderingOff would not survive Instantiate.
|
||||
var hullRenderer = hullNode.GetComponent<MeshRenderer>();
|
||||
if (hullRenderer != null) Hide(hullRenderer, template.Invisible);
|
||||
var collider = AddOrGet<MeshCollider>(hullNode.gameObject);
|
||||
collider.sharedMesh = hullMesh;
|
||||
collider.convex = true;
|
||||
var surface = AddOrGet<HullCollider>(hullNode.gameObject);
|
||||
|
||||
var shieldMarker = Node(plan.Shield);
|
||||
var scale = shieldMarker.localScale;
|
||||
if (!(scale.x > 0 && scale.y > 0 && scale.z > 0))
|
||||
throw new InvalidOperationException($"{ship.Id}: the shield anchor scale must have three positive radii.");
|
||||
var shield = Object.Instantiate(template.Shield.GetComponent<ShieldManager>(), shieldMarker, false);
|
||||
Reset(shield.transform);
|
||||
AddOrGet<ShieldEnvelope>(shield.gameObject);
|
||||
var tractor = Object.Instantiate(template.TractorBeam.GetComponent<TractorBeam>(), Node(plan.Tractor), false);
|
||||
Reset(tractor.transform);
|
||||
|
||||
var thrusters = plan.Thrusters.Select(id =>
|
||||
{
|
||||
// The thruster's mesh is its exhaust's emission surface, never drawn (ruling thrusters-radiators-are-meshes).
|
||||
// The invisible material is serialized, so it survives the prototype's clone, and EntityInstance keeps it as
|
||||
// this renderer's visible material; forceRenderingOff would not survive Instantiate.
|
||||
var hardpoint = AddOrGet<ThrusterHardpoint>(Node(id).gameObject);
|
||||
hardpoint.Emitter = Renderer(id);
|
||||
Hide(hardpoint.Emitter, template.Invisible);
|
||||
return hardpoint;
|
||||
}).ToArray();
|
||||
var radiators = plan.Radiators.Select(id =>
|
||||
{
|
||||
var hardpoint = AddOrGet<RadiatorHardpoint>(Node(id).gameObject);
|
||||
hardpoint.Mesh = Renderer(id);
|
||||
return hardpoint;
|
||||
}).ToArray();
|
||||
var weapons = plan.Weapons.Select(weapon =>
|
||||
{
|
||||
var hardpoint = AddOrGet<WeaponHardpoint>(Node(weapon.Mount).gameObject);
|
||||
hardpoint.FiringPoint = weapon.Muzzles.Select(Node).ToArray();
|
||||
return hardpoint;
|
||||
}).ToArray();
|
||||
|
||||
var lines = visual.Root.transform.Find("Schematic Lines");
|
||||
if (lines != null) lines.gameObject.SetActive(false);
|
||||
|
||||
var instance = AddOrGet<ShipInstance>(visual.Root);
|
||||
instance.MapIcon = mapIcon;
|
||||
instance.InfluencePrefab = null;
|
||||
instance.PingPrefab = template.Ping.transform;
|
||||
instance.InvisibleMaterial = template.Invisible;
|
||||
instance.Shield = shield;
|
||||
instance.HullColliders = new[] { surface };
|
||||
instance.ThrusterHardpoints = thrusters;
|
||||
instance.WeaponHardpoints = weapons;
|
||||
instance.RadiatorHardpoints = radiators;
|
||||
instance.ArticulationPoints = Array.Empty<ArticulationPoint>();
|
||||
instance.DestroyEffect = template.DestroyEffect;
|
||||
instance.TractorBeam = tractor;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Every material slot takes the invisible material, so the renderer draws nothing on the prototype and on every clone.
|
||||
public static void Hide(Renderer renderer, Material invisible) =>
|
||||
renderer.sharedMaterials = Enumerable.Repeat(invisible, renderer.sharedMaterials.Length).ToArray();
|
||||
|
||||
private static void Reset(Transform transform)
|
||||
{
|
||||
transform.localPosition = Vector3.zero;
|
||||
transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
private static T AddOrGet<T>(GameObject gameObject) where T : Component =>
|
||||
gameObject.TryGetComponent<T>(out var found) ? found : gameObject.AddComponent<T>();
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/ShipModShips.cs.meta
Normal file
2
Assets/Scripts/Gameplay/ShipModShips.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b2c0124382433447b5a5679e8b91b57
|
||||
17
Assets/Scripts/Gameplay/ShipModTemplate.cs
Normal file
17
Assets/Scripts/Gameplay/ShipModTemplate.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using UnityEngine;
|
||||
|
||||
// The shared effect prototypes every mod ship is assembled with: the same assets ShipPrefabAuthoring wires into a
|
||||
// prefab ship. It lives on one Addressable prefab, so a built player finds it by key without the Editor.
|
||||
public class ShipModTemplate : MonoBehaviour
|
||||
{
|
||||
// The template prefab's .meta GUID, its Addressables key (Assets/Content is an addressable folder).
|
||||
public const string Key = "5d1f3a8c7e2b4f60a9c4b7e1d3f2a860";
|
||||
|
||||
// Prefab roots; the assembler takes the component it needs from each.
|
||||
public GameObject Shield;
|
||||
public GameObject TractorBeam;
|
||||
public GameObject Ping;
|
||||
public GameObject DestroyEffect;
|
||||
public Material Invisible;
|
||||
public Material MapIcon;
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/ShipModTemplate.cs.meta
Normal file
11
Assets/Scripts/Gameplay/ShipModTemplate.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c3e9a52d8b14f0e8a6d2b1f4c95e703
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Assets/Scripts/Gameplay/ShipModVisual.cs
Normal file
113
Assets/Scripts/Gameplay/ShipModVisual.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GLTFast;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
// A mod package's visual assembly. It does not decide hull cells or hardpoint roles.
|
||||
public static class ShipModVisual
|
||||
{
|
||||
public sealed class Instance
|
||||
{
|
||||
public GameObject Root;
|
||||
public IReadOnlyDictionary<string, Transform> Anchors;
|
||||
public Mesh LineMesh;
|
||||
public Material LineMaterial;
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
DestroyObject(Root);
|
||||
DestroyObject(LineMesh);
|
||||
DestroyObject(LineMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Nodes : GameObjectInstantiator
|
||||
{
|
||||
public Nodes(IGltfReadable gltf, Transform parent) : base(gltf, parent) { }
|
||||
public Transform Get(uint index) => m_Nodes.TryGetValue(index, out var node) ? node.transform : null;
|
||||
}
|
||||
|
||||
public static async Task<Instance> LoadAsync(ShipModCatalog.Package package, Transform parent)
|
||||
{
|
||||
var ship = package.Visual;
|
||||
|
||||
var root = new GameObject("mod-ship:" + ship.Id);
|
||||
root.SetActive(false);
|
||||
root.transform.SetParent(parent, false);
|
||||
var result = new Instance { Root = root };
|
||||
try
|
||||
{
|
||||
// glTFast's default defer agent creates a DontDestroyOnLoad object, which is
|
||||
// unavailable in edit-mode previews. Play mode keeps its frame-budgeted agent.
|
||||
var gltf = new GltfImport(deferAgent: Application.isPlaying ? null : new UninterruptedDeferAgent());
|
||||
if (!await gltf.LoadFile(package.ModelPath))
|
||||
throw new InvalidOperationException($"{ship.Id}: GLB import failed.");
|
||||
var nodes = new Nodes(gltf, root.transform);
|
||||
if (!await gltf.InstantiateMainSceneAsync(nodes))
|
||||
throw new InvalidOperationException($"{ship.Id}: GLB scene instantiation failed.");
|
||||
result.Anchors = ship.Anchors.ToDictionary(anchor => anchor.Id, anchor =>
|
||||
nodes.Get(package.NodeIndices[anchor.ModelNodeId]) ??
|
||||
throw new InvalidOperationException($"{ship.Id}: GLB scene omitted node {anchor.ModelNodeId}."),
|
||||
StringComparer.Ordinal);
|
||||
result.LineMesh = BuildLineMesh(ship.SchematicLines);
|
||||
if (result.LineMesh != null)
|
||||
{
|
||||
var lines = new GameObject("Schematic Lines");
|
||||
lines.transform.SetParent(root.transform, false);
|
||||
lines.AddComponent<MeshFilter>().sharedMesh = result.LineMesh;
|
||||
var shader = Shader.Find("Sprites/Default") ??
|
||||
throw new InvalidOperationException("Sprites/Default shader is unavailable for ship lines.");
|
||||
result.LineMaterial = new Material(shader) { name = "Ship Lines" };
|
||||
lines.AddComponent<MeshRenderer>().sharedMaterial = result.LineMaterial;
|
||||
}
|
||||
root.SetActive(true);
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result.Destroy();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static void DestroyObject(Object target)
|
||||
{
|
||||
if (target == null) return;
|
||||
if (Application.isPlaying) Object.Destroy(target);
|
||||
else Object.DestroyImmediate(target);
|
||||
}
|
||||
|
||||
// Blender Z-up to Unity Y-up through Blender's glTF export and glTFast's handedness conversion.
|
||||
// Segment topology preserves every authored point; display width is currently one screen pixel.
|
||||
public static Mesh BuildLineMesh(IReadOnlyList<ShipPolyline> lines)
|
||||
{
|
||||
if (lines == null || lines.Count == 0) return null;
|
||||
var vertices = new List<Vector3>();
|
||||
var colors = new List<Color>();
|
||||
var segments = new List<int>();
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var count = line.Points.Length / 3;
|
||||
var start = vertices.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var offset = i * 3;
|
||||
vertices.Add(new Vector3(-line.Points[offset], line.Points[offset + 2], -line.Points[offset + 1]));
|
||||
var rgba = line.Color;
|
||||
colors.Add(new Color(rgba?[0] ?? 1, rgba?[1] ?? 1, rgba?[2] ?? 1,
|
||||
(rgba?[3] ?? 1) * (line.Opacities?[i] ?? 1)));
|
||||
if (i > 0) { segments.Add(start + i - 1); segments.Add(start + i); }
|
||||
}
|
||||
if (line.Cyclic && count > 2) { segments.Add(start + count - 1); segments.Add(start); }
|
||||
}
|
||||
var mesh = new Mesh { name = "Captured Ship Lines", indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 };
|
||||
mesh.SetVertices(vertices);
|
||||
mesh.SetColors(colors);
|
||||
mesh.SetIndices(segments, MeshTopology.Lines, 0);
|
||||
mesh.RecalculateBounds();
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/ShipModVisual.cs.meta
Normal file
2
Assets/Scripts/Gameplay/ShipModVisual.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a8a4f72a22b44819a71e43e21c7db894
|
||||
|
|
@ -1,8 +1,16 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class ThrusterHardpoint : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Emitter;
|
||||
|
||||
// Points an exhaust's shape at a hardpoint's emitter, or at nothing when the ship has no such hardpoint. The emitter
|
||||
// carries the invisible material (alpha 0), so the particles never take their colour from its mesh: with Use Mesh
|
||||
// Colors on, Unity's default, they would all be born transparent.
|
||||
public static void WireExhaust(ParticleSystem exhaust, ThrusterHardpoint hardpoint)
|
||||
{
|
||||
var shape = exhaust.shape;
|
||||
shape.useMeshColors = false;
|
||||
shape.meshRenderer = hardpoint != null ? hardpoint.Emitter : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public class ChargeEffectManager : MonoBehaviour
|
|||
public void StartCharging(ChargedWeapon weapon, EquippedItem item, EntityInstance source)
|
||||
{
|
||||
var effect = EffectPrototype.Instantiate<WeaponChargeEffect>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = effect.transform;
|
||||
t.SetParent(barrel);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class ConstantLaserManager : ConstantWeaponEffectManager
|
|||
{
|
||||
var p = LaserPrototype.Instantiate<ConstantLaser>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Range = item.Evaluate(data.Range);
|
||||
var t = p.transform;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class ConstantLightningManager : ConstantWeaponEffectManager
|
|||
{
|
||||
var p = LightningPrototype.Instantiate<ConstantLightning>();
|
||||
p.Source = source;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Barrel = barrel;
|
||||
p.Range = item.Evaluate(data.Range);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class ConstantParticleWeaponManager : ConstantWeaponEffectManager
|
|||
var p = WeaponPrototype.Instantiate<ConstantParticleWeapon>();
|
||||
p.Source = source;
|
||||
p.Target = target;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = p.transform;
|
||||
t.SetParent(barrel);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
if (target != null) p.Target = target.transform;
|
||||
else p.TargetPosition = () => burst;
|
||||
p.Frequency = launcher.DodgeFrequency;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
|
||||
p.Range = weapon.Range;
|
||||
|
|
@ -66,7 +66,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
p.Source = source.transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Frequency = guidance.DodgeFrequency;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
|
||||
p.Range = weapon.Range;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ public class HitscanManager : InstantWeaponEffectManager
|
|||
{
|
||||
var p = Prototype.Instantiate<HitscanEffect>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = p.transform;
|
||||
t.SetParent(barrel, false);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public class LaserManager : InstantWeaponEffectManager
|
|||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Laser>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = p.transform;
|
||||
t.SetParent(barrel);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public class LightningGunManager : InstantWeaponEffectManager
|
|||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = Prototype.Instantiate<Lightning>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.ShotId = shotId;
|
||||
p.Barrel = barrel;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class MineManager : InstantWeaponEffectManager
|
|||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Mine>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var angle = weapon.Spread / 2;
|
||||
p.Source = source;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public class ProjectileManager : InstantWeaponEffectManager
|
|||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Projectile>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var hp = item.Hardpoint;
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var angle = weapon.Spread / 2;
|
||||
p.ShotId = shotId;
|
||||
|
|
|
|||
Loading…
Reference in a new issue