Unity draws Zone.FloatingItems and nothing else; the Unity loot roll, collision pickup, tractor pull and GridObject are gone
ZoneRenderer draws one ItemPickup per FloatingItem (load, ObserveAdd, ObserveRemove, ClearZone); ItemPickup.Bind places it from the sim body and spins it for show. EntityInstance's drop loops, ShieldManager's pickup branch (the whole OnCollisionEnter, which did nothing else), ZoneRenderer.DropItem/DestroyLoot/_loot, TractorBeam's pull, and GameSettings' three loot fields are deleted; WireFloatingItems stripped GridObject from the five pickup prefabs and reassigned ZoneRenderer's four pickup fields in ARPG.unity; FloatingItemsDrawnSmoke (play session, batchmode) pins the lowering. GridObject and TimedDestroy were deleted infa911f2d, sofa911f2dand2565e2c5do not build in Unity. Assets/Resources/Settings.asset keeps three stale serialized GameSettings fields Unity ignores (LFS object, not rewritten). Builds: Unity batchmode compile green at this commit; dotnet green at2565e2c5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2565e2c5d7
commit
c7c7e58508
16 changed files with 576 additions and 252 deletions
227
Assets/Scripts/Editor/FloatingItemsDrawnSmoke.cs
Normal file
227
Assets/Scripts/Editor/FloatingItemsDrawnSmoke.cs
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using float2 = CultMath.float2;
|
||||
|
||||
// Batch proof that ZoneRenderer draws Zone.FloatingItems and nothing else, in a play session with no scene of its own:
|
||||
// the pickup prefabs are the ones ARPG.unity's ZoneRenderer names (so the wiring is read here too), a zone is loaded
|
||||
// into a fresh ZoneRenderer, and the zone's own Release, step, expiry and TryPickUp are what move and remove the
|
||||
// pickups. Zone.Release adds exactly one ItemPickup, placed at the body's position; stepping the zone moves it with the
|
||||
// body; expiry and TryPickUp each destroy it; an item already in the zone when the renderer loads it is drawn too.
|
||||
//
|
||||
// Unity -batchmode -nographics -projectPath <project> -executeMethod FloatingItemsDrawnSmoke.Run -logFile <log>
|
||||
//
|
||||
// Do not pass -quit: Run enters play mode (a domain reload), the check runs there, and the Editor exits itself, 0 on
|
||||
// success and 1 on any failure. Destroy only takes effect in a play session, which is why this is not an edit-mode check.
|
||||
[InitializeOnLoad]
|
||||
public static class FloatingItemsDrawnSmoke
|
||||
{
|
||||
private const string Flag = "FloatingItemsDrawnSmoke.running";
|
||||
private const string Wiring = "FloatingItemsDrawnSmoke.wiring";
|
||||
private static IEnumerator _check;
|
||||
private static int _frames;
|
||||
private static string _work;
|
||||
|
||||
static FloatingItemsDrawnSmoke()
|
||||
{
|
||||
if (SessionState.GetBool(Flag, false)) EditorApplication.playModeStateChanged += OnPlayMode;
|
||||
}
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
SessionState.SetString(Wiring, ReadWiring());
|
||||
SessionState.SetBool(Flag, true);
|
||||
EditorApplication.EnterPlaymode();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogException(exception);
|
||||
EditorApplication.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnPlayMode(PlayModeStateChange change)
|
||||
{
|
||||
if (change != PlayModeStateChange.EnteredPlayMode) return;
|
||||
_work = Path.Combine(Path.GetTempPath(), $"floating-items-smoke-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(_work);
|
||||
_check = Check();
|
||||
EditorApplication.update += Step;
|
||||
}
|
||||
|
||||
private static void Step()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (++_frames > 3000) throw new InvalidOperationException("The check did not finish in 3000 frames.");
|
||||
if (_check.MoveNext()) return;
|
||||
Finish(0);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogException(exception);
|
||||
Finish(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Finish(int code)
|
||||
{
|
||||
EditorApplication.update -= Step;
|
||||
SessionState.SetBool(Flag, false);
|
||||
try { if (Directory.Exists(_work)) Directory.Delete(_work, true); } catch (Exception) { /* a temp directory */ }
|
||||
EditorApplication.Exit(code);
|
||||
}
|
||||
|
||||
private static void Require(bool condition, string what)
|
||||
{
|
||||
if (!condition) throw new InvalidOperationException(what);
|
||||
}
|
||||
|
||||
private static IEnumerator Check()
|
||||
{
|
||||
var settings = AssetDatabase.LoadAssetAtPath<GameSettings>("Assets/Resources/Settings.asset")?.GameplaySettings
|
||||
?? throw new InvalidOperationException("No Settings.asset.");
|
||||
|
||||
// The wiring: the scene's ZoneRenderer names an ItemPickup prefab in each of the four fields, and none of those
|
||||
// prefabs keeps a script that no longer exists.
|
||||
var wired = SessionState.GetString(Wiring, "").Split('|').Select(entry => entry.Split('=')).Select(pair =>
|
||||
(Field: pair[0], Pickup: pair[1] == "" ? null : AssetDatabase.LoadAssetAtPath<GameObject>(pair[1])?.GetComponent<ItemPickup>())).ToArray();
|
||||
Require(wired.Length == 4, "The wiring was not carried into the play session.");
|
||||
foreach (var (name, pickup) in wired)
|
||||
{
|
||||
Require(pickup != null, $"ZoneRenderer.{name} is not an ItemPickup in ARPG.unity.");
|
||||
Require(pickup.ScanLabel != null && pickup.ScanLabelContainer != null, $"{name}'s prefab has no scan label.");
|
||||
Require(!pickup.GetComponentsInChildren<Component>(true).Any(c => c == null), $"{name}'s prefab has a missing script.");
|
||||
}
|
||||
|
||||
var shape = new Shape(5, 5);
|
||||
foreach (var cell in shape.AllCoordinates) shape[cell] = true;
|
||||
var cargoShape = new Shape(4, 4);
|
||||
foreach (var cell in cargoShape.AllCoordinates) cargoShape[cell] = true;
|
||||
var oneCell = new Shape(1, 1);
|
||||
oneCell[new CultMath.int2(0, 0)] = true;
|
||||
var cache = AetheriaStores.Open(Path.Combine(_work, "smoke.cc"), catalogWritable: true);
|
||||
cache.Upsert(new VerseGrammar { Revision = 1 });
|
||||
cache.Upsert(new HullData { Name = "Smoke Hub", HullType = HullType.Station, Shape = shape, Durability = 1000, Mass = 1000 });
|
||||
cache.Upsert(new CargoBayData { Name = "Smoke Crate", Shape = new Shape(), InteriorShape = cargoShape, Durability = 4 });
|
||||
cache.Upsert(new GearData
|
||||
{
|
||||
Name = "Smoke Spare", Hardpoint = HardpointType.Tool, Shape = oneCell, Durability = 1,
|
||||
MinimumTemperature = -1000, MaximumTemperature = 1000, OptimalTemperature = 0, PlateauWidth = 2000
|
||||
});
|
||||
cache.Upsert(new SimpleCommodityData { Name = "Smoke Ore", Shape = oneCell, MaxStack = 100 });
|
||||
cache.FlushAsync().Wait();
|
||||
var ledger = new ProvenanceLedger();
|
||||
for (var i = 1; i <= 8; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = 1 };
|
||||
var items = new ItemManager(cache, ledger, settings, _ => { });
|
||||
var zone = new Zone(items, new PlanetSettings(), new ZonePack(), null, null);
|
||||
EquippableItem Make(string name, int lot) => new EquippableItem
|
||||
{
|
||||
Data = items.ItemData.RefOf<ItemData>(items.ItemData.GetByName<EquippableItemData>(name)), Durability = 1, Lot = lot
|
||||
};
|
||||
|
||||
// A station with a crate takes the picked-up stack. It is not admitted: the zone holds no entity for the renderer to draw.
|
||||
var hubRef = items.ItemData.RefOf<ItemData>(items.ItemData.GetByName<HullData>("Smoke Hub"));
|
||||
var taker = new OrbitalEntity(items, zone, new EquippableItem { Data = hubRef, Durability = 1000, Lot = 1 }, default, new EntitySettings());
|
||||
Require(taker.TryEquip(Make("Smoke Crate", 2), new CultMath.int2(1, 1)), "The smoke station took no crate.");
|
||||
|
||||
// An item already in the zone when the renderer loads it: drawn from the load, not only from the add.
|
||||
var early = zone.Release(Make("Smoke Spare", 3), new float2(5, 6), float2.zero);
|
||||
|
||||
// The renderer's side. Inactive while it is configured, so it runs no Awake or Start of the scene's own.
|
||||
var rootObject = new GameObject("Smoke Zone Root");
|
||||
var rendererObject = new GameObject("Smoke Zone Renderer");
|
||||
rendererObject.SetActive(false);
|
||||
var renderer = rendererObject.AddComponent<ZoneRenderer>();
|
||||
renderer.ZoneRoot = rootObject.transform;
|
||||
foreach (var (name, pickup) in wired)
|
||||
typeof(ZoneRenderer).GetField(name).SetValue(renderer, pickup);
|
||||
renderer.ItemManager = items;
|
||||
renderer.SectorBrushes = new GameObject("Smoke Brushes").transform;
|
||||
renderer.SlimeGravityCamera = new GameObject("Smoke Gravity Camera").AddComponent<Camera>();
|
||||
var slimeObject = new GameObject("Smoke Slime");
|
||||
slimeObject.SetActive(false); // the real Slime needs its compute shader; LoadZone only sets its radius
|
||||
renderer.SlimeRenderer = slimeObject.AddComponent<Slime>();
|
||||
renderer.LoadZone(zone);
|
||||
yield return null;
|
||||
|
||||
ItemPickup[] Pickups() => rootObject.GetComponentsInChildren<ItemPickup>(true).Where(p => p != null).ToArray();
|
||||
void At(ItemPickup pickup, FloatingItem floating, string what)
|
||||
{
|
||||
var at = floating.Body.Position;
|
||||
var want = new Vector3(at.x, zone.GetHeight(at), at.y);
|
||||
Require(Vector3.Distance(pickup.transform.position, want) < 1e-3f,
|
||||
$"{what}: the pickup is at {pickup.transform.position}, the body at {want}.");
|
||||
}
|
||||
|
||||
Require(Pickups().Length == 1, $"load: {Pickups().Length} pickups for one existing floating item.");
|
||||
At(Pickups()[0], early, "load");
|
||||
|
||||
// Release adds exactly one pickup, at the body's position, bound to its item.
|
||||
var ore = new SimpleCommodity { Data = items.ItemData.RefOf<ItemData>(items.ItemData.GetByName<SimpleCommodityData>("Smoke Ore")), Quantity = 7 };
|
||||
var released = zone.Release(ore, new float2(3, 4), new float2(10, 0));
|
||||
yield return null;
|
||||
Require(Pickups().Length == 2, $"release: {Pickups().Length} pickups for two floating items.");
|
||||
var drawn = Pickups().Single(p => p.Item == ore);
|
||||
At(drawn, released, "release");
|
||||
|
||||
// Stepping the zone moves the sim body; the pickup follows it on its next update, with nothing of its own.
|
||||
var before = drawn.transform.position;
|
||||
zone.Update(.5f);
|
||||
yield return null;
|
||||
Require(released.Body.Position.x > 3.5f, "the sim body did not drift.");
|
||||
At(drawn, released, "step");
|
||||
Require(drawn.transform.position != before, "the pickup did not move with the body.");
|
||||
|
||||
// Pickup destroys exactly the picked-up item's pickup.
|
||||
Require(zone.TryPickUp(taker, released.Id), "the station refused a one-cell stack.");
|
||||
yield return null;
|
||||
yield return null;
|
||||
Require(drawn == null, "pickup: the pickup is still there.");
|
||||
Require(Pickups().Length == 1 && Pickups()[0].Item == early.Item, "pickup: the wrong pickup went.");
|
||||
|
||||
// Expiry destroys the pickup of an item nobody took.
|
||||
zone.Update(settings.FloatingItemLifetime + 1f);
|
||||
yield return null;
|
||||
yield return null;
|
||||
Require(zone.FloatingItems.Count == 0, "expiry: the item did not expire.");
|
||||
Require(Pickups().Length == 0, $"expiry: {Pickups().Length} pickups left.");
|
||||
|
||||
// A later release is drawn again, and clearing the renderer takes what is left.
|
||||
zone.Release(Make("Smoke Spare", 4), new float2(1, 1), float2.zero);
|
||||
yield return null;
|
||||
Require(Pickups().Length == 1, "re-release: not drawn.");
|
||||
renderer.ClearZone();
|
||||
yield return null;
|
||||
yield return null;
|
||||
Require(Pickups().Length == 0, "clear: pickups left after ClearZone.");
|
||||
Debug.Log("FLOATING_ITEMS_SMOKE ok");
|
||||
}
|
||||
|
||||
// What ARPG.unity's ZoneRenderer names in each pickup field, read from the saved scene before the play session (a
|
||||
// scene cannot be opened inside one) and carried across the domain reload as the prefabs' asset paths.
|
||||
private static string ReadWiring()
|
||||
{
|
||||
var scene = EditorSceneManager.OpenScene("Assets/Scenes/ARPG.unity", OpenSceneMode.Additive);
|
||||
try
|
||||
{
|
||||
var found = UnityEngine.Object.FindObjectsByType<ZoneRenderer>(FindObjectsInactive.Include, FindObjectsSortMode.None)
|
||||
.Where(r => r.gameObject.scene == scene).ToArray();
|
||||
Require(found.Length == 1, $"ARPG.unity has {found.Length} ZoneRenderers.");
|
||||
var wired = found[0];
|
||||
return string.Join("|", new[]
|
||||
{
|
||||
("SimpleCommodityPickup", wired.SimpleCommodityPickup), ("CompoundCommodityPickup", wired.CompoundCommodityPickup),
|
||||
("GearPickup", wired.GearPickup), ("WeaponPickup", wired.WeaponPickup)
|
||||
}.Select(f => f.Item1 + "=" + (f.Item2 == null ? "" : AssetDatabase.GetAssetPath(f.Item2))));
|
||||
}
|
||||
finally { EditorSceneManager.CloseScene(scene, true); }
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Editor/FloatingItemsDrawnSmoke.cs.meta
Normal file
2
Assets/Scripts/Editor/FloatingItemsDrawnSmoke.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67544a932f794a2458741c731ef04d11
|
||||
75
Assets/Scripts/Editor/WireFloatingItems.cs
Normal file
75
Assets/Scripts/Editor/WireFloatingItems.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
// Detaches the deleted GridObject from the pickup prefabs and points ZoneRenderer's four pickup fields in ARPG.unity at
|
||||
// each prefab's ItemPickup, then saves the prefabs and the scene. Idempotent: a prefab with no missing script is left as
|
||||
// it is, and the fields are set to the same values again.
|
||||
//
|
||||
// Unity -batchmode -projectPath <project> -executeMethod WireFloatingItems.Run -logFile <log>
|
||||
//
|
||||
// Do not pass -quit: Run exits the Editor itself, 0 on success and 1 on any failure. The menu item runs the same wiring.
|
||||
public static class WireFloatingItems
|
||||
{
|
||||
private const string ScenePath = "Assets/Scenes/ARPG.unity";
|
||||
private const string PickupFolder = "Assets/Prefabs/RPG/Pickups/";
|
||||
// The field each prefab filled before this cut (read from ARPG.unity at the cut's base). Icosahedron fills none.
|
||||
private static readonly (string Field, string Prefab)[] Fields =
|
||||
{
|
||||
("SimpleCommodityPickup", "Tetrahedron"),
|
||||
("CompoundCommodityPickup", "Hexahedron"),
|
||||
("GearPickup", "Octahedron"),
|
||||
("WeaponPickup", "Dodecahedron"),
|
||||
};
|
||||
private static readonly string[] Prefabs = { "Tetrahedron", "Hexahedron", "Octahedron", "Dodecahedron", "Icosahedron" };
|
||||
|
||||
[MenuItem("Aetheria/Wire Floating Items")]
|
||||
public static void Menu() => Wire();
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Wire();
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogException(exception);
|
||||
EditorApplication.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Wire()
|
||||
{
|
||||
foreach (var name in Prefabs)
|
||||
{
|
||||
var path = PickupFolder + name + ".prefab";
|
||||
var contents = PrefabUtility.LoadPrefabContents(path);
|
||||
try
|
||||
{
|
||||
var removed = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(contents);
|
||||
if (contents.GetComponent<ItemPickup>() == null) throw new InvalidOperationException($"{path} has no ItemPickup.");
|
||||
if (removed > 0) PrefabUtility.SaveAsPrefabAsset(contents, path);
|
||||
Debug.Log($"WIRE_FLOATING_ITEMS {name} removed={removed}");
|
||||
}
|
||||
finally { PrefabUtility.UnloadPrefabContents(contents); }
|
||||
}
|
||||
|
||||
var scene = EditorSceneManager.OpenScene(ScenePath, OpenSceneMode.Single);
|
||||
var renderer = UnityEngine.Object.FindFirstObjectByType<ZoneRenderer>();
|
||||
if (renderer == null) throw new InvalidOperationException("ARPG.unity has no ZoneRenderer.");
|
||||
var serialized = new SerializedObject(renderer);
|
||||
foreach (var (field, prefab) in Fields)
|
||||
{
|
||||
var pickup = AssetDatabase.LoadAssetAtPath<GameObject>(PickupFolder + prefab + ".prefab").GetComponent<ItemPickup>();
|
||||
var property = serialized.FindProperty(field) ?? throw new InvalidOperationException($"ZoneRenderer has no {field}.");
|
||||
property.objectReferenceValue = pickup;
|
||||
}
|
||||
serialized.ApplyModifiedProperties();
|
||||
EditorSceneManager.MarkSceneDirty(scene);
|
||||
if (!EditorSceneManager.SaveScene(scene)) throw new InvalidOperationException("The scene did not save.");
|
||||
Debug.Log("WIRE_FLOATING_ITEMS ok");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Editor/WireFloatingItems.cs.meta
Normal file
2
Assets/Scripts/Editor/WireFloatingItems.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a56d7dc8471d224f9bed434b39f7c87
|
||||
|
|
@ -301,27 +301,6 @@ public class EntityInstance : MonoBehaviour
|
|||
{
|
||||
if (!this) return;
|
||||
_destroyed = true;
|
||||
foreach (var gear in Entity.Equipment)
|
||||
{
|
||||
if (gear != Entity.EquippedHull && Random.value < ZoneRenderer.Settings.LootDropProbability)
|
||||
{
|
||||
ZoneRenderer.DropItem(
|
||||
Entity.Position.ToUnity(),
|
||||
Random.onUnitSphere * ZoneRenderer.Settings.LootDropVelocity,
|
||||
gear.EquippableItem);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var cargo in Entity.CargoBays)
|
||||
{
|
||||
foreach (var item in cargo.Cargo.Keys)
|
||||
{
|
||||
ZoneRenderer.DropItem(
|
||||
Entity.Position.ToUnity(),
|
||||
Random.onUnitSphere * ZoneRenderer.Settings.LootDropVelocity,
|
||||
item);
|
||||
}
|
||||
}
|
||||
if (DestroyEffect != null)
|
||||
{
|
||||
var t = Instantiate(DestroyEffect).transform;
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ using UnityEngine;
|
|||
public class GameSettings : ScriptableObject
|
||||
{
|
||||
public string StartingHullName = "Longinus";
|
||||
public float PickupLifetime = 30;
|
||||
public float LootDropProbability = .25f;
|
||||
public float LootDropVelocity = 25;
|
||||
public float HeatstrokePhasingFloor = 0;
|
||||
public float HeatstrokePhasingFrequency = 5;
|
||||
public float WormholeDistanceRatio;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,15 @@ using CultMath;
|
|||
using CultMath.UnityBridge;
|
||||
using UnityEngine;
|
||||
using static CultMath.math;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
// How one floating item looks. Zone owns the item's every fact (existence, position, expiry, pickup); once bound,
|
||||
// this reads the latest sim body and draws, spun for show, and writes nothing back (rulings unity-presents-only-r3
|
||||
// and sim-speed-presentation). An unbound pickup (FieldTester's test scene) leaves its transform alone.
|
||||
public class ItemPickup : MonoBehaviour
|
||||
{
|
||||
public float RotationSpeed = 1f;
|
||||
public float GridOffset;
|
||||
public float LabelFadeDuration = .5f;
|
||||
public float LabelPersistDuration = 3;
|
||||
public float LabelDisplayAngle = 15;
|
||||
|
|
@ -15,14 +21,38 @@ public class ItemPickup : MonoBehaviour
|
|||
public TextMeshPro ScanLabel;
|
||||
|
||||
public ItemInstance Item { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public float3 ViewOrigin { get; set; }
|
||||
public float3 ViewDirection { get; set; }
|
||||
|
||||
private float _displayTime;
|
||||
private float _timeOffset;
|
||||
private Zone _zone;
|
||||
private FloatingItem _floating;
|
||||
|
||||
public void Bind(Zone zone, FloatingItem floating)
|
||||
{
|
||||
_zone = zone;
|
||||
_floating = floating;
|
||||
Item = floating.Item;
|
||||
_timeOffset = Random.value * 100;
|
||||
Place();
|
||||
}
|
||||
|
||||
private void Place()
|
||||
{
|
||||
var p = _floating.Body.Position;
|
||||
transform.position = new Vector3(p.x, _zone.GetHeight(p) + GridOffset, p.y);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_floating != null)
|
||||
{
|
||||
Place();
|
||||
transform.localRotation = Quaternion.Euler(
|
||||
sin(Time.time - _timeOffset * RotationSpeed) * 90, 0, cos(Time.time - _timeOffset * RotationSpeed) * 90);
|
||||
}
|
||||
|
||||
var diff = transform.position.ToCultMath() - ViewOrigin;
|
||||
var toThis = normalize(diff);
|
||||
var viewAngle = acos(dot(toThis, ViewDirection)) * Mathf.Rad2Deg;
|
||||
|
|
@ -34,9 +64,4 @@ public class ItemPickup : MonoBehaviour
|
|||
ScanLabel.color = c;
|
||||
ScanLabelContainer.rotation = Quaternion.LookRotation((-toThis).ToUnity());
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ZoneRenderer?.DestroyLoot(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,40 +52,6 @@ public class ShieldManager : MonoBehaviour, IAbsorbPresenter
|
|||
Debug.LogWarning("ShieldManager has no ShieldEnvelope; falling back to its own transform for the hit direction.", this);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
var otherShield = other.collider.GetComponent<ShieldManager>();
|
||||
if (!otherShield)
|
||||
{
|
||||
var gridObject = other.collider.GetComponent<GridObject>();
|
||||
if (gridObject)
|
||||
{
|
||||
var itemPickup = other.collider.GetComponent<ItemPickup>();
|
||||
if (itemPickup)
|
||||
{
|
||||
if (Entity.CargoBays.Any(c => c.TryStore(itemPickup.Item)))
|
||||
{
|
||||
// TODO: Pickup notification!
|
||||
Destroy(itemPickup.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Pickup failed notification!
|
||||
var cp = other.GetContact(0);
|
||||
gridObject.Velocity += cp.normal * 25;
|
||||
Debug.Log("Attempted item pickup, but no space in cargo bay!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Shield collision occurred with grid object, but other collider isn't an item pickup!");
|
||||
}
|
||||
}
|
||||
else
|
||||
Debug.Log("Shield collision occurred, but other collider isn't a shield or a grid object!");
|
||||
}
|
||||
}
|
||||
|
||||
// A shot the shield took ripples it where the shot landed, drawn on the hull as it is drawn. The hull layer is
|
||||
// ImpactPresenter's.
|
||||
public void Absorb(AbsorbEvent e)
|
||||
|
|
|
|||
|
|
@ -14,20 +14,9 @@ public class TractorBeam : MonoBehaviour
|
|||
public void Update()
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(Direction);
|
||||
// The beam draws nothing until it presents a sim grab (loot-3): no particles, and no pull; the simulation
|
||||
// decides every floating item's motion.
|
||||
var emission = ParticleSystem.emission;
|
||||
if (Power > .01f)
|
||||
{
|
||||
var objectFound = false;
|
||||
foreach (var o in Physics.SphereCastAll(transform.position, Radius, Direction, Distance, 1 << 21))
|
||||
{
|
||||
var gridObject = o.collider.GetComponent<GridObject>();
|
||||
if (gridObject == null) continue;
|
||||
objectFound = true;
|
||||
gridObject.Velocity += Vector3.Normalize(transform.position - gridObject.transform.position) * (Traction * Time.deltaTime);
|
||||
}
|
||||
|
||||
emission.rateOverTimeMultiplier = objectFound ? Power : 0;
|
||||
}
|
||||
else emission.rateOverTimeMultiplier = 0;
|
||||
emission.rateOverTimeMultiplier = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -40,10 +40,10 @@ public class ZoneRenderer : MonoBehaviour
|
|||
public LODHandler LODHandler;
|
||||
public Slime SlimeRenderer;
|
||||
public Camera SlimeGravityCamera;
|
||||
public GridObject SimpleCommodityPickup;
|
||||
public GridObject CompoundCommodityPickup;
|
||||
public GridObject GearPickup;
|
||||
public GridObject WeaponPickup;
|
||||
public ItemPickup SimpleCommodityPickup;
|
||||
public ItemPickup CompoundCommodityPickup;
|
||||
public ItemPickup GearPickup;
|
||||
public ItemPickup WeaponPickup;
|
||||
public MineInstance MinePrefab;
|
||||
public VapourCloudInstance CloudPrefab;
|
||||
public Material[] MapGravityMaterials;
|
||||
|
|
@ -94,7 +94,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private bool _showAsteroidUI;
|
||||
|
||||
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
|
||||
private List<ItemPickup> _loot = new List<ItemPickup>();
|
||||
private Dictionary<FloatingItem, ItemPickup> _floatingItems = new Dictionary<FloatingItem, ItemPickup>();
|
||||
private Dictionary<Mine, MineInstance> _mines = new Dictionary<Mine, MineInstance>();
|
||||
private Dictionary<VapourCloud, VapourCloudInstance> _clouds = new Dictionary<VapourCloud, VapourCloudInstance>();
|
||||
|
||||
|
|
@ -236,6 +236,15 @@ public class ZoneRenderer : MonoBehaviour
|
|||
instance.Blast();
|
||||
}));
|
||||
|
||||
// Every floating item, whoever released it (a death drop, jettisoned cargo), is drawn through this one
|
||||
// subscription. An item leaves Zone.FloatingItems by expiry or by pickup, and either way its pickup is gone.
|
||||
foreach (var floating in zone.FloatingItems) LoadFloatingItem(zone, floating);
|
||||
_zoneSubscriptions.Add(zone.FloatingItems.ObserveAdd().Subscribe(e => LoadFloatingItem(zone, e.Value)));
|
||||
_zoneSubscriptions.Add(zone.FloatingItems.ObserveRemove().Subscribe(e =>
|
||||
{
|
||||
if (_floatingItems.Remove(e.Value, out var pickup) && pickup) Destroy(pickup.gameObject);
|
||||
}));
|
||||
|
||||
// Every vapour cloud, whoever vented it, is drawn through this one subscription. A cloud leaves Zone.Clouds
|
||||
// when its opacity has reached nothing, so a removal destroys its fog bank with nothing left to show.
|
||||
foreach (var cloud in zone.Clouds) LoadCloud(zone, cloud);
|
||||
|
|
@ -274,6 +283,29 @@ public class ZoneRenderer : MonoBehaviour
|
|||
_mines.Add(mine, instance);
|
||||
}
|
||||
|
||||
private void LoadFloatingItem(Zone zone, FloatingItem floating)
|
||||
{
|
||||
var prefab = floating.Item switch
|
||||
{
|
||||
SimpleCommodity _ => SimpleCommodityPickup,
|
||||
CompoundCommodity _ => CompoundCommodityPickup,
|
||||
EquippableItem equippableItem when ItemManager.GetData(equippableItem) is WeaponItemData => WeaponPickup,
|
||||
EquippableItem _ => GearPickup,
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
var pickup = Instantiate(prefab, ZoneRoot);
|
||||
pickup.Bind(zone, floating);
|
||||
pickup.ScanLabel.text = ItemManager.Title(floating.Item);
|
||||
if (floating.Item is CraftedItemInstance craftedItemInstance)
|
||||
{
|
||||
var c = ItemManager.GetTier(craftedItemInstance).tier.Color.ToColor();
|
||||
c.a = 0;
|
||||
pickup.ScanLabel.color = c;
|
||||
}
|
||||
else pickup.ScanLabel.color = new Color(.75f, .75f, .75f, 0);
|
||||
_floatingItems.Add(floating, pickup);
|
||||
}
|
||||
|
||||
private void LoadCloud(Zone zone, VapourCloud cloud)
|
||||
{
|
||||
var instance = Instantiate(CloudPrefab);
|
||||
|
|
@ -312,9 +344,9 @@ public class ZoneRenderer : MonoBehaviour
|
|||
if (instance) Destroy(instance.gameObject);
|
||||
_clouds.Clear();
|
||||
|
||||
foreach(var gridObject in _loot)
|
||||
if(gridObject) Destroy(gridObject.gameObject);
|
||||
_loot.Clear();
|
||||
foreach (var pickup in _floatingItems.Values)
|
||||
if (pickup) Destroy(pickup.gameObject);
|
||||
_floatingItems.Clear();
|
||||
|
||||
foreach (var entity in Zone.Entities)
|
||||
{
|
||||
|
|
@ -487,7 +519,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
void Update()
|
||||
{
|
||||
var maxDepth = 0f;
|
||||
foreach (var loot in _loot)
|
||||
foreach (var loot in _floatingItems.Values)
|
||||
{
|
||||
loot.ViewOrigin = PerspectiveEntity.Position;
|
||||
loot.ViewDirection = PerspectiveEntity.Aim;
|
||||
|
|
@ -603,41 +635,6 @@ public class ZoneRenderer : MonoBehaviour
|
|||
// MinimapGravityQuad.transform.position = gravPos;
|
||||
// MinimapTintQuad.transform.position = gravPos - Vector3.up*10;
|
||||
}
|
||||
|
||||
public void DestroyLoot(ItemPickup loot)
|
||||
{
|
||||
_loot.Remove(loot);
|
||||
}
|
||||
|
||||
public void DropItem(Vector3 position, Vector3 velocity, ItemInstance item)
|
||||
{
|
||||
var gridObject = item switch
|
||||
{
|
||||
SimpleCommodity _ => Instantiate(SimpleCommodityPickup),
|
||||
CompoundCommodity _ => Instantiate(CompoundCommodityPickup),
|
||||
EquippableItem equippableItem when ItemManager.GetData(equippableItem) is WeaponItemData => Instantiate(WeaponPickup),
|
||||
EquippableItem _ => Instantiate(GearPickup),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
var t = gridObject.transform;
|
||||
t.parent = ZoneRoot;
|
||||
gridObject.Zone = Zone;
|
||||
t.position = position;
|
||||
gridObject.Velocity = velocity;
|
||||
var itemPickup = gridObject.gameObject.GetComponent<ItemPickup>();
|
||||
itemPickup.Item = item;
|
||||
itemPickup.ZoneRenderer = this;
|
||||
itemPickup.ScanLabel.text = ItemManager.Title(item);
|
||||
if (item is CraftedItemInstance craftedItemInstance)
|
||||
{
|
||||
var c = ItemManager.GetTier(craftedItemInstance).tier.Color.ToColor();
|
||||
c.a = 0;
|
||||
itemPickup.ScanLabel.color = c;
|
||||
}
|
||||
else itemPickup.ScanLabel.color = new Color(.75f, .75f, .75f, 0);
|
||||
gridObject.gameObject.AddComponent<TimedDestroy>().Duration = Settings.PickupLifetime;
|
||||
_loot.Add(itemPickup);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue