Esempio n. 1
0
        /// <summary>
        /// Submits an array of points to draw into the queue.
        /// </summary>
        internal static void Submit(Vector3[] points, Color?color, bool dashed)
        {
            GizmosInstance inst = GetOrCreate();

            //if new frame, reset index
            if (inst.lastFrame != Time.frameCount)
            {
                inst.lastFrame  = Time.frameCount;
                inst.queueIndex = 0;
            }

            //excedeed the length, so make it even bigger
            if (inst.queueIndex >= inst.queue.Length)
            {
                Element[] bigger = new Element[inst.queue.Length + DefaultQueueSize];
                for (int i = inst.queue.Length; i < bigger.Length; i++)
                {
                    bigger[i] = new Element();
                }

                Array.Copy(inst.queue, 0, bigger, 0, inst.queue.Length);
                inst.queue = bigger;
            }

            inst.queue[inst.queueIndex].color  = color ?? Color.white;
            inst.queue[inst.queueIndex].points = points;
            inst.queue[inst.queueIndex].dashed = dashed;

            inst.queueIndex++;
        }
        internal static GizmosInstance GetOrCreate()
        {
            if (!instance)
            {
                var gizmosInstances = FindObjectsOfType <GizmosInstance>();
                for (var i = 0; i < gizmosInstances.Length; i++)
                {
                    instance = gizmosInstances[i];

                    //destroy any extra gizmo instances
                    if (i > 0)
                    {
                        Destroy(gizmosInstances[i]);
                    }
                }

                //none were found, create a new one
                if (!instance)
                {
                    //instance = new GameObject(typeof(GizmosInstance).FullName).AddComponent<GizmosInstance>();
                    //instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
                    instance = Locator.GetPlayerCamera().gameObject.AddComponent <GizmosInstance>();
                }
            }

            return(instance);
        }
Esempio n. 3
0
        internal static GizmosInstance GetOrCreate()
        {
            if (!hotReloaded && instance)
            {
                return(instance);
            }

            bool markDirty = false;

            GizmosInstance[] gizmosInstances = FindObjectsOfType <GizmosInstance>();
            for (int _i = 0; _i < gizmosInstances.Length; _i++)
            {
                instance = gizmosInstances[_i];

                //destroy any extra gizmo instances
                if (_i <= 0)
                {
                    continue;
                }

                if (Application.isPlaying)
                {
                    Destroy(gizmosInstances[_i]);
                }
                else
                {
                    DestroyImmediate(gizmosInstances[_i]);
                    markDirty = true;
                }
            }

            //none were found, create a new one
            if (!instance)
            {
                instance = new GameObject("Popcron.Gizmos.GizmosInstance").AddComponent <GizmosInstance>();
                instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;

                markDirty = true;
            }

            #if UNITY_EDITOR
            //mark scene as dirty
            if (markDirty && !Application.isPlaying)
            {
                Scene scene = SceneManager.GetActiveScene();
                EditorSceneManager.MarkSceneDirty(scene);
            }
            #endif

            hotReloaded = false;

            return(instance);
        }
Esempio n. 4
0
        internal static GizmosInstance GetOrCreate()
        {
            if (hotReloaded || !instance)
            {
                bool             markDirty       = false;
                GizmosInstance[] gizmosInstances = FindObjectsOfType <GizmosInstance>();
                for (int i = 0; i < gizmosInstances.Length; i++)
                {
                    instance = gizmosInstances[i];

                    //destroy any extra gizmo instances
                    if (i > 0)
                    {
                        if (Application.isPlaying)
                        {
                            Destroy(gizmosInstances[i]);
                        }
                        else
                        {
                            DestroyImmediate(gizmosInstances[i]);
                            markDirty = true;
                        }
                    }
                }

                //none were found, create a new one
                if (!instance)
                {
                    instance = new GameObject(typeof(GizmosInstance).FullName).AddComponent <GizmosInstance>();
                    instance.transform.SetParent(TransformParent);
                    instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;

                    markDirty = true;
                }

#if UNITY_EDITOR
                //mark scene as dirty
                if (markDirty && !Application.isPlaying)
                {
                    Scene scene = SceneManager.GetActiveScene();
                    EditorSceneManager.MarkSceneDirty(scene);
                }
#endif

                hotReloaded = false;
            }

            return(instance);
        }
Esempio n. 5
0
        internal static void Add(Vector3[] points, Color?color, bool dashed)
        {
            GizmosInstance inst = GetOrCreate();

            //excedeed the length, so loopback
            if (inst.queueIndex >= DefaultQueueSize)
            {
                inst.queueIndex = 0;
            }

            inst.queue[inst.queueIndex].active = true;
            inst.queue[inst.queueIndex].color  = color ?? Color.white;
            inst.queue[inst.queueIndex].points = points;
            inst.queue[inst.queueIndex].dashed = dashed;

            inst.queueIndex++;
        }
Esempio n. 6
0
        /// <summary>
        /// Draws an element onto the screen
        /// </summary>
        public static void Draw <T>(Color?color, bool dashed, params object[] args) where T : Drawer
        {
            if (!Enabled)
            {
                return;
            }

            Drawer drawer = Drawer.Get <T>();

            if (drawer != null)
            {
                Camera camera = GizmosInstance.currentRenderingCamera;
                int    points = drawer.Draw(ref buffer, args);

                //use frustum culling
                if (FrustumCulling)
                {
                    bool visible = false;
                    if (camera != null)
                    {
                        //calculate the bounds of this element
                        Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                        Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
                        for (int i = 0; i < points; i++)
                        {
                            Vector3 p = buffer[i];
                            if (p.x > max.x)
                            {
                                max.x = p.x;
                            }
                            if (p.y > max.y)
                            {
                                max.y = p.y;
                            }
                            if (p.z > max.z)
                            {
                                max.z = p.z;
                            }
                            if (p.x < min.x)
                            {
                                min.x = p.x;
                            }
                            if (p.y < min.y)
                            {
                                min.y = p.y;
                            }
                            if (p.z < min.z)
                            {
                                min.z = p.z;
                            }
                        }

                        Bounds bounds = new Bounds();
                        bounds.SetMinMax(min, max);

                        GeometryUtility.CalculateFrustumPlanes(camera, cameraPlanes);
                        if (GeometryUtility.TestPlanesAABB(cameraPlanes, bounds))
                        {
                            visible = true;
                        }
                    }
                    else
                    {
                        //no current camera, assume its visible
                        visible = true;
                    }

                    if (!visible)
                    {
                        return;
                    }
                }

                //copy from buffer and add to the queue
                Vector3[] array = new Vector3[points];
                Array.Copy(buffer, array, points);
                GizmosInstance.Add(array, color, dashed);
            }
        }