Esempio n. 1
0
        private bool ValidateStructure()
        {
            EditableStructure.Errors errors = _structure.GetStructureErrors();
            IDictionary <BlockPosition, IPlacedBlock> temp = _structure.GetNotConnectedBlocks();
            bool notConnected = temp != null && temp.Count > 0;

            if (errors == EditableStructure.Errors.None && !notConnected)
            {
                return(true);
            }

            _displayText.text = "Error: " + errors + (notConnected ? ", not connected blocks" : "");
            return(false);
        }
Esempio n. 2
0
        private void Update()
        {
            if (Input.GetButtonDown("Fire1"))
            {
                Place();
            }
            else if (Input.GetButtonDown("Fire2"))
            {
                Delete();
            }

            Rotate(Input.GetAxisRaw("MouseScroll"));
            if (Input.GetButtonDown("Fire3"))
            {
                Switch();
            }

            // ReSharper disable once UnusedVariable
            if (GetSelectedBlock(out GameObject block, out BlockPosition position, out byte rotation))
            {
                if (!position.Equals(_previousPreviewPosition))
                {
                    ShowPreview(position, rotation);
                }
            }
            else
            {
                Destroy(_previewObject);
                _previousPreviewPosition = null;
            }

            if (Input.GetButtonDown("Ability"))
            {
                new Action(() => {
                    EditableStructure.Errors errors = _structure.GetStructureErrors();
                    if (errors != EditableStructure.Errors.None)
                    {
                        Debug.Log("Structure error: " + errors);
                        return;
                    }

                    IDictionary <BlockPosition, IPlacedBlock> notConnected = _structure.GetNotConnectedBlocks();
                    Assert.IsNotNull(notConnected, "The lack of the presence of the Mainframe was not shown among the errors.");
                    if (notConnected.Count != 0)
                    {
                        Debug.Log("Structure error: not connected blocks");
                        return;
                    }

                    BitBuffer someBuffer = new MutableBitBuffer((RealPlacedBlock.SerializedBitsSize
                                                                 * _structure.RealBlockCount + 7) / 8);
                    _structure.Serialize(someBuffer);
                    Debug.Log("Structure: " + string.Join(", ", someBuffer.Array));
                    CompleteStructure complete = CompleteStructure.Create(someBuffer, 1);
                    Assert.IsNotNull(complete, "Own CompleteStructure creation mustn't fail.");

                    complete.transform.position = new Vector3(0, 10, 0);
                    complete.gameObject.AddComponent <LocalBotController>();
                    _camera.gameObject.AddComponent <PlayingCameraController>().Initialize(complete);

                    Destroy(_camera.gameObject.GetComponent <BuildingCameraController>());
                    Destroy(gameObject);

                    CompleteStructure otherStructure = CompleteStructure.Create(ExampleStructure, 2);
                    Assert.IsNotNull(otherStructure, "Other CompleteStructure creation mustn't fail.");
                    otherStructure.transform.position = new Vector3(150, 5, 150);
                }).Invoke();
            }
        }