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);
        }