using System.Collections.Generic;
using Fantasy;
using Fantasy.Async;
using NBC;
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using Unity.Mathematics;
using UnityEngine;
namespace NBF.Fishing2
{
///
/// 单位
///
public class MapUnit : Entity
{
public int ConfigId { get; set; } //配置表id
///
/// 钓组信息
///
public List Gears = new List();
///
/// 是否在地面
///
public bool IsGrounded { get; set; }
///
/// 是否在水里
///
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
{
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();
var unitBasic = GetOrAddComponent();
unitBasic.UpdateInfo(unitInfo);
// unitInfo.Gears
var numericComponent = GetOrAddComponent();
foreach (var kv in unitInfo.Propertys)
{
numericComponent.Set(kv.Key, kv.Value);
}
}
#region View
public async FTask CreateView()
{
var unitUnity = GetComponent();
if (unitUnity != null)
{
unitUnity.Dispose();
}
unitUnity = AddComponent();
await unitUnity.InitUnityObject();
}
#endregion
}
}