示例#1
0
        /// <summary>
        /// Update the widget with a target reference.
        /// </summary>
        /// <param name="trackable">The target component.</param>
        public virtual void UpdateRadarWidget(Trackable trackable)
        {
            // Update the foot
            if (hasFoot)
            {
                foot.localPosition = new Vector3(0f, 0f, -1 * transform.localPosition.z);
            }

            // Update the leg
            if (hasLeg)
            {
                leg.localPosition = new Vector3(0f, 0f, -0.5f * transform.localPosition.z);
                leg.sizeDelta     = new Vector2(leg.sizeDelta.x, Mathf.Abs(transform.localPosition.z));
            }
        }
示例#2
0
        // Called when the parent selector's target changes
        protected virtual void OnParentTargetChanged(Trackable parentTrackable)
        {
            // Update the target list
            if (parentTrackable == null)
            {
                trackables = new List <Trackable>();
            }
            else
            {
                trackables = parentTrackable.ChildTrackables;
            }

            if (scanEveryFrame)
            {
                SelectFirstSelectableTarget();
            }
        }
示例#3
0
        // Called to check if a target is trackable by this radar
        public virtual bool IsTrackable(Trackable target)
        {
            // Check distance
            if (!target.IgnoreTrackingDistance && Vector3.Distance(target.transform.position, transform.position) > range)
            {
                return(false);
            }

            // Check if this tracker can select the team
            bool found = false;

            for (int i = 0; i < trackableTeams.Count; ++i)
            {
                if (trackableTeams[i] == target.Team)
                {
                    found = true;
                }
            }
            if (!found)
            {
                return(false);
            }

            // Check if this target can select the type
            found = false;
            for (int i = 0; i < trackableTypes.Count; ++i)
            {
                if (trackableTypes[i] == target.TrackableType)
                {
                    found = true;
                }
            }
            if (!found)
            {
                return(false);
            }

            if (this.rootTransform != null && target.RootTransform == this.rootTransform)
            {
                return(false);
            }

            return(true);
        }
示例#4
0
 // Called every frame
 protected virtual void Update()
 {
     // If toggled, always look for a new target when none is selected
     if (scanEveryFrame && selectedTarget == null)
     {
         if (defaultToFrontMostTarget)
         {
             Trackable frontMostTarget = GetFrontMostTarget();
             if (frontMostTarget != null)
             {
                 Select(frontMostTarget);
             }
         }
         else
         {
             SelectFirstSelectableTarget();
         }
     }
 }
        // Check if a target is selectable
        protected virtual bool IsSelectable(Trackable target)
        {
            // Check if the team is selectable
            bool teamFound = false;

            for (int i = 0; i < selectableTeams.Count; ++i)
            {
                if (selectableTeams[i] == target.Team)
                {
                    teamFound = true;
                    break;
                }
            }
            if (!teamFound)
            {
                return(false);
            }

            // Check if the type is selectable
            bool typeFound = false;

            for (int i = 0; i < selectableTypes.Count; ++i)
            {
                if (selectableTypes[i] == target.TrackableType)
                {
                    typeFound = true;
                    break;
                }
            }
            if (!typeFound)
            {
                return(false);
            }

            // Check if the depth is selectable
            if (target.Depth > maxDepth)
            {
                return(false);
            }

            return(true);
        }
        // Select a target
        public virtual void Select(Trackable newSelectedTarget)
        {
            if (newSelectedTarget == selectedTarget)
            {
                return;
            }

            // Unselect the currently selected target
            if (selectedTarget != null)
            {
                selectedTarget.Unselect();
            }

            if (newSelectedTarget != null)
            {
                // If toggled, select the highest depth child in the hierarchy.
                if (selectHighestDepthChild)
                {
                    for (int i = 0; i < 1000; ++i)
                    {
                        if (newSelectedTarget.ChildTrackables.Count > 0)
                        {
                            Select(newSelectedTarget.ChildTrackables[0]);
                            return;
                        }
                    }
                }
            }

            // Update the target
            selectedTarget = newSelectedTarget;

            // Call select event on the new target
            if (selectedTarget != null && callSelectEventOnTarget)
            {
                selectedTarget.Select();
            }

            // Call the event
            onSelectedTargetChanged.Invoke(selectedTarget);
        }
示例#7
0
 /// <summary>
 /// Called to set the trackable that this target box represents.
 /// </summary>
 /// <param name="trackable">The trackable that this target box represents.</param>
 public virtual void UpdateTargetBox(Trackable trackable)
 {
     // Call the event
     onTargetBoxUpdated.Invoke(trackable);
 }
示例#8
0
        // Visualize a target tracked by a Tracker component
        protected virtual void Visualize(Tracker tracker, Trackable trackable)
        {
            targetRelPos = tracker.transform.InverseTransformPoint(trackable.transform.position);

            // If target is outside the radar display range and is not clamped to the border, ignore it
            if (targetRelPos.magnitude > radarDisplayRange)
            {
                if (!clampToBorder)
                {
                    return;
                }
            }

            // Get a radar widget that matches the trackable type and display it
            for (int i = 0; i < radarWidgetContainers.Count; ++i)
            {
                for (int j = 0; j < radarWidgetContainers[i].trackableTypes.Count; ++j)
                {
                    if (radarWidgetContainers[i].trackableTypes[j] == trackable.TrackableType)
                    {
                        HUDRadarWidget widget = radarWidgetContainers[i].GetNextAvailable(widgetParent);

                        widget.SetColor(defaultWidgetColor);
                        for (int k = 0; k < teamColors.Count; ++k)
                        {
                            if (teamColors[k].team == trackable.Team)
                            {
                                widget.SetColor(teamColors[k].color);
                            }
                        }

                        bool isSelected = false;
                        for (int k = 0; k < targetSelectors.Count; ++k)
                        {
                            if (targetSelectors[k].SelectedTarget == trackable)
                            {
                                isSelected = true;
                                break;
                            }
                        }
                        widget.SetSelected(isSelected);

                        Vector3 localPos;
                        if (targetRelPos.magnitude > radarDisplayRange)
                        {
                            localPos = (targetRelPos.normalized * radarDisplayRange) * (equatorRadius / radarDisplayRange);

                            widget.SetIsClampedToBorder(true);
                        }
                        else
                        {
                            float amount = (targetRelPos.magnitude / radarDisplayRange);
                            amount   = 1 - Mathf.Pow(1 - amount, scaleExponent);
                            localPos = (amount * equatorRadius) * targetRelPos.normalized;

                            widget.SetIsClampedToBorder(false);
                        }

                        if (VerticalAxisZ)
                        {
                            localPos = Quaternion.Euler(-90, 0, 0) * localPos;
                        }

                        widget.transform.localPosition = localPos;

                        widget.transform.localRotation = Quaternion.identity;

                        widget.UpdateRadarWidget(trackable);

                        return;
                    }
                }
            }
        }
示例#9
0
 /// <summary>
 /// Clear the target.
 /// </summary>
 public virtual void ClearTarget()
 {
     this.target = null;
 }
 /// <summary>
 /// Called when a trackable is destroyed in the scene.
 /// </summary>
 /// <param name="trackable">The trackable.</param>
 public void OnTrackableDestroyed(Trackable trackable)
 {
     trackables.Remove(trackable);
     onTrackableUnregistered.Invoke(trackable);
 }
示例#11
0
 // Called when this tracker stops tracking a target
 protected virtual void OnStoppedTracking(Trackable trackable)
 {
     onStoppedTracking.Invoke(trackable);
 }
示例#12
0
        // Called to check if a target is trackable by this radar
        public virtual bool IsTrackable(Trackable target)
        {
            // Check distance
            if (!target.IgnoreTrackingDistance && Vector3.Distance(target.transform.position, transform.position) > range)
            {
                return(false);
            }

            // Check if this tracker can select the team
            bool found = false;

            for (int i = 0; i < trackableTeams.Count; ++i)
            {
                if (trackableTeams[i] == target.Team)
                {
                    found = true;
                }
            }
            if (!found)
            {
                return(false);
            }

            // Check if this target can select the type
            found = false;
            for (int i = 0; i < trackableTypes.Count; ++i)
            {
                if (trackableTypes[i] == target.TrackableType)
                {
                    found = true;
                }
            }
            if (!found)
            {
                return(false);
            }

            if (this.rootTransform != null && target.RootTransform == this.rootTransform)
            {
                return(false);
            }

            if (lineOfSight)
            {
                Vector3 targetCenter = target.transform.TransformPoint(target.TrackingBounds.center);

                RaycastHit[] hits = Physics.RaycastAll(lineOfSightRefTransform.position, (targetCenter - lineOfSightRefTransform.position).normalized, range, lineOfSightMask);
                System.Array.Sort(hits, (x, y) => x.distance.CompareTo(y.distance));
                for (int i = 0; i < hits.Length; ++i)
                {
                    if (hits[i].collider.attachedRigidbody != null)
                    {
                        if (hits[i].collider.attachedRigidbody.transform == target.RootTransform)
                        {
                            return(true);
                        }

                        if (hits[i].collider.attachedRigidbody == m_Rigidbody)
                        {
                            continue;
                        }

                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#13
0
 // Called when a trackable is registered in the scene
 protected virtual void OnTrackableRegistered(Trackable trackable)
 {
     // Keep track of its tracking state
     trackingStatesByID.Add(TrackingState.NotTracked);
 }
示例#14
0
 /// <summary>
 /// Called to unregister a trackable in the scene.
 /// </summary>
 /// <param name="trackable">The trackable to be unregistered.</param>
 public void Unregister(Trackable trackable)
 {
     trackables.Remove(trackable);
     onTrackableUnregistered.Invoke(trackable);
 }
示例#15
0
        /// <summary>
        /// Set the target Trackable from which to get the hologram.
        /// </summary>
        /// <param name="newTarget">The target Trackable.</param>
        public virtual void SetTarget(Trackable newTarget)
        {
            targetTrackable = newTarget;

            // Clear hologram if null
            if (newTarget == null)
            {
                targetTrackable   = null;
                orientationTarget = null;
                SetHologram(null);
                return;
            }

            orientationTarget = newTarget.transform;

            // Update target label
            if (label != null)
            {
                if (targetTrackable.variablesDictionary.ContainsKey(labelKey))
                {
                    label.gameObject.SetActive(true);
                    label.text = targetTrackable.variablesDictionary[labelKey].StringValue;
                }
                else
                {
                    if (disableLabelIfValueMissing)
                    {
                        label.gameObject.SetActive(false);
                    }
                }
            }

            // Create the hologram
            GameObject hologramPrefab = null;

            if (targetTrackable.variablesDictionary.ContainsKey(hologramPrefabKey))
            {
                hologramPrefab = (GameObject)targetTrackable.variablesDictionary[hologramPrefabKey].ObjectValue;

                // Get the hologram component
                GameObject hologramObject;
                if (PoolManager.Instance != null)
                {
                    hologramObject = PoolManager.Instance.Get(hologramPrefab);
                }
                else
                {
                    hologramObject = GameObject.Instantiate(hologramPrefab);
                }

                Hologram hologram = hologramObject.GetComponent <Hologram>();
                if (hologram == null)
                {
                    Debug.LogError("The hologram prefab " + hologramObject.name + " must have a Hologram component on the root transform, please add one.");
                }

                // Set the hologram
                SetHologram(hologram);

                // Determine the color of the hologram
                Color col = defaultColor;
                if (targetTrackable.Team != null)
                {
                    col = targetTrackable.Team.DefaultColor;
                    for (int i = 0; i < teamColors.Count; ++i)
                    {
                        if (teamColors[i].team == targetTrackable.Team)
                        {
                            col = teamColors[i].color;
                        }
                    }
                }

                // Set the hologram color
                SetColor(col);
            }
        }
示例#16
0
 /// <summary>
 /// Set the target for this target locker.
 /// </summary>
 /// <param name="newTarget">The new target.</param>
 public virtual void SetTarget(Trackable newTarget)
 {
     target = newTarget;
 }
示例#17
0
 /// <summary>
 /// Remove a child trackable, e.g. when a module is unmounted that was trackable.
 /// </summary>
 /// <param name="childTrackable">The child trackable to be removed.</param>
 public void RemoveChildTrackable(Trackable childTrackable)
 {
     childTrackables.Remove(childTrackable);
     childTrackable.SetParentTrackable(null);
     childTrackable.SetDepth(0);
 }
示例#18
0
 /// <summary>
 /// Set the parent trackable for this trackable.
 /// </summary>
 /// <param name="parentTrackable">The parent trackable.</param>
 public void SetParentTrackable(Trackable parentTrackable)
 {
     this.parentTrackable = parentTrackable;
     this.team            = parentTrackable.Team;
 }
示例#19
0
 /// <summary>
 /// Set the target.
 /// </summary>
 /// <param name="target">The new target.</param>
 public virtual void SetTarget(Trackable target)
 {
     this.target = target;
 }
示例#20
0
 /// <summary>
 /// Set the bar fill amount based on a linked variable from a Trackable component.
 /// </summary>
 /// <param name="trackable">The trackable where the linked variable is stored.</param>
 public virtual void Set(Trackable trackable)
 {
     Set(trackable.variablesDictionary);
 }
示例#21
0
        /// <summary>
        /// Show a target box for a given target tracked by a given trackable.
        /// </summary>
        /// <param name="tracker"></param>
        /// <param name="trackable"></param>
        void ShowTargetBox(Tracker tracker, Trackable trackable)
        {
            // Get a target box
            HUDTargetBox targetBox = null;

            for (int i = 0; i < targetBoxContainers.Count; ++i)
            {
                for (int j = 0; j < targetBoxContainers[i].trackableTypes.Count; ++j)
                {
                    if (targetBoxContainers[i].trackableTypes[j] == trackable.TrackableType)
                    {
                        targetBox = targetBoxContainers[i].GetNextAvailable(canvas.transform);
                    }
                }
            }

            // Exit if no target box found
            if (targetBox == null)
            {
                return;
            }

            // Update whether the target is selected by a target selector
            bool isSelectedTarget = false;

            for (int i = 0; i < targetSelectors.Count; ++i)
            {
                if (targetSelectors[i].SelectedTarget == trackable)
                {
                    isSelectedTarget = true;
                    break;
                }
            }
            targetBox.SetIsSelectedTarget(isSelectedTarget);

            // Update world space target box scale (when switching from screen to world space, the target box is simply
            // scaled down to the equivalent world space size relative to the distance from the camera).
            float distanceFromCamera = 0;

            if (isWorldSpace)
            {
                distanceFromCamera = worldSpaceDistanceFromCamera;
                if (useTargetWorldPosition)
                {
                    distanceFromCamera = Vector3.Distance(hudCamera.transform.position, trackable.transform.position);
                }

                float scale = worldSpaceScaleCoefficient * distanceFromCamera;
                targetBox.transform.localScale = new Vector3(scale, scale, scale);
            }

            // Get world space target position
            Vector3 position = trackable.transform.position;

            if (useMeshBoundsCenter)
            {
                position = trackable.transform.TransformPoint(trackable.TrackingBounds.center);
            }

            // Get centered viewport position
            Vector3 centeredViewportPos = HUDTargetBoxesFunctions.GetViewportPosition(position, hudCamera, true);

            // Update whether the target is in view
            bool isInView = viewportRect.Contains(centeredViewportPos) && centeredViewportPos.z > 0;

            targetBox.SetIsInView(isInView);

            // Update the distance
            targetBox.SetDistance(Vector3.Distance(trackable.transform.position, tracker.transform.position));

            // If not in view, calculate screen border or arrow radial position
            float targetBoxAngle = 0;

            if (!isInView)
            {
                switch (targetBoxOffScreenMode)
                {
                case TargetBoxOffScreenMode.ClampedToBorder:
                    centeredViewportPos = HUDTargetBoxesFunctions.ClampToBorder(centeredViewportPos, viewportRect, out targetBoxAngle);
                    break;

                case TargetBoxOffScreenMode.CenterRadial:

                    Vector2 clampedCenteredViewportPosition = new Vector2(centeredViewportPos.x, centeredViewportPos.y).normalized *offscreenArrowsViewportSpaceRadius;

                    centeredViewportPos.x = clampedCenteredViewportPosition.x * (1 / hudCamera.aspect);
                    centeredViewportPos.y = clampedCenteredViewportPosition.y;

                    targetBoxAngle = Mathf.Atan2(centeredViewportPos.y, centeredViewportPos.x) * Mathf.Rad2Deg;

                    break;
                }
            }

            // Update position, rotation and scale of the target box depending on the render mode of the canvas
            AlignHUDElement(targetBox.RectTransform, centeredViewportPos, Quaternion.Euler(0f, 0f, targetBoxAngle), distanceFromCamera);

            // Update the size of the target box
            if (canvas.renderMode == RenderMode.WorldSpace)
            {
                Vector2 viewportSize = HUDTargetBoxesFunctions.GetViewportSize(trackable, extentsCornersArray, hudCamera, viewportRect);
                targetBox.SetSize(GetWorldSpaceSize(viewportSize, distanceFromCamera));
            }
            else
            {
                targetBox.SetSize(Vector2.Scale(HUDTargetBoxesFunctions.GetViewportSize(trackable, extentsCornersArray, hudCamera, canvasRect), canvasRectTransform.sizeDelta));
            }

            // Update the color of the target box
            targetBox.SetColor(defaultColor);
            for (int i = 0; i < teamColors.Count; ++i)
            {
                if (teamColors[i].team == trackable.Team)
                {
                    targetBox.SetColor(teamColors[i].color);
                }
            }

            // Update the target locks
            for (int i = 0; i < targetLockers.Count; ++i)
            {
                if (targetLockers[i].Target == trackable)
                {
                    targetBox.AddLock(targetLockers[i]);
                }
            }

            // Update the lead target info for the target box
            for (int i = 0; i < targetLeaders.Count; ++i)
            {
                if (targetLeaders[i].Target != null && targetLeaders[i].Target == trackable)
                {
                    HUDTargetBox_LeadTargetBoxController leadTargetBoxController = targetBox.GetLeadTargetBox();

                    if (leadTargetBoxController != null)
                    {
                        Vector3 viewportPos = HUDTargetBoxesFunctions.GetViewportPosition(targetLeaders[i].LeadTargetPosition, hudCamera, true);
                        AlignHUDElement(leadTargetBoxController.Box.rectTransform, viewportPos, Quaternion.identity, distanceFromCamera, true, centeredViewportPos);
                        leadTargetBoxController.UpdateLeadTargetBox();
                    }
                }
            }

            targetBox.UpdateTargetBox(trackable);
        }
示例#22
0
 /// <summary>
 /// Set the target for this target locker.
 /// </summary>
 /// <param name="newTarget">The new target.</param>
 public virtual void SetTarget(Trackable newTarget)
 {
     target = newTarget;
     SetLockState(LockState.NoLock);
 }