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));
        }
Пример #2
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));
        }
Пример #3
0
        /// <summary>
        /// Get a userData representation for processing on the asset at assetPath
        /// </summary>
        /// <param name="assetPath"></param>
        /// <returns></returns>
        public static UserDataSerialization Get(string assetPath)
        {
            for (int i = 0; i < m_Cache.Count; ++i)
            {
                if (m_Cache[i].m_Importer != null)
                {
                    if (m_Cache[i].m_Importer.assetPath == assetPath)
                    {
                        return(m_Cache[i]);
                    }
                }
                else
                {
                    Debug.LogError("AssetImporter is null for Asset - this is unexpect to happen and a bug");
                }
            }

            UserDataSerialization ud = new UserDataSerialization(assetPath);

            if (ud.m_Importer != null)
            {
                m_Cache.Add(ud);
                return(m_Cache[m_Cache.Count - 1]);
            }

            return(null);
        }
        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();
        }
        /// <summary>
        /// Parses the userData for the assetPath to PostprocessorData
        /// </summary>
        /// <param name="assetPath"></param>
        /// <returns></returns>
        private static UserDataSerialization ParseForAssetPath(string assetPath)
        {
            AssetImporter importer = AssetImporter.GetAtPath(assetPath);

            Assert.IsNotNull(importer);

            string userData      = importer.userData;
            int    idfStartIndex = userData.IndexOf(searchString, StringComparison.Ordinal);
            int    idfEndIndex   = -1;

            PostprocessorDataList importersPostprocessorData = new PostprocessorDataList();

            if (idfStartIndex != -1)
            {
                idfEndIndex = idfStartIndex + searchString.Length;
                int counter    = 0;
                int startIndex = idfEndIndex;
                while (idfEndIndex < userData.Length)
                {
                    if (userData[idfEndIndex] == '{')
                    {
                        counter++;
                    }
                    else if (userData[idfEndIndex] == '}')
                    {
                        counter--;
                    }

                    if (counter == -1)
                    {
                        break;
                    }
                    ++idfEndIndex;
                }
                Assert.AreEqual(-1, counter);

                string str = userData.Substring(startIndex, idfEndIndex - startIndex);
                importersPostprocessorData = JsonUtility.FromJson <PostprocessorDataList>(str);
                //idfEndIndex += 2;
            }

            UserDataSerialization returnData = new UserDataSerialization();

            returnData.m_Importer = importer;
            returnData.m_ImporterPostprocessorData = importersPostprocessorData;
            returnData.m_UserDataStartIndex        = idfStartIndex;
            returnData.m_UserDataEndIndex          = idfEndIndex;

            return(returnData);
        }
        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 void PreprocessAsset(ImportContext context, bool checkForConformity = true)
        {
            if (checkForConformity)
            {
                if (m_FilterToFolder)
                {
                    List <Filter> filters = new List <Filter>(m_Filters);
                    filters.Add(new Filter(Filter.ConditionTarget.Directory, Filter.Condition.StartsWith, DirectoryPath));
                    if (Filter.Conforms(context.Importer, filters) == false)
                    {
                        return;
                    }
                }
                else if (Filter.Conforms(context.Importer, m_Filters) == false)
                {
                    return;
                }
            }

            bool saveMeta = false;

            if (m_RunOnImport)
            {
                for (int i = 0; i < m_ImportTasks.Count; ++i)
                {
                    if (m_ImportTasks[i] != null)
                    {
                        m_ImportTasks[i].PreprocessTask(context, this);
                        saveMeta = true;
                        if (m_ImportTasks[i].TaskProcessType == BaseImportTask.ProcessingType.Pre)
                        {
                            m_ImportTasks[i].Apply(context, this);
                            m_ImportTasks[i].SetManuallyProcessing(context.AssetPath, false);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < m_ImportTasks.Count; ++i)
                {
                    if (m_ImportTasks[i] != null && m_ImportTasks[i].IsManuallyProcessing(context.Importer))
                    {
                        m_ImportTasks[i].PreprocessTask(context, this);
                        saveMeta = true;
                        if (m_ImportTasks[i].TaskProcessType == BaseImportTask.ProcessingType.Pre)
                        {
                            m_ImportTasks[i].Apply(context, this);
                            m_ImportTasks[i].SetManuallyProcessing(context.AssetPath, false);
                        }
                    }
                }
            }

            if (saveMeta)
            {
                UserDataSerialization data = UserDataSerialization.Get(context.AssetPath);
                if (data != null)
                {
                    data.SaveMetaData();
                }
            }
        }