This commit is contained in:
CortexCore
2023-06-05 16:25:06 +08:00
parent 9027120bb8
commit 4565ff2e35
2947 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
{
"name": "BITKit.WorkdChunk",
"rootNamespace": "",
"references": [
"GUID:a209c53514018594f9f482516f2a6781",
"GUID:14fe60d984bf9f84eac55c6ea033a8f4"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.WorldChunk
{
public interface IWorldChunk
{
Rect GetRect();
void SetActive(bool active);
}
public abstract class WorldChunk : MonoBehaviour, IWorldChunk
{
public static readonly List<IWorldChunk> chunks=new();
public abstract Rect GetRect();
public abstract void SetActive(bool active);
void OnEnable()
{
chunks.Add(this);
}
void OnDisable()
{
chunks.Remove(this);
}
}
}

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace BITKit.WorldChunk
{
public class ObjectChunk : WorldChunk
{
public Vector2 size;
public Renderer[] renderers;
Vector2 posCenter
{
get
{
var pos = transform.position;
return new()
{
x = pos.x,
y = pos.z,
};
}
}
public override Rect GetRect()
{
return new()
{
position = posCenter,
size = size,
};
}
public override void SetActive(bool active)
{
renderers.ForEach(x =>
{
x.enabled = active;
});
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.WorldChunk
{
public class TerrainChunk : WorldChunk
{
public Terrain terrain;
public override Rect GetRect()
{
Vector3 size = terrain.terrainData.size;
return new(transform.position, size);
}
public override void SetActive(bool active)
{
terrain.enabled = active;
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace BITKit.WorldChunk
{
public class WorldChunkManager : MonoBehaviour
{
public Vector2Int playerSize;
Rect playerRect;
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);
}
void OnUpdate()
{
WorldChunk.chunks.ForEach(x =>
{
var isOverlay = playerRect.Overlaps(x.GetRect());
x.SetActive(isOverlay);
});
}
}
}