This commit is contained in:
2026-09-28 16:11:10 +02:00
parent fb630e5a7a
commit b0c6111d57
5 changed files with 92 additions and 8 deletions
+15 -1
View File
@@ -32,6 +32,8 @@ public sealed class PortalServerGrid : MonoBehaviour
private bool rebuild;
private readonly Dictionary<Material, Material> curvedMaterials = new Dictionary<Material, Material>();
private readonly List<Transform> servers = new List<Transform>();
private readonly List<Collider> colliders = new List<Collider>();
private bool collidersEnabled = true;
private float wrapExtent;
// Distance between the centres of two repeated server clusters.
public float RepetitionPeriod => wrapExtent * 2;
@@ -63,6 +65,8 @@ public sealed class PortalServerGrid : MonoBehaviour
if (!meadow) meadow = GetComponent<PortalMeadow>();
if (!meadow) return;
SyncBend();
// Servers are invisible until the player crossed the portal, so they only block once the meadow follows the player.
SetCollidersEnabled(!meadow.Endless || meadow.Following);
if (!rebuild && lastSize == meadow.Size && lastCenter == meadow.Center && lastEndless == meadow.Endless) return;
rebuild = false;
lastSize = meadow.Size;
@@ -77,7 +81,7 @@ public sealed class PortalServerGrid : MonoBehaviour
}
private void LateUpdate()
{
if (!meadow || !meadow.Following || wrapExtent <= 0) return;
if (!meadow || !meadow.Endless || wrapExtent <= 0) return;
Vector3 centre = meadow.SurfaceCenter;
float period = wrapExtent * 2;
foreach (Transform server in servers)
@@ -89,6 +93,12 @@ public sealed class PortalServerGrid : MonoBehaviour
server.localPosition = p;
}
}
private void SetCollidersEnabled(bool enabled)
{
if (collidersEnabled == enabled) return;
collidersEnabled = enabled;
foreach (Collider collider in colliders) if (collider) collider.enabled = enabled;
}
[ContextMenu("Regenerate server rings")]
private void Regenerate() { rebuild = true; }
@@ -104,6 +114,7 @@ public sealed class PortalServerGrid : MonoBehaviour
foreach (Material material in curvedMaterials.Values) if (material) Release(material);
curvedMaterials.Clear();
servers.Clear();
colliders.Clear();
}
private GameObject CreateServer()
{
@@ -182,6 +193,9 @@ public sealed class PortalServerGrid : MonoBehaviour
servers.Add(server.transform);
}
if (count == 0) { Clear(); return; }
colliders.AddRange(generated.GetComponentsInChildren<Collider>(true));
collidersEnabled = true; // As instantiated from the prefab.
SetCollidersEnabled(!meadow.Endless || meadow.Following);
SyncBend();
generated.SetActive(true);
}