Esempio n. 1
0
    private List <FFS_struct> CheckDirections(FFS_struct parent)
    {
        List <FFS_struct> output = new List <FFS_struct>();

        foreach (var dir in BlockProperties.DirectionVector)
        {
            FFS_struct neighbor = new FFS_struct();
            Vector3Int pos      = parent.Block.Position + dir;
            neighbor.Block          = World.GetBlock(pos);
            neighbor.Block.Position = pos;
            if (neighbor.Block.Data.IsSolid)
            {
                if (neighbor.Block.SearchMarker != _searchCount)
                {
                    neighbor.Block.SearchMarker = _searchCount;
                    neighbor.Object             = Instantiate(PhysicsPrefab, neighbor.Block.Position, Quaternion.identity);
                    neighbor.Object.GetComponent <Rigidbody>().Sleep();
                    _physicsObjects.Add(neighbor.Object);
                    output.Add(neighbor);
                    if (parent.Block.Data.IsSolid)
                    {
                        var fj = neighbor.Object.AddComponent <FixedJoint>();
                        if (neighbor.Block.Strength < parent.Block.Strength)
                        {
                            fj.breakForce  = neighbor.Block.Strength;
                            fj.breakTorque = neighbor.Block.Strength;
                        }
                        else
                        {
                            fj.breakForce  = parent.Block.Strength;
                            fj.breakTorque = parent.Block.Strength;
                        }
                        fj.connectedBody = parent.Object.GetComponent <Rigidbody>();
                    }
                }
            }
        }
        return(output);
    }