コード例 #1
0
        public override void DrawAtPoint(Cell cell, Vector2 point)
        {
            var pointInCell = Map.WorldToLocalTile(point);

            cell.Tiles[(int)pointInCell.y * Map.NumberOfTiles + (int)pointInCell.x].TextureIndex = _currentTileIndex;

            var texture = (Texture2D)cell.GetComponent <Renderer>().sharedMaterial.mainTexture;

            // pTexture is point in texture coords
            Vector2 pTexture = pointInCell * Map.TileResolution;

            texture.SetPixels((int)pTexture.x, (int)pTexture.y, Map.TileResolution, Map.TileResolution, _currentTileColors);

            // For performance, don't update right away instead do them all at once at the end
            _textureUpdate.Add(texture);
        }
コード例 #2
0
        public override void DrawAtPoint(Cell cell, Vector2 point)
        {
            // location of entity
            var pointInCell = Map.WorldToLocalTile(point);

            var tile = cell.GetTileFromPointInCell((int)pointInCell.x, (int)pointInCell.y);

            if (tile.EntityIndex != _currentEntityIndex)
            {
                tile.EntityIndex = _currentEntityIndex;

                // Remove old if an object was there already
                var old = tile.Entity;
                Object.DestroyImmediate(old);

                if (_currentEntity != null)
                {
                    var entity = (GameObject)PrefabUtility.InstantiatePrefab(_currentEntity.GetAsset());
                    entity.name     = "(" + pointInCell.x + "," + pointInCell.y + ")";
                    entity.isStatic = true;

                    var parentName = _currentEntityIndex.ToString(CultureInfo.InvariantCulture) + " " +
                                     _currentEntity.GetAsset().name;
                    var parent = cell.transform.Find(parentName);
                    if (parent == null)
                    {
                        var pgo = new GameObject(parentName);
                        parent        = pgo.transform;
                        parent.parent = cell.transform;
                        parent.transform.localPosition = Vector3.zero;
                    }

                    var position = Map.LocalTileToLocalPosition(pointInCell);
                    entity.transform.parent        = parent;
                    entity.transform.localPosition = new Vector3(position.x, tile.Heights, position.y);

                    tile.Entity = entity;

                    EditorUtility.SetSelectedWireframeHidden(entity.GetComponent <Renderer>(), true);
                }
            }
        }