コード例 #1
0
        private void DoVertexStreamsGUI(RenderMode renderMode)
        {
            ParticleSystemRenderer renderer = m_ParticleSystemUI.m_ParticleSystems[0].GetComponent <ParticleSystemRenderer>();

            // render list
            m_NumTexCoords         = 0;
            m_TexCoordChannelIndex = 0;
            m_NumInstancedStreams  = 0;
            m_HasTangent           = false;
            m_HasColor             = false;
            m_HasGPUInstancing     = (renderMode == RenderMode.Mesh) ? renderer.supportsMeshInstancing : false;
            m_VertexStreamsList.DoLayoutList();

            if (!m_ParticleSystemUI.multiEdit)
            {
                // error messages
                string errors = "";

                // check we have the same streams as the assigned shader
                if (m_Material != null)
                {
                    Material material = m_Material.objectReferenceValue as Material;
                    int      totalChannelCount = m_NumTexCoords * 4 + m_TexCoordChannelIndex;
                    bool     tangentError = false, colorError = false, uvError = false;
                    bool     anyErrors = ParticleSystem.CheckVertexStreamsMatchShader(m_HasTangent, m_HasColor, totalChannelCount, material, ref tangentError, ref colorError, ref uvError);
                    if (anyErrors)
                    {
                        errors += "Vertex streams do not match the shader inputs. Particle systems may not render correctly. Ensure your streams match and are used by the shader.";
                        if (tangentError)
                        {
                            errors += "\n- TANGENT stream does not match.";
                        }
                        if (colorError)
                        {
                            errors += "\n- COLOR stream does not match.";
                        }
                        if (uvError)
                        {
                            errors += "\n- TEXCOORD streams do not match.";
                        }
                    }
                }

                // check we aren't using too many texcoords
                int maxTexCoords = ParticleSystem.GetMaxTexCoordStreams();
                if (m_NumTexCoords > maxTexCoords || (m_NumTexCoords == maxTexCoords && m_TexCoordChannelIndex > 0))
                {
                    if (errors != "")
                    {
                        errors += "\n\n";
                    }
                    errors += "Only " + maxTexCoords + " TEXCOORD streams are supported.";
                }

                // check input meshes aren't using too many UV streams
                if (renderMode == RenderMode.Mesh)
                {
                    Mesh[] meshes    = new Mesh[k_MaxNumMeshes];
                    int    numMeshes = renderer.GetMeshes(meshes);
                    for (int i = 0; i < numMeshes; i++)
                    {
                        if (meshes[i].HasChannel(VertexAttribute.TexCoord2))
                        {
                            if (errors != "")
                            {
                                errors += "\n\n";
                            }
                            errors += "Meshes may only use a maximum of 2 input UV streams.";
                        }
                    }
                }

                if (errors != "")
                {
                    GUIContent warning = EditorGUIUtility.TextContent(errors);
                    EditorGUILayout.HelpBox(warning.text, MessageType.Error, true);
                }
            }
        }