Esempio n. 1
0
    public void Add_Force(BlockShape target, Force f)
    {
        if (target.stat)
        {
            return;
        }
        var fd = fdict[f.intensity];

        if (fd == null)
        {
            fdict[f.intensity] = new Dictionary <BlockShape, List <Force> >();
            fd = fdict[f.intensity];
        }
        if (fd.ContainsKey(target) && !fd[target].Contains(f))
        {
            fd[target].Add(f);
        }
        else if (!fd.ContainsKey(target))
        {
            fd[target] = new List <Force>()
            {
                f
            };
        }
    }
Esempio n. 2
0
 public Block(Vector3 position, BlockDirection direction, BlockShape shape)
 {
     this.shape        = shape;
     this.textureChips = new int[shape.meshes.Length];
     this.direction    = direction;
     this.SetPosition(position);
 }
    // TODO unify these two methods below with a single "GetStylePrefabs(BlockStyle)"

    public GameObject GetPrefabForBlockType(BlockShape type, BlockStyle style)
    {
        switch (style)
        {
        case BlockStyle.Stone:
            return(stoneStylePrefabs.GetBlockType(type));

        case BlockStyle.Grass:
            return(grassStylePrefabs.GetBlockType(type));

        case BlockStyle.Space:
            return(metalStylePrefabs.GetBlockType(type));

        case BlockStyle.SnowRock:
            return(snowRockStylePrefabs.GetBlockType(type));

        default:
            int colorId = (int)style;
            if (colorId < 0 || colorId > (int)LastSolidColorStyle)
            {
                Util.LogError($"Bad style given: {style}. Snapping to color 0.");
                colorId = 0;
            }
            return(perColorPrefabs[colorId].GetBlockType(type));
        }
    }
Esempio n. 4
0
 public Block(IVector3 pos)
 {
     this.pos = pos;
     indest   = true;
     no_weld  = new List <IVector3>();
     shape    = new BlockShape(this);
 }
Esempio n. 5
0
 // Start is called before the first frame update
 void Start()
 {
     oldShape = shape;
     SetBlockShape(shape);
     //pivotParent.transform.parent = transform.parent;
     //transform.parent = pivotParent.transform;
 }
Esempio n. 6
0
        protected override void OnPlanning(GraphPlanContext context)
        {
            var graph = context.TFGraph;
            var input = context.TFOutputs[Input.Connection.From];

            context.TFOutputs[Output] = graph.SpaceToBatchND(input, graph.Const(BlockShape.ToTFTensor()), graph.Const(Paddings.ToTFTensor()));
        }
Esempio n. 7
0
    public void Read(BinaryReader reader)
    {
        int fileBlockCount = reader.ReadInt32();

        for (int i = 0; i < fileBlockCount; i++)
        {
            string          name     = reader.ReadString();
            BlockShape      shape    = (BlockShape)reader.ReadByte();
            BlockType       material = (BlockType)reader.ReadByte();
            BlockController block;
            if (material == BlockType.Missing)
            {
                block = SetBlock(reader.ReadVector3Int(), shape);
            }
            else
            {
                block = SetBlock(reader.ReadVector3Int(), shape, material);
            }

            block.name = name;
            block.transform.localRotation = reader.ReadQuaternion();
        }

        ItemManager itemManager   = GameObject.Find("ItemManager").GetComponent <ItemManager>();
        int         fileItemCount = reader.ReadInt32();

        for (int i = 0; i < fileItemCount; i++)
        {
            ItemController newItem = Instantiate(itemManager.Items[(Item)reader.ReadByte()], transform);
            newItem.Manager = itemManager;
            newItem.transform.localPosition = reader.ReadVector3();
            newItem.transform.localRotation = reader.ReadQuaternion();
        }
    }
Esempio n. 8
0
    public BlockController SetBlock(Vector3Int pos, BlockShape shape, BlockType material)
    {
        BlockController block = SetBlock(pos, shape);

        if (block == null)
        {
            return(null);
        }
        block.SetType(material);
        Material     mat = Manager.GetBlockMaterial(material);
        MeshRenderer mr  = block.GetComponent <MeshRenderer>();

        if (mr == null)
        {
            foreach (MeshRenderer mrchild in block.GetComponentsInChildren <MeshRenderer>())
            {
                if (mrchild != null)
                {
                    mrchild.material = mat;
                }
            }
        }
        else
        {
            mr.material = mat;
        }
        return(block);
    }
Esempio n. 9
0
    public void push(BlockShape s, IVector3 dir)
    {
        var moving  = new List <Block>();
        var mshapes = new List <BlockShape>()
        {
            s
        };

        moving.AddRange(s.components);
        for (var i = 0; i < moving.Count(); i++)
        {
            var b    = moving[i];
            var tpos = b.pos + dir;
            var tb   = this[tpos];
            if (tb != null && !mshapes.Contains(tb.shape))
            {
                moving.AddRange(tb.shape.components);
                mshapes.Add(tb.shape);
            }
            if (i > 1000)
            {
                throw new System.Exception("OH SNAP!!!");
            }
        }
        foreach (var b in moving)
        {
            b.Move(this, dir);
        }
    }
Esempio n. 10
0
    // 読み込み
    public void Deserialize(XmlElement node)
    {
        if (node.HasAttribute("type"))
        {
            string typeName = node.GetAttribute("type");
            this.shape = BlockShape.Find(typeName);
        }
        if (this.shape == null)
        {
            this.shape = BlockShape.Find("cube");
        }

        Vector3 position = Vector3.zero;

        if (node.HasAttribute("x"))
        {
            float.TryParse(node.GetAttribute("x"), out position.x);
        }
        if (node.HasAttribute("y"))
        {
            float.TryParse(node.GetAttribute("y"), out position.y);
        }
        if (node.HasAttribute("z"))
        {
            float.TryParse(node.GetAttribute("z"), out position.z);
        }
        this.SetPosition(position);

        if (node.HasAttribute("dir"))
        {
            int dir;
            int.TryParse(node.GetAttribute("dir"), out dir);
            this.direction = (BlockDirection)dir;
        }

        if (node.HasAttribute("tile"))
        {
            string   tileStr      = node.GetAttribute("tile");
            string[] tileStrArray = tileStr.Split(',');
            this.textureChips = Array.ConvertAll <string, int>(tileStrArray, (value) => { return(int.Parse(value)); });
        }

        if (node.HasAttribute("enterable"))
        {
            string enterStr  = node.GetAttribute("enterable");
            bool   enterable = true;
            bool.TryParse(enterStr, out enterable);
            this.enterable = enterable;
        }
        else
        {
            this.enterable = true;
        }

        if (node.HasAttribute("meta"))
        {
            this.metaInfo = node.GetAttribute("meta");
        }
    }
Esempio n. 11
0
        public void BlockShape_Set_Get(BlockShape value)
        {
            var tile = new Tile();

            tile.BlockShape = value;

            Assert.Equal(value, tile.BlockShape);
        }
Esempio n. 12
0
 public Block(BlockScript bs)
 {
     pos     = new IVector3(bs.transform.position);
     indest  = bs.indest;
     no_weld = (from d in bs.no_weld select new IVector3(bs.transform.rotation * d)).ToList();
     shape   = new BlockShape(this);
     this.bs = bs;
 }
Esempio n. 13
0
        public void Apply(BlockShape blockShape, int expectedBlockShape)
        {
            var tile = new Tile();

            tile = blockShape.Apply(tile);

            Assert.That(GetBlockShape(tile), Is.EqualTo(expectedBlockShape));
        }
Esempio n. 14
0
        public void Matches(BlockShape blockShape, int actualBlockShape, bool expected)
        {
            var tile = new Tile();

            tile = SetBlockShape(tile, actualBlockShape);

            Assert.That(blockShape.Matches(tile), Is.EqualTo(expected));
        }
Esempio n. 15
0
        public BlockStructure(BlockType type, BlockState state, SoundType soundType = SoundType.DESTROY_STONE)
        {
            this.type  = type;
            this.state = state;
            this.shape = BlockShape.CUBE;

            topUVs     = sideUVs = botUvs = BlockUVs.AIR_UV;
            topTexture = sideTexture = botTexture = TextureTile.AIR;

            this.soundType = soundType;
        }
Esempio n. 16
0
    public Transform GetBlockShape(BlockShape shape)
    {
        Transform t;

        Shapes.TryGetValue(shape, out t);
        if (t == null)
        {
            Shapes.TryGetValue(BlockShape.Cube, out t);
        }
        return(t);
    }
Esempio n. 17
0
        public void SetShape(BlockShape type)
        {
            if (type == BlockShape.Empty)
            {
                throw new System.Exception("Should not be setting BlockShape of empty!");
            }
            int intVal = ((int)type) - 1;

            Debug.Assert(intVal >= 0 && intVal < 4);

            b0 = (byte)((b0 & ~ShapeMask) | (intVal << ShapeShift));
        }
Esempio n. 18
0
    /// <summary>
    /// 获取注册的方块形状
    /// </summary>
    /// <param name="blockShapeEnum"></param>
    /// <returns></returns>
    public BlockShape GetRegisterBlockShape(BlockShapeEnum blockShapeEnum)
    {
        string blockShapeName = blockShapeEnum.GetEnumName();
        //通过反射获取类
        BlockShape blockShape = ReflexUtil.CreateInstance <BlockShape>($"BlockShape{blockShapeName}");

        if (blockShape == null)
        {
            blockShape = new BlockShape();
        }
        return(blockShape);
    }
 void GetSize(float[] vls, float limit)
 {
     blockShape = BlockShape.length;
     if (vls[whichValueSecondHighest] >= limit)
     {
         blockShape = BlockShape.flat;
         if (vls[whichValueThirdHighest] >= limit)
         {
             blockShape = BlockShape.cube;
         }
     }
 }
Esempio n. 20
0
    public void Add(Vector3 position)
    {
        var block = new Block(position, BlockDirection.Zplus, BlockShape.Find("cube"));

        if (block == null)
        {
            return;
        }
        this.selectedBlocks.AddBlock(block);
        this.LastPosition = position;
        this.dirtyMesh    = true;
    }
Esempio n. 21
0
 public BlockShape Join(BlockShape other)
 {
     foreach (var c in other.components)
     {
         Add(c);
     }
     if (other.stat)
     {
         stat = true;
     }
     return(this);
 }
Esempio n. 22
0
        public BlockStructure(BlockType type, TextureTile tile, BlockShape shape, BlockState state, SoundType soundType = SoundType.DESTROY_STONE)
        {
            this.type  = type;
            this.shape = shape;
            this.state = state;

            topTexture = sideTexture = botTexture = tile;
            topUVs     = BlockUVs.GetTileUVs(tile);
            sideUVs    = BlockUVs.GetTileUVs(tile);
            botUvs     = BlockUVs.GetTileUVs(tile);

            this.soundType = soundType;
        }
        public void Main_tile_Get_rightSlope(BlockShape shape, bool value)
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world[0, 0] = new Tile {
                BlockShape = shape
            };

            Assert.Equal(value, Terraria.Main.tile[0, 0].rightSlope());
        }
        public void Main_tile_Get_blockType_Get(BlockShape value)
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world[0, 0] = new Tile {
                BlockShape = value
            };

            Assert.Equal(value, (BlockShape)Terraria.Main.tile[0, 0].blockType());
        }
    public void UpdatePreviewBlock(BlockShape blockShape, BlockDirection blockDirection)
    {
        if (previewObject != null)
        {
            Destroy(previewObject);
        }

        previewObject      = InstantiatePreview(blockShape);
        previewShape       = blockShape;
        previewDirection   = blockDirection;
        transform.rotation = GetBlockDirectionAsQuaternion(blockDirection);

        NetworkHoverPreview();
    }
        public DirtBlock(/*Vector3 centre,*/ BlockShape shape, Direction facing) :
            base(/*centre,*/ shape, MaterialType.Dirt, facing)
        {
            //Note: texture loading should be done centrally
            //Texture2D tex = ScreenManager.GetInstance().ContentManager.Load<Texture2D>("dirt");//dirt2

            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
            {
                BlockTextures.Add(direction, TextureName.Dirt);
            }
            BlockTextures[Direction.Up] = TextureName.Grass;
            SetFaces();
            GetCubeWireframe();
        }
Esempio n. 27
0
    // ガイド用メッシュを出力
    public void WriteToGuideMesh(BlockGroup blockGroup, BlockMeshMerger mesh)
    {
        BlockShape shape = this.shape;

        bool vertexHasWrote = false;

        for (int i = 0; i < 6; i++)
        {
            // 隣のブロックに完全に覆われていたら省略する
            if (this.IsOcculuded(blockGroup, (BlockDirection)i))
            {
                continue;
            }

            // 壁タイプのガイドは限定的にする
            if (shape.wall > 0)
            {
                int index = this.ToLocalDirection(i);
                if (shape.wall >= 1 && (BlockDirection)index == BlockDirection.Zplus)
                {
                }
                else if (shape.wall >= 2 && (BlockDirection)index == BlockDirection.Xplus)
                {
                }
                else
                {
                    continue;
                }
            }

            // 頂点が書き出されていなければここで書き出す
            if (!vertexHasWrote)
            {
                for (int j = 0; j < EditUtil.cubeVertices.Length; j++)
                {
                    mesh.vertexPos.Add(this.position + EditUtil.cubeVertices[j]);
                }
                vertexHasWrote = true;
            }

            int offset = mesh.vertexPos.Count - EditUtil.cubeVertices.Length;
            mesh.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 0]);
            mesh.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 1]);
            mesh.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 2]);
            mesh.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 0]);
            mesh.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 2]);
            mesh.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 3]);
        }
    }
Esempio n. 28
0
        public BlockStructure(BlockType type, TextureTile top, TextureTile side, TextureTile bottom, BlockShape shape, BlockState state, SoundType soundType = SoundType.DESTROY_STONE)
        {
            this.type  = type;
            this.shape = shape;
            this.state = state;

            this.topTexture  = top;
            this.sideTexture = side;
            this.botTexture  = bottom;
            topUVs           = BlockUVs.GetTileUVs(top);
            sideUVs          = BlockUVs.GetTileUVs(side);
            botUvs           = BlockUVs.GetTileUVs(bottom);

            this.soundType = soundType;
        }
Esempio n. 29
0
    int testIterator = 1; //TEST

    void RenderNewShape()
    {
        currentShape = new BlockShape();
        //currentShape = new BlockShape(testIterator); //TEST
        testIterator = testIterator == 1? 2 : 1; //TEST

        foreach (Block block in currentShape.blocks)
        {
            block.gameObjectBlock = Instantiate(currentShape.prefab);
            SetPositionOfBlock(block);
        }

        currentShape.RollAndChangeColor();
        isMainShapeAlive = true;
    }
Esempio n. 30
0
    // 表示用メッシュを出力
    public void WriteToMesh(BlockGroup blockGroup, BlockMeshMerger meshMerger)
    {
        BlockShape shape = this.shape;

        if (shape.autoPlacement)
        {
            // 自動配置ブロックの処理
            WriteToMeshAutoPlacement(blockGroup, meshMerger);
        }
        else
        {
            // 6方向ブロックメッシュ
            WriteToMeshStandard(blockGroup, meshMerger);
        }
    }
Esempio n. 31
0
 public static Gem.Geo.Mesh GetNavigationMesh(BlockShape Shape)
 {
     InitializeStaticData();
     return ShapeTemplates[Shape].NavigationMesh;
 }