¡¡·ÐÏ©°ÜÆ°¤¬ºÇ½ªÃÏÅÀ¤Þ¤ÇÅþ㤷¤¿¤é¡¢GameManager ¥¯¥é¥¹Â¦¤ËÂФ·¤Æ¡¢°ÜÆ°¤¬´°Î»¤·¤¿¤³¤È¤È¡¢
¼¡¤Î·ÐÏ©¤Î¾ðÊ󤬤¢¤ë¤«¤É¤¦¤«¤òȽÃǤµ¤»¤ë½èÍý¤Î¥á¥½¥Ã¥É¤òÌ¿Îᤷ¤Þ¤¹¡£
³ºÅö¤¹¤ë¥á¥½¥Ã¥É¤ÏÀè¤Û¤É GameManager ¥¯¥é¥¹Â¦¤ËºîÀ®¤·¤Æ¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¤¢¤È¤Ï¡¢¤¹¤Ù¤Æ¤Î·ÐÏ©¤Î°ÜÆ°¤¬´°Î»¤·¤¿¥¿¥¤¥ß¥ó¥°¤Ë
GameManager ¥¯¥é¥¹¤Ø¤ÎÌ¿Îá¤òµ½Ò¤·¤Æ½èÍý¤ò¼Â¹Ô¤·¤Þ¤¹¡£
¡¡¤Þ¤¿¡¢¾éĹŪ¤Ë¤Ê¤Ã¤Æ¤¤¤¿½èÍý¤Î°ìÉô¤Î¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤ò¹Ô¤¤¡¢Linq ¤Î¥á¥½¥Ã¥É¤òÍøÍѤ·¤¿½èÍý¤Ë½ñ¤´¹¤¨¤Æ¤¤¤Þ¤¹¡£
°ìÅÙ½ñ¤¤¤¿½èÍý¤Ç¤¢¤Ã¤Æ¤â¡¢¤½¤ì¤¬²þÁ±¤Ç¤¤ëÆâÍƤʤΤ«¡¢¾ï¤Ë³Îǧ¤ò¤ª¤³¤Ê¤Ã¤Æ¡¢¤è¤ê¤è¤¤½èÍý¤Ë¤·¤Æ¤¤¤¯¤³¤È¤¬¥¹¥¥ë¥¢¥Ã¥×¤ÎÈë·í¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡½èÍý¤¬½ñ¤±¤¿¤é½ª¤ï¤ê¡¢¤Ç¤Ï¤Ê¤¯¤Æ¡¢¿·¤·¤¤½èÍý¤Ë½ñ¤´¹¤¨¤ë¤³¤È¤¬½ÐÍè¤Ê¤¤¤«¤É¤¦¤«¤òÄ´¤Ù¤Æ¤ß¤ë¤³¤È¤¬ÂçÀڤǤ¹¡£
RailMoveController.cs
<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤¤Þ¤¹¡£
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using System.Linq;
public class RailMoveController : MonoBehaviour {
[SerializeField]
private Transform railMoveTarget;
[SerializeField]
private RailPathData currentRailPathData;
private Tween tweenMove;
private Tween tweenRotation;
private Vector3[] paths;
private float[] moveDurations;
private int pathCount;
private GameManager gameManager;
////*¡¡¿·¤·¤¤ÊÑ¿ô¤ÎÀë¸À¤ò£±¤ÄÄɲá¡*////
private int moveCount;
////*¡¡¤³¤³¤Þ¤Ç¡¡*////
/// <summary>
/// RailMoveController ¤Î½é´üÀßÄê
/// </summary>
/// <param name="gameManager"></param>
public void SetUpRailMoveController(GameManager gameManager) {¡¡¡¡¡¡¡¡¡¡//¡¡<=¡¡GameManager ¤è¤ê¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹
this.gameManager = gameManager;
// TODO ¾¤Ë¤â¤¢¤ë¾ì¹ç¤Ë¤ÏÄɵ¡£É¬Íפ˱þ¤¸¤Æ°ú¿ô¤òÄ̤¸¤Æ³°Éô¤«¤é¾ðÊó¤ò¤â¤é¤¦¤è¤¦¤Ë¤¹¤ë
}
/// <summary>
/// ¼¡¤ËºÆÀ¸¤¹¤ë¥ì¡¼¥ë°ÜÆ°¤ÎÌÜŪÃϤȷÐÏ©¤Î¥Ñ¥¹¤ò¼èÆÀ¤·¤ÆÀßÄê
/// </summary>
/// <param name="nextPathDataList"></param>
public void SetNextRailPathData(RailPathData nextRailPathData) {¡¡¡¡¡¡¡¡¡¡//¡¡<=¡¡GameManager ¤è¤ê¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹
// ÌÜŪÃϼèÆÀ
currentRailPathData = nextRailPathData; ;
// °ÜÆ°³«»Ï
StartCoroutine(StartRailMove());
}
/// <summary>
/// ¥ì¡¼¥ë°ÜÆ°¤Î³«»Ï
/// </summary>
/// <returns></returns>
public IEnumerator StartRailMove() {
yield return null;
// ¥Ñ¥¹¤Î¥«¥¦¥ó¥È¤ò½é´ü²½
pathCount = 0;
////*¡¡½èÍý¤Î¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¡¡¤¤¤Þ¤Þ¤Ç¤Î½èÍý¤ò¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Þ¤¹¡¡*////
// °ÜÆ°¤¹¤ëÃÏÅÀ¤ò¼èÆÀ¤¹¤ë¤¿¤á¤ÎÇÛÎó¤Î½é´ü²½
//paths = new Vector3[currentRailPathData.GetPathTrans().Length];
//float totalTime = 0;
// °ÜÆ°¤¹¤ë°ÌÃÖ¾ðÊó¤È»þ´Ö¤ò½çÈÖ¤ËÇÛÎó¤Ë¼èÆÀ
//for (int i = 0; i < currentRailPathData.GetPathTrans().Length; i++) {
// paths[i] = currentRailPathData.GetPathTrans()[i].position;
// totalTime += currentRailPathData.GetRailMoveDurations()[i];
//}
//¡¡¾åµ¤Î½èÍý¤ò°Ê²¼¤Î½èÍý¤Ë½ñ¤´¹¤¨¤Þ¤¹¡¡//
// °ÜÆ°¤¹¤ëÃÏÅÀ¤ò¼èÆÀ¤¹¤ë¤¿¤á¤ÎÇÛÎó¤Î½é´ü²½¤È¾ðÊó¤Î¼èÆÀ
paths = currentRailPathData.GetPathTrans().Select(x => x.position).ToArray();
// °ÜÆ°Àè¤Î¥Ñ¥¹¤Î°ÜÆ°»þ´Ö¤ò¹ç·×
float totalTime = currentRailPathData.GetRailMoveDurations().Sum();
////*¡¡¤³¤³¤Þ¤Ç¡¡*////
// ³Æ¥Ñ¥¹¤´¤È¤Î°ÜÆ°»þ´Ö¤ò¼èÆÀ
moveDurations = currentRailPathData.GetRailMoveDurations();
// ¥Ñ¥¹¤Ë¤è¤ë°ÜÆ°³«»Ï
RailMove();
// °ÜÆ°¤ò°ì»þÄä»ß
PauseMove();
// ¥²¡¼¥à¤Î¿Ê¹Ô¾õÂÖ¤¬°ÜÆ°Ãæ¤Ë¤Ê¤ë¤Þ¤ÇÂÔµ¡
yield return new WaitUntil(() => gameManager.currentGameState == GameState.Play_Move);
// °ÜÆ°³«»Ï
ResumeMove();
Debug.Log("°ÜÆ°³«»Ï");
}
/// <summary>
/// ¥ì¡¼¥ë°ÜÆ°¤Î°ì»þÄä»ß
/// </summary>
public void PauseMove() {
// °ì»þÄä»ß
tweenMove.Pause();
tweenRotation.Pause();
}
/// <summary>
/// ¥ì¡¼¥ë°ÜÆ°¤ÎºÆ³«
/// </summary>
public void ResumeMove() {
// °ÜÆ°ºÆ³«
tweenMove.Play();
tweenRotation.Play();
}
/// <summary>
/// ¥Ñ¥¹¤Î¥«¥¦¥ó¥È¥¢¥Ã¥×(¥Ñ¥¹¤´¤È¤ËÆ°¤«¤¹¾ì¹ç)
/// </summary>
public void CountUp() {
pathCount++;
Debug.Log(pathCount);
// °ÜÆ°
RailMove();
}
/// <summary>
/// 2ÅÀ´Ö¤Î¥Ñ¥¹¤ÎÌÜɸÃÏÅÀ¤òÀßÄꤷ¤Æ°ÜÆ°
/// </summary>
public void RailMove() {
// »Ä¤Ã¤Æ¤¤¤ë¥Ñ¥¹¤¬¤Ê¤¤¾ì¹ç
if (pathCount >= currentRailPathData.GetPathTrans().Length) {
// DOTween ¤òÄä»ß
tweenMove.Kill();
tweenMove = null;
tweenRotation = null;
////* TODO ¤Î¼ÂÁõ *////
// °ÜÆ°´°Î»¤Ëȼ¤¤¡¢°ÜÆ°²ó¿ô¤ò¥«¥¦¥ó¥È¥¢¥Ã¥×
moveCount++;
// °ÜÆ°Àè¤Î³Îǧ¡£°ÜÆ°À褬»Ä¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢¥²¡¼¥à¥Þ¥Í¡¼¥¸¥ã¡¼Â¦¤Çʬ´ô¤Î³Îǧ(¼¡¤Î¥ë¡¼¥ÈÁªÄê¡¢°ÜÆ°Àè¤Îʬ´ô¡¢¥Ü¥¹¡¢¥¯¥ê¥¢¤Î¤¤¤º¤ì¤«)
gameManager.PreparateCheckNextBranch(moveCount);
////* ¤³¤³¤Þ¤Ç *////
Debug.Log("ʬ´ô³Îǧ");
return;
}
// ¥Ñ¥¹¤ÎÀßÄêÍѤÎÇÛÎó¤òÀë¸À
Vector3[] targetPaths;
// ¥Ñ¥¹¤Î¥«¥¦¥ó¥È¿ô¤Ë±þ¤¸¤Æʬ´ô¤·¤Æ¥Ñ¥¹¤òÀßÄê
if (pathCount == 0) {
targetPaths = new Vector3[2] { railMoveTarget.position, paths[pathCount] };
} else {
targetPaths = new Vector3[2] { paths[pathCount - 1], paths[pathCount] };
}
// ¥Ñ¥¹¤Î°ÜÆ°»þ´Ö¤òÀßÄê
float duration = moveDurations[pathCount];
Debug.Log("¥¹¥¿¡¼¥ÈÃÏÅÀ :" + targetPaths[0]);
Debug.Log("ÌÜɸÃÏÅÀ :" + targetPaths[1]);
Debug.Log("°ÜÆ°¤Ë¤«¤«¤ë»þ´Ö :" + duration);
// ¥Ñ¥¹¤Î°ÜÆ°
tweenMove = railMoveTarget.transform.DOPath(targetPaths, duration, pathType).SetEase(Ease.Linear).OnWaypointChange((waypointIndex) => CheckArrivalDestination(waypointIndex));
// ¥«¥á¥é¤Î²óž
tweenRotation = railMoveTarget.transform.DORotate(currentRailPathData.pathDataDetails[pathCount].pathTran.eulerAngles, duration).SetEase(Ease.Linear);
Debug.Log($" ²óž³ÑÅÙ : {currentRailPathData.pathDataDetails[pathCount].pathTran.eulerAngles} ");
}
/// <summary>
/// ¥Ñ¥¹¤ÎÌÜɸÃÏÅÀ¤ËÅþÃ夹¤ë¤¿¤Ó¤Ë¼Â¹Ô¤µ¤ì¤ë
/// </summary>
/// <param name="waypointIndex"></param>
private void CheckArrivalDestination(int waypointIndex) {
if (waypointIndex == 0) {
return;
}
Debug.Log("ÌÜɸÃÏÅÀ ÅþÃå : " + pathCount + " ÈÖÌÜ");
// °ÜÆ°¤Î°ì»þÄä»ß
PauseMove();
// ¥ß¥Ã¥·¥ç¥ó¤¬¤¢¤ë¤«³Îǧ(¥ß¥Ã¥·¥ç¥ó¤¬È¯À¸¤¹¤ë¤«¥²¡¼¥à¥Þ¥Í¡¼¥¸¥ã¡¼Â¦¤ÇȽÄê¤ò¹Ô¤¦)
gameManager.CheckMissionTrigger(pathCount);
// DebugÍÑ ¼¡¤Î¥Ñ¥¹¤ò¥»¥Ã¥È¤·¤Æ°ÜÆ°¤ò¼Â¹Ô
//CountUp();
}
/// <summary>
/// °ÜÆ°ÍѤνèÍý¤¬ÅÐÏ¿¤µ¤ì¤¿¤«³Îǧ
/// </summary>
/// <returns></returns>
public bool GetMoveSetting() {
return tweenMove != null ? true : false;
}
}
¥³¥á¥ó¥È¤ò¤«¤¯