private List <string> GetFilteredAssets(ImportDefinitionProfile profile)
        {
            List <string> associatedAssets = new List <string>();
            List <string> ignorePaths      = new List <string>();
            string        searchFilter;

            List <string> GUIDs;

            // TODO this is probably inefficient, profile and see if there is a more efficient design needed
            if (m_Profile.m_ImportTasks.Count > 0)
            {
                m_Profile.m_ImportTasks[0].GetSearchFilter(out searchFilter, ignorePaths);
                GUIDs = new List <string>(AssetDatabase.FindAssets(searchFilter));

                for (int i = 1; i < m_Profile.m_ImportTasks.Count; ++i)
                {
                    m_Profile.m_ImportTasks[i].GetSearchFilter(out searchFilter, ignorePaths);
                    string[] moduleGUIDs = AssetDatabase.FindAssets(searchFilter);
                    for (int m = GUIDs.Count - 1; m >= 0; --m)
                    {
                        bool guidInModule = false;
                        foreach (string moduleGuiD in moduleGUIDs)
                        {
                            if (GUIDs[m] == moduleGuiD)
                            {
                                guidInModule = true;
                                break;
                            }
                        }
                        if (guidInModule == false)
                        {
                            GUIDs.RemoveAt(m);
                        }
                    }
                }
            }
            else
            {
                GUIDs = new List <string>(AssetDatabase.FindAssets(""));
            }

            //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.GetFilters()))
                {
                    associatedAssets.Add(assetPath);
                }
            }

            return(associatedAssets);
        }
        public override void PreprocessTask(ImportContext context, ImportDefinitionProfile profile)
        {
            UserDataSerialization data = UserDataSerialization.Get(context.AssetPath);
            string profileGuid         = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(profile));

            data.UpdateProcessing(new UserDataSerialization.PostprocessorData(profileGuid, ImportTaskName, Method.AssemblyName, Method.TypeName, Method.Version));
        }
Beispiel #3
0
        public virtual void PreprocessTask(ImportContext context, ImportDefinitionProfile profile)
        {
            UserDataSerialization data = UserDataSerialization.Get(context.AssetPath);
            string profileGuid         = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(profile));

            data.UpdateProcessing(new UserDataSerialization.ImportTaskData(profileGuid, ImportTaskName, Version));
        }
Beispiel #4
0
 public virtual bool Apply(ImportContext context, ImportDefinitionProfile fromProfile)
 {
     if (CanProcess(context.Importer) == false)
     {
         return(false);
     }
     return(true);
 }
        private void SetUserData(AssetImporter importer, ImportDefinitionProfile profile)
        {
            UserDataSerialization data = UserDataSerialization.Get(importer.assetPath);
            string profileGuid         = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(profile));

            data.m_ImporterPostprocessorData.UpdateOrAdd(new UserDataSerialization.PostprocessorData(profileGuid, kImportTaskName, Method.AssemblyName, Method.TypeName, Method.Version));
            data.UpdateImporterUserData();
        }
Beispiel #6
0
 public virtual bool Apply(AssetImporter importer, ImportDefinitionProfile fromProfile)
 {
     if (CanProcess(importer) == false)
     {
         return(false);
     }
     m_AssetsToForceApply.Remove(importer.assetPath);
     return(true);
 }
 public override bool Apply(ImportContext context, ImportDefinitionProfile fromProfile)
 {
     if (string.IsNullOrEmpty(m_MethodString) == false)
     {
         if (Method != null)
         {
             object returnValue = Method.Invoke(context, m_Data);
             if (returnValue != null)
             {
                 return((bool)returnValue);
             }
         }
     }
     return(false);
 }
 private static void RefreshCacheObjects()
 {
     s_Profiles.Clear();
     string[] guids = AssetDatabase.FindAssets("t:ImportDefinitionProfile");
     for (int i = 0; i < guids.Length; ++i)
     {
         string path = AssetDatabase.GUIDToAssetPath(guids[i]);
         ImportDefinitionProfile profile = AssetDatabase.LoadAssetAtPath <ImportDefinitionProfile>(path);
         s_Profiles.Add(new ProfileData
         {
             m_AssetPath = path,
             m_ImportDefinitionProfile = profile
         });
     }
     s_Profiles.Sort();
 }
 public override bool Apply(AssetImporter item, ImportDefinitionProfile fromProfile)
 {
     if (string.IsNullOrEmpty(m_MethodString) == false)
     {
         if (Method != null)
         {
             object returnValue = Method.Invoke(item, m_Data);
             if (returnValue != null)
             {
                 SetUserData(item, fromProfile);
                 return((bool)returnValue);
             }
         }
     }
     return(false);
 }
        public override List <IConformObject> GetConformObjects(string asset, ImportDefinitionProfile profile)
        {
            // Preprocessor versionCode comparison
            // will need someway to store this. It could not work well if imported not using it
            // 1: add it to meta data. Only option is userData, which could conflict with other code packages. This would make it included in the hash for cache server. Which would be required.
            // 2: store a database of imported version data. Could be tricky to keep in sync
            // 3: AssetDatabaseV2 supports asset dependencies

            List <IConformObject> infos = new List <IConformObject>();

            if (Method == null)
            {
                PreprocessorConformObject conformObject = new PreprocessorConformObject("None Selected", 0);
                infos.Add(conformObject);
                return(infos);
            }

            UserDataSerialization userData = UserDataSerialization.Get(asset);
            List <UserDataSerialization.PostprocessorData> data = userData.GetProcessedMethodsData();
            string profileGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(profile));

            if (data != null)
            {
                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].moduleName != ImportTaskName ||
                        data[i].typeName != Method.TypeName ||
                        data[i].assemblyName != Method.AssemblyName ||
                        data[i].importDefinitionGUID != profileGuid)
                    {
                        continue;
                    }

                    PreprocessorConformObject conformObject = new PreprocessorConformObject(Method.TypeName, Method.Version, data[i].version);
                    infos.Add(conformObject);
                    break;
                }
            }
            else
            {
                PreprocessorConformObject conformObject = new PreprocessorConformObject(Method.TypeName, Method.Version);
                infos.Add(conformObject);
            }
            return(infos);
        }
        public override bool Apply(ImportContext context, ImportDefinitionProfile fromProfile)
        {
            if (CanProcess(context.Importer) == false)
            {
                return(false);
            }

            if (m_ConstrainProperties.Count > 0)
            {
                SerializedObject profileSerializedObject = new SerializedObject(ReferenceAssetImporter);
                SerializedObject assetImporterSO         = new SerializedObject(context.Importer);
                CopyConstrainedProperties(assetImporterSO, profileSerializedObject);
            }
            else
            {
                EditorUtility.CopySerialized(ReferenceAssetImporter, context.Importer);
            }

            return(true);
        }
Beispiel #12
0
        void GetAuditorProfiles()
        {
            string[] auditorProfileGUIDs = AssetDatabase.FindAssets("t:ImportDefinitionProfile");

            profiles.Clear();
            foreach (string asset in auditorProfileGUIDs)
            {
                string guidToAssetPath          = AssetDatabase.GUIDToAssetPath(asset);
                ImportDefinitionProfile profile = AssetDatabase.LoadAssetAtPath <ImportDefinitionProfile>(guidToAssetPath);
                if (profile != null)
                {
                    profiles.Add(profile);
                }
            }

            profileNames.Clear();
            foreach (ImportDefinitionProfile assetRule in profiles)
            {
                profileNames.Add(assetRule.name);
            }
        }
Beispiel #13
0
        public override bool Apply(AssetImporter importer, ImportDefinitionProfile fromProfile)
        {
            if (CanProcess(importer) == false)
            {
                return(false);
            }

            if (m_ConstrainProperties.Count > 0)
            {
                SerializedObject profileSerializedObject = new SerializedObject(ReferenceAssetImporter);
                SerializedObject assetImporterSO         = new SerializedObject(importer);
                CopyConstrainedProperties(assetImporterSO, profileSerializedObject);
            }
            else
            {
                EditorUtility.CopySerialized(ReferenceAssetImporter, importer);
            }

            m_AssetsToForceApply.Remove(importer.assetPath);
            return(true);
        }
        public override List <IConformObject> GetConformObjects(string asset, ImportDefinitionProfile profile)
        {
            AssetImporter assetImporter = AssetImporter.GetAtPath(asset);

            if (m_ImporterReference == null)
            {
                return(new List <IConformObject>(0));
            }

            SerializedObject assetImporterSO   = new SerializedObject(assetImporter);
            SerializedObject profileImporterSO = new SerializedObject(ReferenceAssetImporter);

            // TODO Performance: if there are any. check to make sure these are valid constraints, if not, don't include them in the count
            if (m_ConstrainProperties.Count == 0)
            {
                return(CompareSerializedObject(profileImporterSO, assetImporterSO));
            }

            List <IConformObject> infos = new List <IConformObject>();

            for (int i = 0; i < m_ConstrainProperties.Count; ++i)
            {
                SerializedProperty assetRuleSP = profileImporterSO.FindProperty(m_ConstrainProperties[i]);
                if (assetRuleSP == null)
                {
                    continue;                     // could be properties from another Object
                }
                SerializedProperty foundAssetSP = assetImporterSO.FindProperty(m_ConstrainProperties[i]);

                PropertyConformObject conformObject = new PropertyConformObject(m_ConstrainProperties[i]);
                conformObject.SetSerializedProperties(assetRuleSP, foundAssetSP);
                infos.Add(conformObject);
            }

            return(infos);
        }
        /// <summary>
        /// Keep the profile list in sync with the project.
        /// TODO Could keep track of profiles without [InitialiseOnLoadMethod] with validation instead?
        /// </summary>
        /// <param name="importedAssets"></param>
        /// <param name="deletedAssets"></param>
        /// <param name="movedToAssetPaths"></param>
        /// <param name="movedFromAssetPaths"></param>
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedToAssetPaths, string[] movedFromAssetPaths)
        {
            for (int i = 0; i < movedFromAssetPaths.Length; ++i)
            {
                for (int d = 0; d < s_Profiles.Count; ++d)
                {
                    if (s_Profiles[d].m_AssetPath == movedFromAssetPaths[i])
                    {
                        ProfileData def = s_Profiles[d];
                        def.m_AssetPath = movedToAssetPaths[i];
                        def.m_ImportDefinitionProfile.DirectoryPath = null;
                        s_Profiles[d] = def;
                        break;
                    }
                }
            }

            for (int i = 0; i < importedAssets.Length; ++i)
            {
                if (importedAssets[i].EndsWith(".asset") == false)
                {
                    continue;
                }
                ImportDefinitionProfile profile = AssetDatabase.LoadAssetAtPath <ImportDefinitionProfile>(importedAssets[i]);
                if (profile == null)
                {
                    continue;
                }

                bool isInCache = false;
                for (int d = 0; d < s_Profiles.Count; ++d)
                {
                    if (s_Profiles[d].m_AssetPath == importedAssets[i])
                    {
                        isInCache = true;
                        break;
                    }
                }

                if (!isInCache)
                {
                    ProfileData item = new ProfileData();
                    item.m_AssetPath = importedAssets[i];
                    item.m_ImportDefinitionProfile = profile;
                    profile.DirectoryPath          = null;
                    s_Profiles.Add(item);
                }
            }

            for (int i = 0; i < deletedAssets.Length; ++i)
            {
                for (int d = 0; d < s_Profiles.Count; ++d)
                {
                    if (s_Profiles[d].m_AssetPath == deletedAssets[i])
                    {
                        s_Profiles.RemoveAt(d);
                        break;
                    }
                }
            }
        }
        public override void OnInspectorGUI()
        {
            if (m_Profile == null)
            {
                m_Profile = (ImportDefinitionProfile)target;
            }

            Rect        viewRect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth - 23, 0);
            ControlRect layout   = new ControlRect(viewRect.x, viewRect.y, viewRect.width);

            layout.Space(10);
            EditorGUI.PropertyField(layout.Get(), m_FolderOnly, new GUIContent("Lock to folder", "Include a filter to limit this profile to this profile only"));
            EditorGUI.PropertyField(layout.Get(), m_ProcessOnImport, new GUIContent("Process On Import"));
            EditorGUI.PropertyField(layout.Get(), m_SortIndex, new GUIContent("Sort Index"));
            layout.Space(10);

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

            List <Filter> filters = m_Profile.GetFilters(true);

            if (filters == null)
            {
                filters = new List <Filter>();
            }

            int filterCount = filters.Count;

            if (m_FolderOnly.boolValue)
            {
                filterCount++;
            }

            Rect boxAreaRect = layout.Get((16 * filterCount) + (3 * filterCount) + 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;
            int size     = m_FiltersListProperty.arraySize;

            if (m_FolderOnly.boolValue)
            {
                size++;
            }

            for (int i = 0; i < size; ++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;

                if (m_FolderOnly.boolValue && i == size - 1)
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUI.EnumPopup(segmentRect, Filter.ConditionTarget.Directory);
                    segmentRect.x = startX + segWidth;
                    EditorGUI.EnumPopup(segmentRect, Filter.Condition.StartsWith);
                    segmentRect.x = startX + (segWidth * 2);
                    EditorGUI.TextField(segmentRect, m_Profile.DirectoryPath);
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    SerializedProperty filterProperty = m_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)
            {
                m_FiltersListProperty.DeleteArrayElementAtIndex(removeAt);
            }

            Rect layoutRect = layout.Get();

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

            layout.Space(20);

            EditorGUI.LabelField(layout.Get(), "", UnityEngine.GUI.skin.horizontalSlider);

            size = m_Tasks.arraySize;
            for (int i = 0; i < size; ++i)
            {
                if (m_ImportTaskFoldoutStates.Count - 1 < i)
                {
                    m_ImportTaskFoldoutStates.Add(true);
                }

                SerializedProperty taskProperty = m_Tasks.GetArrayElementAtIndex(i);
                BaseImportTask     importTask   = taskProperty.objectReferenceValue as BaseImportTask;
                if (importTask == null)
                {
                    continue;
                }

                if (i > 0)
                {
                    layout.Space(10);
                }

                Rect headerRect = layout.Get(20);
                m_ImportTaskFoldoutStates[i] = EditorGUI.Foldout(headerRect, m_ImportTaskFoldoutStates[i], importTask.name, true);

                Event current = Event.current;
                if (headerRect.Contains(current.mousePosition))
                {
                    if ((current.type == EventType.MouseDown && current.button == 1) || current.type == EventType.ContextClick)
                    {
                        GenericMenu menu = new GenericMenu();
                        if (i == 0)
                        {
                            menu.AddDisabledItem(new GUIContent("Move Up"));
                        }
                        else
                        {
                            menu.AddItem(new GUIContent("Move Up"), false, MoveTaskUpCallback, i);
                        }
                        if (i == size - 1)
                        {
                            menu.AddDisabledItem(new GUIContent("Move Down"));
                        }
                        else
                        {
                            menu.AddItem(new GUIContent("Move Down"), false, MoveTaskDownCallback, i);
                        }

                        menu.AddSeparator("");
                        menu.AddItem(new GUIContent("Delete Import Task"), false, RemoveTaskCallback, i);
                        menu.ShowAsContext();
                        current.Use();
                    }
                    else if (current.type == EventType.MouseDown && current.button == 0)
                    {
                        m_ImportTaskFoldoutStates[i] = !m_ImportTaskFoldoutStates[i];
                    }
                }

                if (m_ImportTaskFoldoutStates[i])
                {
                    layout.BeginArea(5, 5);

                    importTask.DrawGUI(layout);

                    GUI.depth = GUI.depth - 1;
                    GUI.Box(layout.EndArea(), "");
                    GUI.depth = GUI.depth + 1;
                }
            }

            if (size > 0)
            {
                EditorGUI.LabelField(layout.Get(), "", UnityEngine.GUI.skin.horizontalSlider);
            }

            layoutRect = layout.Get();
            if (layoutRect.width > 120)
            {
                layoutRect.x     = layoutRect.x + (layoutRect.width - 120);
                layoutRect.width = 120;
            }

            if (EditorGUI.DropdownButton(layoutRect, new GUIContent("Add Import Task", "Add new Task to this Definition."), FocusType.Keyboard))
            {
                var menu = new GenericMenu();
                for (int i = 0; i < m_ImportTaskTypes.Count; i++)
                {
                    var type = m_ImportTaskTypes[i];
                    menu.AddItem(new GUIContent(type.Name, ""), false, OnAddImportTask, type);
                }

                menu.ShowAsContext();
            }

            GUILayoutUtility.GetRect(viewRect.width, layoutRect.y + layoutRect.height);
            serializedObject.ApplyModifiedProperties();
        }
        private void GenerateTreeElements(ImportDefinitionProfile 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";
            AssetsTreeViewItem assetsesTreeFolder = new AssetsTreeViewItem(activePath.GetHashCode(), 0, activePath, true);

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

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

            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";

                AssetsTreeViewItem active = assetsesTreeFolder;

                List <ConformData> 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 && assetsesTreeFolder.conforms)
                {
                    assetsesTreeFolder.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)
                    {
                        AssetsTreeViewItem item = new AssetsTreeViewItem(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
                    {
                        AssetsTreeViewItem item;
                        if (!items.TryGetValue(id, out item))
                        {
                            item = new AssetsTreeViewItem(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;
                    }
                }
            }
        }
Beispiel #18
0
 public abstract List <IConformObject> GetConformObjects(string asset, ImportDefinitionProfile profile);
Beispiel #19
0
 public ConformData(IImportTask importTask, ImportDefinitionProfile forProfile, string assetPath)
 {
     m_ImportTask     = importTask;
     m_ConformObjects = m_ImportTask.GetConformObjects(assetPath, forProfile);
 }
 public override void PreprocessTask(ImportContext context, ImportDefinitionProfile profile)
 {
     // this task doesn't need to set the metaData
 }