/// <inheritdoc /> public void PrepareTile(Tile tile) { tile.GameObject = _gameObjectFactory.CreateNew( String.Format("tile_{0}", tile.RenderMode.ToString().ToLower())); Observable.Start((() => tile.GameObject.AddComponent(new GameObject())), Scheduler.MainThread); }
public IGameObject Build(Tile tile, Rule rule) { Trace.Debug(LogTag, "Started to build terrain"); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var renderMode = tile.RenderMode; var terrainObject = _gameObjectFactory.CreateNew("terrain", tile.GameObject); // NOTE detect grid parameters for scene mode. For overview use 1x1 grid var cellRowCount = renderMode == RenderMode.Scene ? (int)Math.Ceiling(tile.Rectangle.Height / _maxCellSize) : 1; var cellColumnCount = renderMode == RenderMode.Scene ? (int)Math.Ceiling(tile.Rectangle.Width / _maxCellSize) : 1; var cellHeight = tile.Rectangle.Height / cellRowCount; var cellWidth = tile.Rectangle.Width / cellColumnCount; Trace.Debug(LogTag, "Building mesh canvas.."); var meshCanvas = new MeshCanvasBuilder(_objectPool) .SetTile(tile) .SetScale(MeshCellBuilder.Scale) .Build(renderMode); Trace.Debug(LogTag, "Building mesh cells.."); // NOTE keeping this code single threaded dramatically reduces memory presure for (int j = 0; j < cellRowCount; j++) { for (int i = 0; i < cellColumnCount; i++) { var tileBottomLeft = tile.Rectangle.BottomLeft; var rectangle = new Rectangle2d( tileBottomLeft.X + i * cellWidth, tileBottomLeft.Y + j * cellHeight, cellWidth, cellHeight); var name = String.Format("cell {0}_{1}", i, j); var cell = _meshCellBuilder.Build(meshCanvas, rectangle); BuildCell(tile.Canvas, rule, terrainObject, cell, renderMode, name); } } terrainObject.IsBehaviourAttached = true; sw.Stop(); Trace.Debug(LogTag, "Terrain is build in {0}ms", sw.ElapsedMilliseconds.ToString()); return(terrainObject); }
public IGameObject BuildWay(Tile tile, Rule rule, Way way) { // create parent object for waypoint. Use factory to handle object creation on proper thread. var parent = _gameObjectFactory.CreateNew("waypoints " + way.Id, tile.GameObject); foreach (var coordinate in way.Points) { // detect position var position = GeoProjection.ToMapCoordinate(tile.RelativeNullPoint, coordinate); var elevation = _elevationProvider.GetElevation(coordinate); // create new gameobject on main thread. Observable.Start(() => { var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = new Vector3((float)position.X, elevation + 1, (float)position.Y); sphere.transform.parent = parent.GetComponent <GameObject>().transform; }, Scheduler.MainThread); } // return null as we don't need to attach behaviours return(null); }