(client) feat:添加设置类,子弹添加敌我识别; chore:修改了右键菜单的初始化方式为独立创建,加载定义报错提供更多信息,动画加载出错也返回默认序列。

This commit is contained in:
m0_75251201
2025-08-19 14:36:22 +08:00
parent f67aca0804
commit f4cd5f4a86
57 changed files with 1000 additions and 788 deletions

View File

@ -2,23 +2,25 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Base;
using Entity;
using Prefab;
using UnityEngine;
using UnityEngine.Serialization;
namespace Managers
{
public class EntityManage : Utils.MonoSingleton<EntityManage>, ITick
{
public Dictionary<string, LinkedList<EntityPrefab>> factionEntities = new();
public EntityPrefab entityPrefab;
public EntityPrefab characterPrefab;
public EntityPrefab buildingPrefab;
public EntityPrefab bulletPrefab;
public EntityPrefab defaultEntityPrefab;
private Dictionary<string, Transform> layerCache = new Dictionary<string, Transform>();
private List<Tuple<string, EntityPrefab>> pendingAdditions;
private List<Tuple<string, EntityPrefab>> pendingAdditions = new();
public LinkedList<EntityPrefab> FindEntitiesByFaction(string factionKey)
{
@ -158,7 +160,7 @@ namespace Managers
public void GenerateEntity(Data.EntityDef entityDef, Vector3 pos)
{
// 验证关键参数
if (!entityPrefab)
if (!characterPrefab)
{
Debug.LogError("entityPrefab is null! Assign a valid prefab.");
GenerateDefaultEntity(pos);
@ -177,7 +179,7 @@ namespace Managers
// 调用通用生成逻辑
var result = GenerateEntityInternal(
entityPrefab.gameObject,
characterPrefab.gameObject,
entityLevelTransform,
pos,
entityDef
@ -224,7 +226,8 @@ namespace Managers
/// <summary>
/// 生成子弹实体(含方向设置)
/// </summary>
public void GenerateBulletEntity(Data.BulletDef bulletDef, Vector3 pos, Vector3 dir)
public void GenerateBulletEntity(Data.BulletDef bulletDef, Vector3 pos, Vector3 dir,
Entity.Entity source = null)
{
// 修正:检查正确的预制体 (bulletPrefab)
if (!bulletPrefab)
@ -252,6 +255,11 @@ namespace Managers
// 子弹特有的方向设置
entityComponent => entityComponent.entity.SetTarget(pos + dir)
);
if (result.entity is Bullet bullet)
{
bullet.bulletSource = source;
if (source) bullet.affiliation = source.affiliation;
}
if (!result) GenerateDefaultEntity(pos);
}