Merge master 239f3599 into eureka/aetheria-release-scenarios: ship render fixes
The one conflict, ShipInstance.cs's thruster emitter lookup, keeps the branch's thruster.Item.Hardpoint.Transform and master's new ThrusterHardpoint.WireExhaust(particles, thrusterHardpoint). Master's side as written would have brought back the origin-cell hardpoint lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
4b002b50bc
8 changed files with 134 additions and 26 deletions
|
|
@ -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 == thruster.Item.Hardpoint.Transform);
|
||||
particlesShape.meshRenderer = thrusterHardpoint?.Emitter;
|
||||
ThrusterHardpoint.WireExhaust(particles, thrusterHardpoint);
|
||||
// if (!string.IsNullOrEmpty(thruster.Item.Data.SoundEffectTrigger) && thrusterHardpoint != null)
|
||||
// {
|
||||
// AkSoundEngine.RegisterGameObj(thrusterHardpoint.gameObject);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ 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 prototype is ready, faulted when any mod ship failed to import or assemble.
|
||||
// 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)
|
||||
|
|
@ -39,18 +41,19 @@ public static class ShipModShips
|
|||
if (Application.isPlaying) Object.DontDestroyOnLoad(root);
|
||||
foreach (var hull in hulls)
|
||||
{
|
||||
var package = ShipModCatalog.PackageOf(catalog, hull, modsRoot);
|
||||
var visual = await ShipModVisual.LoadAsync(package, root.transform);
|
||||
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
|
||||
catch (Exception error)
|
||||
{
|
||||
visual.Destroy();
|
||||
throw;
|
||||
visual?.Destroy();
|
||||
Debug.LogError($"Mod ship {hull.Name} skipped: {error.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -103,8 +106,10 @@ public static class ShipModShips
|
|||
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) hullRenderer.forceRenderingOff = true;
|
||||
if (hullRenderer != null) Hide(hullRenderer, template.Invisible);
|
||||
var collider = AddOrGet<MeshCollider>(hullNode.gameObject);
|
||||
collider.sharedMesh = hullMesh;
|
||||
collider.convex = true;
|
||||
|
|
@ -127,7 +132,7 @@ public static class ShipModShips
|
|||
// this renderer's visible material; forceRenderingOff would not survive Instantiate.
|
||||
var hardpoint = AddOrGet<ThrusterHardpoint>(Node(id).gameObject);
|
||||
hardpoint.Emitter = Renderer(id);
|
||||
hardpoint.Emitter.sharedMaterials = Enumerable.Repeat(template.Invisible, hardpoint.Emitter.sharedMaterials.Length).ToArray();
|
||||
Hide(hardpoint.Emitter, template.Invisible);
|
||||
return hardpoint;
|
||||
}).ToArray();
|
||||
var radiators = plan.Radiators.Select(id =>
|
||||
|
|
@ -162,6 +167,10 @@ public static class ShipModShips
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue