using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Gameplay.Common.Attri; namespace Gameplay.Unit.Data { using Framework; using Gameplay.Level; using UnityEngine; public class UnitTransData { public readonly GameUnit owner; [HideFightDebug] private bool _isTransChanged = false; public bool isTransChanged { get { return _isTransChanged; } } [HideFightDebug] private bool _isCellChanged = false; public bool isCellChanged { get { return _isCellChanged; } } [HideFightDebug] private Vector3 _pos; public Vector3 pos { get { return _pos; } set { _SetPos(value); } } [HideFightDebug] private Quaternion _rot; public Quaternion rot { get { return _rot; } } [HideFightDebug] private float _yaw; public float yaw { get { return _yaw; } set { _SetYaw(value); } } public int cellIndex { [FightDebug("当前格子索引")] get; private set; } public int lastCellIndex { [HideFightDebug] get; private set; } [HideFightDebug] 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); } } } private static int _GetCellIndex(Vector3 pos) { var map = LevelManager.Instance.CurrentLevel.Map; if (map == null) return -1; if (map.WorldPosition2TGSCellIndex(pos, out int searchIndex)) { return searchIndex; } DebugUtil.LogError("地图pos越界:{0}", pos); return -2; } public void Reset() { _isTransChanged = false; _isCellChanged = false; } } }