지하 최적화
블록 프리팹 단위 -> 블록 청크 단위 스폰 기타 건설, 조준 관련 사이드이펙트 버그 수정
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
/// <summary>
|
||||
/// Mining behavior for pickaxes and similar tools.
|
||||
/// Supports both legacy MineableBlock and new chunk-based MineableChunk.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Items/Behaviors/Mining Behavior")]
|
||||
public class MiningBehavior : ItemBehavior
|
||||
@@ -27,7 +28,25 @@ public class MiningBehavior : ItemBehavior
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
// Use IDamageable interface for all damageable objects
|
||||
// Try chunk-based mining first (new system)
|
||||
if (target.TryGetComponent<MineableChunk>(out var chunk))
|
||||
{
|
||||
// Get the specific block index from PlayerNetworkController
|
||||
var playerController = user.GetComponent<PlayerNetworkController>();
|
||||
if (playerController != null)
|
||||
{
|
||||
var chunkTarget = playerController.GetCurrentChunkTarget();
|
||||
if (chunkTarget.hasHit && chunkTarget.chunk == chunk)
|
||||
{
|
||||
// Damage the specific block within the chunk
|
||||
chunk.DamageBlockServerRpc(chunkTarget.blockIndex, (byte)Mathf.Min(255, damage));
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback to legacy IDamageable interface
|
||||
if (target.TryGetComponent<IDamageable>(out var damageable))
|
||||
{
|
||||
damageable.TakeDamage(new DamageInfo(damage, DamageType.Mining, user));
|
||||
@@ -37,8 +56,15 @@ public class MiningBehavior : ItemBehavior
|
||||
public override string GetBlockedReason(GameObject user, GameObject target)
|
||||
{
|
||||
if (target == null) return "No target";
|
||||
|
||||
// Check for chunk
|
||||
if (target.TryGetComponent<MineableChunk>(out _))
|
||||
return null; // Chunks are always mineable
|
||||
|
||||
// Check for legacy damageable
|
||||
if (!target.TryGetComponent<IDamageable>(out _))
|
||||
return "Cannot mine this object";
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user