IEnumerator SetSpeedBack(float timz, PathMove enem, PathMove lookat, float speeds) { yield return(new WaitForSeconds(timz)); enem.speedMultiplier = speeds; lookat.speedMultiplier = speeds; }
void Start() { pathMove = GetComponent <PathMove>(); timerCount = TimerLimit = Timer; StartCoroutine(SpawnMonster()); StartCoroutine(SpawnTimerItem()); }
// Use this for initialization void Start() { pathMove = GameObject.FindObjectOfType <PathMove> (); timer = FindObjectOfType <Timer> (); spawnPeriodPhase2 = spawnPeriodInSecs / 2; spawnPeriodPhase3 = spawnPeriodInSecs / 4; InstantiateMovingObstacle(); StartCoroutine(Spawn()); }
public static PathMove Instance() { if (null == s_Inst) { s_Inst = new PathMove(); } return(s_Inst); }
//------------------------------------------------------------------------------------------------------- /** * @brief FindPath 寻路算法 * @param curPos 当前位置 * @param tarPos 目标位置 * @param[out] path 输出路径 */ public bool FindPath(Vector2 curPos, Vector2 tarPos, out List <Vector2> path) { path = null; //UnityEngine.Profiler.BeginSample("FindPath"); PathMove.Instance().findPath(new Vector2(curPos.x, -curPos.y), new Vector2(tarPos.x, -tarPos.y), 0.0f, out path); //UnityEngine.Profiler.EndSample(); if (path.Count <= 0) { return(false); } return(true); }
public void path(string path, bool autoPlay = true, Vector3 startPos = default(Vector3), bool inverse = false) {//路径移动 if (!mUnit.isState(UnitState.Move)) { return; } if (mMove != null) { mMove.stop(mUnit, false); } PathMove pm = new PathMove(); mMove = pm; pm.vTarget = startPos; pm.uTarget = null; pm.play(mUnit, path, autoPlay, inverse); }
//------------------------------------------------------------------------------------------------------- // 获取地图上距离(计算阻挡) public bool CalcDistance(Vector2 curPos, Vector2 tarPos, out float fDistance, TileType tileType = TileType.TileType_None) { if (tileType == TileType.TileType_None) // 直接计算直线距离 { fDistance = Vector2.Distance(curPos, tarPos); return(true); } //if(MapObstacle.Instance.Check()) float ShortestMoveDst = 0.1f; MapGrid dstPt = MapGrid.GetMapGrid(new MapVector2(tarPos.x, tarPos.y)); Vector2 dir = tarPos - curPos; dir.Normalize(); dir *= ShortestMoveDst; MapGrid curPt = new MapGrid(0, 0); var vecDst = tarPos; bool bBlock = false; // 校验 for (; (vecDst - curPos).magnitude > ShortestMoveDst; curPos += dir) { var tmp = MapGrid.GetMapGrid(new MapVector2(curPos.x, curPos.y)); if (curPt != tmp) { curPt = tmp; } else { continue; } if (!MapObstacle.Instance.Check((int)curPt.x, (int)curPt.z, tileType)) { bBlock = true; break; } if (curPt == dstPt) { break; } } fDistance = 0.0f; if (!bBlock) { fDistance = Vector2.Distance(curPos, tarPos); } else { List <Vector2> path = null; if (!PathMove.Instance().findPath(new Vector2(curPos.x, curPos.y), new Vector2(tarPos.x, tarPos.y), 0.0f, out path)) { return(false); } Vector2 lastPos = curPos; for (int i = 0; i < path.Count; ++i) { fDistance += Vector2.Distance(lastPos, path[i]); lastPos = path[i]; } } return(true); }
//------------------------------------------------------------------------------------------------------- // 删除寻路回调 public void RemoveFindPathCallback(Action <List <Vector2> > findPath) { PathMove.Instance().PathFind -= findPath; }
private void Awake() { base.Awake(); pathMove = FindObjectOfType <LevelMaster>().levelStage.GetComponent <PathMove>(); }
private void Awake() { pathMove = new PathMove(); }
void StartTrain() { PathMove pathMove = GameObject.FindObjectOfType <PathMove> (); pathMove.MoveTrain(); }
void Awake() { instance = this; }