Exemple #1
0
        /// <summary>
        /// Set the hologram.
        /// </summary>
        /// <param name="hologram">The new hologram.</param>
        public void SetHologram(Hologram hologram)
        {
            if (this.hologram != null)
            {
                this.hologram.gameObject.SetActive(false);
                this.hologram = null;
            }

            if (hologram == null)
            {
                return;
            }

            // Set the hologram
            hologram.transform.SetParent(hologramParent);
            hologram.transform.localPosition = Vector3.zero;
            hologram.transform.localRotation = Quaternion.identity;

            // Adjust the scale
            Vector3 extents          = hologram.Bounds.extents;
            float   averageDimension = (extents.x + extents.y + extents.z) / 3.0f;
            float   scale            = hologramSize / (averageDimension * 2);

            hologram.transform.localScale = new Vector3(scale, scale, scale);

            for (int i = 0; i < hologram.Materials.Length; ++i)
            {
                hologram.Materials[i].SetFloat("_Scale", scale);
            }

            SetColor(defaultColor);

            this.hologram = hologram;
        }
Exemple #2
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);
            }
        }