Exemplo n.º 1
0
        private List <string> GetFilteredAssets(AuditProfile profile)
        {
            List <string> associatedAssets = new List <string>();
            List <string> ignorePaths      = new List <string>();
            string        typeFilter;

            // TODO see if there is a way to merge
            m_Profile.m_ImporterModule.GetSearchFilter(out typeFilter, ignorePaths);

            string[] GUIDs = AssetDatabase.FindAssets(typeFilter);
            foreach (var assetGUID in GUIDs)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);

                // some items may appear twice, due to sub assets, e.g. Sprite
                if (ignorePaths.Contains(assetPath) || associatedAssets.Contains(assetPath))
                {
                    continue;
                }

                if (Filter.Conforms(assetPath, profile.m_Filters))
                {
                    associatedAssets.Add(assetPath);
                }
            }

            return(associatedAssets);
        }
        public void Draw(SerializedProperty property, ControlRect layout)
        {
            if (m_ImporterReferenceSerializedProperty == null || m_PropertiesArraySerializedProperty == null)
            {
                List <string> propertyNames = new List <string> {
                    "m_ImporterReference", "m_ConstrainProperties"
                };
                List <SerializedProperty> properties = SerializationUtilities.FindPropertiesInClass(property, propertyNames);
                m_ImporterReferenceSerializedProperty = properties[0];
                m_PropertiesArraySerializedProperty   = properties[1];
                if (m_ImporterReferenceSerializedProperty == null || m_PropertiesArraySerializedProperty == null)
                {
                    Debug.LogError("Invalid properties for ImporterPropertiesModule");
                    return;
                }
            }

            if (m_Module == null)
            {
                AuditProfile profile = property.serializedObject.targetObject as AuditProfile;
                if (profile == null)
                {
                    Debug.LogError("ImporterPropertiesModule must be apart of a profile Object");
                    return;
                }
                m_Module = profile.m_ImporterModule;
            }

            if (m_ImporterReferenceSerializedProperty != null)
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    EditorGUI.PropertyField(layout.Get(), m_ImporterReferenceSerializedProperty, new GUIContent("Importer Template"));
                    if (check.changed)
                    {
                        m_Module.m_AssetImporter = null;
                        m_Module.GatherProperties();
                    }
                }
            }

            if (m_ImporterReferenceSerializedProperty.objectReferenceValue != null)
            {
                ConstrainToPropertiesArea(layout);
            }
            else
            {
                Rect r = layout.Get(25);
                EditorGUI.HelpBox(r, "No template Object to constrain properties on.", MessageType.Warning);
            }
        }
        public override void OnInspectorGUI()
        {
            if (m_Profile == null)
            {
                m_Profile = (AuditProfile)target;
            }

            Rect        viewRect = EditorGUILayout.GetControlRect();
            ControlRect layout   = new ControlRect(viewRect.x, viewRect.y, viewRect.width);

            layout.Space(10);
            EditorGUI.PropertyField(layout.Get(), m_ProcessOnImport, new GUIContent("Process On Import"));
            layout.Space(10);

            EditorGUI.LabelField(layout.Get(), "Search Filter's:");

            if (m_Profile.m_Filters == null)
            {
                m_Profile.m_Filters = new List <Filter>();
            }

            Rect boxAreaRect = layout.Get((16 * m_Profile.m_Filters.Count) + (3 * m_Profile.m_Filters.Count) + 6);

            GUI.Box(boxAreaRect, GUIContent.none);

            ControlRect subLayout = new ControlRect(boxAreaRect.x + 3, boxAreaRect.y + 3, boxAreaRect.width - 6, 16);

            subLayout.padding = 3;

            int removeAt = -1;

            for (int i = 0; i < filtersListProperty.arraySize; ++i)
            {
                Rect segmentRect = subLayout.Get();
                segmentRect.x     += 3;
                segmentRect.width -= 6;

                float segWidth = (segmentRect.width - segmentRect.height) / 3;
                segmentRect.width = segWidth - 3;
                float startX = segmentRect.x;

                // TODO how do you get properties for this without looping all???
                SerializedProperty filterProperty = filtersListProperty.GetArrayElementAtIndex(i);
                filterProperty.NextVisible(true);
                do
                {
                    if (filterProperty.propertyType == SerializedPropertyType.Enum && filterProperty.name == "m_Target")
                    {
                        segmentRect.x = startX;
                        EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none);
                    }
                    else if (filterProperty.propertyType == SerializedPropertyType.Enum && filterProperty.name == "m_Condition")
                    {
                        segmentRect.x = startX + segWidth;
                        EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none);
                    }
                    else if (filterProperty.propertyType == SerializedPropertyType.String && filterProperty.name == "m_Wildcard")
                    {
                        segmentRect.x = startX + (segWidth * 2);
                        EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none);
                    }
                } while(filterProperty.NextVisible(false));

                segmentRect.x     = startX + (segWidth * 3);
                segmentRect.width = segmentRect.height;
                if (GUI.Button(segmentRect, "-"))
                {
                    removeAt = i;
                }
            }

            if (removeAt >= 0)
            {
                filtersListProperty.DeleteArrayElementAtIndex(removeAt);
            }

            Rect layoutRect = layout.Get();

            layoutRect.x     = layoutRect.x + (layoutRect.width - 40);
            layoutRect.width = 40;
            if (GUI.Button(layoutRect, "Add"))
            {
                filtersListProperty.arraySize += 1;
            }

            layout.Space(20);

            // TODO do the rest as modules that can be added
            propertiesModuleInspector.Draw(importerModule, layout);

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 4
0
        private void GenerateTreeElements(AuditProfile profile, TreeViewItem root)
        {
            List <string> associatedAssets = GetFilteredAssets(profile);

            // early out if there are no affected assets
            if (associatedAssets.Count == 0)
            {
                Debug.Log("No matching assets found for " + profile.name);
                return;
            }

            string        activePath   = "Assets";
            AssetViewItem assetsFolder = new AssetViewItem(activePath.GetHashCode(), 0, activePath, true);

            if (assetsFolder.children == null)
            {
                assetsFolder.children = new List <TreeViewItem>();
            }
            root.AddChild(assetsFolder);

            Dictionary <int, AssetViewItem> items = new Dictionary <int, AssetViewItem>
            {
                { activePath.GetHashCode(), assetsFolder }
            };

            foreach (var assetPath in associatedAssets)
            {
                // split the path to generate folder structure
                string path    = assetPath.Substring(7);
                var    strings = path.Split(new[] { '/' }, StringSplitOptions.None);
                activePath = "Assets";

                AssetViewItem active = assetsFolder;

                // for each module
                List <IConformObject> conformData = profile.GetConformData(assetPath);
                bool result = true;
                for (int i = 0; i < conformData.Count; ++i)
                {
                    if (conformData[i].Conforms == false)
                    {
                        result = false;
                        break;
                    }
                }

                if (!result && assetsFolder.conforms)
                {
                    assetsFolder.conforms = false;
                }

                AssetImporter    assetImporter   = AssetImporter.GetAtPath(assetPath);
                SerializedObject assetImporterSO = new SerializedObject(assetImporter);

                // the first entries have lower depth
                for (int i = 0; i < strings.Length; i++)
                {
                    activePath += "/" + strings[i];
                    int id = activePath.GetHashCode();

                    if (i == strings.Length - 1)
                    {
                        AssetViewItem item = new AssetViewItem(id, i + 1, strings[i], result)
                        {
                            icon        = AssetDatabase.GetCachedIcon(assetPath) as Texture2D,
                            path        = activePath,
                            conformData = conformData,
                            assetObject = assetImporterSO,
                            isAsset     = true
                        };
                        active.AddChild(item);
                        active = item;
                        if (items.ContainsKey(id))
                        {
                            Debug.LogError("id already in for " + activePath);
                        }
                        items.Add(id, item);
                    }
                    else
                    {
                        AssetViewItem item;
                        if (!items.TryGetValue(id, out item))
                        {
                            item = new AssetViewItem(id, i + 1, strings[i], result)
                            {
                                path = activePath,
                                icon = AssetDatabase.GetCachedIcon(activePath) as Texture2D
                            };
                            active.AddChild(item);
                            items.Add(id, item);
                        }
                        else if (result == false)
                        {
                            if (item.conforms)
                            {
                                item.conforms = false;
                            }
                        }

                        active = item;
                    }
                }
            }
        }