Ejemplo n.º 1
0
    // For Load
    void OnFinishedImagePicker(string message)
    {
        if (LoadTextureFromImagePicker.IsLoaded())
        {
            var        material     = obj.GetComponent <Renderer>().material;
            int        width        = material.mainTexture.width;
            int        height       = material.mainTexture.height;
            const bool createMipmap = true;
            Texture2D  texture      = LoadTextureFromImagePicker.GetLoadedTexture(message, width, height, createMipmap);
            if (texture)
            {
                // Load Texture
#if false
                var lastTexture = material.mainTexture;
                material.mainTexture = texture;
                Destroy(lastTexture);                   // Destroy the last texture
#else
                material.mainTexture = texture;
#endif
            }
            LoadTextureFromImagePicker.ReleaseLoadedImage();
        }
        else
        {
            // Closed
            LoadTextureFromImagePicker.Release();
        }
    }
Ejemplo n.º 2
0
 // For Load
 void OnFinishedImagePicker(string message)
 {
     if (LoadTextureFromImagePicker.IsLoaded())
     {
         int width, height;
         var orgTexWidth  = LoadTextureFromImagePicker.GetLoadedTextureWidth();
         var orgTexHeight = LoadTextureFromImagePicker.GetLoadedTextureHeight();
         if (orgTexWidth > orgTexHeight)
         {
             width  = Mathf.Min(orgTexWidth, maxTextureSize);
             height = width * orgTexHeight / orgTexWidth;
         }
         else
         {
             height = Mathf.Min(orgTexHeight, maxTextureSize);
             width  = height * orgTexWidth / orgTexHeight;
         }
         bool      mipmap  = false;
         Texture2D texture = LoadTextureFromImagePicker.GetLoadedTexture(message, width, height, mipmap);
         if (texture != null)
         {
             // Load Texture
             ReplaceSprite(texture, width, height);
         }
         LoadTextureFromImagePicker.ReleaseLoadedImage();
     }
     else
     {
         // Closed
         LoadTextureFromImagePicker.Release();
     }
 }
Ejemplo n.º 3
0
    // For Load
    void OnFinishedImagePicker(string message)
    {
        lastMessage = message;
        if (targetMaterial && LoadTextureFromImagePicker.IsLoaded())
        {
            int width, height;
            if (bUseOriginalImageSize)
            {
                width  = LoadTextureFromImagePicker.GetLoadedTextureWidth();
                height = LoadTextureFromImagePicker.GetLoadedTextureHeight();
            }
            else
            {
                width  = textureWidth;
                height = textureHeight;
            }
            bool      mipmap  = true;
            Texture2D texture = LoadTextureFromImagePicker.GetLoadedTexture(message, width, height, mipmap);
            if (texture)
            {
                // Load Texture
                Texture lastTexture = targetMaterial.mainTexture;
                targetMaterial.mainTexture = texture;
                Destroy(lastTexture);

                if (isSaveToLocalFile)
                {
                    // Save to local file
                    LoadTextureFromImagePicker.SaveToLocalFile(saveTexFileName, texture);
                }
            }
            LoadTextureFromImagePicker.ReleaseLoadedImage();
        }
        else
        {
            // Closed
            LoadTextureFromImagePicker.Release();
        }
    }