Пример #1
0
        void InitializeRenderers()
        {
            renderers = m_PreviewInstance.GetComponentsInChildren <Renderer>(true);

            if (!m_SourceSortingGroup)
            {
                List <string> editorSortingLayers = EditorExtra.GetSortingLayerNames();

                //Sort renderers front to back taking sorting layer and sorting order into account
                List <KeyValuePair <Renderer, double> > l_renderersOrder = new List <KeyValuePair <Renderer, double> >();

                for (int i = 0; i < renderers.Length; ++i)
                {
                    Renderer l_renderer     = renderers[i];
                    int      l_sortingOrder = l_renderer.sortingOrder;
                    int      l_layerIndex   = editorSortingLayers.IndexOf(l_renderer.sortingLayerName);

                    l_renderersOrder.Add(new KeyValuePair <Renderer, double>(l_renderer,
                                                                             (l_layerIndex * 2.0) + (l_sortingOrder / (double)32767)));
                }

                l_renderersOrder = l_renderersOrder.OrderByDescending((s) => s.Value).ToList();

                //Store renderers in order
                renderers = l_renderersOrder.ConvertAll(s => s.Key).ToArray();
            }

            //Create temp materials for non sprite renderers
            List <MaterialCache> l_materialCacheList = new List <MaterialCache>();

            foreach (Renderer renderer in renderers)
            {
                l_materialCacheList.Add(new MaterialCache(renderer));
            }

            materialCache = l_materialCacheList.ToArray();
        }
        void InitializeRenderers()
        {
            Renderer[] l_renderers = m_PreviewInstance.GetComponentsInChildren <Renderer>();

            List <string> l_sortingLayerNames = new List <string>(l_renderers.Length);

            foreach (Renderer l_renderer in l_renderers)
            {
                l_sortingLayerNames.Add(l_renderer.sortingLayerName);
            }

            //Find the deepest used layer
            List <string> editorSortingLayers = EditorExtra.GetSortingLayerNames();

            int deepestLayerIndex = int.MaxValue;

            foreach (string layerName in l_sortingLayerNames)
            {
                int index = editorSortingLayers.IndexOf(layerName);

                if (index < deepestLayerIndex)
                {
                    deepestLayerIndex = index;
                }
            }

            string deepestLayer = "Default";

            if (deepestLayerIndex >= 0 && deepestLayerIndex < editorSortingLayers.Count)
            {
                deepestLayer = editorSortingLayers[deepestLayerIndex];
            }

            //Sort renderers front to back taking sorting layer and sorting order into account
            //Set deepest layer to all renderers and calculate the sorting order
            List <KeyValuePair <Renderer, double> > l_renderersOrder = new List <KeyValuePair <Renderer, double> >();

            for (int i = 0; i < l_renderers.Length; ++i)
            {
                Renderer l_renderer     = l_renderers[i];
                int      l_sortingOrder = l_renderer.sortingOrder;
                int      l_layerIndex   = editorSortingLayers.IndexOf(l_renderer.sortingLayerName);

                l_renderer.sortingLayerName = deepestLayer;
                l_renderersOrder.Add(new KeyValuePair <Renderer, double>(l_renderer, (l_layerIndex * 2.0) + (l_sortingOrder / (double)32767)));
            }

            l_renderersOrder = l_renderersOrder.OrderByDescending((s) => s.Value).ToList();

            //Store renderers in order
            renderers = l_renderersOrder.ConvertAll(s => s.Key).ToArray();

            //Create temp materials for non sprite renderers
            List <MaterialCache> l_materialCacheList = new List <MaterialCache>();

            foreach (Renderer renderer in renderers)
            {
                l_materialCacheList.Add(new MaterialCache(renderer));
            }

            materialCache = l_materialCacheList.ToArray();
        }