/// <summary>
        /// Calculates values and meshes for all nodes.
        /// </summary>
        /// <param name="renderBuffer">The render buffer that will hold all render instructions.</param>
        /// <param name="commandBuffer">The command buffer that will have all the final mesh rendering instruction that were extracted from a <see cref="RenderBuffer"/>.</param>
        private void ExecuteMasterNode(bool threaded, Rect rect, Matrix4x4 globalMatrix, UIMasterNode masterNode, CommandBuffer commandBuffer)
        {
            masterNode.GetInputValues(m_ValuesTmp);

            Rect localRect = new Rect(Vector2.zero, rect.size);

            //can only be ran on main thread
            foreach (var value in m_ValuesTmp)
            {
                value.Invoke(new UIEventData()
                {
                    EventType = UIEventType.Layout, Rect = localRect
                });
            }

            //can run on multiple threads
            if (threaded)
            {
                m_WaitHandle.Reset(m_ValuesTmp.Count);

                foreach (var a in m_ValuesTmp)
                {
                    var a1 = a;
                    ThreadPool.QueueUserWorkItem(c => a1.Invoke((UIEventData)c), new UIEventData()
                    {
                        EventType = UIEventType.PreRepaint, Rect = localRect, RenderBuffer = m_RenderBuffer, WaitHandle = m_WaitHandle
                    });
                }

                m_WaitHandle.WaitAll();
            }
            else
            {
                foreach (var action in m_ValuesTmp)
                {
                    action.Invoke(new UIEventData()
                    {
                        EventType = UIEventType.PreRepaint, Rect = localRect, RenderBuffer = m_RenderBuffer, MeshRepository = m_MeshRepository
                    });
                }
            }

            //can run only on main thread.
            foreach (var action in m_ValuesTmp)
            {
                action.Invoke(new UIEventData()
                {
                    EventType = UIEventType.Repaint, Rect = localRect, RenderBuffer = m_RenderBuffer, MeshRepository = m_MeshRepository
                });
            }

            var matrix = globalMatrix * Matrix4x4.Translate(rect.position);

            m_RenderBuffer.Populate(commandBuffer, matrix);

            m_ValuesTmp.Clear();
        }
예제 #2
0
        public void Execute(UIRenderBuffer renderBuffer, CommandBuffer commandBuffer)
        {
            GetSlotValues(m_Input, m_ValuesTmp);

            Rect rect      = m_Rect[this];
            Rect localRect = new Rect(Vector2.zero, rect.size);

            foreach (var value in m_ValuesTmp)
            {
                value.Invoke(new UIEventData()
                {
                    EventType = UIEventType.Layout, Rect = localRect
                });
            }

            if (((UIGraphObject)owner.owner).threaded)
            {
                waitHandle.Reset(m_ValuesTmp.Count);

                foreach (var a in m_ValuesTmp)
                {
                    var a1 = a;
                    ThreadPool.QueueUserWorkItem(c => a1.Invoke((UIEventData)c), new UIEventData()
                    {
                        EventType = UIEventType.PreRepaint, Rect = localRect, RenderBuffer = renderBuffer, WaitHandle = waitHandle
                    });
                }

                waitHandle.WaitAll();
            }
            else
            {
                foreach (var action in m_ValuesTmp)
                {
                    action.Invoke(new UIEventData()
                    {
                        EventType = UIEventType.PreRepaint, Rect = localRect, RenderBuffer = renderBuffer
                    });
                }
            }


            foreach (var value in m_ValuesTmp)
            {
                try
                {
                    value.Invoke(new UIEventData()
                    {
                        EventType = UIEventType.Repaint, Rect = localRect, RenderBuffer = renderBuffer
                    });
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            var matrix = m_Matrix[this] * Matrix4x4.Translate(rect.position);

            renderBuffer.Populate(commandBuffer, matrix);

            m_ValuesTmp.Clear();
        }