215 lines
6.6 KiB
C#
215 lines
6.6 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Common;
|
|
using Gameplay.Fight.Protect;
|
|
using Gameplay.Level;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using Gameplay.Vehicle.Impl;
|
|
using Gameplay.Vehicle.State;
|
|
using PhxhSDK;
|
|
using Constants = Framework.Constants;
|
|
|
|
namespace Gameplay.Area
|
|
{
|
|
using UnityEngine;
|
|
using Character;
|
|
|
|
public class RoadLineView
|
|
{
|
|
|
|
public GameObject rootObj;
|
|
|
|
public GameUnit owner;
|
|
|
|
private LineRenderer _lineRender;
|
|
|
|
private int _lastMoveIndex = -1;
|
|
|
|
private readonly bool _useSingleLine = false;
|
|
|
|
public void Init()
|
|
{
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(Constants.ROAD_LINE_PATH);
|
|
rootObj = Object.Instantiate(sampleObj);
|
|
rootObj.transform.position = Vector3.zero;
|
|
rootObj.transform.rotation = Quaternion.Euler(90, 0, 0);
|
|
_lineRender = rootObj.GetComponent<LineRenderer>();
|
|
rootObj.SetActive(false);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
rootObj.Destroy();
|
|
rootObj = null;
|
|
}
|
|
|
|
public void UpdateLine(GameUnit u)
|
|
{
|
|
if (!LevelManager.Instance.CurrentLevel.isInBattle) return;
|
|
|
|
_lastMoveIndex = -1;
|
|
|
|
owner = u;
|
|
if (owner == null)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
public void HideLine()
|
|
{
|
|
_lastMoveIndex = -1;
|
|
owner = null;
|
|
if (rootObj != null)
|
|
{
|
|
rootObj.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private List<Vector3> _GetPointList()
|
|
{
|
|
List<Vector3> result = null;
|
|
switch (owner.gameunitType)
|
|
{
|
|
case EGameUnitType.Character:
|
|
{
|
|
var c = owner as Character;
|
|
var downFsm = c.downFSM;
|
|
if (downFsm == null) return null;
|
|
if (downFsm.currentState == null) return null;
|
|
if (downFsm.currentState.id != EDownState.Move)
|
|
{
|
|
return null;
|
|
}
|
|
var state = downFsm.currentState as DownStateMove;
|
|
result = state.CalcRoadLine();
|
|
}
|
|
break;
|
|
case EGameUnitType.Vehicle:
|
|
{
|
|
var v = owner as NormalVehicle;
|
|
var fsm = v.fsm;
|
|
if (fsm == null) return null;
|
|
if (fsm.currentState == null) return null;
|
|
if (fsm.currentState.id != EVehicleState.Move)
|
|
{
|
|
return null;
|
|
}
|
|
var state = fsm.currentState as VehicleStateMove;
|
|
result = state.CalcRoadLine();
|
|
}
|
|
break;
|
|
case EGameUnitType.BeProtect:
|
|
{
|
|
var b = owner as BeProtectUnit;
|
|
if (b.pathCellIndexs.Count == 0) return null;
|
|
if (owner.statusData.isDead)
|
|
{
|
|
return null;
|
|
}
|
|
result = b.displayPath;
|
|
}
|
|
break;
|
|
|
|
}
|
|
|
|
if (result == null || result.Count == 0) return null;
|
|
|
|
return result;
|
|
}
|
|
|
|
private int _GetNewIndex()
|
|
{
|
|
switch (owner.gameunitType)
|
|
{
|
|
case EGameUnitType.Character:
|
|
{
|
|
var c = owner as Character;
|
|
var downFsm = c.downFSM;
|
|
if (downFsm.currentState.id != EDownState.Move)
|
|
{
|
|
return -1;
|
|
}
|
|
var state = downFsm.currentState as DownStateMove;
|
|
return state.GetCurrentIndex();
|
|
}
|
|
case EGameUnitType.Vehicle:
|
|
{
|
|
var v = owner as NormalVehicle;
|
|
var fsm = v.fsm;
|
|
if (fsm.currentState.id != EVehicleState.Move)
|
|
{
|
|
return -1;
|
|
}
|
|
var state = fsm.currentState as VehicleStateMove;
|
|
return state.GetCurrentIndex();
|
|
}
|
|
case EGameUnitType.BeProtect:
|
|
{
|
|
var b = owner as BeProtectUnit;
|
|
if (b.pathCellIndexs.Count == 0) return -1;
|
|
return b.currentMoveIndex;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
if (owner == null) return;
|
|
var pointList = _GetPointList();
|
|
if (pointList == null)
|
|
{
|
|
rootObj.SetActive(false);
|
|
return;
|
|
}
|
|
if (!rootObj.activeSelf)
|
|
{
|
|
rootObj.SetActive(true);
|
|
}
|
|
var newIndex = _GetNewIndex();
|
|
|
|
if (_useSingleLine)
|
|
{
|
|
_lastMoveIndex = newIndex;
|
|
// 更新全部的
|
|
_lineRender.positionCount = 2;
|
|
var endPos = pointList[0];
|
|
endPos.y = 0.1f;
|
|
var wrapPos = rootObj.transform.InverseTransformPoint(endPos);
|
|
_lineRender.SetPosition(0, wrapPos);
|
|
var currentPos = owner.transData.pos;
|
|
currentPos.y = 0.1f;
|
|
currentPos = rootObj.transform.InverseTransformPoint(currentPos);
|
|
_lineRender.SetPosition(1, currentPos);
|
|
}
|
|
else
|
|
{
|
|
_lastMoveIndex = newIndex;
|
|
// 更新全部的
|
|
var totalCount = pointList.Count - newIndex;
|
|
if (totalCount <= 0)
|
|
{
|
|
_lineRender.positionCount = 0;
|
|
return;
|
|
}
|
|
_lineRender.positionCount = totalCount + 1;
|
|
for (var i = 0; i < totalCount; ++i)
|
|
{
|
|
var setPos = pointList[i];
|
|
setPos.y = 0.1f;
|
|
var wrapPos = rootObj.transform.InverseTransformPoint(setPos);
|
|
_lineRender.SetPosition(i, wrapPos);
|
|
}
|
|
var currentPos = owner.transData.pos;
|
|
currentPos.y = 0.1f;
|
|
currentPos = rootObj.transform.InverseTransformPoint(currentPos);
|
|
_lineRender.SetPosition(totalCount, currentPos);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|