|
|
|
@ -11,6 +11,13 @@ public class Player : MonoBehaviour |
|
|
|
[Header("层级检测")] |
|
|
|
public LayerMask chooseNodeLayerMask;//移动射线选择的层级
|
|
|
|
public LayerMask playerLayerMask;//角色层级
|
|
|
|
[Header("路径")] |
|
|
|
public List<MapUnity> movePath = new List<MapUnity>(); |
|
|
|
|
|
|
|
[Header("动画器")] |
|
|
|
public Animator anim; |
|
|
|
[Header("跑步速度")] |
|
|
|
public float speed =2; |
|
|
|
|
|
|
|
private void Start() |
|
|
|
{ |
|
|
|
@ -47,8 +54,9 @@ public class Player : MonoBehaviour |
|
|
|
else |
|
|
|
{ |
|
|
|
// Debug.Log(raycastHit.collider.gameObject.name);
|
|
|
|
ChooseNode(); |
|
|
|
|
|
|
|
StartCoroutine( MoveToChooseNode()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -67,39 +75,11 @@ public class Player : MonoBehaviour |
|
|
|
|
|
|
|
if(TurnMaster.Instance.playerAction != TurnMaster.PlayerAction.banAction) |
|
|
|
TurnMaster.Instance.playerAction = TurnMaster.PlayerAction.none; |
|
|
|
//todo取消卡牌释放
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void CalculateDistance(Vector3 targetPostion)//计算走了几步,目前先用距离来判断以后要写寻路算法
|
|
|
|
{ |
|
|
|
if(GameManager.Instance.playerOn != null ) |
|
|
|
{ |
|
|
|
Vector3 vec = GameManager.Instance.playerOn.transform.position - targetPostion; |
|
|
|
float length = vec.magnitude; |
|
|
|
Debug.Log(length); |
|
|
|
if(length==0) |
|
|
|
{ |
|
|
|
Debug.Log("无法移动"); |
|
|
|
} |
|
|
|
else if( length <1.5f) |
|
|
|
{ |
|
|
|
//-1
|
|
|
|
GameManager.Instance.playerState.currentStepRange -= 1; |
|
|
|
} |
|
|
|
else if(length<2.5f) |
|
|
|
{ |
|
|
|
//-2
|
|
|
|
GameManager.Instance.playerState.currentStepRange -= 2; |
|
|
|
} |
|
|
|
else if(length <3.5) |
|
|
|
{ |
|
|
|
//-3
|
|
|
|
GameManager.Instance.playerState.currentStepRange -= 3; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public void ChooseNode()//射线检测选择一个mapNode
|
|
|
|
|
|
|
|
IEnumerator MoveToChooseNode()//射线检测选择一个mapNode
|
|
|
|
{ |
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.value); |
|
|
|
if(Physics .Raycast (ray ,out RaycastHit raycastHit,500, chooseNodeLayerMask.value)) |
|
|
|
@ -108,27 +88,29 @@ public class Player : MonoBehaviour |
|
|
|
|
|
|
|
MapUnity mapNode = raycastHit.collider.transform.GetComponent<MapUnity>(); |
|
|
|
|
|
|
|
//计算移动距离来减步数
|
|
|
|
if (mapNode.influenced && mapNode.blocked == false && mapNode.enemyNode == null) |
|
|
|
CalculateDistance(mapNode.gameObject.transform.position); |
|
|
|
//改变缩放翻转
|
|
|
|
FlipLocalScale(raycastHit.point); |
|
|
|
|
|
|
|
//角色移动
|
|
|
|
if (mapNode .influenced &&mapNode .blocked ==false &&mapNode .enemyNode ==null ) |
|
|
|
{ |
|
|
|
if(GameManager.Instance.playerOn != null ) |
|
|
|
//获得路径
|
|
|
|
movePath = AStarManager.Instance.FindPathWithEndNode(GameManager.Instance.playerOn, mapNode); |
|
|
|
//判断能否到达
|
|
|
|
if(movePath .Count -1>GameManager .Instance .playerState .currentStepRange ) |
|
|
|
{ |
|
|
|
GameManager.Instance.playerOn.playerOn = false; |
|
|
|
GameManager.Instance.playerOn.influenced = false; |
|
|
|
Debug.Log("不能移动到该位置"); |
|
|
|
yield break; |
|
|
|
} |
|
|
|
|
|
|
|
//判断寄生是否生效
|
|
|
|
Usermanager.Instance.ParasitismnRealize(GameManager.Instance.playerOn, mapNode); |
|
|
|
Usermanager.Instance.bleedRealize(GameManager.Instance.playerOn, mapNode); |
|
|
|
|
|
|
|
mapNode.playerOn = true; |
|
|
|
GameManager.Instance.playerOn = mapNode; |
|
|
|
//改变动画
|
|
|
|
anim.SetBool("move", true); |
|
|
|
|
|
|
|
this.gameObject.transform.position =new Vector3 ( mapNode.transform.position.x ,0.5f, mapNode.transform.position.z); |
|
|
|
if (GameManager.Instance.playerOn != null ) |
|
|
|
{ |
|
|
|
GameManager.Instance.playerOn.playerOn = false; |
|
|
|
GameManager.Instance.playerOn.influenced = false; |
|
|
|
} |
|
|
|
|
|
|
|
//遍历影响池变色
|
|
|
|
foreach (MapUnity mapUnity in influencePreviewPool) |
|
|
|
@ -137,8 +119,44 @@ public class Player : MonoBehaviour |
|
|
|
} |
|
|
|
influencePreviewPool.Clear(); |
|
|
|
|
|
|
|
//标记终点
|
|
|
|
mapNode.markInfluenced = true; |
|
|
|
|
|
|
|
for (int i=1;i<movePath .Count;i++) |
|
|
|
{ |
|
|
|
bool move = true; |
|
|
|
float time = 0; |
|
|
|
Vector3 startPos= transform.position; |
|
|
|
Vector3 endpos = new Vector3(movePath[i].transform.position.x,transform.position.y, movePath[i].transform.position.z); |
|
|
|
while (move ) |
|
|
|
{ |
|
|
|
transform .position = Vector3.Lerp(startPos, endpos, time += Time.deltaTime*speed); |
|
|
|
if(Vector3 .Distance ( transform .position, endpos) <0.1f) |
|
|
|
{ |
|
|
|
move = false; |
|
|
|
} |
|
|
|
|
|
|
|
yield return 0; |
|
|
|
} |
|
|
|
//判断寄生,流血是否生效
|
|
|
|
Usermanager.Instance.ParasitismnRealize(movePath [i]);//传入当前node
|
|
|
|
Usermanager.Instance.bleedRealize(); |
|
|
|
//减体力
|
|
|
|
GameManager.Instance.playerState.currentStepRange -= 1; |
|
|
|
} |
|
|
|
|
|
|
|
this.gameObject.transform.position = new Vector3(mapNode.transform.position.x, 0.5f, mapNode.transform.position.z); |
|
|
|
mapNode.playerOn = true; |
|
|
|
GameManager.Instance.playerOn = mapNode; |
|
|
|
|
|
|
|
//改变动画
|
|
|
|
anim.SetBool("move", false); |
|
|
|
|
|
|
|
//取消标记终点
|
|
|
|
mapNode.markInfluenced = false; |
|
|
|
TurnMaster.Instance.playerAction = TurnMaster.PlayerAction.none; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -157,7 +175,18 @@ public class Player : MonoBehaviour |
|
|
|
influencePreviewPool.Clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//改变缩放翻转
|
|
|
|
public void FlipLocalScale(Vector3 point) |
|
|
|
{ |
|
|
|
if (point.x < transform.position.x) |
|
|
|
{ |
|
|
|
anim.transform.localScale = new Vector3(-0.17f, 0.17f, 0.17f); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
anim.transform.localScale = new Vector3(0.17f, 0.17f, 0.17f); |
|
|
|
} |
|
|
|
} |
|
|
|
public void StepPreviewInfluencedNode(int step)//可移动格子预览
|
|
|
|
{ |
|
|
|
influencePreviewPool.Clear(); |
|
|
|
|