private Rect LegacyGetRandomBodyRect(Vector2 aInitialPos, Ferr2DT_SegmentDescription aDesc) { #if UNITY_5_4_OR_NEWER UnityEngine.Random.State tSeed = default(UnityEngine.Random.State); #else int tSeed = 0; #endif if (randomByWorldCoordinates) { #if UNITY_5_4_OR_NEWER tSeed = UnityEngine.Random.state; UnityEngine.Random.InitState((int)(aInitialPos.x + aInitialPos.y)); #else tSeed = UnityEngine.Random.seed; UnityEngine.Random.seed = (int)(aInitialPos.x + aInitialPos.y); #endif } Rect body = TerrainMaterial.ToUV(aDesc.body[UnityEngine.Random.Range(0, aDesc.body.Length)]); if (randomByWorldCoordinates) { #if UNITY_5_4_OR_NEWER UnityEngine.Random.state = tSeed; #else UnityEngine.Random.seed = tSeed; #endif } return(body); }
private void LegacyAddSegment(List <Vector2> aSegment, bool aLeftInner, bool aRightInner, List <float> aScale, List <CutOverrides> aCutOverrides, bool aClosed, bool aSmooth, Ferr2DT_TerrainDirection aDir = Ferr2DT_TerrainDirection.None) { Ferr2DT_SegmentDescription desc; if (aDir != Ferr2DT_TerrainDirection.None) { desc = TerrainMaterial.GetDescriptor(aDir); } else { desc = GetDescription(aSegment); } #if UNITY_5_4_OR_NEWER UnityEngine.Random.State tSeed = UnityEngine.Random.state; #else int tSeed = UnityEngine.Random.seed; #endif Rect body = TerrainMaterial.ToUV(desc.body[0]); float bodyWidth = body.width * unitsPerUV.x; #if UNITY_5_4_OR_NEWER UnityEngine.Random.InitState((int)(aSegment[0].x * 100000 + aSegment[0].y * 10000)); #else UnityEngine.Random.seed = (int)(aSegment[0].x * 100000 + aSegment[0].y * 10000); #endif Vector2 capLeftSlideDir = (aSegment[1] - aSegment[0]); Vector2 capRightSlideDir = (aSegment[aSegment.Count - 2] - aSegment[aSegment.Count - 1]); capLeftSlideDir.Normalize(); capRightSlideDir.Normalize(); aSegment[0] -= capLeftSlideDir * desc.capOffset; aSegment[aSegment.Count - 1] -= capRightSlideDir * desc.capOffset; LegacyCreateBody(desc, aSegment, aScale, aCutOverrides, bodyWidth, Mathf.Max(2, splitCount + 2), aClosed); if (!aClosed) { LegacyAddCap(aSegment, desc, aLeftInner, -1, aScale[0], aSmooth); LegacyAddCap(aSegment, desc, aRightInner, 1, aScale[aScale.Count - 1], aSmooth); } #if UNITY_5_4_OR_NEWER UnityEngine.Random.state = tSeed; #else UnityEngine.Random.seed = tSeed; #endif }
private Rect LegacyPickBody(Ferr2DT_SegmentDescription aDesc, List <CutOverrides> aCutOverrides, Vector2 aStartPos, int aCurrIndex, int aCurrCut) { int cutOverride = -1; Rect result = default(Rect); if (aCutOverrides[aCurrIndex].data != null && aCurrCut < aCutOverrides[aCurrIndex].data.Count) { cutOverride = aCutOverrides[aCurrIndex].data[aCurrCut] - 1; } if (cutOverride == -1 || cutOverride >= aDesc.body.Length) { result = LegacyGetRandomBodyRect(aStartPos, aDesc); } else { // trigger this so a random number is consumed LegacyGetRandomBodyRect(aStartPos, aDesc); result = TerrainMaterial.ToUV(aDesc.body[cutOverride]); } return(result); }
/// <summary> /// Retrieves a list of line segments that directly represent the collision volume of the terrain. This includes offsets and removed edges. /// </summary> /// <returns>A list of line segments.</returns> public List <List <Vector2> > LegacyGetColliderVerts() { if (TerrainMaterial == null) { return(new List <List <Vector2> >()); } List <Vector2> tVerts = Path.GetVertsRaw(); // drop a skirt on skirt-based terrain if ((fill == Ferr2DT_FillMode.Skirt || fill == Ferr2DT_FillMode.FillOnlySkirt) && tVerts.Count > 0) { Vector2 start = tVerts[0]; Vector2 end = tVerts[tVerts.Count - 1]; tVerts.Add(new Vector2(end.x, fillY)); tVerts.Add(new Vector2(start.x, fillY)); tVerts.Add(new Vector2(start.x, start.y)); } float fillDist = (TerrainMaterial.ToUV(TerrainMaterial.GetBody((Ferr2DT_TerrainDirection)0, 0)).width *(TerrainMaterial.edgeMaterial.mainTexture.width / pixelsPerUnit)) / (Mathf.Max(1, splitCount)) * splitDist; List <Ferr2DT_TerrainDirection> dirs = new List <Ferr2DT_TerrainDirection>(); List <List <Vector2> > result = new List <List <Vector2> >(); List <List <int> > list = GetSegments(tVerts, out dirs); List <Vector2> curr = new List <Vector2>(); // remove segments that aren't on the terrain for (int i = 0; i < list.Count; i++) { if ((dirs[i] == Ferr2DT_TerrainDirection.Bottom && !collidersBottom) || (dirs[i] == Ferr2DT_TerrainDirection.Left && !collidersLeft) || (dirs[i] == Ferr2DT_TerrainDirection.Top && !collidersTop) || (dirs[i] == Ferr2DT_TerrainDirection.Right && !collidersRight)) { if (curr.Count > 0) { result.Add(new List <Vector2>(curr)); curr.Clear( ); } } else { // create a list of verts and scales for this edge List <float> tScales = null; List <Vector2> tList = null; Ferr2D_Path.IndicesToPath(tVerts, vertScales, list[i], out tList, out tScales); // smooth it! if (smoothPath && tList.Count > 2) { Ferr2D_Path.SmoothSegment(tList, tScales, fillDist, false, out tList, out tScales); } // offset the verts based on scale and terrain edge info tList = LegacyOffsetColliderVerts(tList, tScales, dirs[i]); // sharpen corners properly! if (curr.Count > 0 && sharpCorners) { LegacyMergeCorner(ref curr, ref tList); } curr.AddRange(tList); } } if (sharpCorners) { LegacyMergeCorner(ref curr, ref curr); } if (curr.Count > 0) { result.Add(curr); } return(result); }