fake sector now acts like a real sector

This commit is contained in:
JohnCorby 2022-03-19 22:55:58 -07:00
parent 908bf19114
commit 27a8ff163c
2 changed files with 55 additions and 19 deletions

View File

@ -1,8 +1,51 @@
namespace QSB.SectorSync;
using QSB.Utility;
using System.Collections.Generic;
using UnityEngine;
namespace QSB.SectorSync;
public class FakeSector : Sector
{
public Sector AttachedSector;
public Sector AttachedSector => _parentSector;
public override void Awake() { }
}
public static void CreateOn(GameObject go, Sector parent, float radius)
{
var name = $"{go.name}_FakeSector";
if (go.transform.Find(name))
{
return;
}
var go2 = new GameObject(name);
go2.SetActive(false);
go2.transform.SetParent(go.transform, false);
var fakeSector = go2.AddComponent<FakeSector>();
fakeSector._name = (Name)(-1);
fakeSector._subsectors = new List<Sector>();
fakeSector.SetParentSector(parent);
go2.AddComponent<OWTriggerVolume>();
go2.AddComponent<SphereShape>().radius = radius;
go2.AddComponent<Renderer>().FakeSector = fakeSector;
go2.SetActive(true);
DebugLog.DebugWrite($"fake sector {fakeSector.name} created!\n" +
$"on go {go.name}, parent sector {parent.name}, radius {radius}");
}
private class Renderer : MonoBehaviour
{
public FakeSector FakeSector;
private void OnRenderObject()
{
Popcron.Gizmos.Sphere(transform.position, 1, Color.yellow);
var worldBounds = FakeSector.GetTriggerVolume().GetShape().CalcWorldBounds();
Popcron.Gizmos.Sphere(worldBounds.center, worldBounds.radius, Color.yellow);
}
}
}

View File

@ -46,8 +46,8 @@ public class QSBSectorManager : WorldObjectManager
foreach (var sync in SectoredSyncs)
{
if (sync.hasAuthority
&& sync.IsValid
&& sync.AttachedTransform.gameObject.activeInHierarchy)
&& sync.IsValid
&& sync.AttachedTransform.gameObject.activeInHierarchy)
{
UpdateReferenceSector(sync);
}
@ -76,18 +76,11 @@ public class QSBSectorManager : WorldObjectManager
DebugLog.DebugWrite("Building sectors...", MessageType.Info);
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
{
var timeLoopRing = GameObject.Find("TimeLoopRing_Body");
if (timeLoopRing != null)
{
if (timeLoopRing.GetComponent<FakeSector>() == null)
{
timeLoopRing.AddComponent<FakeSector>().AttachedSector = GameObject.Find("Sector_TimeLoopInterior").GetComponent<Sector>();
}
}
else
{
DebugLog.ToConsole($"Error - TimeLoopRing_Body not found!", MessageType.Error);
}
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, Sector_TimeLoopInterior, radius);
}
QSBWorldSync.Init<QSBSector, Sector>();
@ -96,4 +89,4 @@ public class QSBSectorManager : WorldObjectManager
public override void UnbuildWorldObjects() =>
_isReady = false;
}
}