Exemple #1
0
        /// <inheritdoc />
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var asset = CreateAsset(Path.GetExtension(ctx.assetPath));

            asset.IsReadOnly = true;
            Assert.IsNotNull(ctx.assetPath);

            asset.name = Path.GetFileNameWithoutExtension(ctx.assetPath);

            IEnumerable <Core.Entity> rawEntities;

            using (var input = new FileStream(ctx.assetPath, FileMode.Open))
            {
                using (var reader = new BinaryReader(input))
                {
                    rawEntities = DataSetFile2.Read(MakeReadFunctions(reader));
                }
            }

            var entities = CreateEntityInstances(rawEntities, Path.GetFileName(ctx.assetPath), MakeEntityCreateFunctions());
            var dataSet  = FindDataSet(entities);

            dataSet.OwningDataSetName = asset.name;

            var dataSetGuid = AssetDatabase.AssetPathToGUID(this.assetPath);

            InitializeEntities(entities, dataSetGuid, MakeEntityInitializeFunctions(dataSet, entities));

            asset.SetDataSet(dataSet);

            ctx.AddObjectToAsset("DataSet", asset);
            ctx.SetMainObject(asset);
        }
Exemple #2
0
        public static void ExportDataSet(List <Entity> entities, string exportPath)
        {
            Assert.IsNotNull(exportPath, "exportPath must not be null.");

            Func <uint> generateId = new IdGenerator().Next;

            entityIds = new Dictionary <Entity, uint>();
            foreach (var entity in entities)
            {
                entityIds.Add(entity, generateId());
            }

            var convertedEntities = ConvertEntities(entities, GetEntityAddressAndId).ToList();

            using (var writer = new BinaryWriter(new FileStream(exportPath, FileMode.Create)))
            {
                DataSetFile2.Write(convertedEntities, CreateWriteFunctions(writer));
            }
        }