(client) feat:实现掉落物,UI显示,维度

This commit is contained in:
m0_75251201
2025-08-27 13:56:22 +08:00
parent f04c89046b
commit 0c99e2beee
46 changed files with 6150 additions and 1809 deletions

View File

@ -4,7 +4,6 @@ using System.Linq;
using Base;
using Data;
using Entity;
using Map;
using Prefab;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -46,11 +45,12 @@ namespace Managers
/// <summary> 子弹实体的预制体。 </summary>
public EntityPrefab bulletPrefab;
public EntityPrefab pickupPrefab;
/// <summary> 默认实体的预制体,用于生成失败时的回退。 </summary>
public EntityPrefab defaultEntityPrefab;
// 已移除RegisterDimension 和 UnregisterDimension 方法的相关注释,因为这些方法已不存在且与逻辑无关。
/// <summary>
/// 在指定维度中,根据派系键查找所有实体。
@ -238,7 +238,7 @@ namespace Managers
string dimensionId,
GameObject prefab,
Vector3 pos,
Data.EntityDef def,
EntityDef def,
Action<EntityPrefab> extraInit = null)
{
// 验证维度是否活跃 (通过 Program)。
@ -277,7 +277,7 @@ namespace Managers
_pendingAdditions.Add(Tuple.Create(dimensionId, factionKey, entityComponent));
return entityComponent;
}
catch (System.Exception ex)
catch (Exception ex)
{
if (instantiatedEntity) Destroy(instantiatedEntity);
Debug.LogError($"实体管理器:在维度 '{dimensionId}' 中生成实体失败:{ex.Message}\n{ex.StackTrace}");
@ -345,7 +345,7 @@ namespace Managers
/// <param name="dimensionId">实体所属的维度ID。</param>
/// <param name="entityDef">实体定义对象。</param>
/// <param name="pos">生成位置。</param>
public void GenerateEntity(string dimensionId, Data.EntityDef entityDef, Vector3 pos)
public void GenerateEntity(string dimensionId, EntityDef entityDef, Vector3 pos)
{
if (!characterPrefab)
{
@ -376,7 +376,7 @@ namespace Managers
/// <param name="dimensionId">实体所属的维度ID。</param>
/// <param name="buildingDef">建筑定义对象。</param>
/// <param name="pos">网格位置。</param>
public void GenerateBuildingEntity(string dimensionId, Data.BuildingDef buildingDef, Vector3Int pos)
public void GenerateBuildingEntity(string dimensionId, BuildingDef buildingDef, Vector3Int pos)
{
if (!buildingPrefab)
{
@ -410,7 +410,7 @@ namespace Managers
/// <param name="pos">生成位置。</param>
/// <param name="dir">子弹的初始方向。</param>
/// <param name="source">发射子弹的源实体。</param>
public void GenerateBulletEntity(string dimensionId, Data.BulletDef bulletDef, Vector3 pos, Vector3 dir,
public void GenerateBulletEntity(string dimensionId, BulletDef bulletDef, Vector3 pos, Vector3 dir,
Entity.Entity source = null)
{
if (!bulletPrefab)
@ -453,7 +453,27 @@ namespace Managers
if (result == null) GenerateDefaultEntity(dimensionId, pos);
}
public void GeneratePickupEntity(string dimensionId, ItemDef itemDef, Vector3 pos)
{
if (!pickupPrefab)
{
Debug.LogError("实体管理器pickupPrefab 为空!请分配一个有效的预制体。");
GenerateDefaultEntity(dimensionId, pos);
return;
}
if (itemDef == null)
{
Debug.LogError("实体管理器itemDef 为空!无法生成子弹。");
GenerateDefaultEntity(dimensionId, pos);
return;
}
var result=Instantiate(pickupPrefab, pos, Quaternion.identity);
var pickup = result.GetComponent<Pickup>();
pickup.Init(itemDef);
if (result == null) GenerateDefaultEntity(dimensionId, pos);
}
/// <summary>
/// 在指定维度和位置生成一个默认实体(通常作为回退选项)。
/// </summary>
@ -616,7 +636,7 @@ namespace Managers
// 关系判断:判断当前实体与源实体是否为“敌对”关系。
if (affiliationManager.GetRelation(sourceEntityPrefab.entity, currentEntityPrefab.entity) ==
Data.Relation.Hostile)
Relation.Hostile)
{
return true; // 找到第一个敌对实体即返回 true提高效率。
}
@ -682,7 +702,7 @@ namespace Managers
// 关系判断:判断当前实体与源实体是否为“敌对”关系。
if (affiliationManager.GetRelation(sourceEntityPrefab.entity, currentEntityPrefab.entity) ==
Data.Relation.Hostile)
Relation.Hostile)
{
// 距离判断:如果关系敌对,进一步判断其是否在视野范围内。
var distanceSqr = Vector3.SqrMagnitude(currentEntityPrefab.transform.position - sourcePos);