506 lines
14 KiB
C#
506 lines
14 KiB
C#
using System.Collections;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using DG.Tweening;
|
||
|
||
public class PlayerMove : MonoBehaviour
|
||
{
|
||
public Transform objectToMove; // 要移动的对象
|
||
public Transform[] pathPoints; // 路径上的点的数组
|
||
public float duration = 5f; // 移动的持续时间
|
||
public bool isLooping = false; // 是否循环路径
|
||
int startIndex = 0;
|
||
int endIndex = 0;
|
||
public string room_id;
|
||
public float Speed;
|
||
public Transform EndPos;
|
||
|
||
public Transform TypeEndPos0;
|
||
public Transform TypeEndPos1;
|
||
public Transform TypeEndPos2;
|
||
public Transform TypeEndPos3;
|
||
public Transform TypeEndPos4;
|
||
public Transform TypeEndPos5;
|
||
public Transform TypeEndPos6;
|
||
|
||
public Transform JumpPos;
|
||
|
||
public Transform Pos1Parent;
|
||
public Transform Pos2Parent;
|
||
public Transform Pos3Parent;
|
||
public Transform Pos4Parent;
|
||
public Transform Pos5Parent;
|
||
public Transform Pos6Parent;
|
||
|
||
public Transform OutParent;
|
||
|
||
public Transform ReturnPos;//返回的位置
|
||
|
||
public bool IsBoos;
|
||
|
||
public AllHouseContro allHouseContro;
|
||
|
||
public Transform SelfTextTrans;
|
||
public Transform SelfImage;
|
||
public bool IsOtherWoniu;
|
||
|
||
public PlayerMove player;//玩家
|
||
private void Start()
|
||
{
|
||
Speed = 2f;
|
||
|
||
|
||
|
||
}
|
||
public void MoveOutParent()
|
||
{
|
||
// 记录原始的父物体
|
||
|
||
|
||
// 将 childObject 设为新的 parentObject 的子节点,并放到最后一个位置
|
||
objectToMove.SetParent(OutParent);
|
||
objectToMove.SetAsLastSibling();
|
||
|
||
|
||
}
|
||
public void MoveInParent(Transform Parent)
|
||
{
|
||
objectToMove.SetParent(Parent);
|
||
objectToMove.SetAsFirstSibling();
|
||
}
|
||
|
||
public void JudgeEnd()
|
||
{
|
||
if (EndPos == TypeEndPos1)
|
||
{
|
||
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().HouseId = 1;
|
||
}
|
||
else
|
||
{
|
||
GetComponent<BossContro>().HouseId = 1;
|
||
}
|
||
}
|
||
else if (EndPos == TypeEndPos2)
|
||
{
|
||
|
||
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().HouseId = 2;
|
||
}
|
||
else
|
||
{
|
||
GetComponent<BossContro>().HouseId = 2;
|
||
}
|
||
}
|
||
else if(EndPos == TypeEndPos3)
|
||
{
|
||
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().HouseId = 3;
|
||
}
|
||
else
|
||
{
|
||
GetComponent<BossContro>().HouseId = 3;
|
||
}
|
||
}
|
||
else if (EndPos == TypeEndPos4)
|
||
{
|
||
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().HouseId = 4;
|
||
}
|
||
else
|
||
{
|
||
GetComponent<BossContro>().HouseId = 4;
|
||
}
|
||
}
|
||
else if (EndPos == TypeEndPos5)
|
||
{
|
||
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().HouseId = 5;
|
||
}
|
||
else
|
||
{
|
||
GetComponent<BossContro>().HouseId = 5;
|
||
}
|
||
}
|
||
else if (EndPos == TypeEndPos6)
|
||
{
|
||
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().HouseId = 6;
|
||
}
|
||
else
|
||
{
|
||
GetComponent<BossContro>().HouseId = 6;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
public void SetParentToHouse()
|
||
{
|
||
if (EndPos == TypeEndPos1)
|
||
{
|
||
MoveInParent(Pos1Parent);
|
||
|
||
}
|
||
else if (EndPos == TypeEndPos2)
|
||
{
|
||
|
||
MoveInParent(Pos2Parent);
|
||
|
||
}
|
||
else if (EndPos == TypeEndPos3)
|
||
{
|
||
MoveInParent(Pos3Parent);
|
||
|
||
}
|
||
else if (EndPos == TypeEndPos4)
|
||
{
|
||
MoveInParent(Pos4Parent);
|
||
|
||
}
|
||
else if (EndPos == TypeEndPos5)
|
||
{
|
||
MoveInParent(Pos5Parent);
|
||
|
||
}
|
||
else if (EndPos == TypeEndPos6)
|
||
{
|
||
MoveInParent(Pos6Parent);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
public void ReturnStartPos()//回到起始点
|
||
{
|
||
transform.GetComponent<PlayerMovePos>().ReplySize();//恢复大小
|
||
transform.SetParent(transform.GetComponent<PlayerMovePos>().Parent);
|
||
transform.position=ReturnPos.position;
|
||
transform.GetComponent<PlayerMovePos>().StartPos = ReturnPos;
|
||
}
|
||
|
||
|
||
public bool JudagePos1()
|
||
{
|
||
if (EndPos==TypeEndPos1)
|
||
{
|
||
return true ;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public void StartMove()
|
||
{
|
||
|
||
|
||
// 提取路径中的所有点的位置
|
||
|
||
for (int i = 0; i < pathPoints.Length; i++)
|
||
{
|
||
if (!IsBoos&& objectToMove.GetComponent<PlayerMovePos>().StartPos == pathPoints[i])
|
||
{
|
||
startIndex = i;
|
||
//Debug.Log("Startindex"+i);
|
||
|
||
}
|
||
else if (IsBoos && GetComponent<BossContro>().BoosStartPos== pathPoints[i])
|
||
{
|
||
startIndex = i;
|
||
//Debug.Log("Startindex" + i);
|
||
}
|
||
|
||
if (EndPos == pathPoints[i])
|
||
{
|
||
endIndex = i;
|
||
//Debug.Log("Endindex" + i);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
if (endIndex>startIndex)
|
||
{
|
||
if (IsBoos)
|
||
{
|
||
duration = 2f;
|
||
}
|
||
else
|
||
{
|
||
duration=(endIndex-startIndex)/Speed;
|
||
}
|
||
|
||
Vector3[] waypoints = new Vector3[endIndex-startIndex+1];
|
||
for (int i=startIndex,j=0;j< pathPoints.Length&&i<=endIndex; i++,j++)
|
||
{
|
||
if (!JudagePos1() && pathPoints[i]==JumpPos)
|
||
{
|
||
waypoints[j] = pathPoints[i - 1].position;
|
||
continue;
|
||
|
||
}
|
||
waypoints[j]=pathPoints[i].position;
|
||
|
||
}
|
||
OnMove(waypoints);
|
||
}
|
||
else if(endIndex < startIndex)
|
||
{
|
||
if (IsBoos)
|
||
{
|
||
duration = 3f;
|
||
}
|
||
else
|
||
{
|
||
duration = (startIndex-endIndex) / Speed;
|
||
}
|
||
//duration = (startIndex-endIndex) / Speed;
|
||
Vector3[] waypoints = new Vector3[startIndex-endIndex + 1];
|
||
for (int i = startIndex, j = 0; j < pathPoints.Length && i >= endIndex; i--, j++)
|
||
{
|
||
|
||
if (!JudagePos1() && pathPoints[i] == JumpPos)
|
||
{
|
||
waypoints[j] = pathPoints[i+1].position;
|
||
continue;
|
||
|
||
}
|
||
waypoints[j] = pathPoints[i].position;
|
||
|
||
}
|
||
OnMove(waypoints);
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
public void AfterMove()
|
||
{
|
||
|
||
RectTransform rectTransform = objectToMove.GetComponent<RectTransform>();
|
||
if (IsBoos||!objectToMove.GetComponent<PlayerMovePos>().IsReturn)
|
||
{
|
||
if (!IsBoos)
|
||
{
|
||
//objectToMove.DOMoveY(objectToMove.position.y + 100, 0.5f).OnComplete(() => {
|
||
objectToMove.GetComponent<PlayerMovePos>().Zoomout();//缩小
|
||
rectTransform.DOAnchorPosY(rectTransform.anchoredPosition.y + 80f, 0.5f)
|
||
.OnComplete(() => {
|
||
|
||
|
||
JudgeEnd();
|
||
SetParentToHouse();
|
||
|
||
|
||
objectToMove.GetComponent<PlayerMovePos>().StartPos = EndPos;
|
||
|
||
|
||
objectToMove.GetComponent<PlayerMovePos>().PlayAni.SetInteger("State", 0);
|
||
if (!IsOtherWoniu)
|
||
{
|
||
MaskContro.instance.SetMask(false);
|
||
}
|
||
else
|
||
{
|
||
rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x + Random.Range(-50, 50), rectTransform.anchoredPosition.y);
|
||
}
|
||
|
||
});
|
||
|
||
|
||
//});
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("cscscscscscscscscscscs");
|
||
JudgeEnd();
|
||
GetComponent<BossContro>().BossAni.SetInteger("State", 0);//停止移动
|
||
Debug.Log("nnnnnnnn");
|
||
allHouseContro.ControOneDoorOpen(GetComponent<BossContro>().HouseId,() => {//开门
|
||
|
||
GetComponent<BossContro>().BossAni.SetInteger("State", 1);
|
||
GetComponent<BossContro>().Zoomout();//缩小
|
||
rectTransform.DOAnchorPosY(rectTransform.anchoredPosition.y + 80f, 0.5f).OnComplete(() => {//进房间
|
||
|
||
|
||
|
||
SetParentToHouse();
|
||
|
||
StartCoroutine(BoosAttack());
|
||
GetComponent<BossContro>().BoosStartPos = EndPos;
|
||
|
||
//JudgeSuccOrFail();
|
||
});
|
||
|
||
|
||
});
|
||
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().IsReturn = false;//重置
|
||
MaskContro.instance.SetMask(false);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
IEnumerator BoosAttack()
|
||
{
|
||
GetComponent<BossContro>().BossAni.SetInteger("State", 2);
|
||
yield return new WaitForSeconds(2.1f);
|
||
GetComponent<BossContro>().BossAni.SetInteger("State", 0);
|
||
if (allHouseContro.KillNos.Count>0)
|
||
{
|
||
foreach (int nos in allHouseContro.KillNos)
|
||
{
|
||
GetComponent<BossContro>().allother.KilltheWoniu(nos);
|
||
if (allHouseContro.roomNo==nos)
|
||
{
|
||
player.gameObject.SetActive(false);
|
||
}
|
||
|
||
}
|
||
foreach (HouseBtn houseBtn in allHouseContro.HouseBtnList)
|
||
{
|
||
foreach (int nos in allHouseContro.KillNos)
|
||
{
|
||
if (houseBtn.roomNo!=nos)
|
||
{
|
||
StartCoroutine( GetComponent<BossContro>().allother.ReturnstartPos(houseBtn.roomNo));
|
||
}
|
||
|
||
if (houseBtn.roomNo == nos)
|
||
{
|
||
houseBtn.DarkMask.StartFade();
|
||
//houseBtn.Lightlinp.color = new Color(0, 0, 0, 0);
|
||
}
|
||
|
||
}
|
||
}
|
||
allHouseContro.KillNos.Clear();
|
||
}
|
||
|
||
BettingBtn.instance.GiveMoney(room_id);
|
||
yield return new WaitForSeconds(2f);
|
||
//allHouseContro.BoosReturn();
|
||
//JudgeSuccOrFail();
|
||
}
|
||
|
||
|
||
//public void JudgeSuccOrFail()
|
||
//{
|
||
// Debug.Log("=000000000000000000000000000000000000000000000000");
|
||
// if (GetComponent<BossContro>().BoosStartPos == transform.GetComponent<PlayerMovePos>().StartPos && transform.GetComponent<PlayerMovePos>().HadChoise)
|
||
// {
|
||
// //BossContro.instance.BossAni.SetInteger("State", 2);//boos攻击
|
||
// Debug.Log("失败");//失败
|
||
// FailPanel.instance.ShowPanel();
|
||
// }
|
||
// else if (GetComponent<BossContro>().BoosStartPos != transform.GetComponent<PlayerMovePos>().StartPos && transform.GetComponent<PlayerMovePos>().HadChoise)
|
||
// {
|
||
// Debug.Log("胜利");//胜利
|
||
// SucceePanel.instance.ShowPanel();
|
||
// }
|
||
// else
|
||
// {
|
||
// Debug.Log("没有失败和胜利");//胜利
|
||
// foreach (GameObject item in allHouseContro.bossobj)
|
||
// {
|
||
// item.GetComponent<BossContro>().ReturnParent();
|
||
// }
|
||
// }
|
||
// //HegemonTime.instance.StartCoroutine(HegemonTime.instance.StartGame());//重新计算时间
|
||
//}
|
||
|
||
public void Rotate()
|
||
{
|
||
|
||
Vector3 currentRotation = objectToMove.localEulerAngles;
|
||
currentRotation.y += 180f;
|
||
objectToMove.localEulerAngles = currentRotation;
|
||
|
||
}
|
||
|
||
public void OnMove(Vector3[] waypoints)
|
||
{
|
||
if (!IsBoos)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().PlayAni.SetInteger("State", 1);
|
||
objectToMove.GetComponent<PlayerMovePos>().ReplySize();//恢复大小
|
||
if (!IsOtherWoniu)
|
||
{
|
||
MaskContro.instance.SetMask(true);
|
||
}
|
||
|
||
}
|
||
|
||
MoveOutParent();
|
||
|
||
Tween pathTween = objectToMove.DOPath(waypoints, duration, PathType.Linear)
|
||
.SetEase(Ease.Linear) // 设置线性过渡效果
|
||
.SetLoops(isLooping ? -1 : 0)
|
||
.OnWaypointChange((index) =>
|
||
{
|
||
// 当物体到达某个路径点时回调
|
||
if (index < waypoints.Length - 1)
|
||
{
|
||
Vector3 currentWaypoint = waypoints[index];
|
||
Vector3 nextWaypoint = waypoints[index + 1];
|
||
if (IsBoos)
|
||
{
|
||
if (nextWaypoint.x < currentWaypoint.x && !GetComponent<BossContro>().IsLeft)
|
||
{
|
||
GetComponent<BossContro>().IsLeft = true;
|
||
// 旋转物体使其面向左侧(绕Y轴旋转180度)
|
||
Rotate();
|
||
}
|
||
else if (nextWaypoint.x > currentWaypoint.x && GetComponent<BossContro>().IsLeft)
|
||
{
|
||
GetComponent<BossContro>().IsLeft = false;
|
||
Rotate();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 判断物体是否需要旋转
|
||
if (nextWaypoint.x < currentWaypoint.x && !objectToMove.GetComponent<PlayerMovePos>().IsLeft)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().IsLeft = true;
|
||
// 旋转物体使其面向左侧(绕Y轴旋转180度)
|
||
Rotate();
|
||
}
|
||
else if (nextWaypoint.x > currentWaypoint.x && objectToMove.GetComponent<PlayerMovePos>().IsLeft)
|
||
{
|
||
objectToMove.GetComponent<PlayerMovePos>().IsLeft = false;
|
||
Rotate();
|
||
}
|
||
}
|
||
|
||
}
|
||
})
|
||
.OnComplete(AfterMove);
|
||
}
|
||
} |