Beispiel #1
0
        private void ShowPreview(BlockPosition position, byte rotation)
        {
            Destroy(_previewObject);
            _previousPreviewPosition = position;
            BlockInfo info = BlockFactory.GetInfo(BlockFactory.GetType(_blockType));

            Color color;

            if (_structure.CanAddBlock(position, info, rotation))
            {
                color = Color.white;
            }
            else
            {
                if (_structure.IsPositionOccupied(position))
                {
                    return;
                }
                else
                {
                    color = Color.red;
                }
            }

            RealPlacedBlock block;

            if (info is SingleBlockInfo single)
            {
                block = BlockFactory.MakeSinglePlaced(_structure.transform, single, rotation, position);
            }
            else
            {
                // ReSharper disable once UnusedVariable
                block = BlockFactory.MakeMultiPlaced(_structure.transform, (MultiBlockInfo)info, rotation,
                                                     position, out PlacedMultiBlockPart[] parts);
                if (block == null)
                {
                    return;
                }
            }

            _previewObject = block.gameObject;
            _previewObject.gameObject.name = "PreviewBlock";
            BlockUtilities.RemoveCollider(_previewObject, true);

            color.a = 0.5f;
            BlockUtilities.SetColor(_previewObject, color, true);
        }
Beispiel #2
0
        private void ColorNotConnectedBlocks()
        {
            foreach (RealPlacedBlock block in _previousNotConnected)
            {
                BlockUtilities.SetColor(block.gameObject, Color.white, false);
            }
            _previousNotConnected.Clear();

            IDictionary <BlockPosition, IPlacedBlock> notConnected = _structure.GetNotConnectedBlocks();

            if (notConnected == null)
            {
                return;
            }

            foreach (RealPlacedBlock real in notConnected.Values.OfType <RealPlacedBlock>())
            {
                BlockUtilities.SetColor(real.gameObject, Color.red, false);
                _previousNotConnected.Add(real);
            }
        }