BITFALL/Assets/BITKit/UnityPluginsSupport/Polaris/PolarisTerrainChunk.cs

48 lines
954 B
C#
Raw Normal View History

2023-11-21 18:05:18 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using Pinwheel.Griffin;
2024-01-03 00:27:12 +08:00
using UnityEditor.Build;
2023-11-21 18:05:18 +08:00
using UnityEngine;
namespace BITKit.WorldChunk
{
public class PolarisTerrainChunk : WorldChunk
{
2024-01-03 00:27:12 +08:00
private GTerrainChunk terrain;
private MeshRenderer meshRenderer;
private bool _isLoaded;
private Rect _rect;
2023-11-21 18:05:18 +08:00
private void Start()
{
2024-01-03 00:27:12 +08:00
terrain = GetComponent<GTerrainChunk>();
meshRenderer = GetComponent<MeshRenderer>();
var bounds = meshRenderer.bounds;
var pos = bounds.center;
var size = bounds.size;
_rect = new Rect(
pos.x,
pos.z,
size.x,
size.y
);
2023-11-21 18:05:18 +08:00
Add(this);
destroyCancellationToken.Register(() => { Remove(this); });
2024-01-03 00:27:12 +08:00
_isLoaded = gameObject.activeSelf;
2023-11-21 18:05:18 +08:00
}
2024-01-03 00:27:12 +08:00
public override Rect GetRect() => _rect;
2023-11-21 18:05:18 +08:00
public override void SetActive(bool active)
{
2024-01-03 00:27:12 +08:00
if (_isLoaded == active) return;
2023-11-21 18:05:18 +08:00
terrain.gameObject.SetActive(active);
2024-01-03 00:27:12 +08:00
_isLoaded = active;
2023-11-21 18:05:18 +08:00
}
}
}