49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using Sasalka;
|
|
|
|
public sealed class WorlModelClothSpawner : Component
|
|
{
|
|
[Property] public GameObject Prefab { get; set; }
|
|
[Property] public float Spacing { get; set; } = 50.0f;
|
|
[Property] public float Height { get; set; } = 0.0f;
|
|
|
|
protected override void OnStart()
|
|
{
|
|
if ( !Networking.IsHost ) return;
|
|
|
|
var definitions = ResourceLibrary.GetAll<ClothingItemDefinition>();
|
|
var clothingItemDefinitions = definitions.ToList();
|
|
int total = clothingItemDefinitions.Count();
|
|
|
|
if ( total == 0 )
|
|
{
|
|
Log.Warning( "No clothing definitions found." );
|
|
return;
|
|
}
|
|
|
|
// Вычисляем размер стороны квадрата
|
|
int itemsPerSide = 10; //Math.CeilToInt( Mathf.Sqrt( total ) );
|
|
float halfSize = (itemsPerSide - 1) * Spacing * 0.5f;
|
|
|
|
Log.Info( $"Spawning {total} items in {itemsPerSide}x{itemsPerSide} square grid" );
|
|
|
|
for ( int i = 0; i < total; i++ )
|
|
{
|
|
// Вычисляем позицию в сетке
|
|
int row = i / itemsPerSide;
|
|
int col = i % itemsPerSide;
|
|
|
|
float x = col * Spacing - halfSize;
|
|
float y = row * Spacing - halfSize;
|
|
|
|
Vector3 pos = WorldPosition + new Vector3( x, y, Height );
|
|
|
|
var gO = Prefab.Clone( pos );
|
|
gO.NetworkSpawn( null );
|
|
|
|
var item = gO.Components.Get<InventoryItem>();
|
|
if ( item is not null )
|
|
item.Definition = clothingItemDefinitions[i];
|
|
}
|
|
}
|
|
}
|