Example #1
0
 public void Write(AssetWriter writer)
 {
     writer.WriteAsset(Vertex);
     writer.WriteAsset(Normal);
     writer.WriteAsset(Tangent);
     writer.Write(Index);
 }
Example #2
0
        public void CanSerializeTreeCollection()
        {
            var entity0 = new Entity(new VariableCollection());
            var entity1 = new Entity(new VariableCollection());
            var entity2 = new Entity(new VariableCollection());
            var entity3 = new Entity(new VariableCollection());

            entity1.Parent = entity0;
            entity2.Parent = entity0;
            entity3.Parent = entity1;

            entity0.AddComponent <FakeComp>();
            entity1.AddComponent <FakeComp>();
            entity1.AddComponent <FakeComp>();
            entity2.AddComponent <FakeComp>();
            entity3.AddComponent <FakeComp>();

            collection.Add(entity0);


            Stream stream = new MemoryStream();

            AssetWriter.WriteAsset(stream, collection, new TypeWriterFactory());
            stream.Position = 0;
            var collection2 = AssetReader.ReadAsset <EntityCollection>(stream, new TypeReaderFactory());
        }
Example #3
0
        public void Write(AssetWriter writer)
        {
            if (HasCurrentChannels(writer.Version))
            {
                writer.Write(CurrentChannels);
            }
            writer.Write(VertexCount);

            if (HasChannels(writer.Version))
            {
                writer.WriteAssetArray(Channels);
                writer.AlignStream(AlignType.Align4);
            }
            if (HasStreams(writer.Version))
            {
                if (IsStreamStatic(writer.Version))
                {
                    for (int i = 0; i < StaticStreamCount; i++)
                    {
                        writer.WriteAsset(Streams[i]);
                    }
                }
                else
                {
                    writer.WriteAssetArray(Channels);
                }
            }

            writer.WriteArray(Data);
            writer.AlignStream(AlignType.Align4);
        }
        public void SaveAsset(string relativePath, object asset)
        {
            string filePath = Path.GetFullPath(Path.Combine(this.RootDirectory, relativePath + ASSET_EXT));

            using (Stream stream = new FileStream(filePath, FileMode.CreateNew))
            {
                AssetWriter.WriteAsset(stream, asset, this.twfactory);
            }
        }
        public void CanSerializeValidTypes([ValueSource("Values")] object value)
        {
            var stream = new System.IO.MemoryStream();

            AssetWriter.WriteAsset(stream, value, new TypeWriterFactory());
            stream.Position = 0;
            object result = AssetReader.ReadAsset <object>(stream, new TypeReaderFactory());

            Assert.AreEqual(value, result);
        }
        public void CanSerializeCharacters([Random(char.MinValue, char.MaxValue, 5)] int val)
        {
            this.writerProviderMock.Setup((w) => w.GetTypeWriter(typeof(char))).Returns(new CharacterWriter());
            this.readerProviderMock.Setup((w) => w.GetTypeReader(typeof(char))).Returns(new CharacterReader());

            AssetWriter.WriteAsset(this.stream, (char)val, this.writerProviderMock.Object);
            this.stream.Position = 0;
            var result = AssetReader.ReadAsset <char>(stream, this.readerProviderMock.Object);

            Assert.AreEqual((char)val, result);
        }
        public void CanSerializeSignedBytes([Random(sbyte.MinValue, sbyte.MaxValue, 5)] int val)
        {
            this.writerProviderMock.Setup((w) => w.GetTypeWriter(typeof(sbyte))).Returns(new SignedByteWriter());
            this.readerProviderMock.Setup((w) => w.GetTypeReader(typeof(sbyte))).Returns(new SignedByteReader());

            AssetWriter.WriteAsset(this.stream, (sbyte)val, this.writerProviderMock.Object);
            this.stream.Position = 0;
            var result = AssetReader.ReadAsset <sbyte>(stream, this.readerProviderMock.Object);

            Assert.AreEqual((sbyte)val, result);
        }
        public void CanSerializeUnsignedIntegers([Random(uint.MinValue, uint.MaxValue, 5)] double val)
        {
            this.writerProviderMock.Setup((w) => w.GetTypeWriter(typeof(uint))).Returns(new UInt32Writer());
            this.readerProviderMock.Setup((w) => w.GetTypeReader(typeof(uint))).Returns(new UInt32Reader());


            AssetWriter.WriteAsset(this.stream, (uint)val, this.writerProviderMock.Object);
            this.stream.Position = 0;
            var result = AssetReader.ReadAsset <uint>(stream, this.readerProviderMock.Object);

            Assert.AreEqual((uint)val, result);
        }
        public void CanSerializeDoubles([Random(double.MinValue, double.MaxValue, 5)] double val)
        {
            this.writerProviderMock.Setup((w) => w.GetTypeWriter(typeof(double))).Returns(new DoubleWriter());
            this.readerProviderMock.Setup((w) => w.GetTypeReader(typeof(double))).Returns(new DoubleReader());


            AssetWriter.WriteAsset(this.stream, (double)val, this.writerProviderMock.Object);
            this.stream.Position = 0;
            var result = AssetReader.ReadAsset <double>(stream, this.readerProviderMock.Object);

            Assert.AreEqual((double)val, result);
        }
        public void CanSerializeSignedLongs([Random(long.MinValue, long.MaxValue, 5)] double val)
        {
            this.writerProviderMock.Setup((w) => w.GetTypeWriter(typeof(long))).Returns(new Int64Writer());
            this.readerProviderMock.Setup((w) => w.GetTypeReader(typeof(long))).Returns(new Int64Reader());


            AssetWriter.WriteAsset(this.stream, (long)val, this.writerProviderMock.Object);
            this.stream.Position = 0;
            var result = AssetReader.ReadAsset <long>(stream, this.readerProviderMock.Object);

            Assert.AreEqual((long)val, result);
        }
Example #11
0
        public void CanSerializeSimple()
        {
            this.entity.Name = "Daniel";
            this.entity.AddVar <string>("Bear", "Dancing in the forest of mordor is a weak cat!");

            Stream memstream = new MemoryStream();

            AssetWriter.WriteAsset(memstream, entity, new TypeWriterFactory());
            memstream.Position = 0;
            var entity2 = AssetReader.ReadAsset <Entity>(memstream, new TypeReaderFactory());

            Assert.AreEqual(entity.Name, entity2.Name);
            Assert.AreEqual(entity.GetVar <string>("Bear"), entity2.GetVar <string>("Bear"));
        }
        public void CanSerializeBooleans()
        {
            this.writerProviderMock.Setup((w) => w.GetTypeWriter(typeof(bool))).Returns(new BooleanWriter());
            this.readerProviderMock.Setup((w) => w.GetTypeReader(typeof(bool))).Returns(new BooleanReader());


            AssetWriter.WriteAsset(this.stream, true, this.writerProviderMock.Object);
            this.stream.Position = 0;
            var result = AssetReader.ReadAsset <bool>(stream, this.readerProviderMock.Object);

            Assert.IsTrue(result);

            this.stream.Position = 0;
            AssetWriter.WriteAsset(this.stream, false, this.writerProviderMock.Object);
            this.stream.Position = 0;
            result = AssetReader.ReadAsset <bool>(stream, this.readerProviderMock.Object);

            Assert.IsTrue(!result);
        }
Example #13
0
    public void SaveCache()
    {
                #if UNITY_EDITOR
        //	save texture assets
        var mf = GetComponent <MeshFilter>();
        var DumbTriangleMesh = mf ? mf.sharedMesh : null;

        BlockPositions   = AssetWriter.WriteAsset(CacheAssetPath + "/PositionData", BlockPositions);
        BlockColours     = AssetWriter.WriteAsset(CacheAssetPath + "/ColourData", BlockColours);
        DumbTriangleMesh = AssetWriter.WriteAsset(CacheAssetPath + "/DumbTriangleMesh", DumbTriangleMesh);

        if (mf)
        {
            mf.sharedMesh = DumbTriangleMesh;
        }
                #else
        throw new System.Exception("SaveCache only for editor");
                #endif
    }
Example #14
0
        public void CanSerializeSimpleCollection()
        {
            var entity0 = new Entity(new VariableCollection());

            entity0.Name = "Entity0";
            var entity1 = new Entity(new VariableCollection());

            entity1.Name = "Entity1";

            collection.Add(entity0);
            collection.Add(entity1);

            Stream stream = new MemoryStream();

            AssetWriter.WriteAsset(stream, collection, new TypeWriterFactory());
            stream.Position = 0;
            var collection2 = AssetReader.ReadAsset <EntityCollection>(stream, new TypeReaderFactory());

            Assert.NotNull(collection2.Find(x => x.Name == "Entity0"));
            Assert.NotNull(collection2.Find(x => x.Name == "Entity1"));
        }
Example #15
0
        public void CanSerializeAndDeserializeFSM()
        {
            fsm.AddState("Test");
            var state = fsm.AddState("Foo");

            state.AddTransition("BAR", "Test");

            fsm.AddVariable("some_int", 2);
            fsm.AddVariable("some_string", "Hell0");


            var stream = new MemoryStream();

            var wfactory = new TypeWriterFactory();
            var rfactory = new TypeReaderFactory();

            AssetWriter.WriteAsset(stream, fsm, wfactory);

            stream.Position = 0;
            var result = AssetReader.ReadAsset <FSMComponent>(stream, rfactory);
        }
        private T ImportAndLoadAsset <T>(string relativePath, string filePath, string assetPath, IImporter importer, IProcessor processor)
        {
            object asset;

            using (Stream stream = new FileStream(filePath, FileMode.Open))
            {
                asset = this.resourceLoader.ImportContent(stream, Path.GetExtension(filePath), importer);
            }
            asset = this.resourceLoader.ProcessContent(relativePath, asset, this, processor);

            if (this.ShouldSaveAllLoadedAssets)
            {
                using (Stream stream = new FileStream(assetPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    AssetWriter.WriteAsset(stream, asset, this.twfactory);
                    stream.Position = 0;
                    asset           = AssetReader.ReadAsset <T>(stream, this.trfactory);
                }
            }

            return((T)asset);
        }
Example #17
0
        public void CanSerializeHirachyOfEntities()
        {
            var entity1 = new Entity(new VariableCollection());
            var entity2 = new Entity(new VariableCollection());
            var entity3 = new Entity(new VariableCollection());

            entity1.Parent = entity;
            entity2.Parent = entity1;
            entity3.Parent = entity;

            entity.Name  = "Entity0";
            entity1.Name = "Entity1";
            entity2.Name = "Entity2";
            entity3.Name = "Entity3";

            Stream memstream = new MemoryStream();

            AssetWriter.WriteAsset(memstream, entity, new TypeWriterFactory());
            memstream.Position = 0;
            var resultEntity = AssetReader.ReadAsset <Entity>(memstream, new TypeReaderFactory());

            Assert.IsTrue(resultEntity.Children.Count <Entity>() == 2);
        }