Пример #1
0
    private void ReplaceWithWire(ElementBase element)
    {
        var firstPos  = new Vector3Int(ConnectionsMaker.GetConnectPosition(true, element).x, ConnectionsMaker.GetConnectPosition(true, element).y, Scheme.GetWiresCount() + 2);
        var secondPos = new Vector3Int(ConnectionsMaker.GetConnectPosition(false, element).x, ConnectionsMaker.GetConnectPosition(false, element).y, Scheme.GetWiresCount() + 2);
        var wire      = new Wire(firstPos, secondPos, element.angle);

        Scheme.AddElement(wire);
        var texture = Resources.Load <Texture2D>("Sprites/HalfWireSprite");

        var tile = new Tile
        {
            sprite = Sprite.Create(texture,
                                   new Rect(0, 0, texture.width, texture.height),
                                   new Vector2(0.0f, 0.5f),
                                   100,
                                   1,
                                   SpriteMeshType.Tight,
                                   Vector4.zero
                                   )
        };

        var scale = wire.pivotPosition.x == wire.secondPosition.x
            ? (Math.Abs(wire.pivotPosition.y - wire.secondPosition.y) + 0.01f) / 2
            : (Math.Abs(wire.pivotPosition.x - wire.secondPosition.x) + 0.01f) / 2;
        var rotation = Quaternion.Euler(0, 0, element.angle);

        var m = tile.transform;

        m.SetTRS(Vector3.zero, rotation, new Vector3(scale, 1, 1));
        tile.transform = m;

        tile.name = "Wire";

        map.GetComponent <Tilemap>().SetTile(wire.pivotPosition, tile);
    }
Пример #2
0
    public void BackupElement()
    {
        if (backupElement != null)
        {
            if (backupElement is LabeledChainElement)
            {
                ((LabeledChainElement)backupElement).AddLabel(backupString, backupElement.pivotPosition);
                if (backupElement is Conductor)
                {
                    ((Conductor)backupElement).FixLabel();
                }
                else
                {
                    ((LabeledChainElement)backupElement).FixLabel();
                }
            }
            Scheme.AddElement(backupElement);
            var        angle    = backupElement.angle;
            Quaternion rotation = Quaternion.Euler(0, 0, angle);
            var        m        = backupTile.transform;

            m.SetTRS(Vector3.zero, rotation, Vector3.one);
            backupTile.transform = m;
            map.SetTile(backupPos, backupTile);
            SetMove();
        }
    }
Пример #3
0
        public bool Restart()
        {
            _map = GameObject.Find("Map").GetComponent <Tilemap>();

            if (_backupElements.Count == 0)
            {
                return(false);
            }

            foreach (var element in Scheme.elements.Values)
            {
                _map.SetTile(element.pivotPosition, new Tile());
            }

            Scheme.Clear();

            foreach (var element in _backupElements)
            {
                Scheme.AddElement(element);

                if (element is LabeledChainElement labeledChainElement)
                {
                    labeledChainElement.AddLabel(
                        labeledChainElement.labelStr,
                        labeledChainElement.pivotPosition
                        );
                    switch (labeledChainElement)
                    {
                    case Resistor resistor:
                        resistor.FixLabel();
                        break;

                    case Conductor conductor:
                        conductor.FixLabel();
                        break;
                    }
                }

                _map.SetTile(element.pivotPosition, _backupTiles[element]);
            }

            return(true);
        }
Пример #4
0
 private void AddElementToScheme(ElementBase element)
 {
     Scheme.AddElement(element);
 }