120 lines
2.9 KiB
C#
120 lines
2.9 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 单位
|
|
/// </summary>
|
|
public class MapUnit : Entity
|
|
{
|
|
public int ConfigId { get; set; } //配置表id
|
|
|
|
/// <summary>
|
|
/// 钓组信息
|
|
/// </summary>
|
|
public List<MapUnitGear> Gears = new List<MapUnitGear>();
|
|
|
|
/// <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
|
|
}
|
|
} |