コード例 #1
0
 public void Initialize(GeoAudioObjectModel geoAudioObjectModel, AudioClip clip)
 {
     this.id              = geoAudioObjectModel.id;
     this.clip            = clip;
     this.gpsLocation.lat = geoAudioObjectModel.position.lat;
     this.gpsLocation.lng = geoAudioObjectModel.position.lng;
     Debug.Log("initialized " + geoAudioObjectModel.name);
     this.GetComponent <AudioSource>().clip = clip;
 }
コード例 #2
0
    IEnumerator LoadAudioFromServer(string url,
                                    AudioType audioType,
                                    GeoAudioObjectModel audioObj)
    {
        var request = UnityWebRequestMultimedia.GetAudioClip(url, audioType);

        // Debug.Log("1!!!");
        yield return(request.SendWebRequest());


        if (!request.isHttpError && !request.isNetworkError)
        {
            //////////////////////
            Vector3 objectPlace =
                GPSEncoder.GPSToUCS(audioObj.position.lat, audioObj.position.lng);

            // if distance to POI greater then maxDistanceToPOIGeoObject units then normalize to maxDistanceToPOIGeoObject
            double diffInMBetweenUserAndGpsOfObject = DistanceBetween2GeoobjectsInM(currentLocation.lat,
                                                                                    currentLocation.lng, audioObj.position.lat, audioObj.position.lng);


            GameObject newGameObject =
                Instantiate(audioPrefabGameObject, objectPlace, Quaternion.identity) as GameObject;

            newGameObject.transform.SetParent(ToNorth.transform);
            newGameObject.tag = nameof(GeoAudioObject);
            // Debug.Log("2!!!");
            AudioClip audio = DownloadHandlerAudioClip.GetContent(request);
            // Debug.Log(newGameObject.GetComponent<GeoAudioObject>() + "       ");
            // init content of geoObject(point of interest)
            newGameObject.GetComponent <GeoAudioObject>()
            .Initialize(audioObj, audio);
            // Debug.Log("3!!!");
            Debug.Log($" {DateTime.Now:HH:mm:ss tt} Placed object {audioObj.name} " +
                      $"at location lat: {audioObj.position.lat}, lng: {audioObj.position.lng}. " +
                      $"\n Updated Distance to {diffInMBetweenUserAndGpsOfObject}m");

            // add to dict of initedGeoObjects
            geoObjectsInScene.Add(audioObj.id, newGameObject);
            newGameObject.GetComponent <AudioSource>().volume = 0;
            newGameObject.GetComponent <AudioSource>().Play();

            ///////////////////////
            ///audioSource.Play();
        }
        else
        {
            Debug.LogErrorFormat("error request [{0}, {1}]", url, request.error);
        }

        request.Dispose();
    }