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

32 lines
907 B
C#
Raw Normal View History

2023-06-08 14:09:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace BITKit.WorldChunk
{
public class WorldChunkManager : MonoBehaviour
{
public Vector2Int playerSize;
2023-11-21 18:05:18 +08:00
private Rect playerRect;
private void FixedUpdate()
2023-06-08 14:09:50 +08:00
{
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);
}
2023-11-21 18:05:18 +08:00
private void OnUpdate()
2023-06-08 14:09:50 +08:00
{
2023-11-21 18:05:18 +08:00
foreach (var x in WorldChunk.ChunksArray)
2023-06-08 14:09:50 +08:00
{
var isOverlay = playerRect.Overlaps(x.GetRect());
x.SetActive(isOverlay);
2023-11-21 18:05:18 +08:00
}
2023-06-08 14:09:50 +08:00
}
}
}