Beispiel #1
0
    void Update()
    {
        // Update the indicator location
        if (placementIndicatorEnabled)
        {
            UpdatePlacementPose();
            UpdatePlacementIndicator();
        }

        // Context is always facing to the camera
        if (labelList.Count != 0)
        {
            foreach (GameObject t in labelList)
            {
                t.transform.LookAt(Camera.main.transform);
                t.transform.Rotate(new Vector3(0, 180, 0));
            }
        }

        if (landmarkList.Count != 0)
        {
            foreach (GameObject l in landmarkList)
            {
                l.transform.LookAt(Camera.main.transform);
                l.transform.Rotate(new Vector3(0, 180, 0));
            }
        }

        if (profilePanel.activeSelf)
        {
            profilePanel.transform.LookAt(Camera.main.transform);
            profilePanel.transform.Rotate(new Vector3(0, 180, 0));
        }

        // Detect tapping
        if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began))
        {
            Ray        raycast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit raycastHit;
            if (Physics.Raycast(raycast, out raycastHit))
            {
                #region SHOW_CITY_PROFILE
                // Display city profile
                if (raycastHit.collider.CompareTag("Pin"))
                {
                    // Compute the scaling factor
                    float distanceScale = (raycastHit.collider.transform.position - referenceOrigin).magnitude / 1000;

                    // Display the panel before the other sprites by shifting a very small value so that it is not occluded
                    // A. Dynamic distance
                    //profilePanel.transform.position = raycastHit.collider.transform.position * 0.99f;

                    // B. Fixed distance
                    profilePanel.transform.position = Camera.main.transform.position + 1.0f * (raycastHit.point - Camera.main.transform.position).normalized;

                    // Fetch selected landmark information
                    CORE.LocationInfo selectedLocation = CORE.LOCATION_DATABASE[int.Parse(raycastHit.collider.name)];

                    // Assign information to the panel
                    profilePanel.transform.Find("Label_CityName").GetComponent <Text>().text        = selectedLocation.name;
                    profilePanel.transform.Find("Label_CityCountry").GetComponent <Text>().text     = selectedLocation.country + "";
                    profilePanel.transform.Find("Label_CityDescription").GetComponent <Text>().text = selectedLocation.description;
                    profilePanel.transform.Find("Button_Portal").gameObject.SetActive(selectedLocation.panorama);

                    // Reset images just in case the target images are not available
                    profilePanel.transform.Find("Image_CityLandmark").gameObject.GetComponent <Image>().sprite = defaultLandmark;
                    profilePanel.transform.Find("Image_CountryFlag").gameObject.GetComponent <Image>().sprite  = defaultFlag;

                    // Load images from local resources
                    StartCoroutine(CORE.LoadImageToSprite(Path.Combine(Application.streamingAssetsPath, CORE.IMAGE_FOLDER_CITY, CORE.FileNameParser(selectedLocation.name) + CORE.IMAGE_FORMAT), (result) =>
                    {
                        profilePanel.transform.Find("Image_CityLandmark").gameObject.GetComponent <Image>().sprite = result;
                    }));

                    StartCoroutine(CORE.LoadImageToSprite(Path.Combine(Application.streamingAssetsPath, CORE.IMAGE_FOLDER_FLAG, CORE.FileNameParser(selectedLocation.country) + CORE.IMAGE_FORMAT), (result) =>
                    {
                        profilePanel.transform.Find("Image_CountryFlag").gameObject.GetComponent <Image>().sprite = result;
                    }));

                    StartCoroutine(CORE.LoadImageToTexture(Path.Combine(Application.streamingAssetsPath, CORE.IMAGE_FOLDER_PANORAMA, CORE.FileNameParser(selectedLocation.name) + CORE.IMAGE_FORMAT), (result) =>
                    {
                        mappedEarth.transform.Find("Portal_Panorama").GetComponent <Renderer>().material.SetTexture("_Texture", result);
                    }));

                    panoramaPanel.transform.Find("Text").GetComponent <Text>().text = selectedLocation.landmark;

                    // Append formatted string to the url
                    url = Path.Combine(CORE.SEARCH_ENGINE_PATH, CORE.FileNameParser(selectedLocation.name));

                    // Scale the panel
                    // A. Dynamic scale
                    //profilePanel.transform.localScale = Vector3.one * UIPanelScaleDynamic * distanceScale;

                    // B. Fixed scale
                    profilePanel.transform.localScale = Vector3.one * UIPanelScaleFixed;

                    // Rotate the panel to face the user
                    profilePanel.transform.LookAt(Camera.main.transform);
                    profilePanel.transform.Rotate(new Vector3(0, 180, 0));

                    // Show the panel
                    profilePanel.SetActive(true);
                }
                #endregion
            }
        }
    }