NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Unit/Data/UnitTransData.cs

160 lines
3.5 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-12-07 19:04:49 +08:00
using Gameplay.Common.Attri;
2023-08-22 19:08:45 +08:00
2023-12-13 16:20:41 +08:00
namespace Gameplay.Unit.Data
2023-08-22 19:08:45 +08:00
{
using Framework;
using Gameplay.Level;
using UnityEngine;
public class UnitTransData
{
2023-10-19 15:00:19 +08:00
public readonly GameUnit owner;
2023-08-22 19:08:45 +08:00
public int bornCellIndex;
public int claimCellIndex;
2023-08-22 19:08:45 +08:00
2023-12-07 19:04:49 +08:00
[HideFightDebug]
2023-08-22 19:08:45 +08:00
private bool _isTransChanged = false;
public bool isTransChanged
{
get
{
return _isTransChanged;
}
}
2023-12-07 19:04:49 +08:00
[HideFightDebug]
2023-08-22 19:08:45 +08:00
private bool _isCellChanged = false;
public bool isCellChanged
{
get
{
return _isCellChanged;
}
}
2023-12-07 19:04:49 +08:00
[HideFightDebug]
2023-08-22 19:08:45 +08:00
private Vector3 _pos;
public Vector3 pos
{
get
{
return _pos;
}
set
{
_SetPos(value);
}
}
2023-12-07 19:04:49 +08:00
[HideFightDebug]
2023-08-22 19:08:45 +08:00
private Quaternion _rot;
public Quaternion rot
{
get
{
return _rot;
}
}
2023-12-07 19:04:49 +08:00
[HideFightDebug]
2023-08-22 19:08:45 +08:00
private float _yaw;
public float yaw
{
get
{
return _yaw;
}
set
{
_SetYaw(value);
}
}
public int cellIndex
{
2023-12-07 19:04:49 +08:00
[FightDebug("当前格子索引")]
2023-08-22 19:08:45 +08:00
get;
private set;
}
public int lastCellIndex
{
2023-12-07 19:04:49 +08:00
[HideFightDebug]
2023-08-22 19:08:45 +08:00
get;
private set;
}
2023-12-07 19:04:49 +08:00
[HideFightDebug]
public bool disableEvent
{
get;
set;
}
2023-08-22 19:08:45 +08:00
public UnitTransData(GameUnit unit)
{
owner = unit;
cellIndex = -1;
lastCellIndex = -1;
claimCellIndex = -1;
2023-08-22 19:08:45 +08:00
_pos = Vector3.zero;
_rot = Quaternion.identity;
_yaw = 0;
}
private void _SetYaw(float newYaw)
{
_yaw = newYaw;
_rot = Quaternion.Euler(0, _yaw, 0);
_isTransChanged = true;
}
private void _SetPos(Vector3 newPos)
{
_pos = newPos;
_isTransChanged = true;
var newCellIndex = _GetCellIndex(newPos);
if (newCellIndex != cellIndex)
{
lastCellIndex = cellIndex;
// DebugUtil.LogFormat("player cellIndex 发生改变: old:{0}, new:{1}", cellIndex, newCellIndex);
cellIndex = newCellIndex;
_isCellChanged = true;
if (!disableEvent)
{
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, owner);
}
owner.TriggerCellIndexChange();
2023-08-22 19:08:45 +08:00
}
}
2023-10-19 15:00:19 +08:00
private static int _GetCellIndex(Vector3 pos)
2023-08-22 19:08:45 +08:00
{
var map = LevelManager.Instance.CurrentLevel.Map;
if (map == null) return -1;
if (map.WorldPosition2TGSCellIndex(pos, out int searchIndex))
{
return searchIndex;
}
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("地图pos越界:{0}", pos);
2023-08-22 19:08:45 +08:00
return -2;
}
public void Reset()
{
_isTransChanged = false;
_isCellChanged = false;
}
}
}