Exemple #1
0
        /// <summary>
        /// Grab a radar display element from the pool
        /// </summary>
        /// <returns></returns>
        RadarPoolInstance GetDisplayElement()
        {
            if (radarPool.Count > 1)
            {
                return(radarPool.Dequeue());
            }
            else
            {
                RadarPoolInstance rf = null;
                for (int i = 0; i < 4; i++)
                {
                    GameObject go = new GameObject("Tracker");
                    go.transform.SetParent(this.transform);
                    MeshFilter   f = go.AddComponent <MeshFilter>();
                    MeshRenderer r = go.AddComponent <MeshRenderer>();
                    r.material = this.trackerMaterial;

                    go.SetActive(false);

                    if (rf == null)
                    {
                        RadarPoolInstance rpi = new RadarPoolInstance();
                        rpi.gameObject = go;
                        rpi.filter     = f;
                        rpi.renderer   = r;
                        rf             = rpi;
                    }
                }
                return(rf);
            }
        }
Exemple #2
0
        /// <summary>
        /// Update position of radar elements from their real world positions relative to this display
        /// </summary>
        void Update()
        {
            float scale = displaySize / worldRange;

            List <Color>   colours = new List <Color>();
            List <Vector3> points  = new List <Vector3>();

            foreach (Radar3dElement element in scene.elements)
            {
                Vector3 localPos = this.transform.InverseTransformPoint(element.transform.position);
                float   distance = localPos.magnitude;

                if (distance * distance < worldRange * worldRange)
                {
                    //Draw
                    MeshFilter mf;
                    if (!this.usedFilters.ContainsKey(element))
                    {
                        RadarPoolInstance rpi = GetDisplayElement();
                        rpi.gameObject.transform.localScale = Vector3.one * element.scale;
                        mf = rpi.filter;
                        rpi.renderer.material.color = element.color;
                        mf.gameObject.SetActive(true);
                        mf.sharedMesh             = element.shape;
                        this.usedFilters[element] = rpi;
                    }
                    else
                    {
                        mf = this.usedFilters[element].filter;
                    }

                    mf.transform.localPosition = localPos * scale;

                    colours.Add(element.color);
                    points.Add(mf.transform.localPosition);
                    points.Add(new Vector3(mf.transform.localPosition.x, 0, mf.transform.localPosition.z));
                }
                else
                {
                    //Hide

                    if (this.usedFilters.ContainsKey(element))
                    {
                        RadarPoolInstance rpi = this.usedFilters[element];
                        this.usedFilters.Remove(element);
                        rpi.gameObject.SetActive(false);
                        this.radarPool.Enqueue(rpi);
                    }
                }

                this.colours = colours.ToArray();
                this.points  = points.ToArray();
            }
        }