BITFALL/Assets/BITKit/Unity/Scripts/WorldChunk/WorldChunkManager.cs

32 lines
907 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace BITKit.WorldChunk
{
public class WorldChunkManager : MonoBehaviour
{
public Vector2Int playerSize;
private Rect playerRect;
private void FixedUpdate()
{
var cameraPos = Camera.main.transform.position;
Vector2 position = new()
{
x = cameraPos.x - playerSize.x / 2,
y = cameraPos.z - playerSize.y / 2,
};
playerRect = new(position, playerSize);
OnUpdate();
//ThreadHelper.Add(OnUpdate);
}
private void OnUpdate()
{
foreach (var x in WorldChunk.ChunksArray)
{
var isOverlay = playerRect.Overlaps(x.GetRect());
x.SetActive(isOverlay);
}
}
}
}