2023-08-22 19:08:45 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Gameplay.Common
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool _isTransChanged = false;
|
|
|
|
|
|
public bool isTransChanged
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _isTransChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _isCellChanged = false;
|
|
|
|
|
|
public bool isCellChanged
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _isCellChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Vector3 _pos;
|
|
|
|
|
|
public Vector3 pos
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_SetPos(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Quaternion _rot;
|
|
|
|
|
|
public Quaternion rot
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _rot;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private float _yaw;
|
|
|
|
|
|
public float yaw
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _yaw;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_SetYaw(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int cellIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
private set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int lastCellIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
private set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool disableEvent = false;
|
|
|
|
|
|
|
|
|
|
|
|
public UnitTransData(GameUnit unit)
|
|
|
|
|
|
{
|
|
|
|
|
|
owner = unit;
|
|
|
|
|
|
cellIndex = -1;
|
|
|
|
|
|
lastCellIndex = -1;
|
|
|
|
|
|
_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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|