private static void RenderGridImageAsPngFile(GridType gridType) { var gridLines = GridCreator.CreateGrid(gridType, ImageWidth, ImageHeight, false); var outputPath = Path.Combine(Path.GetTempPath(), "ScreenGrid"); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } using (var image = new Bitmap(ImageWidth, ImageHeight)) { using (var g = Graphics.FromImage(image)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.Clear(Color.Transparent); using (var pen = new Pen(Color.Black)) { foreach (var line in gridLines) { g.DrawLine( pen, new Point((int)(line.p1.X * (ImageWidth - 1)), (int)(line.p1.Y * (ImageHeight - 1))), new Point((int)(line.p2.X * (ImageWidth - 1)), (int)(line.p2.Y * (ImageHeight - 1)))); } } } image.Save(Path.Combine(outputPath, gridType.ToString() + ".png"), System.Drawing.Imaging.ImageFormat.Png); } }
private void OnValidate() { if (Creator == null) { Creator = FindObjectOfType <GridCreator>(); } }
void OnSelectionChange() // Checks for grid selection change, selects the current object if it is a grid. { if (Selection.activeGameObject != null) { if (Selection.activeGameObject.tag == "Grid") { if (selectedGrid != null) { selectedGridCreator.isSelected = false; } selectedGrid = Selection.activeGameObject; selectedGridCreator = selectedGrid.GetComponent<GridCreator>(); selectedGridCreator.isSelected = true; isGridSelected = true; } else { if (selectedGrid != null) { selectedGridCreator.isSelected = false; } isGridSelected = false; } } else { if (selectedGrid != null) { selectedGridCreator.isSelected = false; } isGridSelected = false; } Repaint(); }
public void Start() { // TEMPORARY CODE to get a layer SortingLayer[] sortingLayers = SortingLayer.layers; foreach (SortingLayer sl in sortingLayers) { if (sl.name == "Ground") { movementLayer = sl; } } baseRenderer = this.GetComponent <SpriteRenderer>(); player = (PlayerControls)FindObjectOfType(typeof(PlayerControls)); gridCreator = (GridCreator)FindObjectOfType(typeof(GridCreator)); GE = (GolemEnums)FindObjectOfType(typeof(GolemEnums)); stats = GE.StructGen(arms, core, frame, head, legs, torso, weapon1, weapon2); currentCoords = new TileCoords(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y), movementLayer); if (faction == Faction.Player) { baseRenderer.color = new Color(0.5f, 0.5f, 1f, 1f); } else if (faction == Faction.Enemy1 || faction == Faction.Enemy2) { baseRenderer.color = new Color(1f, 0f, 0f, 1f); } player.unitDict.Add(currentCoords, this.gameObject); }
public void ThreeByThreeTiltedGridWithLargeNumbers() { // arrange List <Point> points = new List <Point>(); points.Add(new Point(117000, 141000)); points.Add(new Point(137000, 143000)); points.Add(new Point(100000, 100000)); points.Add(new Point(99000, 120000)); points.Add(new Point(138000, 123000)); points.Add(new Point(120000, 101000)); points.Add(new Point(97000, 140000)); points.Add(new Point(118000, 121000)); points.Add(new Point(140000, 103000)); // act GridCreator gridCreator = new GridCreator(); Grid grid = gridCreator.CreateGrid(points); // assert Assert.AreEqual(grid.GetPoint(0, 0), new Point(97000, 140000)); // row 1 column 1 Assert.AreEqual(grid.GetPoint(1, 0), new Point(117000, 141000)); // row 1 column 2 Assert.AreEqual(grid.GetPoint(2, 0), new Point(137000, 143000)); // row 1 column 3 Assert.AreEqual(grid.GetPoint(0, 1), new Point(99000, 120000)); // row 2 column 1 Assert.AreEqual(grid.GetPoint(1, 1), new Point(118000, 121000)); // row 2 column 2 Assert.AreEqual(grid.GetPoint(2, 1), new Point(138000, 123000)); // row 2 column 3 Assert.AreEqual(grid.GetPoint(0, 2), new Point(100000, 100000)); // row 3 column 1 Assert.AreEqual(grid.GetPoint(1, 2), new Point(120000, 101000)); // row 3 column 2 Assert.AreEqual(grid.GetPoint(2, 2), new Point(140000, 103000)); // row 3 column 3 Assert.AreEqual(grid.GetAlpha().Value, 4.3); // check alpha }
private void Awake() { // Initialize grid Vector3[,] grid = GridCreator.Create2DGrid(gridWidth, cellWidth, GridCreator.Axes.XZ); Vector3[] positionsForLineRenderer = new Vector3[gridWidth * gridWidth]; gridPoints = new GridPoint[gridWidth, gridWidth]; for (int i = 0; i < gridWidth; i++) { for (int j = 0; j < gridWidth; j++) { gridPoints[i, j] = new GridPoint(grid[i, j]); //gridPoints[i, j].targetPosition = gridPoints[i, j].position + Vector3.up * Random.Range(0f, 40f); positionsForLineRenderer[i * gridWidth + j] = gridPoints[i, j].position; //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); //cube.transform.parent = transform; //cube.transform.localPosition = gridPositions[i, j]; //GameObject newLetter = Instantiate(letterPrefab); //newLetter.transform.parent = transform; //gridPoints[i, j].letter = newLetter; } } m_LineRenderer.positionCount = positionsForLineRenderer.Length; m_LineRenderer.SetPositions(positionsForLineRenderer); // Set up noise noiseOffset = Random.insideUnitCircle * 1000f; targetScale = noiseScale; NodeServerManager.APIReturned += ProcessWord; }
public void ThreeByThreeTiltedGridWithDecimalNumbers() { // arrange List <Point> points = new List <Point>(); points.Add(new Point(11.7, 14.1)); points.Add(new Point(13.7, 14.3)); points.Add(new Point(10, 10)); points.Add(new Point(9.9, 12)); points.Add(new Point(13.8, 12.3)); points.Add(new Point(12, 10.1)); points.Add(new Point(9.7, 14)); points.Add(new Point(11.8, 12.1)); points.Add(new Point(14, 10.3)); // act GridCreator gridCreator = new GridCreator(); Grid grid = gridCreator.CreateGrid(points); // assert Assert.AreEqual(grid.GetPoint(0, 0), new Point(9.7, 14)); // row 1 column 1 Assert.AreEqual(grid.GetPoint(1, 0), new Point(11.7, 14.1)); // row 1 column 2 Assert.AreEqual(grid.GetPoint(2, 0), new Point(13.7, 14.3)); // row 1 column 3 Assert.AreEqual(grid.GetPoint(0, 1), new Point(9.9, 12)); // row 2 column 1 Assert.AreEqual(grid.GetPoint(1, 1), new Point(11.8, 12.1)); // row 2 column 2 Assert.AreEqual(grid.GetPoint(2, 1), new Point(13.8, 12.3)); // row 2 column 3 Assert.AreEqual(grid.GetPoint(0, 2), new Point(10, 10)); // row 3 column 1 Assert.AreEqual(grid.GetPoint(1, 2), new Point(12, 10.1)); // row 3 column 2 Assert.AreEqual(grid.GetPoint(2, 2), new Point(14, 10.3)); // row 3 column 3 Assert.AreEqual(grid.GetAlpha().Value, 4.3); // check alpha }
public static IEnumerable <IGameObject> InitCollection() { list = new List <IGameObject>(); GridCreator.Grid = GridCreator.CreateGrid(PointCreator.CreatePoints()); var background = BaseGameObject.CreateStaticObject(AnimationType.MazeBlue, 0, 0); var tempList = PointCreator.CreatePoints().Select(GameObjectCreator.CreateOGameObject).Where(x => x != null).ToList(); var pac = tempList.OfType <Pacman>().First(); GrandArbiter grandArbiter = new GrandArbiter { Maze = (Background)background, Blinky = tempList.OfType <Blinky>().First() }; pac.Arbiter = grandArbiter; list.Add(background); list.AddRange(tempList); return(list); }
void OnSceneGUI() { // Takes control of the Unity scene when a grid is selected //int controlID = ; HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); gridCreator = Selection.activeGameObject.GetComponent <GridCreator>(); if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && !EditorApplication.isCompiling) { //Undo.RecordObject(gridCreator, "Edited grid creator"); Vector3 mousePos = Event.current.mousePosition; // Gets mouse position mousePos.y = Screen.height - mousePos.y - 36.0f; // Corrects for odd Unity issue Vector3 mouseInWorld = SceneView.lastActiveSceneView.camera.ScreenToWorldPoint(mousePos); // Converts mouse to world Vector2 clickedCoords = new Vector2(Mathf.RoundToInt(mouseInWorld.x), Mathf.RoundToInt(mouseInWorld.y)); // Converst to Vector2 coordinate system if (Event.current.button == 0) { gridCreator.UseTool(clickedCoords); } else if (Event.current.button == 1) { gridCreator.PickColor(clickedCoords); } } }
private void Start() { gridCreator = GetComponentInChildren <GridCreator>(); GameObject Canvas = GameObject.Find("Canvas"); ressources = Canvas.GetComponentsInChildren <Ressources>(); }
void Update() { // Check for next scene indicator if (Input.GetKeyDown("t")) { dungeonPlayerScene(); } if (Application.loadedLevel == 1 && !built) { GameObject go = GameObject.Find("GridManager"); GridCreator gc = (GridCreator)go.GetComponent(typeof(GridCreator)); gc.BuildGrid(); built = true; } if (Application.loadedLevel == 2 && !built) { //if (size != 0) { GameObject go = GameObject.Find("GridManager"); GridCreator gc = (GridCreator)go.GetComponent(typeof(GridCreator)); gc.BuildGrid(); built = true; //} } }
public void Setup() { _spyWriter = new Mock <IWriter>(); _presenter = new CommandLinePresenter(_spyWriter.Object); _testGenerationViewModel = new GenerationViewModel(GridCreator.GetOnlyAliveCenterGrid(), 0); }
private void Awake() { _cameraPoints = FindObjectOfType <CameraPoints>(); _gridCreator = FindObjectOfType <GridCreator>(); _camera = GetComponent <Camera>(); _spawner = FindObjectOfType <Spawner>(); }
public void ThreeByThreeStraightGridWithNormalNumbers() { // arrange List <Point> points = new List <Point>(); points.Add(new Point(14, 14)); points.Add(new Point(12, 10)); points.Add(new Point(12, 12)); points.Add(new Point(14, 10)); points.Add(new Point(10, 10)); points.Add(new Point(14, 12)); points.Add(new Point(10, 12)); points.Add(new Point(10, 14)); points.Add(new Point(12, 14)); // act GridCreator gridCreator = new GridCreator(); Grid grid = gridCreator.CreateGrid(points); // assert Assert.AreEqual(grid.GetPoint(0, 0), new Point(10, 14)); // row 1 column 1 Assert.AreEqual(grid.GetPoint(1, 0), new Point(12, 14)); // row 1 column 2 Assert.AreEqual(grid.GetPoint(2, 0), new Point(14, 14)); // row 1 column 3 Assert.AreEqual(grid.GetPoint(0, 1), new Point(10, 12)); // row 2 column 1 Assert.AreEqual(grid.GetPoint(1, 1), new Point(12, 12)); // row 2 column 2 Assert.AreEqual(grid.GetPoint(2, 1), new Point(14, 12)); // row 2 column 3 Assert.AreEqual(grid.GetPoint(0, 2), new Point(10, 10)); // row 3 column 1 Assert.AreEqual(grid.GetPoint(1, 2), new Point(12, 10)); // row 3 column 2 Assert.AreEqual(grid.GetPoint(2, 2), new Point(14, 10)); // row 3 column 3 Assert.AreEqual(grid.GetAlpha().Value, 0); // check alpha }
public void AddTrees(GridCreator grid, float scale) { List<List<GameObject>> trees = new List<List<GameObject>>(); trees.Add(CreateListOfPrefabs(grid.conetreePrefab, 0, -1, scale)); trees.Add(CreateListOfPrefabs(grid.woodtreePrefab, 1, -1,scale)); FillWithTrees(grid, trees, scale); }
public GameServer(string location = LOCATION) : base(location) { grid = GridCreator.Creator1(50, 50, 0); //grid = GridCreator.Creator1(20, 20, 0); Console.WriteLine("Map Generated!"); Console.WriteLine(ItemCrafting.Instance.ToString()); Console.WriteLine("Crafter generated!"); gameActions = new List <GameAction>(); }
void Start() { gridchecker = waypointSet.GetComponent <GridCreator>(); //while (!gridchecker.finished) { } waypoints = new WaypointGraph(waypointSet); path = new List <int>(); pathfinder = createPathfinder(); pathfinder.navGraph = waypoints.navGraph; }
public override void OnInspectorGUI() { DrawDefaultInspector(); TileManager[] tiles = new TileManager[targets.Length]; if (GUILayout.Button("Generate Object")) { for (int i = 0; i < tiles.Length; i++) { tiles [i] = (TileManager)targets [i]; FurnitureBehaviour objectOnTile = tiles [i].transform.GetComponentInChildren <FurnitureBehaviour> (); if (objectOnTile != null) { DestroyImmediate(objectOnTile.gameObject); } switch (tiles [i].tileStartStatus) { case StartObject.ZoneWall: tiles [i].BuildProp(GridCreator.Self().zoneWall); break; case StartObject.ZoneDoor: tiles [i].BuildProp(GridCreator.Self().zoneDoor); break; case StartObject.ForOfWar: tiles [i].BuildProp(GridCreator.Self().fogOfWar); break; default: break; } } } if (GUILayout.Button("Rotate Object")) { for (int i = 0; i < tiles.Length; i++) { tiles [i] = (TileManager)targets [i]; FurnitureBehaviour objectTemp = tiles [i].transform.GetComponentInChildren <FurnitureBehaviour> (); if (objectTemp != null) { Transform objectToRotate = objectTemp.transform; Quaternion rotation = objectToRotate.rotation; rotation.eulerAngles = new Vector3(objectToRotate.rotation.eulerAngles.x, objectToRotate.rotation.eulerAngles.y + 90, objectToRotate.rotation.eulerAngles.z); objectToRotate.rotation = rotation; } } } }
private void MakeGrid() { var creator = new GridCreator(); //grid tekenen lukt al, hier blijven we dus af creator.SetupGrid(g, 8, 8); creator.FillWithEllipseWithEvent(g, t_MouseLeftButtonUp, Ellipse_IsMouseDirectlyOverChanged); // creator.FillWithEllipseWithEvent(g); }
public void ShouldCalculateUsedSpace() { KnotHash kh = new KnotHash(); GridCreator g = new GridCreator(kh); var grid = g.Generate("flqrgnkx"); Defragmentor f = new Defragmentor(); Assert.Equal(8108, f.GetUsedSpace(grid)); }
public void ShouldCountConnectedComponents() { KnotHash kh = new KnotHash(); GridCreator g = new GridCreator(kh); var grid = g.Generate("flqrgnkx"); Defragmentor f = new Defragmentor(); Assert.Equal(1242, f.CountUsedGroups(grid)); }
private void Awake() { if (Instance != null) { Destroy(Instance.gameObject); } Instance = this; GenerateGrid(); SetCameraPosition(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); GridCreator gridScript = (GridCreator)target; if (GUILayout.Button("Build Grid")) { gridScript.CreateGrid(); } }
static void Main(string[] args) { KnotHash kh = new KnotHash(); GridCreator d = new GridCreator(kh); Defragmentor f = new Defragmentor(); var square = d.Generate("nbysizxe"); // Part one Console.WriteLine(f.GetUsedSpace(square)); // Part two Console.WriteLine(f.CountUsedGroups(square)); }
public void GenerateGrids() { KnotHash kh = new KnotHash(); GridCreator g = new GridCreator(kh); var grid = g.Generate("flqrgnkx"); Assert.Equal(128, grid.Length); foreach (var row in grid) { Assert.Equal(128, row.Length); } }
void OnTriggerEnter(Collider Target) { if (Target.tag == "Player") { IsPlayer = true; Transform mmCell = GridCreator.MiniMap[(int)(gameObject.transform.position.x / scaling), (int)(gameObject.transform.position.z / scaling)]; mmCell.renderer.material.color = Color.red; if (mmCell.transform.position.x == GridCreator.GoalBlock.transform.position.x && mmCell.transform.position.z == GridCreator.GoalBlock.transform.position.z) { GridCreator.MazeComplete(); } } }
private static string RenderGridImageAsXamlPath(GridType gridType) { var gridLines = GridCreator.CreateGrid(gridType, ImageWidth, ImageHeight, false); var result = new StringBuilder(); foreach (var line in gridLines) { var command = String.Format(CultureInfo.InvariantCulture, "M{0:F4},{1:F4}L{2:F4},{3:F4}", line.p1.X, line.p1.Y, line.p2.X, line.p2.Y); result.Append(command); } return(result.ToString()); }
public void load() { rd = SaveLoad.load(); GridCreator gc = (GridCreator)gameObject.GetComponent(typeof(GridCreator)); GameObject[] tiles = GameObject.FindGameObjectsWithTag("Tile"); foreach (GameObject item in tiles) { Destroy(item); } //gc.BuildGrid (size); gc.BuildGrid(); }
// Use this for initialization void Start() { // Note from TJ: This returns only one grid (with all its layers). If you ever use more than one grid for any reason it will return the first. gridCreator = (GridCreator)FindObjectOfType(typeof(GridCreator)); //TEMPORARY? SortingLayer[] sortingLayers = SortingLayer.layers; foreach (SortingLayer sl in sortingLayers) { if (sl.name == "Ground") { movementLayer = sl; } } }
public override void OnInspectorGUI() { DrawDefaultInspector(); GridCreator gridScirpt = (GridCreator)target; if (GUILayout.Button("Generate Grid")) { gridScirpt.GenerateGrid(); } if (GUILayout.Button("Update Prefabs")) { gridScirpt.ChangePrefabProperties(); } }
public static void Register(Type type) { var key = GetModelKey(type); if (key.IsNullOrEmpty()) { throw new HxException($"{type.AssemblyQualifiedName} 没有找到ModelKey定义"); } if (Schemes.ContainsKey(key)) { throw new HxException($"ModelKey 存在重复定义:{key}"); } var scheme = GridCreator.Create(type); Schemes.TryAdd(key, scheme); }
//Create everything public void mainProgramWithoutWaitingTime() { DestroyOldMaze (); if (useRandomSeed) { seed = Random.Range (0, 1000000000).ToString (); } pseudoRandom = new System.Random (seed.GetHashCode ()); newGridCreator = new GridCreator (length, width); gridWidth = newGridCreator.getGridWidth (); gridLength = newGridCreator.getGridLength (); newGridCreator.MainProgramm (); Room[,] tmp = newGridCreator.getGridOfRooms (); xGap = wall.GetComponent<Renderer> ().bounds.size.x; zGap = wall.GetComponent<Renderer> ().bounds.size.z; deadEndList = new List<GameObject> (); GameObject mainCam = GameObject.FindGameObjectWithTag ("MainCamera"); mainCam.transform.position = new Vector3 (xGap * ((gridLength / 2) - 1) + xGap / 2, 100, zGap * (gridWidth / 2)); mainCam.transform.rotation = Quaternion.Euler (90, 0, 0); mainCam.GetComponent<Camera> ().orthographic = true; mainCam.GetComponent<Camera> ().orthographicSize = xGap * ((gridLength / 2) + 2); Labyrinth = new GameObject (); Labyrinth.name = "Labyrinth"; Labyrinth.tag = "Labyrinth"; GameObject generalMaze = new GameObject (); generalMaze.name = "GeneralMaze"; generalMaze.transform.parent = Labyrinth.transform; fillMazeWithTiles (tmp, generalMaze); buildBorderWalls (Labyrinth); if(Application.isPlaying) Destroy(this); else DestroyImmediate(this); }
public void AddBuildings(GridCreator grid, List<List<Vector3>> streets, float scale) { List<List<GameObject>> buildings = new List<List<GameObject>>(); buildings.Add(CreateListOfPrefabs(grid.housePrefab, -1, 0, scale)); buildings.Add(CreateListOfPrefabs(grid.skyscraperPrefab, -1, 1, scale)); int buildingIndex = 1; for (int i = 0; i < streets.Count; i++) { List<Vector2> side1 = new List<Vector2>(); List<Vector2> side2 = new List<Vector2>(); ComputeContourPoints(out side1, out side2, streets[i], 4f); for (int j = 0; j < side1.Count-1; j++) { Vector3 pointFrom = new Vector3(side1[j].x, 0f, side1[j].y); Vector3 pointTo = new Vector3(side1[j+1].x, 0f, side1[j+1].y); buildingIndex = FillWithBuildings(grid, scale, pointFrom, pointTo, buildingIndex, streets[i][j], streets[i][j + 1], buildings); pointFrom = new Vector3(side2[j].x, 0f, side2[j].y); pointTo = new Vector3(side2[j + 1].x, 0f, side2[j + 1].y); buildingIndex = FillWithBuildings(grid, scale, pointFrom, pointTo, buildingIndex, streets[i][j], streets[i][j + 1], buildings); } } foreach (GameObject house in buildings[0]) { if (house.GetComponent<Building>() != null) DestroyImmediate(house.gameObject); } foreach (GameObject skyscraper in buildings[1]) { if (skyscraper.GetComponent<Building>() != null) DestroyImmediate(skyscraper.gameObject); } }
//Paint cell true = add // false = delete void PaintCell(GridCreator.CellType type) { Vector3 gridPos = GetGridPosition(grid.mouseWorldPosition); //if x or z position of mouse is out of grid //set a correct int value if (gridPos.x < 0) gridPos.x = -1; if (gridPos.z < 0) gridPos.z = -1; for (int y = 0; y < grid.brushSize; y++) { for (int x = 0; x < grid.brushSize; x++) { //paint cells if (gridPos.x + x >= 0 && gridPos.z + y >= 0 && gridPos.x + x < grid.worldMap.GetLength(0) && gridPos.z + y < grid.worldMap.GetLength(1)) { grid.worldMap[(int)gridPos.x + x, (int)gridPos.z + y] = type; } } } EditorUtility.SetDirty(grid); Cursor.visible = false; }
private void OnEnable() { grid = (GridCreator)target; grid.GenerateMaps(true); redoStack = new LinkedList<GridCreator.CellType[,]>(); undoStack = new LinkedList<GridCreator.CellType[,]>(); current = (GridCreator.CellType[,])grid.worldMap.Clone(); undoStack.AddLast(new LinkedListNode<GridCreator.CellType[,]>(grid.worldMap)); }
//uncommenting the while and "currDist" makes the building density higher public int FillWithBuildings(GridCreator grid, float scale, Vector3 pointFrom, Vector3 pointTo, int buildingIndex, Vector3 firstTilePoint, Vector3 secondTilePoint, List<List<GameObject>> buildings) { int collisions = 0; int numOfTry = 0; GameObject building; Vector3 position = pointFrom; Vector3 streetPosition = firstTilePoint; var distance = Vector3.Distance(pointFrom, pointTo); var streetDistance = Vector3.Distance(firstTilePoint, secondTilePoint); var direction = (pointTo - pointFrom); direction.Normalize(); direction.y = 0f; var streetDirection = (secondTilePoint - firstTilePoint); streetDirection.Normalize(); streetDirection.y = 0f; var offset = 0.6f; var streetOffset = (streetDistance * offset) / distance; //while (currDist < distance) //{ //check for collision in current position collisions = 0; numOfTry = 0; var buildingType = GetGridType(position, grid); do { numOfTry += 1; if (buildingType == GridCreator.CellType.Residential) building = buildings[0][Random.Range(0, buildings[0].Count)]; else if (buildingType == GridCreator.CellType.SkyScraper) building = buildings[1][Random.Range(0, buildings[1].Count)]; else { List<GameObject> currList = buildings[Random.Range(0, 2)]; building = currList[Random.Range(0, currList.Count)]; } Vector3 colliderSize = building.gameObject.GetComponent<BoxCollider>().size; collisions = Physics.OverlapSphere(position, scale * Mathf.Max(colliderSize.x, colliderSize.y, colliderSize.z) / 2).Length; } while (collisions > 1 && numOfTry < Mathf.Max(buildings[0].Count, buildings[1].Count)); if (collisions > 0 && collisions <= 1) { buildingIndex += 1; building = Instantiate(building); building.name = "building" + buildingIndex; building.transform.position = position; building.transform.parent = this.transform; building.transform.localScale = new Vector3(scale, scale, scale); building.transform.rotation = Quaternion.LookRotation((position - streetPosition).normalized); } position = position + (offset * direction); streetPosition = streetPosition + (streetOffset * streetDirection); //} return buildingIndex; }
public void FillWithTrees(GridCreator grid, List<List<GameObject>> trees, float scale) { int i = 1; int numOfTry = 0; float colliderRadius = 0f; Vector3 randPoint = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), Random.Range(min.z, max.z)); randPoint.y = 0f; Vector3 gridPos = new Vector3((Mathf.Floor(randPoint.x - grid.transform.position.x / 1) / grid.globalScale), 0.05f, (Mathf.Floor(randPoint.z - grid.transform.position.z / 1) / grid.globalScale)); GameObject tree; while (numOfTry < maxTry) { if (IsForestPoint(grid, gridPos)) { if (grid.worldMap[(int)gridPos.x, (int)gridPos.z] == GridCreator.CellType.ConeForest) tree = trees[0][Random.Range(0, trees[0].Count)]; else if (grid.worldMap[(int)gridPos.x, (int)gridPos.z] == GridCreator.CellType.Woods) tree = trees[1][Random.Range(0, trees[1].Count)]; else { List<GameObject> currList = trees[Random.Range(0, 2)]; tree = currList[Random.Range(0, currList.Count)]; } foreach (Transform child in tree.transform) colliderRadius = child.GetComponent<CapsuleCollider>().radius * (scale + 0.02f); int collisions = Physics.OverlapSphere(GridToTerrain(randPoint), colliderRadius).Length; if (collisions <= 1) { numOfTry = 0; tree = Instantiate(tree); tree.name = "tree" + i; tree.transform.position = GridToTerrain(randPoint); tree.transform.parent = this.transform; tree.transform.localScale = new Vector3(scale, scale, scale); i += 1; } else numOfTry += 1; } else { numOfTry += 1; } randPoint = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), Random.Range(min.z, max.z)); randPoint.y = 0f; gridPos = new Vector3((Mathf.Floor(randPoint.x - grid.transform.position.x / 1) / grid.globalScale), 0.05f, (Mathf.Floor(randPoint.z - grid.transform.position.z / 1) / grid.globalScale)); } foreach (GameObject conetree in trees[0]) { if (conetree.GetComponent<ProcTree>() != null) DestroyImmediate(conetree.gameObject); } foreach (GameObject woodtree in trees[1]) { if (woodtree.GetComponent<ProcTree>() != null) DestroyImmediate(woodtree.gameObject); } trees[0].Clear(); trees[1].Clear(); trees.Clear(); }
public GridCreator.CellType GetGridType(Vector3 point, GridCreator grid) { Vector3 gridPos = new Vector3((Mathf.Floor(point.x - grid.transform.position.x / 1) / grid.globalScale), 0.05f, (Mathf.Floor(point.z - grid.transform.position.z / 1) / grid.globalScale)); //if x or z position of mouse is out of grid //set a correct int value if (gridPos.x< 0) gridPos.x = -1; if (gridPos.z< 0) gridPos.z = -1; if (gridPos.x >= 0 && gridPos.z >= 0 && gridPos.x < grid.worldMap.GetLength(0) && gridPos.z < grid.worldMap.GetLength(1)) { return grid.worldMap[(int)gridPos.x, (int)gridPos.z]; } return GridCreator.CellType.Empty; }
public bool IsForestPoint(GridCreator grid, Vector3 pos) { return (grid.worldMap[(int)pos.x, (int)pos.z] == GridCreator.CellType.Forest || grid.worldMap[(int)pos.x, (int)pos.z] == GridCreator.CellType.ConeForest || grid.worldMap[(int)pos.x, (int)pos.z] == GridCreator.CellType.Woods); }
public void Populate(GridCreator grid) { min = grid.startingPoint; max = grid.endingPoint; gridSize = new Vector3(max.x - min.x, 1f, max.z - min.z); List<List<Vector3>> sampledStreet = SampleStreets(grid.streets); if (sampledStreet.Count > 0) { ComputeStreetIntersections(sampledStreet); ComputeIntersectionClusters(); List<GameObject> streetWeb = CreateStreets(sampledStreet); //offsetting from polyline CreateSideWalks(streetWeb, sampledStreet); //offsetting from polyline AddBuildings(grid, sampledStreet, 0.4f); } AddTrees(grid, 0.1f); }
// Inspector GUI public override void OnInspectorGUI() { // Draw the base gui base.OnInspectorGUI (); if(gridCreator == null) { gridCreator = Selection.activeGameObject.GetComponent<GridCreator>(); } // Init level button Rect button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { if(confirmInit) { gridCreator.ClearMap(); gridCreator.InitMap(); SceneView.RepaintAll(); confirmInit = false; } else { confirmInit = true; } } GUILayout.Label (confirmInit ? "Confirm Init (Map will be overriden)" : "Init map"); EditorGUILayout.EndHorizontal (); // Create level button button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { gridCreator.CreateMap(); SceneView.RepaintAll(); } GUILayout.Label ("Create map"); EditorGUILayout.EndHorizontal (); // Clear level button button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { gridCreator.ClearMap(); SceneView.RepaintAll(); } GUILayout.Label ("Clear map"); EditorGUILayout.EndHorizontal (); // Start editing button button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { gridCreator = Selection.activeGameObject.GetComponent<GridCreator>(); gridPos = gridCreator.transform.position; maxgridPos = gridPos + new Vector3(gridCreator.mapWidth * gridCreator.blockWidth, gridCreator.mapHeight * gridCreator.blockHeight, 0); lastTool = Tools.current; editing = true; SceneView.RepaintAll(); } GUILayout.Label ("Start Editing"); EditorGUILayout.EndHorizontal (); // Stop editing button button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { gridCreator = Selection.activeGameObject.GetComponent<GridCreator>(); gridCreator.selectedTool = -1; gridCreator.selectedTile.Set(-1, -1); gridCreator.lastSelectedTile.Set(-1, -1); Tools.current = lastTool; editing = false; SceneView.RepaintAll(); } GUILayout.Label ("Stop Editing"); EditorGUILayout.EndHorizontal (); // Save button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { SaveLevel(); } GUILayout.Label ("Save Level"); EditorGUILayout.EndHorizontal (); // Autosave toggle button EditorGUILayout.BeginHorizontal ("Button"); autosave = GUILayout.Toggle(autosave, "Autosave"); autosaveTimer = GUILayout.HorizontalSlider(autosaveTimer, 5f, 180f); GUILayout.Label(autosaveTimer.ToString("000") + "s"); EditorGUILayout.EndHorizontal (); // Load button = EditorGUILayout.BeginHorizontal ("Button"); if (GUI.Button (button, GUIContent.none)) { if(confirmLoad) { LoadLevel(); confirmLoad = false; } else { confirmLoad = true; } } GUILayout.Label (confirmLoad ? "Confirm Load" : "Load Level"); EditorGUILayout.EndHorizontal (); // Autosave if time is correct float time = (float)EditorApplication.timeSinceStartup; if(autosave && time > lastTime + autosaveTimer) { SaveLevel(); lastTime = time; } Event ev = Event.current; if (ev.type == EventType.MouseDown) { confirmInit = false; confirmLoad = false; } }