示例#1
0
    private void loadReadyForegroundImages()
    {
        string debugName = "ERROR";

        if (nextForegroundImages.Count > 0 && nextForegroundImages.Peek().isReady())
        {
            ForegroundOperation nextImageOp = nextForegroundImages.Dequeue();
            debugName = nextImageOp.getResourcePath();
            WWW nextImage = nextImageOp.getStream();
            try {
                Texture2D texture = new Texture2D(4, 4, TextureFormat.DXT1, false);
                nextImage.LoadImageIntoTexture(texture);
                nextImage.Dispose();
                nextImage = null;

                GameObject newSprite = GameObject.Instantiate <GameObject>(foregroundSpritePrefab);
                newSprite.SetActive(true);
                newSprite.transform.parent     = foreground.transform;
                newSprite.transform.localScale = currentNovel.getForegroundScale();

                float newX = nextImageOp.getX();
                float newY = -(currentNovel.getForegroundHeight(texture) + nextImageOp.getY());
                newSprite.transform.localPosition = new Vector3(newX, newY, 0);
                newSprite.transform.localRotation = new Quaternion();
                SpriteRenderer renderer = newSprite.GetComponent <SpriteRenderer>();
                renderer.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2());

                //Keep track of the current foreground images
                currentForegroundImages.Add(newSprite);

                //background.transform.GetComponent<Renderer>().material.mainTexture = texture;
            } catch (System.Exception e) {
                Debug.Log("Could not load texture from " + debugName + " into a texture, skipping operation! " + e.Message);
            }
        }
    }
示例#2
0
 //Call this from the backgroundOperation to queue up a new background image
 public void prepareForegroundImage(ForegroundOperation nextForegroundImage)
 {
     this.nextForegroundImages.Enqueue(nextForegroundImage);
     //TODO figured out the coordinate system, now create a shell class to hold the coordinates and then instantiate and apply texture to new sprite
 }