public void BuildHero(Vector2Int pos) { Vector3 localPos = CMapUtil.GetTileCenterPosByColRow(pos); localPos.y = GameConst.DEFAULT_TERRAIN_HEIGHT + 0.1f; ProxyPool.HeroProxy.CreateHeroEntity(localPos); }
//创建, 地图中可以空置的位置 private Vector2Int FindFreeTileNotInDict(Dictionary <int, bool> dict) { Vector2Int pos = CMapUtil.FindRandomNodeLocation(m_numCols, m_numRows); int key = GetKey(pos.x, pos.y); bool block = dict.ContainsKey(key); int maxTryTimes = 100; int tryTimes = 0; while (block && tryTimes < maxTryTimes) { pos = CMapUtil.FindRandomNodeLocation(m_numCols, m_numRows); key = GetKey(pos.x, pos.y); block = dict.ContainsKey(key); tryTimes++; } if (tryTimes == maxTryTimes) { Debug.LogError("check forest num, we can not find free tile in walkable grid!"); return(CDarkConst.INVALID_VEC2INT); } return(pos); }
private IEnumerator CoroutineBuild() { for (int row = 0; row < m_assetGrid.NumRows; row++) { yield return(new WaitForEndOfFrame()); for (int col = 0; col < m_assetGrid.NumCols; col++) { var mid = m_assetGrid.GetNodeType(col, row); if (mid <= 0) { continue; } var level = m_assetGrid.GetNodeSubType(col, row); if (level <= 0) { continue; } var pos = CMapUtil.GetTileCenterPosByColRow(col, row); pos.y = GameConst.DEFAULT_TERRAIN_HEIGHT + 0.1f; CreateMonsterAtPos(mid, level, pos); } } }
public void SetUseGroundNormal(bool bNormal) { UsingGroundNormal = bNormal; if (!UsingGroundNormal && (ObjType == OBJ_TYPE.HOSTPLAYER || ObjType == OBJ_TYPE.ELSEPLAYER)) { transform.rotation = CMapUtil.GetUpNormalRotation(transform.forward); } }
private static int PlayEarlyWarningGfx(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 2; if (count == 6 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(LuaTable), typeof(LuaTable), typeof(LuaTable), typeof(float), typeof(bool))) { float lifeTime = (float)LuaScriptMgr.GetNumber(L, 5); if (lifeTime < 0.01f) { LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } string gfxName = LuaScriptMgr.GetString(L, 1); int fxId = 0; CFxOne fx = CFxCacheMan.Instance.RequestFxOne(gfxName, -1, out fxId); if (fx == null) { LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } Vector3 pos = LuaScriptMgr.GetVector3(L, 2); Vector3 dir = LuaScriptMgr.GetVector3(L, 3); Vector3 scale = LuaScriptMgr.GetVector3(L, 4); bool doNotUseProjector = LuaScriptMgr.GetBoolean(L, 6); Transform trans = fx.transform; trans.position = pos; trans.rotation = CMapUtil.GetMapNormalRotationWithDistance(pos, dir, Math.Max(scale.x, scale.z)); //法线为地面法线 trans.localScale = Vector3.one; fx.IsFixRot = false; if (fx.EarlyWarning == null) { fx.EarlyWarning = new EarlyWarningInfo(); } fx.EarlyWarning.Set(Time.time, lifeTime, scale, doNotUseProjector); fx.Play(lifeTime + 0.2f); LuaScriptMgr.Push(L, fx.gameObject); LuaScriptMgr.Push(L, fx.ID); } else { LogParamError("PlaySkillIndicatorGfx", count); LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); } return(CheckReturnNum(L, count, nRet)); }
//相机遇遮挡时拉进的设置 private bool CollisionFix(int layerMask) { CameraTraceResult bLastCollide = _CamTraceResult; if (bLastCollide == CameraTraceResult.NoHit || _IsDistChange) { dist_before_hit = _DistOffset; _IsDistChange = false; } Vector3 vDelta = -dist_before_hit * _RealDir; bool isFix = false; Vector3 vTracePos; float fDistance; _CamTraceResult = CMapUtil.CameraTrace(layerMask, _CurTargetPos, 0.02f, vDelta, out vTracePos, out fDistance); if (_CamTraceResult == CameraTraceResult.HitTerrain) { if (fDistance > 0.1f) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { _RealPos = vTracePos; } else { vDelta.Normalize(); _RealPos = _CurTargetPos + vDelta * 0.1f; } _DistOffsetDest = fDistance; isFix = true; } else if (_CamTraceResult == CameraTraceResult.HitCameraCollision) { if (fDistance > _MinCamCollisionDist) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { _RealPos = vTracePos; } else { vDelta.Normalize(); _RealPos = _CurTargetPos + vDelta * _MinCamCollisionDist; } } else { if (bLastCollide != CameraTraceResult.NoHit) //从有碰撞到无碰撞 { _DistOffset = _DistOffsetDest = dist_before_hit; } } return(isFix); }
//确保在地面一定高度 private void MapHeightFix() { float fHeight = 0.0f; if (CMapUtil.GetMapHeight(_RealPos, _CameraRadius, out fHeight)) { if (_RealPos.y < fHeight + _CameraTerrainHitHeight) { _RealPos.y = fHeight + _CameraTerrainHitHeight; } } }
//获取经过地形和碰撞调整后的跟随相机的位置 private Vector3 GetGameCamPosAfterCollionFix(float fHeightOffset) { var game_cam_pos = CCamCtrlMan.Instance.GetGameCamCtrl().GetCamCurPos(); //根据当前跟随相机的位置参数获取相机回正的原始位置 //根据地形和相机碰撞体,调整目标相机位置 Vector3 lookAtPos = GetRealLookAtPos(fHeightOffset); Vector3 vDelta = game_cam_pos - lookAtPos; Vector3 vTracePos; float fDistance; var ret = CMapUtil.CameraTrace(CUnityUtil.LayerMaskTerrainCameraCollision, lookAtPos, 0.02f, vDelta, out vTracePos, out fDistance); if (ret == CameraTraceResult.HitTerrain) { if (fDistance > 0.1f) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { game_cam_pos = vTracePos; } else { vDelta.Normalize(); game_cam_pos = lookAtPos + vDelta * 0.1f; } } else if (ret == CameraTraceResult.HitCameraCollision) { if (fDistance > _MinCamCollisionDist) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { game_cam_pos = vTracePos; } else { vDelta.Normalize(); game_cam_pos = lookAtPos + vDelta * _MinCamCollisionDist; } } //确保在地面一定高度 float fHeight = 0.0f; if (CMapUtil.GetMapHeight(game_cam_pos, _CameraRadius, out fHeight)) { if (game_cam_pos.y < fHeight + _CameraTerrainHitHeight) { game_cam_pos.y = fHeight + _CameraTerrainHitHeight; } } return(game_cam_pos); }
//获取经过地形和碰撞调整后的相机位置 private Vector3 GetCamPosAfterCollionFix(Vector3 dest_pos) { var cam_pos = dest_pos; //根据地形和相机碰撞体,调整目标相机位置 Vector3 vDelta = cam_pos - _CurTargetPos; Vector3 vTracePos; float fDistance; var ret = CMapUtil.CameraTrace(CUnityUtil.LayerMaskTerrainCameraCollision, _CurTargetPos, 0.02f, vDelta, out vTracePos, out fDistance); if (ret == CameraTraceResult.HitTerrain) { if (fDistance > 0.1f) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { cam_pos = vTracePos; } else { vDelta.Normalize(); cam_pos = _CurTargetPos + vDelta * 0.1f; } } else if (ret == CameraTraceResult.HitCameraCollision) { if (fDistance > _MinCamCollisionDist) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { cam_pos = vTracePos; } else { vDelta.Normalize(); cam_pos = _CurTargetPos + vDelta * _MinCamCollisionDist; } } //确保在地面一定高度 float fHeight = 0.0f; if (CMapUtil.GetMapHeight(cam_pos, _CameraRadius, out fHeight)) { if (cam_pos.y < fHeight + _CameraTerrainHitHeight) { cam_pos.y = fHeight + _CameraTerrainHitHeight; } } return(cam_pos); }
public AIMap(CEncodedObjectInputBufferI bin) { bin.nextTag(TAG); Dictionary <string, string> A = bin.getAttributes(); int width = EncodeUtil.parseInt(A[GAME_MAP_WIDTH_ATTR]); int height = EncodeUtil.parseInt(A[GAME_MAP_HEIGHT_ATTR]); bool vwrap = EncodeUtil.fromBoolString(A[GAME_MAP_VWRAP_ATTR]); bool hwrap = EncodeUtil.fromBoolString(A[GAME_MAP_HWRAP_ATTR]); mapUtil_ = new CMapUtil(width, hwrap, height, vwrap); stackCount_ = EncodeUtil.parseUInt(A[STACKCOUNT]); string mb = bin.getObjectText(TMAP_TAG); mapBytes_ = mb.ToCharArray(); var tmp = new List <string>(); EncodeUtil.decodeStringList(WASTELAND, tmp, bin); foreach (string s in tmp) { wasteland_.Add(s, true); } tmp.Clear(); EncodeUtil.decodeStringList(MINES, tmp, bin); foreach (string s in tmp) { mines_.Add(s, true); } tmp.Clear(); EncodeUtil.decodeStringList(ROAD, tmp, bin); foreach (string s in tmp) { roads_.Add(s, true); } tmp.Clear(); EncodeUtil.decodeDSI(RESOURCES, resources_, bin); bin.endTag(TAG); }
private void CoroutineBuild() { for (int row = 0; row < m_grid.NumRows; row++) { for (int col = 0; col < m_grid.NumCols; col++) { bool walkable = m_grid.IsWalkable(col, row); if (!walkable) { continue; } var pos = CMapUtil.GetTileCenterPosByColRow(col, row); pos.y = GameConst.DEFAULT_TERRAIN_HEIGHT + 0.05f; LoadAndCreateTile(pos); } } }
private void OnClickMap(CEvent evt) { if (!gameState.InHeroRound) { Debug.Log("<OnClickMap> Not In Hero Round"); return; } if (m_entity.IsFollowingPath) { Debug.Log("<OnClickMap> Hero IsFollowingPath"); return; } CMouseEvent e = evt as CMouseEvent; var tile = CMapUtil.GetTileByPos(e.WorldPosition); if (!TMap.Instance.Walkable(tile.x, tile.y)) { Debug.Log("<OnClickMap> Click UnWalkable Tile"); return; } var pos = m_entity.TilePosition; var dist = tile.ManhattanMagnitude(pos); if (dist > m_entity.AttributeSet.MoveRange) { Debug.Log("<OnClickMap> Click Tile Out Of Range"); return; } var target = CMapUtil.GetTileByPos(e.WorldPosition); var waypoints = CTileNavigationSystem.Instance.GetWayPointBetween(pos, target); if (dist > waypoints.Count) { Debug.Log("<OnClickMap> Click Tile Out Of Range"); return; } m_entity.OnClickMap(); m_entity.ShowMoveRange(false); MoveToLocation(waypoints, result => m_entity.ShowMoveRange(true)); }
protected void UpdateBehaviors() { if (ObjType == OBJ_TYPE.SUBOBJECT) { return; } float dt = Time.deltaTime; LinkedListNode <Behavior> curNode = _ActiveBehaviorList.First; while (curNode != null) { Behavior b = curNode.Value; if (b.Tick(dt)) { if (!b.ReActive) { LinkedListNode <Behavior> tempNode = curNode.Next; RemoveBehavior(b.Type); curNode = tempNode; } else { b.ReActive = false; curNode = curNode.Next; } } else { curNode = curNode.Next; } } if (UsingGroundNormal && (ObjType == OBJ_TYPE.HOSTPLAYER || ObjType == OBJ_TYPE.ELSEPLAYER)) { var destRot = CMapUtil.GetMapNormalRotation(transform.position, transform.forward, 0.75f); // 非匀速Lerp无限接近目标值 transform.rotation = Quaternion.Slerp(transform.rotation, destRot, Behavior.RotationLerpFactor); } }
private IEnumerator CoroutineBuild() { for (int row = 0; row < m_assetGrid.NumRows; row++) { yield return(new WaitForEndOfFrame()); for (int col = 0; col < m_assetGrid.NumCols; col++) { var subType = m_assetGrid.GetNodeSubType(col, row); var prefab = GetPrefabBySubType(subType); if (string.IsNullOrEmpty(prefab)) { continue; } var pos = CMapUtil.GetTileCenterPosByColRow(col, row); pos.y = GameConst.DEFAULT_TERRAIN_HEIGHT; LoadAndCreateTile(prefab, pos); } } }
void Awake() { m_tran = transform; int len = m_maxView * 2 + 1; for (int c = 0; c < len; c++) { for (int r = 0; r < len; r++) { var go = new GameObject($"{c}_{r}"); var gt = go.transform; gt.parent = m_tran; gt.localPosition = CMapUtil.GetTileLeftBottomPosByColRow(c - m_maxView, r - m_maxView); AssetManager.LoadTilePrefab("map_common", "TileFlag", gt, Vector3.zero); int id = r * 1000 + c; m_dict[id] = go; } } }
public AIMap(int w, bool hw, int h, bool vw, uint sc) { mapUtil_ = new CMapUtil(w, hw, h, vw); stackCount_ = sc; var sbw = new StringBuilder(""); for (int i = 0; i < mapUtil_.width_; i++) { sbw.Append(EmpireCC.CT_BLANK); } var mstr = new StringBuilder(""); for (int i = 0; i < mapUtil_.height_; i++) { mstr.Append(sbw.ToString()); } mapBytes_ = mstr.ToString().ToCharArray(); }
public virtual void prepare( int mapWidth, bool horzWrap, int mapHeight, bool vertWrap, CDLLHints hints, CGameMapParameters mparams, WBQueryI unitData, StringPollerI distributor, MapCallbackI callback, string logpath, string logname, int loglevel) { if (reallogger_ == null) { reallogger_ = new CLog(logpath, logname, loglevel); logger_ = new CSubLog("MapMaker", reallogger_); } distributor_ = distributor; callback_ = callback; unitData_ = unitData; mapUtil_ = new CMapUtil(mapWidth, horzWrap, mapHeight, vertWrap); mparams_ = mparams; //build the map output for (int i = 0; i < mapWidth * mapHeight; i++) { mapLocs_.Add(new TempMapStruct()); } //the default seed - object may get replaced random_ = new CMTRandom(); }
private bool CollisionFix(int layerMask) { bool bHideTarget = false; CameraTraceResult bLastCollide = _CamTraceResult; if (bLastCollide == CameraTraceResult.NoHit || _IsDistChangeByForce) { dist_before_hit = _DistOffset; _IsDistChangeByForce = false; } Vector3 vDelta = -dist_before_hit * _RealDir; Vector3 vTracePos; float fDistance; _CamTraceResult = CMapUtil.CameraTrace(layerMask, _CurLookAtPos, _CameraRadius, vDelta, out vTracePos, out fDistance); if (_CamTraceResult == CameraTraceResult.HitTerrain) { _IsQuickRecoverDist = false; _DistOffset = _DistOffsetDest; float dist = fDistance; if (fDistance <= 0.1f) //避免出现摄像机位置和碰撞位置重合的情况,这时方向会乱 { dist = 0.1f; } //_CurHeightOffset = GetHeightOffsetByDistOffset(dist); //real_look_at_pos = GetRealLookPos(_CurHeightOffset); vDelta.Normalize(); _RealPos = _CurLookAtPos + vDelta * dist; } else if (_CamTraceResult == CameraTraceResult.HitCameraCollision) { _IsQuickRecoverDist = false; _DistOffset = _DistOffsetDest; float dist = fDistance; if (fDistance <= _MinCamCollisionDist) { dist = _MinCamCollisionDist; } vDelta.Normalize(); _RealPos = _CurLookAtPos + vDelta * dist; } else { if (bLastCollide != CameraTraceResult.NoHit) { _DistOffset = Mathf.Clamp(dist_before_hit, CamConfig.CamMinOffsetDist, _CurMaxDistOffset); //_DistOffset = (_CurLookAtPos - _RealPos).magnitude; //_DistOffset = Mathf.Clamp(_DistOffset, CamConfig._CamMinOffsetDist, _CurMaxDistOffset); _IsQuickRecoverDist = true; } _RealPos = _CurLookAtPos - _DistOffset * _RealDir; } bool bTerrainFix = false; float fTargetHeight; if (!CMapUtil.GetMapHeight(_CurLookAtPos, _CameraRadius, out fTargetHeight)) { fTargetHeight = CUnityUtil.InvalidHeight; } //确保在地面一定高度 float fHeight = 0.0f; if (CMapUtil.GetMapHeight(_RealPos, _CameraRadius, out fHeight)) { Vector3 vPos = _RealPos; if (vPos.y < fHeight + _CameraTerrainHitHeight) { vPos.y = fHeight + _CameraTerrainHitHeight; if ((vPos - _CurLookAtPos).sqrMagnitude < _DistOffset * _DistOffset) { _RealPos = vPos; bTerrainFix = true; } //_DistOffset = (_CurLookAtPos - _RealPos).magnitude; } //不能低于目标所在的高度 if (fTargetHeight != CUnityUtil.InvalidHeight && vPos.y < fTargetHeight + _CameraTerrainHitHeight) { vPos.y = fTargetHeight + _CameraTerrainHitHeight; _RealPos = vPos; bTerrainFix = true; } } if (!bTerrainFix) { bHideTarget = (_RealPos - _CurLookAtPos).sqrMagnitude < _MinCamHostDist * _MinCamHostDist; } return(bHideTarget); }
public void Print() { CMapUtil.PrintGird(m_map); }
public void PrintGrid() { CMapUtil.PrintGird(m_mapWalkableData); }
public void DrawGrid() { CMapUtil.DrawGrid(m_mapWalkableData); }
//////////////////////////////////////////////////////////////////// //Reloading protected AIPlayerData( int position, string path, string logname, Dictionary <string, string> caMap, CEncodedObjectInputBufferI bin, AIEventInterfaceI aiEvent, AICommandInterfaceI command, AIQueryI query, AICheatI cheat, int logLevel) : base(position, path, logname, caMap, bin, aiEvent, command, query, cheat, logLevel) { dlogger_ = new CSubLog("PlayerData:" + Convert.ToString(position), realLog_); curturn_ = EncodeUtil.parseInt(caMap[CUR_TURN]); numPlayers_ = EncodeUtil.parseInt(caMap[NUM_PLAYERS]); rdWeight_ = EncodeUtil.parseInt(caMap[RD_WEIGHT]); unitsBeforeDrain_ = EncodeUtil.parseInt(caMap[UNITS_BEFORE_DRAIN]); bin.nextTag(CPlayer.TAGS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(CPlayer.TAGS)) { players_.Add(new CPlayer(bin)); } } bin.endTag(CPlayer.TAGS); bin.nextTag(SPOTU); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(SPOTU)) { CUnit u = CUnit.decodeCUnit(bin, query_); masterObjects_.Add(u.gid_, u); spotMap_.Add(u.gid_, u); spots_.Add(u); } } bin.endTag(SPOTU); bin.nextTag(SPOTC); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(SPOTC)) { CProducerUnit c = CProducerUnit.decodeCProducerUnit(bin, query_); masterObjects_.Add(c.gid_, c); knownCitiesVec_.Add(c); spotMap_.Add(c.gid_, c); spots_.Add(c); } } bin.endTag(SPOTC); bin.nextTag(SPOTP); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(SPOTP)) { CProducerUnit p = CProducerUnit.decodeCProducerUnit(bin, query); masterObjects_.Add(p.gid_, p); spotMap_.Add(p.gid_, p); spots_.Add(p); } } bin.endTag(SPOTP); bin.nextTag(CITIES); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(CITIES)) { CProducerUnit c = CProducerUnit.decodeCProducerUnit(bin, query_); masterObjects_.Add(c.gid_, c); knownCitiesVec_.Add(c); cities_.Add(c); cityMap_.Add(c.gid_, c); } } bin.endTag(CITIES); bin.nextTag(UNITS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(UNITS)) { CUnit u = CUnit.decodeCUnit(bin, query_); masterObjects_.Add(u.gid_, u); unitMap_.Add(u.gid_, u); units_.Add(u); } } bin.endTag(UNITS); bin.nextTag(PRODUCERS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(PRODUCERS)) { CProducerUnit p = CProducerUnit.decodeCProducerUnit(bin, query_); masterObjects_.Add(p.gid_, p); producers_.Add(p); producerMap_.Add(p.gid_, p); unitMap_.Add(p.gid_, p); units_.Add(p); } } bin.endTag(PRODUCERS); bin.nextTag(CSupplyRoute.TAGS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(CSupplyRoute.TAGS)) { var csr = new CSupplyRoute(bin); supplySources_.Add(csr.rid_, csr); } } bin.endTag(CSupplyRoute.TAGS); map_ = new AIMap(bin); mapUtil_ = map_.mapUtil_; gameRules_ = new CGameRules(bin); vc_ = new CVictoryConditions(bin); bin.nextTag(CProposal.TAGS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(CProposal.TAGS)) { var p = new CProposal(bin); proposals_.Add(p); } } bin.endTag(CProposal.TAGS); bin.nextTag(CProductionReportData.TAGS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(CProductionReportData.TAGS)) { var prd = new CProductionReportData(bin); prodReport_.Add(prd); } } bin.endTag(CProductionReportData.TAGS); random_ = new CMTRandom(AI_RANDOM_TAG, bin); //retrieve flyover foUnit_ = null; if (caMap.ContainsKey(FOUNIT_ID)) { uint fid = EncodeUtil.parseUInt(caMap[FOUNIT_ID]); foUnit_ = masterObjects_[fid]; } }
/*地图中随机一个位置*/ public Vector2Int FindRandomNodeLocation() { return(CMapUtil.FindRandomNodeLocation(m_mapMeta.Rows, m_mapMeta.Cols)); }
//////////////////////////////////////////////////////////// //Game State - This event is sent initially and on reloads //Gives the current state of your forces and what you can see private void processGameState(CStateEvent gse) { //Player Information numPlayers_ = gse.players_.Count; for (int i = 0; i < numPlayers_; i++) { players_.Add(gse.players_[i]); if (i == position_) { pname_ = gse.players_[i].pname_; } } curturn_ = gse.curturn_; rdWeight_ = gse.rdWeight_; unitsBeforeDrain_ = gse.unitsBeforeDrain_; //Map Information mapUtil_ = new CMapUtil(gse.w_, gse.hw_, gse.h_, gse.vw_); map_ = new AIMap(gse.w_, gse.hw_, gse.h_, gse.vw_, gse.gameRules_.stackCount_); uint fogid = gse.flyoverGid_; addMapLocations(gse.exploredLocs_); addCities(gse.cities_); addProds(gse.prods_); addUnits(gse.units_); addSpots(gse.spots_); addSupplyRoutes(gse.routes_); gameRules_ = gse.gameRules_; vc_ = gse.vc_; if (gse.proposals_ != null) { foreach (CProposal p in gse.proposals_) { proposals_.Add(p); } } //Grab Flyover if need be (Basic and Standard Games) if (fogid != CUnitConstants.NOUNIT) { foUnit_ = getUnit(fogid); } prodReport_.Clear(); if (gse.prodData_ != null) { foreach (CProductionReportData prd in gse.prodData_) { prodReport_.Add(prd); } } gameStateReceived(); }
//我们移动到下一帧的时候, 探测能否过去, 有时候甚至需要顺着边缘挤过去 private bool TryMove(Vector3 currPos, Vector3 pos) { Vector3 left, right; float halfLength = m_spacial.Length * 0.5f; float halfWidth = m_spacial.Width * 0.5f; //确认tile级的面向方向 int directionConst = 0; float dx = Mathf.Abs(pos.x - currPos.x); float dz = Mathf.Abs(pos.z - currPos.z); if (dx > dz) { if (pos.x > currPos.x) { directionConst = CUnitSpacialComp.DIRECTION_RIGHT; } else { directionConst = CUnitSpacialComp.DIRECTION_LEFT; } } else { if (pos.z > currPos.z) { directionConst = CUnitSpacialComp.DIRECTION_UP; } else { directionConst = CUnitSpacialComp.DIRECTION_DOWN; } } if (directionConst == CUnitSpacialComp.DIRECTION_UP) { left = new Vector3(pos.x - halfLength, 0, pos.z + halfWidth); right = new Vector3(pos.x + halfLength, 0, pos.z + halfWidth); } else if (directionConst == CUnitSpacialComp.DIRECTION_DOWN) { left = new Vector3(pos.x + halfLength, 0, pos.z - halfWidth); right = new Vector3(pos.x - halfLength, 0, pos.z - halfWidth); } else if (directionConst == CUnitSpacialComp.DIRECTION_LEFT) { left = new Vector3(pos.x - halfWidth, 0, pos.z - halfLength); right = new Vector3(pos.x - halfWidth, 0, pos.z + halfLength); } else { left = new Vector3(pos.x + halfWidth, 0, pos.z + halfLength); right = new Vector3(pos.x + halfWidth, 0, pos.z - halfLength); } Vector2Int leftTile = CMapUtil.GetTileByPos(left.x, left.z); bool canLeft = CTileNavigationSystem.Instance.IsWalkable(leftTile.x, leftTile.y); Vector2Int rightTile = CMapUtil.GetTileByPos(right.x, right.z); bool canRight = CTileNavigationSystem.Instance.IsWalkable(rightTile.x, rightTile.y); //Debug.Log("canleft -----" + canLeft.ToString() + "----- left tile " + leftTile.ToString()); //Debug.Log("canRight -----" + canRight.ToString() + "----- right tile " + rightTile.ToString()); if (canLeft && canRight) { return(true); } /* oh, no. sth is in front of me, 所以得停止前进 */ if (!canLeft && !canRight) { return(false); } /* 有一侧可以通过,绕着边缘, 挤过去 */ float lowspeed = m_mover.MaxSpeed * 0.8f; Vector3 edge = Vector3.zero; float edgeRight, edgeLeft; if (directionConst == CUnitSpacialComp.DIRECTION_UP) { edge = new Vector3(-lowspeed, 0, 0); edgeLeft = (leftTile.x + 1.0f); edgeLeft = edgeLeft - left.x; } else if (directionConst == CUnitSpacialComp.DIRECTION_DOWN) { edge = new Vector3(lowspeed, 0, 0); edgeLeft = leftTile.x; edgeLeft = left.x - edgeLeft; } else if (directionConst == CUnitSpacialComp.DIRECTION_LEFT) { edge = new Vector3(0, 0, -lowspeed); edgeLeft = (leftTile.y + 1.0f); edgeLeft = edgeLeft - left.z; } else { edge = new Vector3(0, 0, lowspeed); edgeLeft = leftTile.y; edgeLeft = left.z - edgeLeft; } /* 左前方不能通行, */ if (!canLeft && edgeLeft < 0.5f) { m_mover.Move(-edge, false); return(true); } /* 右前方不能通行, 但 右边缘擦肩而过*/ edgeRight = m_spacial.Length - edgeLeft; if (!canRight && edgeRight < 0.5f) { m_mover.Move(edge, false); return(true); } //有一边不能通过, 但又挤不过去 return(false); }