private void GenGeometry()
        {
            Vector3 baseSize;
            Vector3 basePos;

            for (var x = 0; x < _room.Width; x++)
            for (var y = 0; y < _room.Height; y++)
            for (var z = 0; z < _room.Depth; z++)
            {
                var side = _room.roomBuffer[x, y, z];
                baseSize = Vector3.one*scale;
                basePos = new Vector3(x, y, z) *scale;

                var posIntVector = basePos.ToIntVector();
                if (posIntVector.Equals(_room.entryPoint))
                {
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = basePos;
                    geo.transform.localScale = baseSize*0.5f;
                    geo.GetComponent<MeshRenderer>().material.color = Color.red;
                }
                else if (posIntVector.Equals(_room.door))
                {
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = basePos;
                    geo.transform.localScale = baseSize*0.5f;
                    geo.GetComponent<MeshRenderer>().material.color = Color.green;
                }

                if ((side & Sides.Top) > 0)
                {
                    var pos = basePos + Vector3.up*0.5f;
                    var size = baseSize.ScaleBy(1, 0.1f, 1);
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = pos;
                    geo.transform.localScale = size;
                }

                if ((side & Sides.Bottom) > 0)
                {
                    var pos = basePos - Vector3.up*0.5f;
                    var size = baseSize.ScaleBy(1, 0.1f, 1);
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = pos;
                    geo.transform.localScale = size;
                }

                if ((side & Sides.Left) > 0)
                {
                    var pos = basePos + Vector3.left*0.5f;
                    var size = baseSize.ScaleBy(0.1f, 1, 1);
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = pos;
                    geo.transform.localScale = size;
                }

                if ((side & Sides.Right) > 0)
                {
                    var pos = basePos + Vector3.right*0.5f;
                    var size = baseSize.ScaleBy(0.1f, 1, 1);
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = pos;
                    geo.transform.localScale = size;
                }

                if ((side & Sides.Front) > 0)
                {
                    var pos = basePos + Vector3.forward*0.5f;
                    var size = baseSize.ScaleBy(1, 1, 0.1f);
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = pos;
                    geo.transform.localScale = size;
                }

                if ((side & Sides.Rear) > 0)
                {
                    var pos = basePos - Vector3.forward*0.5f;
                    var size = baseSize.ScaleBy(1, 1, 0.1f);
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = pos;
                    geo.transform.localScale = size;
                }

                if (side == Sides.None)
                {
                    var geo = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    geo.transform.position = basePos;
                    geo.transform.localScale = baseSize;
                    geo.GetComponent<MeshRenderer>().material.color = Color.yellow;
                }
            }
        }
        private void GenGeometry()
        {
            Vector3 baseSize;
            Vector3 pos;

            for (var x = 0; x < _room.Width; x++)
            for (var y = 0; y < _room.Height; y++)
            for (var z = 0; z < _room.Depth; z++)
            {
                var side = _room.roomBuffer[x, y, z];
                baseSize = Vector3.one;
                pos = new Vector3(x, y, z);

                var posIntVector = pos.ToIntVector();
                if (posIntVector.Equals(_room.entryPoint))
                {
                    var entryNode = entry.Instantiate();
                    entryNode.transform.parent = transform;
                    entryNode.transform.localPosition = new Vector3 (pos.x,pos.y-.15f,pos.z);
                    Destroy(entryNode.GetComponent<Collider>());
                        }
                        else if (posIntVector.Equals(_room.door))
                        {
                            var exitNode = exit.InstantiateToParentLocal(transform);
                            exitNode.transform.localPosition = pos;

                            if ((side & Sides.Top) > 0)
                            {
                                exitNode.transform.localEulerAngles = Vector3.right*180;
                            }
                            if ((side & Sides.Left) > 0)
                            {
                                exitNode.transform.localEulerAngles = Vector3.forward*-90;
                            }
                            if ((side & Sides.Right) > 0)
                            {
                                exitNode.transform.localEulerAngles = Vector3.forward*90;
                            }
                            if ((side & Sides.Front) > 0)
                            {
                                exitNode.transform.localEulerAngles = Vector3.right*-90;
                            }
                            if ((side & Sides.Rear) > 0)
                            {
                                exitNode.transform.localEulerAngles = Vector3.right * 90;
                            }
                        }

                        if (x == 0)
                        {
                            if (side == Sides.None)
                    {
                        var geo = spikesRight.InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos + Vector3.left;
                    }
                }
                if (x == _room.Width - 1)
                {
                     if (side == Sides.None)
                    {
                        var geo = spikesLeft.InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos + Vector3.right;
                    }
                }

                if (y == 0)
                {
                    if (side == Sides.None)
                    {
                        var geo = spikesTop.InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos + Vector3.down;
                    }
                }
                if (y == _room.Height - 1)
                {
                    if (side == Sides.None)
                    {
                        var geo = spikesBottom.InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos + Vector3.up;
                    }
                }

                if (z == 0)
                {
                    if (side == Sides.None)
                    {
                        var geo = spikesFront.InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos + Vector3.back;
                    }
                }
                if (z == _room.Depth - 1)
                {
                    if (side == Sides.None)
                    {
                        var geo = spikesBack.InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos + Vector3.forward;
                    }
                }

                if ((side & Sides.Top) > 0)
                {
                    var next = y < _room.Height - 1 ? _room.roomBuffer[x, y + 1, z] : Sides.None;
                    if ((next & Sides.Bottom) == 0)
                    {
                        var geo = topSideWalls.SelectRandom().InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos;
                    }
                    
                    if (next != Sides.None && (side & Sides.Bottom) == 0)
                    {
                        var localPosition = pos + Vector3.up;
                        var intVector = localPosition.ToIntVector();
                        if (!intVector.Equals(_room.door) && !intVector.Equals(_room.entryPoint))
                        {
                            var spikeGeo = spikesBottom.InstantiateToParentLocal(transform);
                            spikeGeo.transform.localPosition = localPosition;
                        }
                    }
                    //_geoWalls.Add(geo);
                }

                if ((side & Sides.Bottom) > 0)
                {
                    var geo = bottomSideWalls.SelectRandom().InstantiateToParentLocal(transform);
                    geo.transform.localPosition = pos;

                    var next = y > 0 ? _room.roomBuffer[x, y - 1, z] : Sides.None;
                    if (next != Sides.None && (side & Sides.Top) == 0)
                    {
                        var localPosition = pos + Vector3.down;
                        var intVector = localPosition.ToIntVector();
                        if (!intVector.Equals(_room.door) && !intVector.Equals(_room.entryPoint))
                        {
                            var rearGeo = spikesTop.InstantiateToParentLocal(transform);
                            rearGeo.transform.localPosition = localPosition;
                        }
                    }
                    _geoWalls.Add(geo);
                        }

                if ((side & Sides.Left) > 0)
                {
                    var geo = leftSideWalls.SelectRandom().InstantiateToParentLocal(transform);
                    geo.transform.localPosition = pos;

                    var next = x > 0 ? _room.roomBuffer[x - 1, y, z] : Sides.None;
                    if (next != Sides.None && (side & Sides.Right) == 0)
                    {
                        var localPosition = pos + Vector3.left;
                        var intVector = localPosition.ToIntVector();
                        if (!intVector.Equals(_room.door) && !intVector.Equals(_room.entryPoint))
                        {
                            var rearGeo = spikesRight.InstantiateToParentLocal(transform);
                            rearGeo.transform.localPosition = localPosition;
                        }
                    }
                }

                if ((side & Sides.Right) > 0)
                {
                    var next = x < _room.Width - 1 ? _room.roomBuffer[x + 1, y, z] : Sides.None;
                    if ((next & Sides.Left) == 0)
                    {
                        var geo = rightSideWalls.SelectRandom().InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos;
                    }

                    if (next != Sides.None && (side & Sides.Left) == 0)
                    {
                        var localPosition = pos + Vector3.right;
                        var intVector = localPosition.ToIntVector();
                        if (!intVector.Equals(_room.door) && !intVector.Equals(_room.entryPoint))
                        {
                            var rearGeo = spikesLeft.InstantiateToParentLocal(transform);
                            rearGeo.transform.localPosition = localPosition;
                        }
                    }
                }

                if ((side & Sides.Front) > 0)
                {
                    var next = z < _room.Depth - 1 ? _room.roomBuffer[x, y, z + 1] : Sides.None;

                    if ((next & Sides.Rear) == 0)
                    {
                        var geo = frontSideWalls.SelectRandom().InstantiateToParentLocal(transform);
                        geo.transform.localPosition = pos;
                    }

                    if (next != Sides.None && (side & Sides.Rear) == 0)
                    {
                        var localPosition = pos + Vector3.forward;
                        var intVector = localPosition.ToIntVector();
                        if (!intVector.Equals(_room.door) && !intVector.Equals(_room.entryPoint))
                        {
                            var rearGeo = spikesBack.InstantiateToParentLocal(transform);
                            rearGeo.transform.localPosition = localPosition;
                        }
                    }
                }

                if ((side & Sides.Rear) > 0)
                {
                   var geo = backSideWalls.SelectRandom().InstantiateToParentLocal(transform);
                    geo.transform.localPosition = pos;

                    var next = z > 0 ? _room.roomBuffer[x, y, z - 1] : Sides.None;
                    if (next != Sides.None && (side & Sides.Front) == 0)
                    {
                        var localPosition = pos + Vector3.back;
                        var intVector = localPosition.ToIntVector();
                        if (!intVector.Equals(_room.door) && !intVector.Equals(_room.entryPoint))
                        {
                            var rearGeo = spikesFront.InstantiateToParentLocal(transform);
                            rearGeo.transform.localPosition = localPosition;
                        }
                    }
                }

                if (side == Sides.None)
                {
                    var geo = acidPieces.SelectRandom().Instantiate();
                    geo.transform.parent = transform;
                    geo.transform.localPosition = pos;
                    geo.transform.localScale = baseSize;
                }
            }
        }
        private void OnDrawGizmos()
        {
            if (_room == null)
                return;

            Vector3 size;
            Vector3 pos;

            Gizmos.color = Color.magenta;

            int itemIndex = -1;
            for (int index = 0; index < _room.solutionPath.Count; index++)
            {
                var int3 = _room.solutionPath[index];
                itemIndex++;

                if (itemIndex > 0)
                {
                    Gizmos.DrawLine(_room.solutionPath[itemIndex - 1].ToV3(), int3.ToV3());
                }
            }

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        var side = _room.roomBuffer[x, y, z];
                        size = Vector3.one*scale*-1;
                        pos = new Vector3(x, y, z)*scale;

                        var posIntVector = pos.ToIntVector();
                        if (posIntVector.Equals(_room.entryPoint))
                        {
                            Gizmos.color = _startColor;
                            Gizmos.DrawCube(pos, size);
                        }
                        else if (posIntVector.Equals(_room.door))
                        {
                            Gizmos.color = _endColor;
                            Gizmos.DrawCube(pos, size);
                        }
                        /*
                            if ((side & Sides.Top) > 0)
                            {
                                var pos = pos + Vector3.up*0.5f;
                                var size = size.ScaleBy(1, 0.1f, 1);

                                Gizmos.color = _pathColor;
                                Gizmos.DrawCube(pos, size);
                            }

                            if ((side & Sides.Bottom) > 0)
                            {
                                var pos = pos + Vector3.up * 0.5f;
                                var size = size.ScaleBy(1, 0.1f, 1);

                                Gizmos.color = _pathColor;
                                Gizmos.DrawCube(pos, size);
                            }

                            if ((side & Sides.Left) > 0)
                            {
                                var pos = pos + Vector3.left * 0.5f;
                                var size = size.ScaleBy(0.1f, 1, 1);

                                Gizmos.color = _pathColor;
                                Gizmos.DrawCube(pos, size);
                            }

                            if ((side & Sides.Right) > 0)
                            {
                                var pos = pos + Vector3.right * 0.5f;
                                var size = size.ScaleBy(0.1f, 1, 1);

                                Gizmos.color = _pathColor;
                                Gizmos.DrawCube(pos, size);
                            }

                            if ((side & Sides.Front) > 0)
                            {
                                var pos = Vector3.forward * 0.5f;
                                var size = size.ScaleBy(1, 1, 0.1f);

                                Gizmos.color = _pathColor;
                                Gizmos.DrawCube(pos, size);
                            }

                            if ((side & Sides.Rear) > 0)
                            {
                                var pos = pos + Vector3.forward * 0.5f;
                                var size = size.ScaleBy(1, 1, 0.1f);

                                Gizmos.color = _pathColor;
                                Gizmos.DrawCube(pos, size);
                            }
                        if (side == Sides.None)
                        {
                            Gizmos.color = _wireColor;
                            Gizmos.DrawWireCube(pos, size);
                        }
                        */
                    }
                }
            }
        }