public IEnumerator movefromApoint2Bpoint(ICell from, ICell to) { var mapSize = mapController.GetMapSize(); Vector3 fromVisualPos = HexCoords.GetHexVisualCoords(from.Point, mapSize); Vector3 toVisualPos = HexCoords.GetHexVisualCoords(to.Point, mapSize); float t = 0; float total = 0.1f * 60; enterCellPoint(from.Point); while (t < total) { //t += (0.1f * entityConfig.speed_config); t += 0.1f * runtimeData.speed; if (t / total < 0.5) { //enterCellPoint(from.Point); } else { enterCellPoint(to.Point); } this.transform.position = Vector3.Lerp(fromVisualPos, toVisualPos, t / total); entityVisual.PlayAnim(EntityAnimEnum.Run); yield return(null); } }
private void applyView() { Vector3 v = HexCoords.GetHexVisualCoords(dest); v.y = 20; this.transform.position = Vector3.Lerp(this.transform.position, v, Time.deltaTime * focusSpeed); //this.transform.position = v; }
private void enterCellPoint(Vector2Int point) { if (currentCell.x == point.x && currentCell.y == point.y) { return; } currentCell = point; calculateRangeOnEnterPoint(); this.transform.LookAt(HexCoords.GetHexVisualCoords(point)); fireEntityEvent(entityEvent.enterNewCell); }
private int GetRangeEntity(int R, GameEntity[] range, bool wantopsite = true) { #if UNITYCLIENT int length = Physics.OverlapSphereNonAlloc(HexCoords.GetHexVisualCoords(CurrentPoint), R, forSensor, 1 << LayerMask.NameToLayer(ProjectConsts.Layer_Entity)); int i = 0; for (int m = 0; m < length && m < range.Length; m++) { GameEntity entity = forSensor[m].GetComponentInParent <GameEntity>(); if (wantopsite) { if (entity != null && beEneymyToMe(entity)) { range[i++] = entity; } } else { if (entity != null && entity != this) { range[i++] = entity; } } } return(Mathf.Min(length, i)); #else //List<Vector3Int> cuberange = Neighbors.GetCubeRange(Coords.Point_to_Cube(CurrentPoint), R,cubeRange); List <Vector3Int> cuberange = pursueRangeCubeSpace; int i = 0; for (int m = 0; m < GameEntityMgr.Instance.GetAllEntities().Count&& i < range.Length; m++) { GameEntity entity = GameEntityMgr.Instance.GetAllEntities()[m]; //if (cuberange.Contains(Coords.Point_to_Cube(entity.CurrentPoint))) if (cuberange.Contains(entity.CurrentCubePoint)) { if (wantopsite) { if (beEneymyToMe(entity)) { range[i++] = entity; } } else { range[i++] = entity; } } } return(i); #endif }
void Update() { if (controller == null || GameEntityMgr.Instance == null) { return; } GameEntity entity = GameEntityMgr.Instance.GetRandomAlivePlayerEntity(); Vector3 position_worldSpace = viewer.position; //坐标转换至chunkspace中 position_worldSpace -= HexCoords.GetHexVisualCoords(controller.GetMap().GetChunks()[Vector2Int.zero].GetCenter()); viewerPosition_inChunkSpace.x = position_worldSpace.x; viewerPosition_inChunkSpace.y = position_worldSpace.z; viewerPosition_inChunkSpace.x += viewRect.x; viewerPosition_inChunkSpace.y += viewRect.y; UpdateVisibleChunks(); }
void initUniRxPrograming() { RX_LastMoveFrom = new Vector2ReactiveProperty(CurrentPoint); RX_LastMoveTo = new Vector2ReactiveProperty(CurrentPoint); RX_currentPoint = new Vector2ReactiveProperty(CurrentPoint); RX_LastClickCell.Subscribe(_ => { RX_targetEntity.Value = null; }); //如何过滤过快的点击切换路径? //假若RX_LastClickCell的输入频率是 0.3s 内来了 10个数据(玩家0.3s内点击了10个可以移动的地方) //则以最后一个数据为准作为通知 RX_LastClickCell.Throttle(TimeSpan.FromSeconds(0.2f)).Subscribe(_ => { RX_PathChanged.Value = true; }); RX_currentPoint.Subscribe(point => { mapController.SetStartPoint(Vector2Int.CeilToInt(point)); }); RX_LastMoveTo.Subscribe((to) => { m_Transform.LookAt(HexCoords.GetHexVisualCoords(Vector2Int.CeilToInt(to))); RX_moveFromA2BPer.Value = 0; RX_moveSpeed.Value = 1; }); RX_LastMoveTo.Buffer(RX_LastMoveTo.Where(point => point == RX_currentPoint.Value).Throttle(TimeSpan.FromSeconds(C_TimeToReachOnePoint))).Subscribe(_ => { RX_moveSpeed.Value = 0; }); #region 控制移动 RX_moveFromA2BPer.Skip(1).Subscribe(per => { entityVisual.Run2(); Vector3 fromVisualPos = Coords.PointToVisualPosition(Vector2Int.CeilToInt(RX_LastMoveFrom.Value)); Vector3 toVisualPos = Coords.PointToVisualPosition(Vector2Int.CeilToInt(RX_LastMoveTo.Value)); Vector3 v = Vector3.Lerp(fromVisualPos, toVisualPos, RX_moveFromA2BPer.Value); m_Transform.position = v; //float near_start_or_near_dst = -0.5f + per; if (per >= 0.5f) { RX_currentPoint.Value = RX_LastMoveTo.Value; } else { RX_currentPoint.Value = RX_LastMoveFrom.Value; } }); var idle = RX_moveSpeed.Where(speed => speed == 0); var confused = idle.Where(_ => { return(false); }); idle.Subscribe(_ => { entityVisual.Idle2(); }); #endregion //0 0.5 0.9 1 1 1 0 0.6 1 -> 0 0.5 0.9 1 0 0.6 1 RX_reachFragment = RX_moveFromA2BPer.DistinctUntilChanged(); RX_reachFragment.Subscribe(_ => { //Debug.Log(_); }); RX_reachFragment.Where(per => per == 1).Subscribe(_ => { RXEnterCellPoint(Vector2Int.CeilToInt(RX_currentPoint.Value)); } ); RX_moveFromA2BPer.Buffer(RX_moveFromA2BPer.Where(per => per == 1).Throttle(TimeSpan.FromSeconds(0.3f))) .Where(buffer => GameCore.GetGameStatus() == GameStatus.Run && buffer.Count >= 2).Subscribe(_ => { if (GameEntityMgr.GetSelectedEntity() == this) { ShowEyeSight(); } }); RX_PathChanged.Where(changed => changed).Subscribe(_ => { //allowMove = false; RX_PathChanged.Value = false; Disposable_movementTimeLine?.Dispose(); IList <ICell> path = mapController.CalculatePath(); //Disposable_movementTimeLine = Observable.FromCoroutine(MoveM).Subscribe(unit => Disposable_movementTimeLine = Observable.FromCoroutine((tok) => MoveMS(path)).SelectMany(aftermove).Subscribe(); //RX_moveAlongPath(path, tellmeHowToMove(UseForClickCellMove)); //Disposable_movementTimeLine = Observable.EveryUpdate().CombineLatest(RX_reachFragment, (frame, per) => //{ // return per; //}).Where(per => per >= 1).Where(per => //{ // if (!controllRemote.PTiliMove(1)) // { // Disposable_movementTimeLine.Dispose(); // return false; // } // return true; //}).StartWith(1).Subscribe(h => //{ // Debug.Log("reach and show next fragment"); // if (path.Count > 1) // { // RX_LastMoveFrom.Value = path[0].Point; // RX_LastMoveTo.Value = path[1].Point; // path.RemoveAt(0); // } // else // { // Disposable_movementTimeLine.Dispose(); // } //}); //if (path.Count > 0) //{ // //转变为 (1-2)-(2-3)-(3-4)-(4-5)队列 // var rawPath = path.ToObservable<ICell>(); // var skipheader = rawPath.Skip(1); // var from_to_pathset = rawPath.Zip(skipheader, (raw, skip) => // { // return new FromAndTo(raw.Point, skip.Point); // }); // //要求路线按每隔 XXs 发出1个,其中第一段希望立即发出 这个时间没有基于gamecore状态 // var timeLine = Observable.EveryUpdate().CombineLatest(RX_reachFragment, (frame, per) => // { // return per; // }).Where(per => per == 1); // Disposable_movementTimeLine = timeLine.Subscribe(async (__) => // { // var s = await from_to_pathset.ToYieldInstruction(); // Debug.Log(__ + s.from.ToString() + " " + s.to); // RX_LastMoveFrom.Value = s.from; // RX_LastMoveTo.Value = s.to; // }); // Disposable_movementTimeLine = timeLine.StartWith(1).Zip(from_to_pathset, (time, from_to) => // { // return new { from_to = from_to, per = time }; // }).Where(zip => zip.per == 1).Do(zip => // { // Debug.Log("change next "); // var from_to = zip.from_to; // RX_LastMoveFrom.Value = from_to.from; // RX_LastMoveTo.Value = from_to.to; // }, // () => // { // }).Subscribe(); //} }); RX_alive.Value = BeAlive(); var onDeath = RX_alive.Where(alive => !alive); onDeath.Subscribe(_ => { Disposable_moveFromA2BPer.Dispose(); }, () => { }); //检测当前选中的玩家和第一个被点击的非玩家对象 var getFrameStream = Observable.EveryUpdate(); var selectEntityStream = getFrameStream.Select(_ => GameEntityMgr.GetSelectedEntity()); // 1 0 2 0 1 var onSelectEntityChangedStream = selectEntityStream.DistinctUntilChanged().Where(newEntity => newEntity != null); // 1 0 2 0 1 => 1 2 1 var selectEntityChooseNPCStream = RX_targetEntity.DistinctUntilChanged(); //1 0 2 onSelectEntityChangedStream.Subscribe(_ => { //Debug.Log(_.entityID); }); selectEntityChooseNPCStream.Subscribe(_ => { }); //选中玩家后,第一次选中不同的npc var rx_selectPlayer_then_npc = onSelectEntityChangedStream.CombineLatest(selectEntityChooseNPCStream, (frameDuringSelected, choosenpc) => { //int error = -1; //if (choosenpc == null) // return error; //if (choosenpc.BeAlive()) //{ // return choosenpc.entityID; //} //return error; return(choosenpc); }) /*.DistinctUntilChanged()*/.Where(combineResults => /*combineResults != -1*/ combineResults != null); rx_selectPlayer_then_npc.Subscribe(npc => { Debug.Log(npc.entityID); //move to entity then attack IList <ICell> path2reachEntity = mapController.GetPathFinder().FindPathOnMap(mapController.GetMap().GetCell(CurrentPoint), mapController.GetMap().GetCell(npc.CurrentPoint), mapController.GetMap()); ForgetMovement(); Disposable_movementTimeLine = Observable.FromCoroutine((tok) => MoveMS(path2reachEntity)).SelectMany(aftermove).Subscribe(); //RX_moveAlongPath(path2reachEntity, tellmeHowToMove(UseForBattleMove)); //Observable.FromCoroutine(playerAction2Entity).Subscribe(); }); var rx_selectPlayer_then_mapcell = getFrameStream.CombineLatest(RX_LastClickCell.DistinctUntilChanged(), (frameDuringSelected, selectPoint) => { return(selectPoint); }).DistinctUntilChanged(); rx_selectPlayer_then_mapcell.Subscribe(Cell => { //Debug.Log(Cell); }); }