Esempio n. 1
0
        public override ExportPointer CreateExportPointer(Object asset, bool isLocal)
        {
            if (isLocal)
            {
                throw new NotSupportedException();
            }

            MonoScript script = m_scripts[asset];

            if (s_unityEngine.IsMatch(script.AssemblyName))
            {
                if (MonoScript.IsReadNamespace(script.File.Version))
                {
                    int fileID = Compute(script.Namespace, script.Name);
                    return(new ExportPointer(fileID, UnityEngineGUID, AssetExporter.ToExportType(asset)));
                }
                else
                {
                    ScriptInfo scriptInfo = script.GetScriptInfo();
                    if (scriptInfo != default)
                    {
                        int fileID = Compute(scriptInfo.Namespace, scriptInfo.Name);
                        return(new ExportPointer(fileID, UnityEngineGUID, AssetExporter.ToExportType(asset)));
                    }
                }
            }

            long       exportID   = GetExportID(asset);
            EngineGUID uniqueGUID = script.GUID;

            return(new ExportPointer(exportID, uniqueGUID, AssetExporter.ToExportType(asset)));
        }
        private void ReadAssets(EndianStream stream, long startPosition)
        {
            m_assets.Clear();
            using (AssetStream ustream = new AssetStream(stream.BaseStream, Version, Platform))
            {
                foreach (ObjectInfo info in Metadata.Objects.Values)
                {
                    AssetInfo assetInfo;
                    if (ObjectInfo.IsReadTypeIndex(Header.Generation))
                    {
                        RTTIBaseClassDescriptor typemeta = Metadata.Hierarchy.Types[info.TypeIndex];
                        assetInfo = new AssetInfo(this, info.PathID, typemeta.ClassID);
                    }
                    else
                    {
                        assetInfo = new AssetInfo(this, info.PathID, (ClassIDType)info.ClassID);
                    }

                    long   pathID = info.PathID;
                    Object asset  = ReadAsset(ustream, assetInfo, startPosition + Header.DataOffset + info.DataOffset, info.DataSize);
                    if (asset != null)
                    {
                        m_assets.Add(pathID, asset);
                    }
                }
            }
        }
Esempio n. 3
0
        public IExportCollection CreateCollection(Object asset)
        {
            if (OcclusionCullingSettings.IsCompatible(asset))
            {
                if (asset.File.IsScene)
                {
                    return(new SceneExportCollection(this, asset.File));
                }
                else
                {
                    return(new PrefabExportCollection(this, asset));
                }
            }
            else
            {
                switch (asset.ClassID)
                {
                case ClassIDType.NavMeshData:
                    return(new EmptyExportCollection());

                case ClassIDType.AnimatorController:
                    return(new AnimatorControllerExportCollection(this, asset));

                case ClassIDType.TagManager:
                    return(new ManagerExportCollection(this, asset));

                default:
                    return(new AssetExportCollection(this, asset));
                }
            }
        }
Esempio n. 4
0
 public void Export(IExportContainer container, Object asset, string path)
 {
     using (FileStream fileStream = new FileStream(path, FileMode.CreateNew, FileAccess.Write))
     {
         asset.ExportBinary(container, fileStream);
     }
 }
Esempio n. 5
0
        public IExportCollection CreateCollection(Object @object)
        {
            switch (@object)
            {
            case RenderSettings renderSettings:
                return(new SkipExportCollection(this, renderSettings));

            case OcclusionCullingSettings cullSettings:
                return(new SkipExportCollection(this, cullSettings));

            case NavMeshSettings navSettings:
                return(new SkipExportCollection(this, navSettings));

            case BuildSettings buildSettings:
                return(new SkipExportCollection(this, buildSettings));

            case MonoScript monoScript:
                return(new SkipExportCollection(this, monoScript, monoScript.ClassName));

            case AssetBundle bundle:
                string name = string.IsNullOrEmpty(bundle.AssetBundleName) ? bundle.Name : bundle.AssetBundleName;
                return(new EmptyExportCollection(this, name));

            default:
                return(new SkipExportCollection(this, (NamedObject)@object));
            }
        }
        protected string GetUniqueFileName(Object @object, string dirPath)
        {
            string fileName;

            switch (@object)
            {
            case NamedObject named:
                fileName = named.Name;
                break;

            case Prefab prefab:
                fileName = prefab.GetName();
                break;

            case MonoBehaviour monoBehaviour:
                fileName = monoBehaviour.Name;
                break;

            default:
                fileName = @object.GetType().Name;
                break;
            }
            fileName = FileNameRegex.Replace(fileName, string.Empty);

            fileName = DirectoryUtils.GetMaxIndexName(dirPath, fileName);
            fileName = $"{fileName}.{@object.ExportExtension}";
            return(fileName);
        }
Esempio n. 7
0
        public IExportCollection CreateCollection(Object asset)
        {
            if (!asset.IsValid)
            {
                Logger.Instance.Log(LogType.Warning, LogCategory.Export, $"Can't export '{asset}' because it isn't valid");
                return(new EmptyExportCollection());
            }

            if (OcclusionCullingSettings.IsCompatible(asset))
            {
                if (asset.File.IsScene)
                {
                    return(new SceneExportCollection(this, asset.File));
                }
                else
                {
                    return(new PrefabExportCollection(this, asset));
                }
            }
            else
            {
                switch (asset.ClassID)
                {
                case ClassIDType.NavMeshData:
                    return(new EmptyExportCollection());

                default:
                    return(new AssetExportCollection(this, asset));
                }
            }
        }
        private Object ReadAsset(AssetStream stream, AssetInfo assetInfo, long offset, int size)
        {
            Object asset = Collection.AssetFactory.CreateAsset(assetInfo);

            if (asset == null)
            {
                return(null);
            }

            stream.BaseStream.Position = offset;
            if (Config.IsGenerateGUIDByContent)
            {
                byte[] data = stream.ReadBytes(size);
                asset.Read(data);

                using (MD5 md5 = MD5.Create())
                {
                    byte[] md5Hash = md5.ComputeHash(data);
                    assetInfo.GUID = new UtinyGUID(md5Hash);
                }
            }
            else
            {
                stream.AlignPosition = offset;
                asset.Read(stream);
                long read = stream.BaseStream.Position - offset;
                if (read != size)
                {
                    throw new Exception($"Read {read} but expected {size} for object {asset.GetType().Name}");
                }
            }
            return(asset);
        }
        public override IExportCollection CreateCollection(Object @object)
        {
            if (@object is Component comp)
            {
                @object = comp.GameObject.GetObject(comp.File);
            }
            if (@object.ClassID == ClassIDType.GameObject)
            {
                GameObject go = (GameObject)@object;
                @object = go.GetRoot();
            }

            if (@object.ClassID == ClassIDType.GameObject)
            {
                GameObject go     = (GameObject)@object;
                Prefab     prefab = new Prefab(go);
                IEnumerable <EditorExtension> prefabContent = EnumeratePrefabContent(prefab);
                PrefabExportCollection        collection    = new PrefabExportCollection(this, prefab, prefabContent);
                return(collection);
            }
            else
            {
                if ([email protected])
                {
                    throw new ArgumentException($"Unsupported export object type {@object.ClassID}", nameof(@object));
                }

                AssetExportCollection collection = new AssetExportCollection(this, @object);
                return(collection);
            }
        }
Esempio n. 10
0
        private Object ReadAsset(AssetReader reader, AssetInfo assetInfo, long offset, int size)
        {
            Object asset = Collection.AssetFactory.CreateAsset(assetInfo);

            if (asset == null)
            {
                return(null);
            }

            reader.BaseStream.Position = offset;
            if (Config.IsGenerateGUIDByContent)
            {
                byte[] data = reader.ReadBytes(size);
#if !DEBUG
                try
#endif
                {
                    asset.Read(data);
                }
#if !DEBUG
                catch
                {
                    Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{reader.Version}] '{Name}'");
                    throw;
                }
#endif

                using (MD5 md5 = MD5.Create())
                {
                    byte[] md5Hash = md5.ComputeHash(data);
                    assetInfo.GUID = new EngineGUID(md5Hash);
                }
            }
            else
            {
                using (AssetReader alignReader = new AssetReader(reader, offset))
                {
#if !DEBUG
                    try
#endif
                    {
                        asset.Read(alignReader);
                    }
#if !DEBUG
                    catch
                    {
                        Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{reader.Version}] '{Name}'");
                        throw;
                    }
#endif
                }
                long read = reader.BaseStream.Position - offset;
                if (read != size)
                {
                    throw new Exception($"Read {read} but expected {size} for asset type {asset.ClassID}. Version[{reader.Version}] '{Name}'");
                }
            }
            return(asset);
        }
        public ExportPointer CreateExportPointer(Object @object, bool isLocal)
        {
            string exportID = GetExportID(@object);

            return(isLocal ?
                   new ExportPointer(exportID) :
                   new ExportPointer(exportID, Asset.GUID, AssetExporter.ToExportType(Asset.ClassID)));
        }
Esempio n. 12
0
 public void Export(IExportContainer container, Object asset, string path, Action <IExportContainer, Object, string> callback)
 {
     using (FileStream fileStream = new FileStream(path, FileMode.CreateNew, FileAccess.Write))
     {
         asset.ExportBinary(container, fileStream);
     }
     callback?.Invoke(container, asset, path);
 }
 public long GetExportID(Object asset)
 {
     if (asset == m_asset)
     {
         return(ExportCollection.GetMainExportID(m_asset));
     }
     throw new ArgumentException(nameof(asset));
 }
Esempio n. 14
0
 public string GetExportID(Object @object)
 {
     if (@object == m_asset)
     {
         return($"{(int)m_asset.ClassID}00000");
     }
     throw new ArgumentException(nameof(@object));
 }
Esempio n. 15
0
 public override long GetExportID(Object asset)
 {
     if (asset == Asset)
     {
         return(1);
     }
     throw new ArgumentException(nameof(asset));
 }
Esempio n. 16
0
        private void OnScriptExported(IExportContainer container, Object asset, string path)
        {
            MonoScript   script   = (MonoScript)asset;
            MonoImporter importer = new MonoImporter(script);
            Meta         meta     = new Meta(importer, script.GUID);

            ExportMeta(container, meta, path);
        }
 public virtual string GetExportID(Object @object)
 {
     if (@object == Asset)
     {
         return(GetMainExportID(Asset));
     }
     throw new ArgumentException(nameof(@object));
 }
 public override string GetExportID(Object @object)
 {
     if (@object == Asset)
     {
         return(base.GetExportID(@object));
     }
     return(m_exportIDs[@object]);
 }
 public override bool IsContains(Object @object)
 {
     if (base.IsContains(@object))
     {
         return(true);
     }
     return(m_exportIDs.ContainsKey(@object));
 }
        public Object GetAsset(long pathID)
        {
            Object asset = FindAsset(pathID);

            if (asset == null)
            {
                throw new Exception($"Object with path ID {pathID} wasn't found");
            }

            return(asset);
        }
Esempio n. 21
0
        public Object GetObject(long pathID)
        {
            Object @object = FindObject(pathID);

            if (@object == null)
            {
                throw new Exception($"Object with path ID {pathID} wasn't found");
            }

            return(@object);
        }
        private void ReadAsset(AssetStream stream, AssetEntry info, long startPosition)
        {
            long        pathID    = info.PathID;
            ClassIDType classID   = AssetEntryToClassIDType(info);
            AssetInfo   assetInfo = new AssetInfo(this, pathID, classID);
            Object      asset     = ReadAsset(stream, assetInfo, startPosition + Header.DataOffset + info.DataOffset, info.DataSize);

            if (asset != null)
            {
                AddAsset(pathID, asset);
            }
        }
Esempio n. 23
0
        public override ExportPointer CreateExportPointer(Object asset, bool isLocal)
        {
            if (isLocal)
            {
                throw new NotSupportedException();
            }

            ulong      exportID   = GetExportID(asset);
            EngineGUID uniqueGUID = m_scripts[asset].GUID;

            return(new ExportPointer(exportID, uniqueGUID, AssetExporter.ToExportType(asset)));
        }
        public override IExportCollection CreateCollection(Object @object)
        {
            switch (@object.ClassID)
            {
            case ClassIDType.Texture2D:
            case ClassIDType.Cubemap:
                return(new TextureExportCollection(this, (Texture2D)@object));

            default:
                return(new AssetExportCollection(this, @object));
            }
        }
Esempio n. 25
0
        public ExportPointer CreateExportPointer(Object @object, bool isLocal)
        {
            if (isLocal)
            {
                throw new ArgumentException(nameof(isLocal));
            }

            string    exportId = GetExportID(@object);
            AssetType type     = AssetExporter.ToExportType(@object.ClassID);

            return(new ExportPointer(exportId, UtinyGUID.MissingReference, type));
        }
        public ExportPointer CreateExportPointer(Object asset, bool isLocal)
        {
            if (isLocal)
            {
                throw new ArgumentException(nameof(isLocal));
            }

            long      exportId = GetExportID(asset);
            AssetType type     = AssetExporter.ToExportType(asset);

            return(new ExportPointer(exportId, EngineGUID.MissingReference, type));
        }
Esempio n. 27
0
 private void AddAsset(long pathID, Object asset)
 {
     if (!IsScene)
     {
         // save IsScene value for optimization purpose
         if (asset.ClassID.IsSceneSettings())
         {
             IsScene = true;
         }
     }
     m_assets.Add(pathID, asset);
 }
Esempio n. 28
0
        public IExportCollection CreateCollection(Object asset)
        {
            switch (asset.ClassID)
            {
            case ClassIDType.Texture2D:
            case ClassIDType.Cubemap:
                return(new TextureExportCollection(this, (Texture2D)asset, false));

            default:
                return(new AssetExportCollection(this, asset));
            }
        }
 public void Export(IExportContainer container, Object asset, string path)
 {
     using (FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             YAMLWriter   writer = new YAMLWriter();
             YAMLDocument doc    = asset.ExportYAMLDocument(container);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
 }
Esempio n. 30
0
 public void Export(IExportContainer container, Object asset, string path, Action <IExportContainer, Object, string> callback)
 {
     using (FileStream fileStream = FileUtils.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             YAMLWriter   writer = new YAMLWriter();
             YAMLDocument doc    = asset.ExportYAMLDocument(container);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
     callback?.Invoke(container, asset, path);
 }