角色预制体创建
This commit is contained in:
85
Assets/Scripts/Fishing2/Unit/MapUnit.cs
Normal file
85
Assets/Scripts/Fishing2/Unit/MapUnit.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user