コード例 #1
0
ファイル: Flyby.cs プロジェクト: morbidintel/WebCity
    /// <summary>
    /// Coroutine that does the actual flyby logic.
    /// </summary>
    /// <param name="delay">delay between each location, in seconds.</param>
    /// <remarks>
    /// This logic is in a coroutine so that we don't have to put it in Update;
    /// Coroutines provide an easy way to keep track of time past
    /// </remarks>
    IEnumerator FlybyCoroutine(float delay)
    {
        // wait for delay, if there's any
        if (delay > 0)
        {
            yield return(new WaitForSecondsRealtime(delay));
        }

        IsDoingFlyby = true;

        while (true)
        {
            foreach (var l in locations)
            {
                // calculate distance manually because we want to fly nearer
                Vector3 northeast  = MapCamera.LatLongToUnity(l.viewport.northeast),
                         southwest = MapCamera.LatLongToUnity(l.viewport.southwest);
                float diag         = (northeast - southwest).magnitude;         // viewport diagonal distance
                float dist         = Mathf.Clamp(diag / 2f, 0.5f, camera.maxDistance);

                camera.SetCameraViewport(l, dist, true);
                camera.TargetElevation = 30f;                 // nice angle

                // wait for delay to fly to next location
                yield return(new WaitForSecondsRealtime(flybyInterval));
            }
        }
    }