Beispiel #1
0
    void populateGroupByFilters()
    {
        string      qualifiedInterfaceName = "DigitalOpus.MB.Core.IGroupByFilter";
        var         interfaceFilter        = new TypeFilter(InterfaceFilter);
        List <Type> types = new List <Type>();

        foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
        {
            System.Collections.IEnumerable typesIterator = null;
            try
            {
                typesIterator = ass.GetTypes();
            }
            catch (Exception e)
            {
                //Debug.Log("The assembly that I could not read types for was: " + ass.GetName());
                //suppress error
                e.Equals(null);
            }
            if (typesIterator != null)
            {
                foreach (Type ty in ass.GetTypes())
                {
                    var myInterfaces = ty.FindInterfaces(interfaceFilter, qualifiedInterfaceName);
                    if (myInterfaces.Length > 0)
                    {
                        types.Add(ty);
                    }
                }
            }
        }

        List <string>         filterNames = new List <string>();
        List <IGroupByFilter> filters     = new List <IGroupByFilter>();

        filterNames.Add("None");
        filters.Add(null);
        foreach (Type tt in types)
        {
            if (!tt.IsAbstract && !tt.IsInterface)
            {
                IGroupByFilter instance = (IGroupByFilter)Activator.CreateInstance(tt);
                filterNames.Add(instance.GetName());
                filters.Add(instance);
            }
        }
        groupByOptionNames   = filterNames.ToArray();
        groupByOptionFilters = filters.ToArray();
    }
Beispiel #2
0
    void drawTabAnalyseScene()
    {
        //first time we are displaying collect the filters
        if (groupByOptionNames == null || groupByOptionNames.Length == 0)
        {
            var type  = typeof(IGroupByFilter);
            var types = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(s => s.GetTypes())
                        .Where(p => type.IsAssignableFrom(p));

            List <string>         filterNames = new List <string>();
            List <IGroupByFilter> filters     = new List <IGroupByFilter>();
            filterNames.Add("None");
            filters.Add(null);
            foreach (Type tt in types)
            {
                if (!tt.IsAbstract && !tt.IsInterface)
                {
                    IGroupByFilter instance = (IGroupByFilter)Activator.CreateInstance(tt);
                    filterNames.Add(instance.GetName());
                    filters.Add(instance);
                }
            }
            groupByOptionNames   = filterNames.ToArray();
            groupByOptionFilters = filters.ToArray();

            //set filter initial values
            for (int i = 0; i < groupByOptionFilters.Length; i++)
            {
                if (groupByOptionFilters[i] is GroupByShader)
                {
                    groupByFilterIdxs[0] = i;
                    break;
                }
            }
            for (int i = 0; i < groupByOptionFilters.Length; i++)
            {
                if (groupByOptionFilters[i] is GroupByStatic)
                {
                    groupByFilterIdxs[1] = i;
                    break;
                }
            }
            for (int i = 0; i < groupByOptionFilters.Length; i++)
            {
                if (groupByOptionFilters[i] is GroupByRenderType)
                {
                    groupByFilterIdxs[2] = i;
                    break;
                }
            }
            for (int i = 0; i < groupByOptionFilters.Length; i++)
            {
                if (groupByOptionFilters[i] is GroupByOutOfBoundsUVs)
                {
                    groupByFilterIdxs[3] = i;
                    break;
                }
            }
            groupByFilterIdxs[4] = 0;             //none
        }
        if (groupByFilterIdxs == null || groupByFilterIdxs.Length < NUM_FILTERS)
        {
            groupByFilterIdxs = new int[] {
                0, 0, 0, 0, 0
            };
        }
        EditorGUILayout.HelpBox("List shaders in scene prints a report to the console of shaders and which objects use them. This is useful for planning which objects to combine.", UnityEditor.MessageType.None);

        groupByFilterIdxs[0] = EditorGUILayout.Popup("Group By:", groupByFilterIdxs[0], groupByOptionNames);
        for (int i = 1; i < NUM_FILTERS; i++)
        {
            groupByFilterIdxs[i] = EditorGUILayout.Popup("Then Group By:", groupByFilterIdxs[i], groupByOptionNames);
        }

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Select Folder For Combined Material Assets"))
        {
            generate_AssetsFolder = EditorUtility.SaveFolderPanel("Create Combined Material Assets In Folder", "", "");
            generate_AssetsFolder = "Assets" + generate_AssetsFolder.Replace(Application.dataPath, "") + "/";
        }
        EditorGUILayout.LabelField("Folder: " + generate_AssetsFolder);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("List Shaders In Scene"))
        {
            EditorUtility.DisplayProgressBar("Analysing Scene", "", .05f);
            try{
                listMaterialsInScene();
            } catch (Exception ex) {
                Debug.LogError(ex.StackTrace);
            } finally {
                EditorUtility.ClearProgressBar();
            }
        }

        if (GUILayout.Button("Bake Every MeshBaker In Scene"))
        {
            try{
                MB3_TextureBaker[] texBakers = (MB3_TextureBaker[])FindObjectsOfType(typeof(MB3_TextureBaker));
                for (int i = 0; i < texBakers.Length; i++)
                {
                    texBakers[i].CreateAtlases(updateProgressBar, true, new MB3_EditorMethods());
                }
                MB3_MeshBakerCommon[] mBakers = (MB3_MeshBakerCommon[])FindObjectsOfType(typeof(MB3_MeshBakerCommon));
                for (int i = 0; i < mBakers.Length; i++)
                {
                    if (mBakers[i].textureBakeResults != null)
                    {
                        MB3_MeshBakerEditorFunctions.BakeIntoCombined(mBakers[i]);
                    }
                }
            } catch (Exception e) {
                Debug.LogError(e);
            }finally{
                EditorUtility.ClearProgressBar();
            }
        }
        EditorGUILayout.EndHorizontal();

        if (sceneAnalysisResults.Count > 0)
        {
            float height = position.height - 150f;
            if (height < 500f)
            {
                height = 500f;
            }
            MB_EditorUtil.DrawSeparator();
            scrollPos2 = EditorGUILayout.BeginScrollView(scrollPos2, false, true);           //(scrollPos2,, GUILayout.Width(position.width - 20f), GUILayout.Height(height));
            EditorGUILayout.LabelField("Shaders In Scene", EditorStyles.boldLabel);
            for (int i = 0; i < sceneAnalysisResults.Count; i++)
            {
                List <GameObjectFilterInfo> gows = sceneAnalysisResults[i];
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Generate Baker", GUILayout.Width(200)))
                {
                    createAndSetupBaker(gows, generate_AssetsFolder);
                }
                string descr = gows[0].GetDescription(GameObjectFilterInfo.filters, gows[0]);

                EditorGUILayout.LabelField(descr, EditorStyles.wordWrappedLabel);
                EditorGUILayout.EndHorizontal();
                sceneAnalysisResultsFoldouts[i] = EditorGUILayout.Foldout(sceneAnalysisResultsFoldouts[i], "");
                if (sceneAnalysisResultsFoldouts[i])
                {
                    EditorGUI.indentLevel += 1;
                    for (int j = 0; j < gows.Count; j++)
                    {
                        if (gows[j].go != null)
                        {
                            EditorGUILayout.LabelField(gows[j].go.name + "  " + gows[j].GetDescription(GameObjectFilterInfo.filters, gows[j]));
                        }
                    }
                    EditorGUI.indentLevel -= 1;
                }
            }
            EditorGUILayout.EndScrollView();
            MB_EditorUtil.DrawSeparator();
        }
    }