Пример #1
0
    void Update()
    {
        // Touch Event
        bool    touched  = false;
        Vector2 touchPos = Vector2.zero;

        //
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (Input.touchCount > 0)
            {
                // Touches
                for (int i = 0; i < Input.touchCount; ++i)
                {
                    Touch touch = Input.GetTouch(i);
                    if (touch.phase == TouchPhase.Began)
                    {
                        touchPos.x = touch.position.x;
                        touchPos.y = touch.position.y;
                        touched    = true;
                        break;                          // Single Touch
                    }
                }
            }
        }
        else
        {
            // Mouse
            if (Input.GetMouseButtonDown(0))
            {
                touchPos.x = Input.mousePosition.x;
                touchPos.y = Input.mousePosition.y;
                touched    = true;
            }
        }

        // Check Touch to Object
        if (touched)
        {
            // Hit Check
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(touchPos);
            if (Physics.Raycast(ray, out hit, 100.0f))
            {
                // HIt!!
                GameObject hitPlane = hit.collider.gameObject;

                if (hitPlane.Equals(objTexPhoto))
                {
                    // Photo
#if UNITY_IPHONE
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        obj = objTexPhoto;
                        LoadTextureFromImagePicker.ShowPhotoLibrary(this.name, "OnFinishedImagePicker");
                    }
                    else
#endif
                    {
                        Debug.Log("Touched on Photo");
                    }
                }
                else if (hitPlane.Equals(objTexCamera))
                {
                    // Camera
#if UNITY_IPHONE
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        obj = objTexCamera;
                        LoadTextureFromImagePicker.ShowCamera(this.name, "OnFinishedImagePicker");
                    }
                    else
#endif
                    {
                        Debug.Log("Touched on Camera");
                    }
                }
                else if (hitPlane.Equals(objSave))
                {
                    // Save
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        textSave.text = "Saving..";
                        StartCoroutine("CaptureScreen");
                    }
                    else
                    {
                        Debug.Log("Touched on Save Button");
                    }
                }
            }
        }
    }
Пример #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);
    }