public void Setup(GridArray <TileArrayObject> grid) { this.grid = grid; visualNodeList = new List <Transform>(); visualNodeArray = new Transform[grid.GetHeight(), grid.GetWidth()]; // Initialize for (int row = 0; row < grid.GetHeight(); row++) { for (int col = 0; col < grid.GetWidth(); col++) { Vector3 gridPosition = grid.GetWorldPosition(row, col) + 0.5f * new Vector3(grid.GetCellSize(), grid.GetCellSize()); Transform visualNode = CreateVisualNode(gridPosition); visualNodeArray[row, col] = visualNode; visualNodeList.Add(visualNode); } } UpdateVisual(grid); grid.OnGridObjectChanged += (object sender, GridArray <TileArrayObject> .OnGridObjectChangedEventArgs eventArgs) => { updateVisual = true; }; }
// Use this for initialization void Start() { player = FindObjectOfType <PlayerController>(); gridArray = FindObjectOfType <GridArray>(); anim = FindObjectOfType <Animator>(); body = GetComponent <Rigidbody>(); }
public NetworkEdges(IEnvelope bounds) { if (bounds != null) { _gridArray = new GridArray <List <NetworkEdge> >(bounds, new int[] { 200, 180, 160, 130, 100, 70, 50, 25, 18, 10, 5, 2 }, new int[] { 200, 180, 160, 130, 100, 70, 50, 25, 18, 10, 5, 2 }); } }
public override void OnInspectorGUI() { GridArray gridArray = target as GridArray; gridArray.sizeXZ = EditorGUILayout.IntField("Size XZ", gridArray.sizeXZ); gridArray.sizeY = EditorGUILayout.IntField("Size Y", gridArray.sizeY); gridArray.height = EditorGUILayout.IntField("Height", gridArray.height); gridArray.scale = EditorGUILayout.FloatField("Scale", gridArray.scale); gridArray.perlinScale = EditorGUILayout.FloatField("Perlin Scale", gridArray.perlinScale); gridArray.perlinFreq = EditorGUILayout.FloatField("Perlin Freq", gridArray.perlinFreq); gridArray.pointDensity = EditorGUILayout.IntField("Point Density", gridArray.pointDensity); gridArray.voxelSurfacePrototype = EditorGUILayout.ObjectField( "voxelSurfacePrototype", gridArray.voxelSurfacePrototype, typeof(VoxelSurface), false) as VoxelSurface; gridArray.editMode = (EditMode)EditorGUILayout.EnumPopup(gridArray.editMode); gridArray.buildRadius = EditorGUILayout.FloatField("Build Radius", gridArray.buildRadius); gridArray.material = EditorGUILayout.ObjectField( "material", gridArray.material, typeof(Material), false) as Material; gridArray.materialScale = EditorGUILayout.FloatField("Material Scale", gridArray.materialScale); EditorGUILayout.LabelField("HasNavMesh " + (gridArray.navMesh != null)); if (gridArray.navMesh != null) { EditorGUILayout.LabelField("connections=" + gridArray.navMesh.connections.Count); EditorGUILayout.LabelField("positions=" + gridArray.navMesh.positions.Count); } if (gridArray.path != null) { EditorGUILayout.LabelField("path length=" + gridArray.path.Count); } else { EditorGUILayout.LabelField("no path"); } if (GUILayout.Button("Initialize")) { gridArray.Initialize(); } if (GUILayout.Button("Generate")) { gridArray.Generate(); } if (GUILayout.Button("Set Material")) { gridArray.SetMaterial(); } if (GUILayout.Button("Grow Tree")) { FindObjectOfType <TreeGrower>().GrowTree(); } gridArray.UpdateMesh(); }
void ImportImage(BaseMesh _target, Texture2D _sourceTexture) { if (_sourceTexture == null) { EditorUtility.DisplayDialog("Error!", "Import image field is empty. " + "Please assign any image from project to import it as a level.\n " + "And please make that texture read/write enabled in import settings.", "Got it!"); return; } //Just to make the texture readable from Import settings. string path = AssetDatabase.GetAssetPath(_sourceTexture); TextureImporter importSetting = (TextureImporter)AssetImporter.GetAtPath(path); importSetting.isReadable = true; importSetting.generateMipsInLinearSpace = false; importSetting.npotScale = TextureImporterNPOTScale.None; AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); //Parsing image and converting it into Map. _target.GridColumnCount = _sourceTexture.width; _target.GridRowCount = _sourceTexture.height; GridArray [] tempGridArray = new GridArray[_target.GridColumnCount]; for (int i = 0; i < tempGridArray.GetLength(0); i++) { tempGridArray[i] = new GridArray(new Grid [_target.GridRowCount]); } for (int i = 0; i < _target.GridColumnCount; i++) { for (int j = 0; j < _target.GridRowCount; j++) { Color readColor = _sourceTexture.GetPixel(i, j); bool filled; if (((readColor.r + readColor.g + readColor.b) / 3) < 0.5f) { filled = true; } else { filled = false; } tempGridArray[i].gridRow[j] = new Grid(filled, i, j, new Vector3(_target.GridXOffset + i * _target.gridScale + _target.gridScale / 2, _target.yOffset, _target.GridZOffset + j * _target.gridScale + _target.gridScale / 2)); } } _target.gridArrayColumn = tempGridArray; }
public void Dispose() { if (_graphics != null) { _graphics.Dispose(); _graphics = null; } if (_bm != null) { _bm.Dispose(); _bm = null; } _gridArrayPolygons = null; }
public void Dispose() { if (_canvas != null) { _canvas.Dispose(); _canvas = null; } if (_bitmap != null) { _bitmap.Dispose(); _bitmap = null; } _gridArrayPolygons = null; }
// Update display public void UpdateVisual(GridArray <TileArrayObject> grid) { HideNodeVisuals(); for (int row = 0; row < grid.GetHeight(); row++) { for (int col = 0; col < grid.GetWidth(); col++) { TileArrayObject gridObject = grid.GetGridObject(row, col); Transform visualNode = visualNodeArray[row, col]; visualNode.gameObject.SetActive(true); SetupVisualNode(visualNode, gridObject); } } }
void RefreshGridArray() { if (gridArrayColumn == null) { gridArrayColumn = new GridArray [gridColumnCount]; for (int i = 0; i < gridArrayColumn.GetLength(0); i++) { gridArrayColumn[i] = new GridArray(new Grid [gridRowCount]); } } GridArray [] tempGridArray = new GridArray[gridColumnCount]; for (int i = 0; i < tempGridArray.GetLength(0); i++) { tempGridArray[i] = new GridArray(new Grid [gridRowCount]); } for (int i = 0; i < gridColumnCount; i++) { for (int j = 0; j < gridRowCount; j++) { if (i < gridArrayColumn.GetLength(0) && gridArrayColumn[i] != null && j < gridArrayColumn[i].gridRow.GetLength(0) && gridArrayColumn [i].gridRow [j] != null) { tempGridArray[i].gridRow[j] = gridArrayColumn[i].gridRow[j]; tempGridArray[i].gridRow[j].pos = new Vector3(gridXOffset + i * gridScale + gridScale / 2, yOffset, gridZOffset + j * gridScale + gridScale / 2); } else { tempGridArray[i].gridRow[j] = new Grid(false, i, j, new Vector3(gridXOffset + i * gridScale + gridScale / 2, yOffset, gridZOffset + j * gridScale + gridScale / 2)); } } } gridArrayColumn = null; gridArrayColumn = tempGridArray; }
public NewCrozzle(int c, int r, string[] words) { this.cols = c; this.rows = r; this.activeWordList = new List <WordArray>(); this.coordList = new List <CoordinateList>(); this.word_list = new WordArray[words.Length]; int n = 0; foreach (string s in words) { word_list[n] = new WordArray(); word_list[n].x = -1; word_list[n].y = -1; word_list[n].number = -1; word_list[n].vertical = false; word_list[n].word = s; n++; } this.crozzle_board = new GridArray[rows][]; for (int i = 0; i < rows; i++) { crozzle_board[i] = new GridArray[cols]; for (int j = 0; j < cols; j++) { crozzle_board[i][j] = new GridArray(); } } for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { crozzle_board[i][j].targetChar = EMPTYCHAR; //target character, hidden crozzle_board[i][j].indexDisplay = ' '; //used to display index number of word start crozzle_board[i][j].value = '-'; //actual current letter shown on board } } }
public void Init(IDisplay display, bool directDraw) { try { if (display == null) { return; } //if (_bm != null && (_bm.Width != display.iWidth || _bm.Height != display.iHeight)) { Dispose(); } if (_bitmap == null) { _bitmap = GraphicsEngine.Current.Engine.CreateBitmap(display.iWidth, display.iHeight, GraphicsEngine.PixelFormat.Rgba32); } _canvas = _bitmap.CreateCanvas(); //using (var brush = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.Transparent)) //{ // _canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangle(0, 0, _bitmap.Width, _bitmap.Height)); //} _bitmap.MakeTransparent(); _back = _bitmap.GetPixel(0, 0); _first = true; _directDraw = directDraw; //_bm.MakeTransparent(Color.White); _gridArrayPolygons = new GridArray <List <IAnnotationPolygonCollision> >( new Envelope(0.0, 0.0, display.iWidth, display.iHeight), new int[] { 50, 25, 18, 10, 5, 2 }, new int[] { 50, 25, 18, 10, 5, 2 }); } catch { Dispose(); } }
public void Interact(Ray ray, RaycastHit hit) { if (Input.GetMouseButtonDown(0)) { GridArray gridArray = hit.collider.gameObject.GetComponentInParent <GridArray>(); var explosion = Instantiate(explosionPrototype); explosion.Play(); explosion.transform.position = hit.point - ray.direction * 0.3f; explosion.transform.rotation = Quaternion.LookRotation(-ray.direction); digHead.transform.position = hit.transform.position; digHead.GetComponent <AudioSource>().PlayOneShot(digClip); gridArray.Dig(hit.point, 2f); } if (Input.GetMouseButtonDown(1)) { GridArray gridArray = hit.collider.gameObject.GetComponentInParent <GridArray>(); gridArray.Build(hit.point, 2f); } }
public void Init(IDisplay display, bool directDraw) { try { if (display == null) { return; } //if (_bm != null && (_bm.Width != display.iWidth || _bm.Height != display.iHeight)) { Dispose(); } if (_bm == null) { _bm = new Bitmap(display.iWidth, display.iHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } _graphics = System.Drawing.Graphics.FromImage(_bm); using (SolidBrush brush = new SolidBrush(Color.Transparent)) { _graphics.FillRectangle(brush, 0, 0, _bm.Width, _bm.Height); } _back = _bm.GetPixel(0, 0); _first = true; _directDraw = directDraw; //_bm.MakeTransparent(Color.White); _gridArrayPolygons = new GridArray <List <IAnnotationPolygonCollision> >( new Envelope(0.0, 0.0, display.iWidth, display.iHeight), new int[] { 50, 25, 18, 10, 5, 2 }, new int[] { 50, 25, 18, 10, 5, 2 }); } catch { Dispose(); } }
// Constructor public TileArray(int height, int width, float cellSize, Vector3 originPosition) { grid = new GridArray <TileArrayObject>(height, width, cellSize, originPosition, (int row, int col) => new TileArrayObject(row, col)); }
public double[,] CreateTerrain(int detail, IProgress <RenderProgress> status) { var grid = new GridArray <double>(detail) { CurrentLevel = 0 }; // Seed the edged //edge at (0,0) var target = 2 * (Math.Pow(2, detail + 1) - 1); var h00 = NextRandom(MinimumHeight, MaximumHeight); grid[0, 0] = h00; grid[1, 0] = h00; grid[0, 1] = h00; grid[1, 1] = h00; for (var currentLevel = 1; currentLevel <= detail; currentLevel++) { grid.CurrentLevel = currentLevel; var baseValue = 2 * (Math.Pow(2, currentLevel) - 1); // perform diamond step for (var x = 1; x < grid.CurrentSize; x += 2) { status?.Report(new RenderProgress() { Progress = x / grid.CurrentSize * 50, Level = currentLevel }); for (var y = 1; y < grid.CurrentSize; y += 2) { var intersection = GetTargetInterval(grid, x, y, true); if (intersection == null) { currentLevel -= 2; goto backtrace; } grid[x, y] = NextRandom(intersection.Value); } } // perform square step for (var x = 1; x < grid.CurrentSize; x += 2) { status?.Report(new RenderProgress() { Progress = x / grid.CurrentSize * 50 + 50, Level = currentLevel }); for (var y = 1; y < grid.CurrentSize; y += 2) { foreach (var direction in orthogonalDirections) { (var cx, var cy) = grid.GetNeighbor(x, y, direction); var intersection = GetTargetInterval(grid, cx, cy, false); if (intersection == null) { currentLevel -= 2; goto backtrace; } grid[cx, cy] = NextRandom(intersection.Value); } } } continue; backtrace: ; } return(grid); }
private (double, double)? GetTargetInterval(GridArray <double> instance, int x, int y, bool diamond) { var directions = diamond ? diagonalDirections : orthogonalDirections; return(Intersect(directions.Select(d => instance.GetAngle(x, y, d, MaximulDeltaAngle)).ToArray())); }