示例#1
0
 // GPS 모드를 끌 때 잠시 gpsObject들을 despawn 시키는 함수
 private void DespawnObjects()
 {
     for (int i = 0; i < listGPSObject.Count; i++)
     {
         GPSObject gpsObj = listGPSObject[i].GetComponent <GPSObject>();
         gpsObj.objParent.SetActive(false);
     }
 }
        public void UpdateLocation(CLLocation newLocation)
        {
            double roundedLatitude  = Math.Floor(newLocation.Coordinate.Latitude);
            double roundedLongitude = Math.Floor(newLocation.Coordinate.Longitude);

            // If location is cupertino, we are in simulator. Lets set it to Norway to speed things up

            /*if (roundedLatitude == POIConst.cupertinoLatitude && roundedLongitude == POIConst.cupertinoLongitude)
             * {
             *  newLocation = new CLLocation(POIConst.stabekkLatitude, POIConst.stabekkLongitude);
             * }*/

            var previousLocation = lastKnownLocation;

            lastKnownLocation = newLocation;
            gpsPosFound       = true;

            GpsCoverage previousGpsCoverage = gpsCoverage;
            GpsCoverage newGpsCoverage      = GpsCoverage.None;

            newGpsCoverage = IOSMapUtil.GetAccuracyType(newLocation.HorizontalAccuracy,
                                                        highAndLowAccuracyDivider,
                                                        GpsCoverage.Low,
                                                        GpsCoverage.High);

            gpsCoverage = newGpsCoverage;

            GPSObject gpsObject = new GPSObject();

            gpsObject.accuracy       = newLocation.HorizontalAccuracy;
            gpsObject.gpsCoordinates = newLocation.Coordinate;
            gpsObject.storedDateTime = DateTime.Now;
            gpsCurrentPositionObject = gpsObject;

            gpsEventOccured = true;

            if (newLocation.HorizontalAccuracy <= gpsAccuracyRequirement)
            {
                AppDelegate.current.mainViewController.InvokeOnMainThread(delegate
                {
                    AppDelegate.current.locationManager.lastPositionType = PositionTypeConst.found;
                    NSNotificationCenter.DefaultCenter.PostNotificationName(EventConst.setupPosition, null);
                });
            }
            else
            {
                AppDelegate.current.mainViewController.InvokeOnMainThread(delegate
                {
                    AppDelegate.current.locationManager.lastPositionType = PositionTypeConst.finding;
                    NSNotificationCenter.DefaultCenter.PostNotificationName(EventConst.setupPosition, null);
                });
            }

            UpdateGPSPositionIfSignificantChange(newLocation, previousLocation);
        }
示例#3
0
    // 서버로부터 받은 현재 위치 주변의 gpsObject 데이터를 기반으로 테이블 데이터와 매칭하여 오브젝트들을 생성한다.
    public void CreateGPSObject(GetGPSObjectListResult result)
    {
        getGPSObjectListResult = result;

        GPSObjectTable goTable = new GPSObjectTable();

        for (int i = 0; i < result.gpsObjectList.Count; i++)
        {
            // Table과 매칭시켜 i 번째 gpsObject의 정보를 받아온다
            goTable = TableManager.Instance.gpsObjectTable.Find(t => t.id == result.gpsObjectList[i].id);

            // 해당되는 prefab을 불러와 scene에 생성한다
            System.Text.StringBuilder sb = new System.Text.StringBuilder("prefab/AR/GPS/");
            GameObject go = Instantiate(Resources.Load(sb.Append(goTable.model).ToString())) as GameObject;

            // 현재 gpsObject의 정보 입력
            GPSObject gpsObj = go.GetComponent <GPSObject>();
            gpsObj.id   = result.gpsObjectList[i].id;
            gpsObj.type = goTable.type;
            gpsObj.lat  = result.gpsObjectList[i].lat;
            gpsObj.lon  = result.gpsObjectList[i].lon;

            // 현재 유저의 위치로부터 gpsObject의 거리를 화면에 표시할 Text 오브젝트 생성
            GameObject goText = Instantiate(Resources.Load("prefab/AR/GPS/DistanceText")) as GameObject;
            gpsObj.distText = goText.GetComponent <TextMesh>();
            gpsObj.distText.transform.localPosition += new Vector3(0f, -0.08f, 0f);  // initialize text position

            // gpsObject와 text를 묶어줄 부모 객체 생성
            gpsObj.objParent = new GameObject();
            System.Text.StringBuilder nameSb = new System.Text.StringBuilder("GPSObject_");
            gpsObj.objParent.name = nameSb.Append(gpsObj.id).ToString();

            gpsObj.objParent.transform.SetParent(objectSpawner.transform);
            go.transform.parent = gpsObj.objParent.transform;
            gpsObj.distText.transform.parent = gpsObj.objParent.transform;

            gpsObj.objParent.SetActive(false);

            // 리스트에 추가, 이후 MoveObjects()에서 관리
            listGPSObject.Add(go);
        }
    }