예제 #1
0
    private void CalculateBulletProjection()
    {
        var     camRay = GetComponentInParent <Camera>().ScreenPointToRay(_screenCenterPos);
        Vector3 direction;

        bool raycastShot;

        RaycastHit hit;

        if (Physics.Raycast(camRay, out hit, 1000.0f, BulletRaycastMask))
        {
            direction   = (hit.point - _bulletSpawnPoint.position).normalized;
            raycastShot = true;
        }
        else
        {
            direction   = transform.forward;
            raycastShot = false;
        }

        // Convert the bullet's spawn point to a GPS position that can be synced across the network
        var       bulletSpawnGpsPos = XRSessionManager.GetSession().LocalPositionToGps(_bulletSpawnPoint.position);
        GpsStruct bulletGpsPos      = new GpsStruct {
            Latitude  = bulletSpawnGpsPos.Latitude,
            Longitude = bulletSpawnGpsPos.Longitude,
            Height    = bulletSpawnGpsPos.Height
        };

        CmdShootBullet(bulletGpsPos, direction, raycastShot);
    }
예제 #2
0
    private void CmdSpawnTarget(GpsStruct gpsPos, Quaternion rotation)
    {
        // Spawns target in temporary safe location before each client moves the target to their
        // own corresponding world coordinates in the 'Target' script based on the synced GPS position
        GameObject target = Instantiate(_targetPrefab, Vector3.up * 1000, rotation);

        target.GetComponent <Target> ().GpsPos      = gpsPos;
        target.GetComponent <Target> ().Orientation = rotation;

        NetworkServer.Spawn(target);            // Spawns the target on clients
    }
예제 #3
0
    private void CmdShootBullet(GpsStruct bulletGpsPos, Vector3 direction, bool raycastShot)
    {
        // Spawns the bullet, its location and direction will be adjusted on the clients in the 'Bullet' script afterwards
        GameObject bullet = Instantiate(_bulletPrefab);

        Bullet bulletScript = bullet.GetComponent <Bullet> ();

        bulletScript.GpsPos      = bulletGpsPos;
        bulletScript.Direction   = direction;
        bulletScript.RaycastShot = raycastShot;

        NetworkServer.Spawn(bullet);            // Spawns the bullet on clients
    }
    // Prepares to sync the local player's GPS and orientation values across the network
    // Function only called by local player
    private void SendNetworkPlayerValues()
    {
        // Convert the Player's Unity coordinates to GPS coordinates
        var gpsPos = XRSessionManager.GetSession().LocalPositionToGps(transform.position);

        // Converts the Sturfee 'GpsPosition' class to a struct with the same values so it can be transferred across the network
        GpsStruct newPlayerGpsPos = new GpsStruct
        {
            Latitude  = gpsPos.Latitude,
            Longitude = gpsPos.Longitude,
            Height    = gpsPos.Height
        };

        CmdSetPlayerTransform(newPlayerGpsPos, transform.rotation);
    }
예제 #5
0
    // Sturfee event called when 'DetectSurfaceAtPoint' completes
    public void OnDetectSurfacePointComplete(Sturfee.Unity.XR.Core.Models.Location.GpsPosition gpsPos, UnityEngine.Vector3 normal)
    {
        ScreenMessageController.Instance.SetText("Target Placed", 2.5f);

        _activeHitscan             = false;
        _targetButton.interactable = true;

        GpsStruct targetGpsPos = new GpsStruct
        {
            Latitude  = gpsPos.Latitude,
            Longitude = gpsPos.Longitude,
            Height    = gpsPos.Height
        };

        CmdSpawnTarget(targetGpsPos, Quaternion.LookRotation(normal));
    }
 private void RpcSetPlayerTransform(GpsStruct gpsPos, Quaternion rotation)
 {
     PlayerGpsPos      = gpsPos;
     PlayerOrientation = rotation;
 }
 private void CmdSetPlayerTransform(GpsStruct gpsPos, Quaternion rotation)
 {
     RpcSetPlayerTransform(gpsPos, rotation);
 }