private void CreateSmoothGroups()
        {
            if (m_selection == null)
            {
                return;
            }

            foreach (PBMesh pbMesh in m_selection.GetSelectedMeshes())
            {
                if (!m_smoothGroups.ContainsKey(pbMesh))
                {
                    m_smoothGroups.Add(pbMesh, new PBSmoothGroupData(pbMesh));
                }
            }
        }
        private void RefreshSelectionAndPivotPoint()
        {
            m_selection.Clear();

            IMeshEditor editor = m_tool.GetEditor();

            if (editor == null)
            {
                return;
            }

            MeshSelection meshSelection = editor.GetSelection();

            if (meshSelection != null)
            {
                foreach (PBMesh mesh in meshSelection.GetSelectedMeshes())
                {
                    ManualUVSelection uvSelection = new ManualUVSelection(mesh.gameObject);
                    m_selection.Add(uvSelection);

                    if (MeshSelected != null)
                    {
                        MeshSelected(uvSelection);
                    }
                }

                Select(meshSelection);
            }

            RefreshPivotPoint();
        }
        private void UpdateEditorsPanel()
        {
            foreach (Transform child in m_contentPanel)
            {
                SmoothGroupEditor editor = child.GetComponent <SmoothGroupEditor>();
                Unsubscribe(editor);

                Destroy(child.gameObject);
            }

            IMeshEditor meshEditor = m_proBuilderTool.GetEditor();

            if (meshEditor == null)
            {
                return;
            }

            MeshSelection selection = meshEditor.GetSelection();

            if (selection == null)
            {
                return;
            }

            selection = selection.ToFaces(false);
            if (!selection.HasFaces)
            {
                return;
            }

            const int maxVisibleGroups = 8;
            int       index            = 0;

            foreach (PBMesh pbMesh in selection.GetSelectedMeshes())
            {
                index++;
                if (index == maxVisibleGroups)
                {
                    return;
                }

                SmoothGroupEditor editor = Instantiate(m_groupPrefab, m_contentPanel);
                editor.Data = m_smoothGroups[pbMesh];
                Subscribe(editor);
            }
        }
Example #4
0
        private void CreateUVRenderers()
        {
            HashSet <PBMesh> selectedMeshes = new HashSet <PBMesh>();
            IMeshEditor      meshEditor     = m_tool.GetEditor();

            if (meshEditor != null)
            {
                MeshSelection selection = meshEditor.GetSelection();
                if (selection != null)
                {
                    selectedMeshes = new HashSet <PBMesh>(selection.GetSelectedMeshes());
                }
            }

            int delta = selectedMeshes.Count() - m_uvRenderers.Count;

            if (delta > 0)
            {
                m_uvRenderersRoot.SetActive(false);
                for (int i = 0; i < delta; ++i)
                {
                    ManualUVRenderer renderer = m_uvRenderersRoot.AddComponent <ManualUVRenderer>();
                    renderer.Window = Window;
                    m_uvRenderers.Add(renderer);
                }
                m_uvRenderersRoot.SetActive(true);
            }
            else
            {
                delta = -delta;
                for (int i = 0; i < delta; ++i)
                {
                    Destroy(m_uvRenderers[m_uvRenderers.Count - 1]);
                    m_uvRenderers.RemoveAt(m_uvRenderers.Count - 1);
                }
            }

            foreach (PBMesh mesh in m_meshToRenderer.Keys.ToArray())
            {
                if (!selectedMeshes.Contains(mesh))
                {
                    m_meshToRenderer.Remove(mesh);
                }
            }

            int index = 0;

            foreach (PBMesh mesh in selectedMeshes)
            {
                ManualUVRenderer uvRenderer = m_uvRenderers[index];
                switch (m_tool.Mode)
                {
                case ProBuilderToolMode.Vertex:
                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Vertex;
                    break;

                case ProBuilderToolMode.Edge:
                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Edge;
                    break;

                case ProBuilderToolMode.Face:
                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Face;
                    break;
                }

                index++;

                m_meshToRenderer[mesh] = uvRenderer;
            }
        }
        private void UpdateTexturesDrowDown()
        {
            HashSet <PBMesh>  selectedMeshes = new HashSet <PBMesh>();
            IMeshEditor       meshEditor     = m_tool.GetEditor();
            HashSet <Texture> textures       = new HashSet <Texture>();

            if (meshEditor != null)
            {
                MeshSelection selection = meshEditor.GetSelection();
                if (selection != null)
                {
                    foreach (PBMesh mesh in selection.GetSelectedMeshes())
                    {
                        Renderer renderer = mesh.GetComponent <Renderer>();
                        if (renderer != null)
                        {
                            foreach (Material material in renderer.sharedMaterials)
                            {
                                if (material != null && material.MainTexture() != null && !textures.Contains(material.MainTexture()))
                                {
                                    textures.Add(material.MainTexture());
                                }
                            }
                        }
                    }
                }
            }

            m_textures = textures.ToArray();
            m_texturesDropDown.ClearOptions();

            if (m_textures.Length == 0)
            {
                m_texturesDropDown.gameObject.SetActive(false);
                m_texturePreview.material.MainTexture(null);
                return;
            }

            m_texturesDropDown.gameObject.SetActive(true);

            List <string> options       = new List <string>();
            int           selectedIndex = -1;

            for (int i = 0; i < m_textures.Length; ++i)
            {
                Texture texture = m_textures[i];
                if (texture == m_lastSelectedTexture)
                {
                    selectedIndex = i;
                }

                options.Add(i + ". " + (string.IsNullOrEmpty(texture.name) ? "Texture" : texture.name));
            }
            m_texturesDropDown.AddOptions(options);

            if (selectedIndex == -1)
            {
                selectedIndex = 0;
            }

            m_texturePreview.material.MainTexture(m_textures[selectedIndex]);
            m_texturesDropDown.SetValueWithoutNotify(selectedIndex);
        }