mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-10 16:14:45 +00:00
fake sectors: much work, shapes have to be done manually :(
This commit is contained in:
parent
46a7f6aa3e
commit
17098e1c1e
@ -8,14 +8,13 @@ namespace QSB.SectorSync;
|
||||
|
||||
public class FakeSector : Sector
|
||||
{
|
||||
public float Radius;
|
||||
|
||||
public static void CreateOn(GameObject go, float radius, Sector parent)
|
||||
public static void Create<T>(GameObject go, Sector parent, Action<T> initShape)
|
||||
where T : Shape
|
||||
{
|
||||
var name = $"{go.name}_FakeSector";
|
||||
var name = $"FakeSector_{go.name}";
|
||||
if (go.transform.Find(name))
|
||||
{
|
||||
DebugLog.DebugWrite($"fake sector {name} already exists", MessageType.Warning);
|
||||
DebugLog.DebugWrite($"{name} already exists", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -24,13 +23,13 @@ public class FakeSector : Sector
|
||||
go2.transform.SetParent(go.transform, false);
|
||||
|
||||
var fakeSector = go2.AddComponent<FakeSector>();
|
||||
fakeSector._name = (Name)(-1);
|
||||
fakeSector._subsectors = new List<Sector>();
|
||||
fakeSector.Radius = radius;
|
||||
fakeSector.SetParentSector(parent);
|
||||
|
||||
go2.AddComponent<OWTriggerVolume>();
|
||||
go2.AddComponent<SphereShape>().radius = fakeSector.Radius;
|
||||
// go2.AddComponent<DebugRenderer>().FakeSector = fakeSector;
|
||||
initShape(go2.AddComponent<T>());
|
||||
go2.AddComponent<DebugRenderer>().FS = fakeSector;
|
||||
|
||||
go2.SetActive(true);
|
||||
}
|
||||
@ -38,7 +37,7 @@ public class FakeSector : Sector
|
||||
private class DebugRenderer : MonoBehaviour
|
||||
{
|
||||
[NonSerialized]
|
||||
public FakeSector FakeSector;
|
||||
public FakeSector FS;
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
@ -47,7 +46,17 @@ public class FakeSector : Sector
|
||||
return;
|
||||
}
|
||||
|
||||
Popcron.Gizmos.Sphere(FakeSector.transform.position, FakeSector.Radius, Color.yellow);
|
||||
var shape = FS._owTriggerVolume._shape;
|
||||
var center = shape.GetWorldSpaceCenter();
|
||||
switch (shape)
|
||||
{
|
||||
case SphereShape sphereShape:
|
||||
Popcron.Gizmos.Sphere(center, sphereShape.radius, Color.yellow);
|
||||
break;
|
||||
case BoxShape boxShape:
|
||||
Popcron.Gizmos.Cube(center, boxShape.transform.rotation, boxShape.size, Color.yellow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
@ -58,9 +67,7 @@ public class FakeSector : Sector
|
||||
return;
|
||||
}
|
||||
|
||||
DebugGUI.DrawLabel(FakeSector.transform,
|
||||
$"{FakeSector.name}\n" +
|
||||
$"{FakeSector._parentSector.name} | {FakeSector.Radius}");
|
||||
DebugGUI.DrawLabel(FS.transform, FS.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,10 @@ public class QSBSectorDetector : MonoBehaviour
|
||||
if (validSectors.Count == 0)
|
||||
{
|
||||
validSectors = QSBWorldSync.GetWorldObjects<QSBSector>()
|
||||
.Where(x => x.ShouldSyncTo(type))
|
||||
.Where(x =>
|
||||
// we only wanna sync to the major ones when far away
|
||||
x.Type != Sector.Name.Unnamed &&
|
||||
x.ShouldSyncTo(type))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class QSBSectorManager : WorldObjectManager
|
||||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
|
||||
{
|
||||
DebugLog.DebugWrite("Building sectors...", MessageType.Info);
|
||||
await CreateFakeSectors(ct);
|
||||
await this.Try("creating fake sectors", () => CreateFakeSectors(ct));
|
||||
|
||||
QSBWorldSync.Init<QSBSector, Sector>();
|
||||
_isReady = QSBWorldSync.GetWorldObjects<QSBSector>().Any();
|
||||
@ -89,28 +89,62 @@ public class QSBSectorManager : WorldObjectManager
|
||||
return;
|
||||
}
|
||||
|
||||
var TimeLoopRing_Body = GameObject.Find("TimeLoopRing_Body");
|
||||
var Sector_TimeLoopInterior = GameObject.Find("Sector_TimeLoopInterior").GetComponent<Sector>();
|
||||
// use same radius as parent sector
|
||||
var radius = Sector_TimeLoopInterior.GetTriggerVolume().GetShape().CalcWorldBounds().radius;
|
||||
FakeSector.CreateOn(TimeLoopRing_Body, radius, Sector_TimeLoopInterior);
|
||||
// time loop spinning ring
|
||||
{
|
||||
var TimeLoopRing_Body = GameObject.Find("TimeLoopRing_Body");
|
||||
var Sector_TimeLoopInterior = GameObject.Find("Sector_TimeLoopInterior").GetComponent<Sector>();
|
||||
// use same shape as parent sector
|
||||
var shape = (SphereShape)Sector_TimeLoopInterior.GetTriggerVolume().GetShape();
|
||||
FakeSector.Create<SphereShape>(TimeLoopRing_Body, Sector_TimeLoopInterior,
|
||||
x => x.radius = shape.radius);
|
||||
}
|
||||
|
||||
// th elevators
|
||||
foreach (var elevator in QSBWorldSync.GetUnityObjects<Elevator>())
|
||||
{
|
||||
var colliders = elevator.GetComponentsInChildren<Collider>();
|
||||
await colliders.Select(x =>
|
||||
UniTask.WaitUntil(() => x.bounds.extents != Vector3.zero, cancellationToken: ct));
|
||||
// hack: wait for QSBElevator to the box shape on, and just use that
|
||||
BoxShape shape = null;
|
||||
await UniTask.WaitUntil(() => elevator.TryGetComponent(out shape), cancellationToken: ct);
|
||||
|
||||
static float Size(Collider collider)
|
||||
FakeSector.Create<BoxShape>(elevator.gameObject,
|
||||
elevator.GetComponentInParent<Sector>(),
|
||||
x =>
|
||||
{
|
||||
x.center = shape.center;
|
||||
x.size = shape.size;
|
||||
});
|
||||
}
|
||||
|
||||
// rafts
|
||||
foreach (var raft in QSBWorldSync.GetUnityObjects<RaftController>())
|
||||
{
|
||||
FakeSector.Create<BoxShape>(raft.gameObject,
|
||||
raft._sector,
|
||||
x =>
|
||||
{
|
||||
// todo: figure out a good shape for the raft ride volume
|
||||
x.size = Vector3.one * 10;
|
||||
});
|
||||
}
|
||||
|
||||
// todo cage elevators
|
||||
// todo prisoner elevator
|
||||
|
||||
// OPC probe
|
||||
{
|
||||
var probe = Locator._orbitalProbeCannon
|
||||
.GetRequiredComponent<OrbitalProbeLaunchController>()
|
||||
._probeBody;
|
||||
if (probe)
|
||||
{
|
||||
var extents = collider.bounds.extents;
|
||||
return Mathf.Max(extents.x, extents.y, extents.z);
|
||||
FakeSector.Create<SphereShape>(probe.gameObject,
|
||||
null,
|
||||
x =>
|
||||
{
|
||||
// todo: figure out a good radius for this sector
|
||||
x.radius = 100;
|
||||
});
|
||||
}
|
||||
|
||||
var largestCollider = colliders.MaxBy(Size);
|
||||
FakeSector.CreateOn(largestCollider.gameObject,
|
||||
Size(largestCollider),
|
||||
largestCollider.GetComponentInParent<Sector>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.SectorSync.WorldObjects;
|
||||
|
||||
public class QSBSector : WorldObject<Sector>
|
||||
{
|
||||
private Sector.Name Type => AttachedObject.GetName();
|
||||
public Sector.Name Type => AttachedObject.GetName();
|
||||
public Transform Transform
|
||||
{
|
||||
get
|
||||
@ -90,11 +90,6 @@ public class QSBSector : WorldObject<Sector>
|
||||
|
||||
private float GetRadius()
|
||||
{
|
||||
if (AttachedObject is FakeSector fakeSector)
|
||||
{
|
||||
return fakeSector.Radius;
|
||||
}
|
||||
|
||||
// TODO : make this work for other stuff, not just shaped triggervolumes
|
||||
var trigger = AttachedObject.GetTriggerVolume();
|
||||
if (trigger && trigger.GetShape())
|
||||
|
Loading…
x
Reference in New Issue
Block a user