Add matter spawn range
This commit is contained in:
@@ -136,6 +136,13 @@ namespace PerfectWorld.Scripts.Managers
|
||||
|
||||
private void SpawnMatterCube(int matterId)
|
||||
{
|
||||
// Check if matter is within 1000 units of the host player
|
||||
if (!IsMatterWithinPlayerRange(matterId, 10000f))
|
||||
{
|
||||
Debug.Log($"Matter {matterId} is too far from player, skipping spawn");
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the pickupItem component in the scene and create cube for this specific matter
|
||||
pickupItem pickupScript = UnityEngine.Object.FindFirstObjectByType<pickupItem>();
|
||||
if (pickupScript != null)
|
||||
@@ -150,6 +157,13 @@ namespace PerfectWorld.Scripts.Managers
|
||||
|
||||
private void NotifyPickupItem(int matterId)
|
||||
{
|
||||
// Check if matter is within 1000 units of the host player
|
||||
if (!IsMatterWithinPlayerRange(matterId, 1000f))
|
||||
{
|
||||
Debug.Log($"Matter {matterId} is too far from player, skipping notification");
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the pickupItem component in the scene and update cubes
|
||||
pickupItem pickupScript = UnityEngine.Object.FindFirstObjectByType<pickupItem>();
|
||||
if (pickupScript != null)
|
||||
@@ -157,6 +171,43 @@ namespace PerfectWorld.Scripts.Managers
|
||||
pickupScript.UpdateMatterCubes();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a matter is within the specified distance from the host player
|
||||
/// </summary>
|
||||
/// <param name="matterId">The matter ID to check</param>
|
||||
/// <param name="maxDistance">Maximum distance in Unity units</param>
|
||||
/// <returns>True if matter is within range, false otherwise</returns>
|
||||
private bool IsMatterWithinPlayerRange(int matterId, float maxDistance)
|
||||
{
|
||||
// Get the matter data
|
||||
if (!matterDataStorage.TryGetValue(matterId, out info_matter matterData))
|
||||
{
|
||||
Debug.LogWarning($"Matter data not found for ID: {matterId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the host player
|
||||
var hostPlayer = GameController.Instance?.GetHostPlayer();
|
||||
if (hostPlayer == null)
|
||||
{
|
||||
Debug.LogWarning("Host player not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert matter position to Unity Vector3
|
||||
Vector3 matterPosition = new Vector3(matterData.pos.x, matterData.pos.y, matterData.pos.z);
|
||||
|
||||
// Get player position
|
||||
Vector3 playerPosition = hostPlayer.transform.position;
|
||||
|
||||
// Calculate distance
|
||||
float distance = Vector3.Distance(matterPosition, playerPosition);
|
||||
|
||||
Debug.Log($"Matter {matterId} distance from player: {distance:F2} units (max: {maxDistance})");
|
||||
|
||||
return distance <= maxDistance;
|
||||
}
|
||||
|
||||
// Public methods for players to access matter data
|
||||
public info_matter? GetMatterData(int matterId)
|
||||
|
||||
Reference in New Issue
Block a user