80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using Gameplay.Area;
|
|
using Gameplay.Effect;
|
|
using Gameplay.Unit;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
using Constants = Framework.Constants;
|
|
|
|
namespace Gameplay.Level.Select
|
|
{
|
|
public class SelectView
|
|
{
|
|
|
|
private GameUnit _selectUnit;
|
|
public GameUnit selectUnit => _selectUnit;
|
|
|
|
private EffectPlayingData _circleEffect;
|
|
private Transform _groundTrans;
|
|
|
|
private const int _circleEffectId = 1;
|
|
|
|
private int _lastCellIndex = -1;
|
|
|
|
public void Init()
|
|
{
|
|
_circleEffect = EffectManager.instance.PlayEffectById(_circleEffectId);
|
|
var groundSampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(Constants.CHARACTER_SELECT_GROUND_GFX);
|
|
var groundObj = Object.Instantiate(groundSampleObj);
|
|
_groundTrans = groundObj.transform;
|
|
|
|
_SetActive(false);
|
|
}
|
|
|
|
private void _SetActive(bool active)
|
|
{
|
|
_circleEffect.SetActive(active);
|
|
_groundTrans.gameObject.SetActive(active);
|
|
}
|
|
|
|
public void SetOwner(GameUnit owner)
|
|
{
|
|
if (_selectUnit == owner) return;
|
|
_selectUnit = owner;
|
|
if (_selectUnit == null)
|
|
{
|
|
_SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_SetActive(true);
|
|
LogicUpdate();
|
|
}
|
|
}
|
|
|
|
public void LogicUpdate()
|
|
{
|
|
if (_selectUnit == null) return;
|
|
|
|
// circle 一直跟随
|
|
var pos = _selectUnit.transform.position;
|
|
_circleEffect.transform.position = pos;
|
|
|
|
// ground 按cellindex 跟随
|
|
_UpdateGroundEffect();
|
|
}
|
|
|
|
private void _UpdateGroundEffect()
|
|
{
|
|
var cellIndex = _selectUnit.transData.cellIndex;
|
|
if (cellIndex == _lastCellIndex) return;
|
|
_lastCellIndex = cellIndex;
|
|
var posGround = AreaManager.instance.GetCellPosByIndex(cellIndex);
|
|
_groundTrans.position = posGround;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
}
|