/** Returns a rect containing the indices of all tiles touching the specified bounds. * \param rect Graph space rectangle (in graph space all tiles are on the XZ plane regardless of graph rotation and other transformations, the first tile has a corner at the origin) */ public static IntRect GetTouchingTilesInGraphSpace(this NavmeshBase self, Rect rect) { // Calculate world bounds of all affected tiles var r = new IntRect(Mathf.FloorToInt(rect.xMin / self.TileWorldSizeX), Mathf.FloorToInt(rect.yMin / self.TileWorldSizeZ), Mathf.FloorToInt(rect.xMax / self.TileWorldSizeX), Mathf.FloorToInt(rect.yMax / self.TileWorldSizeZ)); // Clamp to bounds r = IntRect.Intersection(r, new IntRect(0, 0, self.tileXCount - 1, self.tileZCount - 1)); return(r); }
/** Returns a rect containing the indices of all tiles touching the specified bounds */ public static IntRect GetTouchingTiles(this NavmeshBase self, Bounds bounds) { bounds = self.transform.InverseTransform(bounds); // Calculate world bounds of all affected tiles var r = new IntRect(Mathf.FloorToInt(bounds.min.x / self.TileWorldSizeX), Mathf.FloorToInt(bounds.min.z / self.TileWorldSizeZ), Mathf.FloorToInt(bounds.max.x / self.TileWorldSizeX), Mathf.FloorToInt(bounds.max.z / self.TileWorldSizeZ)); // Clamp to bounds r = IntRect.Intersection(r, new IntRect(0, 0, self.tileXCount - 1, self.tileZCount - 1)); return(r); }
/// <summary> /// Gets the final point score. /// /// Note: if the reach bou is not 0, the topest player will get it. /// if more than 1 player has the same topest score, let the one who is the nearest EKaze.Ton be topest. /// </summary> public static List <PlayerTenbouChangeInfo> GetPointScore(List <Player> playerList, ref int reachBou) { List <Player> playerList_Sort = new List <Player>(playerList); playerList_Sort.Sort(SortPlayer); // topest player int topestPlayerIndex = 0; //马: 20-10 (20,10,-10,-20) int ShunMa = 10; int BackTenbou = GameSettings.Back_Tenbou; float Base = 1000f; int TopBonus = Math.FloorToInt((BackTenbou - GameSettings.Init_Tenbou) / Base * playerList.Count); //20pt if (reachBou > 0) { playerList_Sort[topestPlayerIndex].increaseTenbou(reachBou * GameSettings.Reach_Cost); reachBou = 0; } // calculate points List <PlayerTenbouChangeInfo> resultPointList = new List <PlayerTenbouChangeInfo>(); int totalPoint = 0; int bonus = 0; Player player; for (int i = 0; i < playerList_Sort.Count; i++) { player = playerList_Sort[i]; bonus = (i == topestPlayerIndex)? TopBonus : 0; PlayerTenbouChangeInfo ptci = new PlayerTenbouChangeInfo(); ptci.playerKaze = player.JiKaze; ptci.current = player.Tenbou; ptci.changed = Math.FloorToInt((player.Tenbou - BackTenbou) / Base + ((2 - i) * ShunMa) + bonus); resultPointList.Add(ptci); totalPoint += ptci.changed; } // adjust if (totalPoint != 0) { resultPointList[topestPlayerIndex].changed -= totalPoint; } return(resultPointList); }
private bool CalculateRects(UMAData.GeneratedMaterial material) { Rect nullRect = new Rect(0, 0, 0, 0); packTexture.Init(umaGenerator.atlasResolution, umaGenerator.atlasResolution, false); for (int atlasElementIndex = 0; atlasElementIndex < material.materialFragments.Count; atlasElementIndex++) { var tempMaterialDef = material.materialFragments[atlasElementIndex]; if (tempMaterialDef.isRectShared) { continue; } int width = Mathf.FloorToInt(tempMaterialDef.baseOverlay.textureList[0].width * material.resolutionScale * tempMaterialDef.slotData.overlayScale); int height = Mathf.FloorToInt(tempMaterialDef.baseOverlay.textureList[0].height * material.resolutionScale * tempMaterialDef.slotData.overlayScale); // If either width or height are 0 we will end up with nullRect and potentially loop forever if (width == 0 || height == 0) { tempMaterialDef.atlasRegion = nullRect; continue; } tempMaterialDef.atlasRegion = packTexture.Insert(width, height, MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit); if (tempMaterialDef.atlasRegion == nullRect) { if (umaGenerator.fitAtlas) { if (Debug.isDebugBuild) { Debug.LogWarning("Atlas resolution is too small, Textures will be reduced.", umaData.gameObject); } return(false); } else { if (Debug.isDebugBuild) { Debug.LogError("Atlas resolution is too small, not all textures will fit.", umaData.gameObject); } } } } return(true); }
public List <Vector3> SmoothSimple(List <Vector3> path) { if (path.Count < 2) { return(path); } List <Vector3> subdivided; if (uniformLength) { // Clamp to a small value to avoid the path being divided into a huge number of segments maxSegmentLength = Mathf.Max(maxSegmentLength, 0.005f); float pathLength = 0; for (int i = 0; i < path.Count - 1; i++) { pathLength += Vector3.Distance(path[i], path[i + 1]); } int estimatedNumberOfSegments = Mathf.FloorToInt(pathLength / maxSegmentLength); // Get a list with an initial capacity high enough so that we can add all points subdivided = ListPool <Vector3> .Claim(estimatedNumberOfSegments + 2); float distanceAlong = 0; // Sample points every [maxSegmentLength] world units along the path for (int i = 0; i < path.Count - 1; i++) { var start = path[i]; var end = path[i + 1]; float length = Vector3.Distance(start, end); while (distanceAlong < length) { subdivided.Add(Vector3.Lerp(start, end, distanceAlong / length)); distanceAlong += maxSegmentLength; } distanceAlong -= length; } // Make sure we get the exact position of the last point subdivided.Add(path[path.Count - 1]); } else { subdivisions = Mathf.Max(subdivisions, 0); if (subdivisions > 10) { Debug.LogWarning("Very large number of subdivisions. Cowardly refusing to subdivide every segment into more than " + (1 << subdivisions) + " subsegments"); subdivisions = 10; } int steps = 1 << subdivisions; subdivided = ListPool <Vector3> .Claim((path.Count - 1) *steps + 1); Polygon.Subdivide(path, subdivided, steps); } if (strength > 0) { for (int it = 0; it < iterations; it++) { Vector3 prev = subdivided[0]; for (int i = 1; i < subdivided.Count - 1; i++) { Vector3 tmp = subdivided[i]; // prev is at this point set to the value that subdivided[i-1] had before this loop started // Move the point closer to the average of the adjacent points subdivided[i] = Vector3.Lerp(tmp, (prev + subdivided[i + 1].ToUnityV3()) / 2F, strength); prev = tmp; } } } return(subdivided); }