public static AssetTypeValueField GetMonoBaseField(AssetsManager am, AssetsFileInstance inst, AssetFileInfoEx info, string managedPath)
        {
            AssetsFile             file      = inst.file;
            AssetTypeTemplateField baseField = new AssetTypeTemplateField();

            baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, info.curFileType), 0);
            AssetTypeInstance mainAti = new AssetTypeInstance(baseField, file.reader, false, info.absoluteFilePos);

            if (file.typeTree.pTypes_Unity5[info.curFileTypeOrIndex].scriptIndex != 0xFFFF)
            {
                AssetTypeInstance scriptAti    = am.GetExtAsset(inst, mainAti.GetBaseField().Get("m_Script")).instance;
                string            scriptName   = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString();
                string            assemblyName = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString();
                string            assemblyPath = Path.Combine(managedPath, assemblyName);
                if (File.Exists(assemblyPath))
                {
                    MonoClass mc = new MonoClass();
                    mc.Read(scriptName, assemblyPath, inst.file.header.format);
                    AssetTypeTemplateField[] monoTemplateFields = mc.children;

                    AssetTypeTemplateField[] templateField = baseField.children.Concat(monoTemplateFields).ToArray();
                    baseField.children      = templateField;
                    baseField.childrenCount = (uint)baseField.children.Length;

                    mainAti = new AssetTypeInstance(baseField, file.reader, false, info.absoluteFilePos);
                }
            }
            return(mainAti.GetBaseField());
        }
示例#2
0
        public static AssetTypeValueField GetMonoBaseField(AssetsManager am, AssetsFileInstance inst, AssetFileInfoEx info, string managedPath, bool cached = true)
        {
            AssetsFile             file      = inst.file;
            AssetTypeTemplateField baseField = new AssetTypeTemplateField();

            baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, info.curFileType), 0);
            AssetTypeInstance mainAti     = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos);
            ushort            scriptIndex = AssetHelper.GetScriptIndex(file, info);

            if (scriptIndex != 0xFFFF)
            {
                AssetTypeInstance scriptAti       = am.GetExtAsset(inst, mainAti.GetBaseField().Get("m_Script")).instance;
                string            scriptName      = scriptAti.GetBaseField().Get("m_ClassName").GetValue().AsString();
                string            scriptNamespace = scriptAti.GetBaseField().Get("m_Namespace").GetValue().AsString();
                string            assemblyName    = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString();
                string            assemblyPath    = Path.Combine(managedPath, assemblyName);

                if (scriptNamespace != string.Empty)
                {
                    scriptName = scriptNamespace + "." + scriptName;
                }

                if (File.Exists(assemblyPath))
                {
                    AssemblyDefinition asmDef;
                    if (cached)
                    {
                        if (!loadedAssemblies.ContainsKey(assemblyName))
                        {
                            loadedAssemblies.Add(assemblyName, GetAssemblyWithDependencies(assemblyPath));
                        }
                        asmDef = loadedAssemblies[assemblyName];
                    }
                    else
                    {
                        asmDef = GetAssemblyWithDependencies(assemblyPath);
                    }

                    MonoDeserializer mc = new MonoDeserializer();
                    mc.Read(scriptName, asmDef, inst.file.header.format);
                    List <AssetTypeTemplateField> monoTemplateFields = mc.children;

                    AssetTypeTemplateField[] templateField = baseField.children.Concat(monoTemplateFields).ToArray();
                    baseField.children      = templateField;
                    baseField.childrenCount = baseField.children.Length;

                    mainAti = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos);
                }
            }
            return(mainAti.GetBaseField());
        }