static void AddDecoTerrain(Ferr2DT_TerrainMaterial aMaterial) { GameObject obj = new GameObject("New Terrain"); Ferr2D_Path path = obj.AddComponent <Ferr2D_Path>(); Ferr2DT_PathTerrain terrain = obj.AddComponent <Ferr2DT_PathTerrain>(); path.Add(new Vector2(-6, 6)); path.Add(new Vector2(6, 6)); terrain.fill = Ferr2DT_FillMode.Skirt; terrain.createCollider = false; terrain.SetMaterial(aMaterial); terrain.RecreatePath(); obj.isStatic = true; obj.transform.position = GetSpawnPos(); Selection.activeGameObject = obj; EditorGUIUtility.PingObject(obj); }
static GameObject CreateBaseTerrain(Ferr2DT_TerrainMaterial aMaterial, bool aCreateColliders) { GameObject obj = new GameObject("New Terrain"); Ferr2D_Path path = obj.AddComponent <Ferr2D_Path>(); Ferr2DT_PathTerrain terrain = obj.AddComponent <Ferr2DT_PathTerrain>(); bool hasEdges = aMaterial.Has(Ferr2DT_TerrainDirection.Bottom) || aMaterial.Has(Ferr2DT_TerrainDirection.Left) || aMaterial.Has(Ferr2DT_TerrainDirection.Right); if (hasEdges) { path.Add(new Vector2(-6, 0)); path.Add(new Vector2(-6, 6)); path.Add(new Vector2(6, 6)); path.Add(new Vector2(6, 0)); path.closed = true; } else { path.Add(new Vector2(-6, 6)); path.Add(new Vector2(6, 6)); terrain.splitCorners = false; path.closed = false; } if (aMaterial.fillMaterial != null) { if (hasEdges) { terrain.fill = Ferr2DT_FillMode.Closed; } else { terrain.fill = Ferr2DT_FillMode.Skirt; terrain.splitCorners = true; } } else { terrain.fill = Ferr2DT_FillMode.None; } terrain.smoothPath = Ferr_Menu.SmoothTerrain; terrain.pixelsPerUnit = Ferr_Menu.PPU; terrain.createCollider = aCreateColliders; terrain.SetMaterial(aMaterial); terrain.RecreatePath(true); obj.isStatic = true; obj.transform.position = GetSpawnPos(); return(obj); }
/// <summary> /// Adds a terrain vertex at the specified index, or at the end if the index is -1. Returns the index of the added vert. /// </summary> /// <param name="aPt">The terrain point to add, z is always 0</param> /// <param name="aAtIndex">The index to put the point at, or -1 to put at the end</param> /// <returns>Index of the point</returns> public int AddPoint(Vector2 aPt, int aAtIndex = -1) { if (path == null) { path = GetComponent <Ferr2D_Path>(); } if (directionOverrides == null) { directionOverrides = new List <Ferr2DT_TerrainDirection>(); } if (aAtIndex == -1) { path.Add(aPt); directionOverrides.Add(Ferr2DT_TerrainDirection.None); return(path.pathVerts.Count); } else { path.pathVerts.Insert(aAtIndex, aPt); directionOverrides.Insert(aAtIndex, Ferr2DT_TerrainDirection.None); return(aAtIndex); } }