private IEnumerator CoChangeColor(Color newColor)
        {
            //Change color of all the indicator panel items
#if UNITY_2019_2_OR_NEWER
            TryGetComponent(out IndicatorTarget target);
            IndicatorPanel IPanel = target.IndicatorPanel;
#else
            IndicatorPanel IPanel = GetComponent <IndicatorTarget>().IndicatorPanel;
#endif
            while (IPanel == null)
            {
                IPanel = GetComponent <IndicatorTarget>().IndicatorPanel;
                yield return(null);
            }

            //Changes all graphic colors
            Graphic[] graphics = IPanel.GetComponentsInChildren <Graphic>(true);
            if (graphics.Length > 0)
            {
                for (int i = 0; i < graphics.Length; i++)
                {
                    graphics[i].color = newColor;
                }
            }
        }
        private IEnumerator CoCreateTargetCamera()
        {
            mPanel = mTarget.IndicatorPanel;

            while (mPanel == null)
            {
                mPanel = mTarget.IndicatorPanel;
                yield return(null);
            }

            //  Now that the indicator panel exist, create the camera
            CreateTargetCamera();
        }
        private IEnumerator IECoCreateDistanceTracker()
        {
            mPanel = mTarget.IndicatorPanel;

            while (mPanel == null)
            {
                mPanel = mTarget.IndicatorPanel;
                yield return(null);
            }

            //Now that the indicator panel exist, create the tracker
            CreateDistanceTracker();
        }
Example #4
0
        /// <summary>
        /// Create & set-up the indicator panel
        /// </summary>
        private void InitializeIndicator()
        {
            //If no custom indicator panel is assigned to this gameobject, the viewer default indicator panel will be used instead
            if (customIndicatorPanel == null)
            {
                customIndicatorPanel = mViewer.defaultIndicatorPanel;
            }

            //If customIndicatorPanel is still null because there is no viewer default, throw error
            try
            {
                //Create the runtime indicator object and assign it under the canvas.
                GameObject panel = Instantiate(customIndicatorPanel, Vector2.zero, Quaternion.identity) as GameObject;
                panel.name = name + " indicator";
                panel.transform.SetParent(mViewer.IndicatorCanvas.transform);
#if UNITY_2019_2_OR_NEWER
                panel.TryGetComponent(out mPanel);
#else
                mPanel = panel.GetComponent <IndicatorPanel>();
#endif

                //Set the offset position of the onscreen image.
                if (mPanel.onScreen != null)
                {
                    mPanel.onScreen.transform.position += new Vector3(onScreenOffset.x, onScreenOffset.y, 0);
                }

                //Assign the initial z position && scale value
                //previousZposition = IPanel.transform.position.z;
                //previousScale = IPanel.transform.localScale;

                //Add this target to the list of targets if not already
                if (!IndicatorViewer.Targets.Contains(this))
                {
                    IndicatorViewer.Targets.Add(this);
                }

                //initial indicator toggle
                if (OnScreen(mViewer.viewerCamera.WorldToScreenPoint(transform.position), mViewer.viewerCamera))
                {
                    if (mPanel.onScreen != null)
                    {
                        ToggleOnScreen(true);
                    }
                    if (mPanel.offScreen != null)
                    {
                        ToggleOffScreen(false);
                    }
                }
                else
                {
                    if (mPanel.onScreen != null)
                    {
                        ToggleOnScreen(false);
                    }
                    if (mPanel.offScreen != null)
                    {
                        ToggleOffScreen(true);
                    }
                }
            }
            catch
            { Debug.LogError("The 'DefaultIndicatorPanel' requires a UnityUI Panel object!", mViewer); }
        }