Files
Fishing2/Assets/Scripts/Fishing2/Unit/MapUnit.cs
2025-12-15 12:30:59 +08:00

114 lines
2.8 KiB
C#

using Fantasy;
using Fantasy.Async;
using NBC;
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using Unity.Mathematics;
using UnityEngine;
namespace NBF.Fishing2
{
/// <summary>
/// 单位
/// </summary>
public class MapUnit : Entity
{
public int ConfigId { get; set; } //配置表id
/// <summary>
/// 是否在地面
/// </summary>
public bool IsGrounded { get; set; }
/// <summary>
/// 是否在水里
/// </summary>
public bool IsInWater { get; set; }
public float Speed { get; set; }
public float RotationSpeed { get; set; }
private Vector3 position; //坐标
public Vector3 Position
{
get => position;
set
{
// Vector3 oldPos = position;
position = value;
// Scene.EventComponent.Publish(new ChangePosition() { MapUnit = this, OldPos = oldPos });
}
}
public Vector3 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 MapUnitState State { get; set; }
public string StateArgs { get; set; }
#region System
public class MapUnitDestroySystem : DestroySystem<MapUnit>
{
protected override void Destroy(MapUnit self)
{
}
}
#endregion
public void ChangeState(MapUnitState state, string args)
{
Scene.EventComponent.Publish(new ChangeState() { MapUnit = this, State = state, Args = args });
}
public void SetUnitInfo(MapUnitInfo unitInfo)
{
GetOrAddComponent<ObjectWait>();
var unitBasic = GetOrAddComponent<MapUnitBasic>();
unitBasic.UpdateInfo(unitInfo);
// unitInfo.Gears
var numericComponent = GetOrAddComponent<NumericComponent>();
foreach (var kv in unitInfo.Propertys)
{
numericComponent.Set(kv.Key, kv.Value);
}
}
#region View
public async FTask CreateView()
{
var unitUnity = GetComponent<UnitUnityComponent>();
if (unitUnity != null)
{
unitUnity.Dispose();
}
unitUnity = AddComponent<UnitUnityComponent>();
await unitUnity.InitUnityObject();
}
#endregion
}
}