コード例 #1
0
        /// <summary>
        /// ダウンロードが終了した
        /// </summary>
        /// <param name="downloadCount">画像のダウンロードが終了した数</param>
        /// <param name="maxCount">画像検索APIで指定した検索数</param>
        /// <param name="texture">ダウンロードしたテクスチャ</param>
        public void ShowImages(int downloadCount, int maxCount, Texture texture)
        {
            // テクスチャのリサイズ
            float w = texture.width;
            float h = texture.height;
            float ratio = w / h;
            if (ratio >= (float)imageWitdh / (float)imageHeight)
            {
                TextureScale.Scale((Texture2D)texture, imageWitdh, (int)(imageWitdh / ratio));
            }
            else
            {
                TextureScale.Scale((Texture2D)texture, (int)(imageHeight * ratio), imageHeight);
            }

            //各オブジェクトを円状に配置する
            Vector3 imagePosition = parent.transform.position;
            float angleDiff = 360f / maxCount;
            float angle = (90 - angleDiff * downloadCount) * Mathf.Deg2Rad;
            imagePosition.x += radius * Mathf.Cos(angle);
            imagePosition.y = parent.transform.position.y;
            imagePosition.z += radius * Mathf.Sin(angle);

            int index = downloadCount - 1;
            // 以前のインスタンスを廃棄
            if (sr[index] != null)
            {
                Destroy(sr[index].gameObject);
            }
            sr[index] = (SpriteRenderer)Instantiate(imageUnit, imagePosition, Quaternion.identity, parent);
            sr[index].sprite = Sprite.Create((Texture2D)texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            sr[index].gameObject.name = "ImageUnit" + index.ToString();
        }
コード例 #2
0
    private void DrawMap()
    {
        Puts("Drawing map...");

        var width  = _config.RenderResolution.Width;
        var height = _config.RenderResolution.Height;

        var coordinateConverter        = new CoordinateConverter(width, height);
        var raycastCoordinateConverter = new RaycastCoordinateConverter(coordinateConverter);

        var layers = new List <ILayer>();

        Puts("Initializing background layer...");
        var backgroundTextureProvider =
            new SeamlessProvider(new BitmapProvider(_config.BackgroundTexturePath.FullPath), width, height);
        var backgroundLayer = new BitmapLayer(backgroundTextureProvider, NormalColorBlending.Instance);

        layers.Add(backgroundLayer);

        Puts("Initializing splat layers...");
        foreach (var splatConfiguration in _config.SplatConfigurations)
        {
            Puts($"Splat #{splatConfiguration.Index}...");
            var splatTextureProvider =
                new SeamlessProvider(new BitmapProvider(splatConfiguration.TexturePath.FullPath), width, height);
            var splatMask  = new SplatMask(coordinateConverter, splatConfiguration.Index);
            var splatLayer = new MaskedBitmapLayer(splatTextureProvider, splatMask, NormalColorBlending.Instance);
            layers.Add(splatLayer);
        }

        Puts("Initializing materials source...");
        var materialSource =
            new DetailsLayer.MaterialSource(_config.DetailsConfiguration.MaterialConfigurations, width, height);

        Puts("Initializing details layer...");
        var detailsLayer = new DetailsLayer(raycastCoordinateConverter, materialSource,
                                            _config.DetailsConfiguration.RaycastLayers);

        layers.Add(detailsLayer);

        Puts("Initializing light layer...");
        var lightningLayer = new LightLayer(raycastCoordinateConverter, _config.LightConfiguration,
                                            _config.LightConfiguration.RaycastLayers);

        layers.Add(lightningLayer);

        Puts("Initializing water layer...");
        var waterTextureProvider =
            new SeamlessProvider(new BitmapProvider(_config.WaterConfiguration.TexturePath.FullPath), height, width);
        var waterMask = new WaterMask(raycastCoordinateConverter, _config.WaterConfiguration.MinOpacity,
                                      _config.WaterConfiguration.MaxDepth, _config.WaterConfiguration.RaycastLayers);
        var waterLayer = new MaskedBitmapLayer(waterTextureProvider, waterMask, NormalColorBlending.Instance);

        layers.Add(waterLayer);

        Puts("Initializing layer group...");
        var layerGroup = new LayerGroup(layers);

        var result  = new Texture2D(width, height);
        var wrapper = new TextureWrapper(result);

        Puts("Drawing...");
        layerGroup.Draw(wrapper);

        Puts("Resizing to result resolution...");
        TextureScale.Scale(result, _config.ResultResolution.Width, _config.ResultResolution.Height);

        Puts("Saving result...");
        Directory.CreateDirectory(_config.ResultPath.FullPath);
        result.SaveAsPng(PathToResult);

        wrapper.Dispose();

        Puts("Done.");
    }