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 OnSelectionChanged()
        {
            m_selection = null;
            IMeshEditor meshEditor = m_proBuilderTool.GetEditor();

            if (meshEditor == null)
            {
                return;
            }

            m_selection = meshEditor.GetSelection();

            ClearSmoothGroups();
            CreateSmoothGroups();
            UpdateEditorsPanel();
        }
Example #3
0
        public static void Extrude(this IProBuilderTool tool, float distance)
        {
            IMeshEditor     meshEditor = tool.GetEditor();
            MeshEditorState oldState   = meshEditor.GetState();

            meshEditor.Extrude(distance);
            MeshEditorState newState = meshEditor.GetState();

            tool.UpdatePivot();
            tool.RecordState(meshEditor, oldState, newState);
        }
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);
        }