Ejemplo n.º 1
0
        public void CopyEntityTest()
        {
            var idGen = new IDGenerator();
            var box   = new Box(Coordinate.One * -100, Coordinate.One * 100);

            // Create an entity with children
            var ent = new Entity(idGen.GetNextObjectID());

            ent.EntityData.Name = "Test";
            ent.EntityData.Properties.Add(new Property {
                Key = "key1", Value = "value1"
            });
            ent.EntityData.Properties.Add(new Property {
                Key = "key2", Value = "value2"
            });
            ent.EntityData.Flags = 12345;

            var solids = new BlockBrush().Create(idGen, box, null, 0);

            foreach (var mo in solids)
            {
                mo.SetParent(ent);
            }

            // Copy and reconstruct
            var gs = VmfProvider.CreateCopyStream(new List <MapObject> {
                ent
            });
            var pasted = VmfProvider.ExtractCopyStream(gs, idGen).ToList();

            // Test object
            Assert.AreEqual(1, pasted.Count);
            Assert.IsInstanceOfType(pasted[0], typeof(Entity));

            // Test entity
            var pastedEnt = (Entity)pasted[0];

            Assert.AreEqual("Test", pastedEnt.EntityData.Name);
            Assert.AreEqual(12345, pastedEnt.EntityData.Flags);

            // Test properties
            Assert.AreEqual(2, pastedEnt.EntityData.Properties.Count);
            var k1 = pastedEnt.EntityData.Properties.FirstOrDefault(x => x.Key == "key1");
            var k2 = pastedEnt.EntityData.Properties.FirstOrDefault(x => x.Key == "key1");

            Assert.IsNotNull(k1);
            Assert.IsNotNull(k2);
            Assert.AreEqual(k1.Value, "value1");
            Assert.AreEqual(k2.Value, "value1");

            // Test child
            Assert.AreEqual(1, pastedEnt.ChildCount);
            Assert.IsInstanceOfType(pastedEnt.GetChildren().ToList()[0], typeof(Solid));

            // Check number of sides, values of sides not so important
            var pastedSolid = (Solid)pastedEnt.GetChildren().ToList()[0];

            Assert.AreEqual(6, pastedSolid.Faces.Count);
        }
Ejemplo n.º 2
0
        private Map GenerateInvalidSolidMap(decimal variance, decimal startLocation, decimal cubeSize)
        {
            var map   = new Map();
            var block = new BlockBrush();
            var st    = Coordinate.One * startLocation;
            var brush = block.Create(map.IDGenerator, new Box(st, st + Coordinate.One * cubeSize), null, 0).OfType <Solid>().First();
            var verts = brush.Faces.SelectMany(x => x.Vertices).Where(x => x.Location == st).ToList();

            verts.ForEach(x => x.Location.X -= variance);
            brush.SetParent(map.WorldSpawn);
            return(map);
        }
Ejemplo n.º 3
0
        public void TestMapObjectSerialisation()
        {
            // compare the *'s:
            // brush -> GS -> string* -> GS -> brush -> GS -> string*

            var brush        = new BlockBrush();
            var b            = brush.Create(new IDGenerator(), new Box(Coordinate.Zero, Coordinate.One * 100), null, 0);
            var serialised   = GenericStructure.Serialise(b);
            var toString     = serialised.ToString();
            var parsed       = GenericStructure.Parse(new StringReader(toString));
            var deserialised = GenericStructure.Deserialise <List <MapObject> >(parsed.First());
            var reserialised = GenericStructure.Serialise(deserialised);

            Assert.AreEqual(serialised.ToString(), reserialised.ToString());
        }
Ejemplo n.º 4
0
    void CreateBrush()
    {
        //获得由picker选中的笔刷对象
        BasicBlock block = voxelMap.GetBlockBrush;

        if (block != null)
        {
            GameObject go = new GameObject("Brush");
            go.transform.SetParent(voxelMap.transform);

            //笔刷中保存笔刷实例的引用
            brush = go.AddComponent <BlockBrush> ();
            brush.m_meshFilter = go.AddComponent <MeshFilter> ();
            brush.m_meshRender = go.AddComponent <MeshRenderer> ();

            brush.m_tag = block.m_tag;

            //使用brush的方法对笔刷实例的组件进行修改
            brush.m_brushSize = voxelMap.GetBlockSize();
            brush.UpdateBrush(block.m_gameobject.GetComponentInChildren <MeshFilter> (),
                              block.m_gameobject.GetComponentInChildren <MeshRenderer> ());
        }
    }