public override void Draw()
        {
            for (int i = 0; i < m_AnalyzedData.Subshaders.Count; i++)
            {
                AnalyzedSubshaderData subshader = m_AnalyzedData.Subshaders[i];

                if (drawHeader(subshader, EDataType.Subshader, i.ToString(), string.Empty))
                {
                    EditorGUILayout.BeginVertical();
                    GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);
                    EditorGUILayout.LabelField("LOD : ", subshader.LOD.ToString());

                    for (int j = 0; j < subshader.Passes.Count; j++)
                    {
                        AnalyzedPassData pass = subshader.Passes[j];

                        if (drawHeader(pass, EDataType.Pass, j.ToString(), pass.PassName))
                        {
                            GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);

                            EditorGUILayout.LabelField("Name : ", pass.PassName);

                            for (int k = 0; k < pass.Variants.Count; k++)
                            {
                                AnalyzedVariantData variant = pass.Variants[k];

                                //TODO 这里需要分页,避免变体过多导致GUI卡顿

                                if (drawHeader(variant, EDataType.Variant, k.ToString(), getShortVariantName(variant.VariantName)))
                                {
                                    GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);
                                    EditorGUILayout.LabelField("Name : ", variant.VariantName);

                                    ShaderDataDrawerBase drawer;
                                    if (!ShaderDrawer.TryGetValue(variant.GPUVendorType, out drawer))
                                    {
                                        Debug.LogError("无法获取到" + variant.GPUVendorType.ToString() + "的绘制器");
                                    }
                                    else
                                    {
                                        for (int l = 0; l < variant.Shaders.Count; l++)
                                        {
                                            AnalyzedShaderDataBase shader = variant.Shaders[l];

                                            if (drawHeader(shader, EDataType.Shader, shader.ShaderType.ToString(), string.Empty))
                                            {
                                                GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);

                                                if (!string.IsNullOrEmpty(shader.ERROR))
                                                {
                                                    EditorGUILayout.HelpBox(shader.ERROR, MessageType.Error);
                                                }
                                                else
                                                {
                                                    drawer.Draw(shader);
                                                }

                                                GUITools.EndContents();
                                            }
                                        }
                                    }
                                    GUITools.EndContents();
                                }
                            }

                            GUITools.EndContents();
                        }
                    }
                    GUITools.EndContents();
                    EditorGUILayout.EndVertical();
                }
            }
        }
        private void OnGUI()
        {
            m_ScrollPosition     = GUILayout.BeginScrollView(m_ScrollPosition, false, true);
            m_SettingsFolderOpen = GUITools.DrawHeader("设置", false, m_SettingsFolderOpen, true);
            if (m_SettingsFolderOpen)
            {
                GUITools.BeginContents(GUITools.Styles.WizardBoxStyle);

                EditorGUI.BeginDisabledGroup(ShaderAnalyzer.Instance.CurrentStageType != EAnalyzeStageType.None);
                m_CurrentShader = EditorGUILayout.ObjectField(new GUIContent("Shader"), m_CurrentShader, typeof(Shader), false) as Shader;
                m_SkipUnused    = EditorGUILayout.Toggle(new GUIContent("是否跳过当前场景未使用的变体", ""), m_SkipUnused);
                EditorGUI.BeginChangeCheck();
                m_APIType = (EAPIType)EditorGUILayout.EnumPopup(new GUIContent("要编译的着色器语言类型"), m_APIType,
                                                                (Enum index) =>
                {
                    bool show = true;
                    switch ((EAPIType)index)
                    {
                    case EAPIType.None:
                    case EAPIType.All:
                    case EAPIType.Vulkan:
                        show = false;
                        break;
                    }

                    return(show);
                },
                                                                false
                                                                );
                if (EditorGUI.EndChangeCheck())
                {
                    initVendors();
                }

                EditorGUI.BeginChangeCheck();
                m_VendorsSelected = EditorGUILayout.Popup(new GUIContent("GPU厂商"), m_VendorsSelected, m_Vendors);
                if (EditorGUI.EndChangeCheck())
                {
                    initVendor();
                }

                m_GPUModelsSelected = EditorGUILayout.Popup(new GUIContent("目标GPU模型"), m_GPUModelsSelected, m_ModelNames);

                EditorGUI.BeginDisabledGroup(m_CurrentShader == null);

                if (GUILayout.Button("解析"))
                {
                    if (m_CurrentVendor.VendorType == EGPUVendorType.Mali)
                    {
                        if (string.IsNullOrEmpty(Settings.MaliOfflineCompilePath))
                        {
                            Debug.LogError("请设置Mali离线编译器路径!");
                            return;
                        }
                    }
                    ShaderAnalyzer.Instance.Analyze(this.getAnalyzeParams(), analyzeCallback);
                    GUITools.ClearContentDepth();
                    GUIUtility.ExitGUI();
                }

                EditorGUI.EndDisabledGroup();
                EditorGUI.EndDisabledGroup();

                GUITools.EndContents();
            }

            if (m_AnalyzedData != null)
            {
                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();

                m_AnalyzedDataDrawType = (EAnalyzedDataViewType)EditorGUILayout.EnumPopup(m_AnalyzedDataDrawType);
                if (EditorGUI.EndChangeCheck())
                {
                    ViewerMap[m_AnalyzedDataDrawType].Init(m_AnalyzedData);
                }

                EditorGUILayout.LabelField("解析数据");

                GUITools.BeginContents(GUITools.Styles.WizardBoxStyle);
                EditorGUILayout.BeginVertical();

                EditorGUILayout.LabelField("GPU信息 : ", m_AnalyzedData.GPUModelInfo.ModelName);
                EditorGUILayout.LabelField("硬件信息 : ", m_AnalyzedData.Hardware);
                EditorGUILayout.LabelField("驱动信息 : ", m_AnalyzedData.Driver);

                EditorGUILayout.EndVertical();
                GUITools.EndContents();
                ViewerMap[m_AnalyzedDataDrawType].Draw();
            }
            GUILayout.EndScrollView();
        }
Exemplo n.º 3
0
        public override void Draw()
        {
            GUITools.BeginContents(GUITools.Styles.WizardBoxStyle);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(m_CurrentSortField != null ? "着色器类型" : (m_DescendingOrder ? "着色器类型 ▼" : "着色器类型 ▲"), GUILayout.MinWidth(m_MINWIDTH)))
            {
                if (m_CurrentSortField != null)
                {
                    m_DescendingOrder  = false;
                    m_CurrentSortField = null;
                }
                else
                {
                    m_DescendingOrder = !m_DescendingOrder;
                }

                m_List.Sort(sort);
            }
            GUILayout.Button(new GUIContent("源代码", "点击着色器代码可以复制到剪贴板"), GUILayout.MinWidth(m_MINWIDTH));

            foreach (var item in m_FieldInfoMap)
            {
                bool click = false;

                GUIContent buttonText;
                if (item.Value != null)
                {
                    buttonText = new GUIContent(item.Value.Abbreviate, item.Value.Tooltip);
                }
                else
                {
                    buttonText = new GUIContent(item.Key.Name);
                }

                if (m_CurrentSortField == item.Key)
                {
                    buttonText.text = buttonText.text + (m_DescendingOrder ? " ▼" : " ▲");
                }

                click = GUILayout.Button(buttonText, GUILayout.MinWidth(m_MINWIDTH));

                if (click)
                {
                    if (m_CurrentSortField != item.Key)
                    {
                        m_DescendingOrder = true;
                    }
                    else
                    {
                        m_DescendingOrder = !m_DescendingOrder;
                    }

                    m_CurrentSortField = item.Key;
                    m_List.Sort(sort);
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical();
            for (int i = 0; i < m_List.Count; i++)
            {
                //TODO 这里需要分页,避免着色器过多导致GUI卡顿

                AnalyzedShaderDataBase shader = m_List[i];
                if (!string.IsNullOrEmpty(shader.ERROR))
                {
                    GUILayout.Button(shader.ERROR);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();

                    ShaderParem param = m_ParamMap[shader];
                    GUILayout.Button(new GUIContent(shader.ShaderType.ToString(), getTooltip(param)), GUILayout.MinWidth(m_MINWIDTH));

                    if (GUILayout.Button(new GUIContent("着色器代码", shader.SourceCode), GUILayout.MinWidth(m_MINWIDTH)))
                    {
                        GUIUtility.systemCopyBuffer = shader.SourceCode;
                    }

                    foreach (var item in m_FieldInfoMap)
                    {
                        FieldInfo field = item.Key;
                        GUILayout.Button(field.GetValue(shader).ToString(), GUILayout.MinWidth(m_MINWIDTH));
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
            GUITools.EndContents();
        }