角色预制体创建

This commit is contained in:
2025-09-03 00:15:43 +08:00
parent 48f608e534
commit 186fec4472
100 changed files with 1025 additions and 349 deletions

View File

@@ -0,0 +1,85 @@
using NBC;
using NBC.Entitas;
using Unity.Mathematics;
namespace NBF.Fishing2
{
/// <summary>
/// 单位
/// </summary>
public class MapUnit : Entity
{
public int ConfigId { get; set; } //配置表id
private float3 position; //坐标
public float3 Position
{
get => position;
set
{
float3 oldPos = position;
position = value;
Scene.EventComponent.Publish(new ChangePosition() { MapUnit = this, OldPos = oldPos });
}
}
public float3 Forward
{
get => math.mul(Rotation, math.forward());
set => Rotation = quaternion.LookRotation(value, math.up());
}
private quaternion rotation;
public quaternion Rotation
{
get => rotation;
set
{
rotation = value;
Scene.EventComponent.Publish(new ChangeRotation() { MapUnit = this });
}
}
public uint State { get; set; }
public string StateArgs { get; set; }
public void ChangeState(uint state, string args)
{
Scene.EventComponent.Publish(new ChangeState() { MapUnit = this, State = state, Args = args });
}
#region
public static MapUnit Create(Map map, MapUnitInfo unitInfo, bool isMainPlayer = false)
{
var unit = Entity.Create<MapUnit>(map.Scene, true, true);
unit.SetUnitInfo(unitInfo);
return null;
}
#endregion
public void SetUnitInfo(MapUnitInfo unitInfo)
{
NumericComponent numericComponent = AddComponent<NumericComponent>();
foreach (var kv in unitInfo.KV)
{
numericComponent.Set(kv.Key, kv.Value);
}
}
public UnitConfig Config()
{
return UnitConfig.Get(ConfigId);
}
public UnitType UnitType()
{
return Config().Type;
}
}
}