Init Homebase
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6928b42621b979b478f0ae236c575df8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Entities;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Authoring
|
||||
{
|
||||
/// <summary>
|
||||
/// Authoring for the baked <see cref="BaseAnchor"/> singleton — the shared home base's fixed anchor
|
||||
/// and planar build-grid coordinate space. Place once in the gameplay subscene; the GameObject's
|
||||
/// position is the plot center (and the player spawn-ring center). The baker derives GridOrigin (the
|
||||
/// min-XZ corner of cell (0,0)) so the plot is centered on the anchor. The entity carries no transform
|
||||
/// (TransformUsageFlags.None) — the position is baked as flat data. Present identically on client and
|
||||
/// server (baked, not replicated). Draws the plot footprint as an editor gizmo when selected.
|
||||
/// </summary>
|
||||
public class BaseAnchorAuthoring : MonoBehaviour
|
||||
{
|
||||
[Min(0.01f)]
|
||||
[Tooltip("World-unit size of one square build-grid cell.")]
|
||||
public float CellSize = 1f;
|
||||
|
||||
[Min(1)]
|
||||
[Tooltip("Build-grid extent in cells along X and Z (square plot).")]
|
||||
public int PlotSize = 32;
|
||||
|
||||
private class BaseAnchorBaker : Baker<BaseAnchorAuthoring>
|
||||
{
|
||||
public override void Bake(BaseAnchorAuthoring authoring)
|
||||
{
|
||||
// Data singleton: no transform on the entity, but we read the GameObject position as data.
|
||||
var entity = GetEntity(authoring, TransformUsageFlags.None);
|
||||
|
||||
float3 anchorPos = authoring.transform.position;
|
||||
var dims = new int2(authoring.PlotSize, authoring.PlotSize);
|
||||
float cell = authoring.CellSize;
|
||||
var gridOrigin = new float3(
|
||||
anchorPos.x - dims.x * cell * 0.5f,
|
||||
anchorPos.y,
|
||||
anchorPos.z - dims.y * cell * 0.5f);
|
||||
|
||||
AddComponent(entity, new BaseAnchor
|
||||
{
|
||||
AnchorPos = anchorPos,
|
||||
GridOrigin = gridOrigin,
|
||||
CellSize = cell,
|
||||
GridDims = dims,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Editor-only footprint gizmo: draws the claimed plot bounds on the base plane when selected.
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
float extent = CellSize * PlotSize;
|
||||
Gizmos.color = new Color(0.2f, 0.8f, 1f, 0.9f);
|
||||
Gizmos.DrawWireCube(transform.position, new Vector3(extent, 0.05f, extent));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b53184727e358b4eb27f68ae25504d8
|
||||
@@ -0,0 +1,32 @@
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Authoring
|
||||
{
|
||||
/// <summary>
|
||||
/// Authoring for the shared storage-container ghost prefab: an ownerless INTERPOLATED ghost whose
|
||||
/// replicated <see cref="StorageEntry"/> buffer is the shared inventory any player deposits into /
|
||||
/// withdraws from (server-authoritative, applied by StorageOpReceiveSystem). Add a
|
||||
/// GhostAuthoringComponent (Interpolated) to the prefab so clients see its contents replicate.
|
||||
/// <c>GetEntity(TransformUsageFlags.Dynamic)</c> gives it a runtime world transform, set at spawn to
|
||||
/// the base cell center.
|
||||
/// </summary>
|
||||
public class SharedStorageContainerAuthoring : MonoBehaviour
|
||||
{
|
||||
[Min(0f)]
|
||||
[Tooltip("Interaction radius (world units) for the deposit/withdraw test; reserved for proximity gating.")]
|
||||
public float InteractRadius = 2f;
|
||||
|
||||
private class SharedStorageContainerBaker : Baker<SharedStorageContainerAuthoring>
|
||||
{
|
||||
public override void Bake(SharedStorageContainerAuthoring authoring)
|
||||
{
|
||||
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
|
||||
AddComponent<SharedStorageContainer>(entity);
|
||||
AddComponent(entity, new HitRadius { Value = authoring.InteractRadius });
|
||||
AddBuffer<StorageEntry>(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cc6285a9b8958a47a61a07550b7f792
|
||||
@@ -0,0 +1,38 @@
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Entities;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Authoring
|
||||
{
|
||||
/// <summary>
|
||||
/// Authoring for the baked <see cref="StorageSpawner"/> singleton (mirrors UpgradePickupSpawnerAuthoring).
|
||||
/// Place once in the gameplay subscene; the server-only SharedStorageSpawnSystem reads it, instantiates
|
||||
/// the storage-container ghost at the base-grid cell center (BaseGridMath.CellToWorld), then destroys
|
||||
/// the singleton so it fires exactly once. The entity carries no transform; only the prefab needs one.
|
||||
/// </summary>
|
||||
public class StorageSpawnerAuthoring : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Storage-container ghost prefab to instantiate. Must carry SharedStorageContainerAuthoring + a GhostAuthoringComponent.")]
|
||||
public GameObject ContainerPrefab;
|
||||
|
||||
[Tooltip("Build-grid cell at which to place the container (cell center, on the base plane).")]
|
||||
public Vector2Int Cell = new Vector2Int(16, 22);
|
||||
|
||||
private class StorageSpawnerBaker : Baker<StorageSpawnerAuthoring>
|
||||
{
|
||||
public override void Bake(StorageSpawnerAuthoring authoring)
|
||||
{
|
||||
var entity = GetEntity(authoring, TransformUsageFlags.None);
|
||||
|
||||
AddComponent(entity, new StorageSpawner
|
||||
{
|
||||
Prefab = authoring.ContainerPrefab != null
|
||||
? GetEntity(authoring.ContainerPrefab, TransformUsageFlags.Dynamic)
|
||||
: Entity.Null,
|
||||
Cell = new int2(authoring.Cell.x, authoring.Cell.y),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 968b8c85b6f69ae438e56cb1f19a2450
|
||||
Reference in New Issue
Block a user