Beispiel #1
0
        private void Update()
        {
            if (IsNewLayer)
            {
                IsNewLayer     = false;
                InitialHeading = Input.compass.trueHeading;
                HeadingShown   = Input.compass.trueHeading;
            }

            // Set any error text onto the canvas
            if (!IsEmpty(ErrorMessage) && InfoText != null)
            {
                InfoText.GetComponent <Text>().text = ErrorMessage;
                return;
            }

            if (WaitingForLayerSelection)
            {
                InfoText.GetComponent <Text>().text = _selectingText;
                return;
            }

            long nowTicks = DateTime.Now.Ticks;
            var  second   = nowTicks / 10000000L;

            var arObjectState = ArObjectState;

            if (StartTicks == 0 || arObjectState == null)
            {
                string progress = string.Empty;
                for (long s = _initialSecond; s < second; s++)
                {
                    progress += ".";
                }
                InfoText.GetComponent <Text>().text = _loadingText + progress;
                return;
            }

            if (arObjectState.IsDirty)
            {
                lock (arObjectState)
                {
                    if (arObjectState.ArObjectsToDelete.Any())
                    {
                        arObjectState.DestroyArObjects();
                    }
                    if (arObjectState.ArPois.Any())
                    {
                        CreateArObjects(arObjectState, null, SceneAnchor.transform, arObjectState.ArPois);
                        arObjectState.ArPois.Clear();
                    }
                    arObjectState.SetArObjectsToPlace();
                    arObjectState.IsDirty = false;
                }
            }
            var hit = arObjectState.HandleAnimations(StartTicks, nowTicks);

            if (_currentSecond == second)
            {
                _framesPerCurrentSecond++;
            }
            else
            {
                if (_currentSecond == second - 1)
                {
                    _framesPerSecond = _framesPerCurrentSecond;
                }
                else
                {
                    _framesPerSecond = 1;
                }
                _framesPerCurrentSecond = 1;
                _currentSecond          = second;
            }

            // Set any error text onto the canvas
            if (!IsEmpty(ErrorMessage) && InfoText != null)
            {
                InfoText.GetComponent <Text>().text = ErrorMessage;
                return;
            }

            // Calculate heading
            var currentHeading = CurrentHeading;

            if (Math.Abs(currentHeading - HeadingShown) > 180)
            {
                if (currentHeading < HeadingShown)
                {
                    currentHeading += 360;
                }
                else
                {
                    HeadingShown += 360;
                }
            }
            HeadingShown += (currentHeading - HeadingShown) / 10;
            while (HeadingShown > 360)
            {
                HeadingShown -= 360;
            }

            // Place the ar objects
            var arObjectsToPlace = arObjectState.ArObjectsToPlace;

            if (arObjectsToPlace != null)
            {
                foreach (var arObject in arObjectsToPlace)
                {
                    var jump = false;

                    // Linearly interpolate from current position to target position
                    Vector3 position;
                    if (AreaSize > 0 && AreaWidth > 0 &&
                        (Math.Abs(arObject.WrapperObject.transform.position.x - arObject.TargetPosition.x) > AreaWidth * .75 ||
                         Math.Abs(arObject.WrapperObject.transform.position.z - arObject.TargetPosition.z) > AreaSize * .75))
                    {
                        // Jump if area handling is active and distance is too big
                        position = new Vector3(arObject.TargetPosition.x, arObject.TargetPosition.y, arObject.TargetPosition.z);
                        jump     = true;
                    }
                    else
                    {
                        position = Vector3.Lerp(arObject.WrapperObject.transform.position, arObject.TargetPosition, .5f / _framesPerSecond);
                    }
                    arObject.WrapperObject.transform.position = position;

                    if (AreaSize > 0)
                    {
                        // Scale the objects at the edge of the area
                        var scale = arObject.Scale;
                        if (scale < 0)
                        {
                            scale = 1;
                        }
                        Vector3 localScale;
                        if (jump)
                        {
                            if (scale < 1)
                            {
                                scale = 0.01f;
                            }
                            localScale = new Vector3(scale, scale, scale);
                        }
                        else
                        {
                            localScale = new Vector3(scale, scale, scale);
                            localScale = Vector3.Lerp(arObject.WrapperObject.transform.localScale, localScale, 1f / _framesPerSecond);
                        }
                        arObject.WrapperObject.transform.localScale = localScale;
                    }
                }
            }
            SceneAnchor.transform.localEulerAngles = new Vector3(0, DeviceAngle - InitialHeading, 0);

            // Turn the ar objects
            if (CameraIsInitializing)
            {
                InitialHeading     = HeadingShown;
                InitialCameraAngle = ArCamera.transform.eulerAngles.y;
            }

            if (InfoText != null)
            {
                // Set info text
                if (!ShowInfo)
                {
                    InfoText.GetComponent <Text>().text = string.Empty;
                    return;
                }

                var firstArObject = arObjectState.ArObjects.FirstOrDefault();
                if (!IsEmpty(InformationMessage))
                {
                    // This is for debugging, put the strings used below into the information message of your layer
                    var message = InformationMessage;
                    if (message.Contains("{"))
                    {
                        message = message.Replace("{F}", "" + _framesPerSecond);
                        message = message.Replace("{N}", "" + arObjectState.Count);
                        message = message.Replace("{A}", "" + arObjectState.NumberOfAnimations);
                        message = message.Replace("{T}", "" + TriggerObjects.Count);

                        message = message.Replace("{I}", "" + (int)InitialHeading);
                        message = message.Replace("{D}", "" + DeviceAngle);
                        message = message.Replace("{Y}", "" + (int)SceneAnchor.transform.eulerAngles.y);
                        message = message.Replace("{H}", "" + (int)HeadingShown);
                        message = message.Replace("{C}", "" + (int)currentHeading);

                        message = message.Replace("{LAT}", UsedLatitude.ToString("F6"));
                        message = message.Replace("{LON}", UsedLongitude.ToString("F6"));

                        message = message.Replace("{LAT1}", (firstArObject != null ? firstArObject.Latitude : 0).ToString("F6"));
                        message = message.Replace("{LON1}", (firstArObject != null ? firstArObject.Longitude : 0).ToString("F6"));
                        message = message.Replace("{D1}", (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, firstArObject.Latitude, firstArObject.Longitude) : 0).ToString("F1"));
                        message = message.Replace("{DNS1}", (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, firstArObject.Latitude, UsedLongitude) : 0).ToString("F1"));
                        message = message.Replace("{DEW1}", (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, UsedLatitude, firstArObject.Longitude) : 0).ToString("F1"));
                    }
                    InfoText.GetComponent <Text>().text = message;
                    return;
                }

                InfoText.GetComponent <Text>().text =
                    ""
                    //+ "B " + _bleachingValue
                    //+ " CA " + (_locationLatitude).ToString("F6")
                    //+ " A " + (_locationHorizontalAccuracy).ToString("F6")
                    //+ "" + (UsedLatitude).ToString("F6")
                    //+ " CO " + (_locationLongitude).ToString("F6")
                    //+ " " + (UsedLongitude).ToString("F6")
                    //+ " AS " + _areaSize
                    //+ " F " + DisplayAnimationValueForward.ToString("F1")
                    //+ " R " + DisplayAnimationValueRight.ToString("F1")
                    //+ " % " + DisplayPercentage.ToString("F1")
                    //+ " Z " + DisplayGoalPosition.z.ToString("F1")
                    //+ " X " + DisplayGoalPosition.x.ToString("F1")
                    //+ " Y " + DisplayGoalPosition.y.ToString("F1")
                    //+ " Z " + (LastObject != null ? LastObject.TargetPosition : Vector3.zero).z.ToString("F1")
                    //+ " X " + (LastObject != null ? LastObject.TargetPosition : Vector3.zero).x.ToString("F1")
                    //+ " Y " + (LastObject != null ? LastObject.TargetPosition : Vector3.zero).y.ToString("F1")
                    //+ " OH " + (firstArObject != null ? firstArObject.Latitude : 0).ToString("F6")
                    //+ " OL " + (firstArObject != null ? firstArObject.Longitude : 0).ToString("F6")
                    //+ " D " + (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, firstArObject.Latitude, firstArObject.Longitude) : 0).ToString("F1")
                    //+ " F " + _framesPerSecond
                    //+ " C " + _cameraTransform.eulerAngles.y.ToString("F")
                    + " I " + (int)InitialHeading
                    + " D " + (int)DeviceAngle
                    + " Y " + (int)SceneAnchor.transform.eulerAngles.y
                    + " H " + (int)HeadingShown
                    + " C " + (int)currentHeading
                    //+ " IH " + _initialHeading.ToString("F")
                    + " N " + arObjectState.ArObjects.Sum(x => x.GameObjects.Count)
                    //+ " O " + _onFocusAnimations.Count
                    //+ " R " + ray.ToString()
                    //+ " R " + ray.origin.x.ToString("F1") + " " + ray.origin.y.ToString("F1") + " " + ray.origin.z.ToString("F1")
                    //+ " " + ray.direction.x.ToString("F1") + " " + ray.direction.y.ToString("F1") + " " + ray.direction.z.ToString("F1")
                    + (hit ? " h " : string.Empty)
                ;
            }
        }
Beispiel #2
0
        protected virtual void Update()
        {
            // Set any error text onto the canvas
            if (!IsEmpty(ErrorMessage) && InfoText != null)
            {
                InfoText.GetComponent <Text>().text = ErrorMessage;
                return;
            }

            long nowTicks = DateTime.Now.Ticks;
            var  second   = nowTicks / 10000000L;

            var arObjectState = ArObjectState;

            if (StartTicks == 0 || arObjectState == null)
            {
                string progress = string.Empty;
                for (long s = _initialSecond; s < second; s++)
                {
                    progress += ".";
                }
                InfoText.GetComponent <Text>().text = _loadingText + progress;
                return;
            }

            if (arObjectState.IsDirty)
            {
                lock (arObjectState)
                {
                    SceneAnchor.transform.eulerAngles = Vector3.zero;

                    if (arObjectState.ArObjectsToDelete.Any())
                    {
                        arObjectState.DestroyArObjects();
                    }
                    if (arObjectState.ArPois.Any())
                    {
                        CreateArObjects(arObjectState, null, SceneAnchor.transform, arObjectState.ArPois);
                        arObjectState.ArPois.Clear();
                    }
                    arObjectState.SetArObjectsToPlace();
                    arObjectState.IsDirty = false;
                }
            }
            SceneAnchor.transform.localEulerAngles = new Vector3(0, DeviceAngle - InitialHeading, 0);
            arObjectState.HandleAnimations(StartTicks, nowTicks);

            if (_currentSecond == second)
            {
                _framesPerCurrentSecond++;
            }
            else
            {
                if (_currentSecond == second - 1)
                {
                    _framesPerSecond = _framesPerCurrentSecond;
                }
                else
                {
                    _framesPerSecond = 1;
                }
                _framesPerCurrentSecond = 1;
                _currentSecond          = second;
            }

            // Set any error text onto the canvas
            if (!IsEmpty(ErrorMessage) && InfoText != null)
            {
                InfoText.GetComponent <Text>().text = ErrorMessage;
                return;
            }

            // Calculate heading
            var currentHeading = CurrentHeading;

            if (Math.Abs(currentHeading - HeadingShown) > 180)
            {
                if (currentHeading < HeadingShown)
                {
                    currentHeading += 360;
                }
                else
                {
                    HeadingShown += 360;
                }
            }
            HeadingShown += (currentHeading - HeadingShown) / 10;
            while (HeadingShown > 360)
            {
                HeadingShown -= 360;
            }

            if (InfoText != null)
            {
                // Set info text
                if (!ShowInfo)
                {
                    InfoText.GetComponent <Text>().text = string.Empty;
                    return;
                }

                var firstArObject   = arObjectState.ArObjects.FirstOrDefault();
                var firstGameObject = firstArObject?.GameObjects.FirstOrDefault();

                if (!IsEmpty(InformationMessage))
                {
                    // This is for debugging, put the strings used below into the information message of your layer
                    var message = InformationMessage;
                    if (message.Contains("{"))
                    {
                        message = message.Replace("{F}", "" + _framesPerSecond);
                        message = message.Replace("{N}", "" + arObjectState.Count);
                        message = message.Replace("{A}", "" + arObjectState.NumberOfAnimations);
                        message = message.Replace("{T}", "" + TriggerObjects.Count);

                        message = message.Replace("{I}", "" + (int)InitialHeading);
                        message = message.Replace("{D}", "" + DeviceAngle);
                        message = message.Replace("{Y}", "" + (int)SceneAnchor.transform.eulerAngles.y);
                        message = message.Replace("{H}", "" + (int)HeadingShown);
                        message = message.Replace("{C}", "" + (int)currentHeading);

                        message = message.Replace("{LAT}", UsedLatitude.ToString("F6"));
                        message = message.Replace("{LON}", UsedLongitude.ToString("F6"));

                        message = message.Replace("{LAT1}", (firstArObject != null ? firstArObject.Latitude : 0).ToString("F6"));
                        message = message.Replace("{LON1}", (firstArObject != null ? firstArObject.Longitude : 0).ToString("F6"));
                        message = message.Replace("{D1}", (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, firstArObject.Latitude, firstArObject.Longitude) : 0).ToString("F1"));
                        message = message.Replace("{DNS1}", (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, firstArObject.Latitude, UsedLongitude) : 0).ToString("F1"));
                        message = message.Replace("{DEW1}", (firstArObject != null ? CalculateDistance(UsedLatitude, UsedLongitude, UsedLatitude, firstArObject.Longitude) : 0).ToString("F1"));
                    }
                    InfoText.GetComponent <Text>().text = message;
                    return;
                }

                InfoText.GetComponent <Text>().text =
                    ""
                    //+ "" + (UsedLatitude).ToString("F6")
                    //+ " " + (UsedLongitude).ToString("F6")
                    + "F " + _framesPerSecond
                    + " N " + arObjectState.Count
                    + " T " + TriggerObjects.Count
                    + " A " + arObjectState.NumberOfAnimations
                    + " Z " + (firstGameObject != null ? firstGameObject.transform.position : Vector3.zero).z.ToString("F1")
                    + " X " + (firstGameObject != null ? firstGameObject.transform.position : Vector3.zero).x.ToString("F1")
                    + " Y " + (firstGameObject != null ? firstGameObject.transform.position : Vector3.zero).y.ToString("F1")
                ;
            }
        }