Пример #1
0
 public void LoadTexture()
 {
             #if UNITY_IPHONE
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         LoadTextureFromImagePicker.SetPopoverAutoClose(true);
         LoadTextureFromImagePicker.SetPopoverToCenter();
         LoadTextureFromImagePicker.ShowPhotoLibrary(gameObject.name, "OnFinishedImagePicker");
     }
             #endif
 }
Пример #2
0
    void OnGUI()
    {
        // Swithes
        GUI.Label(new Rect(0, Screen.height * 0.5f, 100, 30), "Options:");
        bUseOriginalImageSize        = GUI.Toggle(new Rect(0, Screen.height * 0.5f + 30, 400, 30), bUseOriginalImageSize, "Use Original Image Size");
        iPadPopover_DisableAutoClose = GUI.Toggle(new Rect(0, Screen.height * 0.5f + 60, 400, 30), iPadPopover_DisableAutoClose, "iPad Popover: Disable Auto Close");
        isDefaultFrontCamera         = GUI.Toggle(new Rect(0, Screen.height * 0.5f + 90, 400, 30), isDefaultFrontCamera, "Default Front Camera");
        isSaveToLocalFile            = GUI.Toggle(new Rect(0, Screen.height * 0.5f + 120, 400, 30), isSaveToLocalFile, "Save/Resume last selected image to local file");

        // Buttons
        float buttonWidth   = Screen.width / 3;
        float buttonHeight  = Screen.height / 5;
        float buttonMargine = buttonWidth / 3;
        Rect  buttonRect    = new Rect(0, Screen.height - buttonHeight, buttonWidth, buttonHeight);

        buttonRect.x = buttonMargine;
        if (targetMaterial == null)
        {
            GUI.Box(buttonRect, "(Set Target Material)");
        }
        else if (GUI.Button(buttonRect, GetButtonLabel("Camera")))
        {
                        #if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                LoadTextureFromImagePicker.SetDefaultFrontCamera(isDefaultFrontCamera);
                LoadTextureFromImagePicker.SetPopoverToCenter();
                LoadTextureFromImagePicker.ShowCamera(gameObject.name, "OnFinishedImagePicker");
            }
                        #endif
        }
        buttonRect.x = buttonMargine + buttonWidth + buttonMargine;
        if (targetMaterial == null)
        {
            GUI.Box(buttonRect, "(Set Target Material)");
        }
        else if (GUI.Button(buttonRect, GetButtonLabel("Load Image\nfrom PhotoLibrary")))
        {
                        #if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                LoadTextureFromImagePicker.SetPopoverAutoClose(iPadPopover_DisableAutoClose == false);
                LoadTextureFromImagePicker.SetPopoverTargetRect(buttonRect.x, buttonRect.y, buttonWidth, buttonHeight);
                LoadTextureFromImagePicker.ShowPhotoLibrary(gameObject.name, "OnFinishedImagePicker");
            }
                        #endif
        }
        //
        // for Save Image
        buttonRect.width  = Screen.width / 4;
        buttonRect.height = Screen.height / 6;
        buttonMargine     = 0;
        buttonRect.y      = 0;
        buttonRect.x      = buttonMargine + (buttonRect.width + buttonMargine) * 1;
        if (GUI.Button(buttonRect, GetButtonLabel("Save JPG\nto PhotoLibrary")))
        {
                        #if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                saveAsPng = false;
                StartCoroutine("CaptureScreen");
            }
                        #endif
        }
        buttonRect.x = buttonMargine + (buttonRect.width + buttonMargine) * 2;
        if (GUI.Button(buttonRect, GetButtonLabel("Save PNG\nto PhotoLibrary")))
        {
                        #if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                saveAsPng = true;
                StartCoroutine("CaptureScreen");
            }
                        #endif
        }


        // Disp Texture Size
        if (targetMaterial)
        {
            Texture targetTexture = targetMaterial.mainTexture;
            GUI.Label(new Rect(0, 0, 400, 100), "Current Texture Size:\n" + "width=" + targetTexture.width + ", height=" + targetTexture.height);
        }

        // Disp Last Message
        GUI.Label(new Rect(0, 80, 200, 60), "Last Result:\n" + lastMessage);
    }