コード例 #1
0
ファイル: TilePlacer.cs プロジェクト: ot-vinta/TEC_Game2.0
    private void MoveSprite()
    {
        if (!leftMousePressed)
        {
            Vector3 newPos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3 position = new Vector3(newPos.x, newPos.y, 0);

            MoveToNearestCell(position);
        }

        if (Input.GetMouseButtonDown(0) && !leftMousePressed && !PressedUnderButton())
        {
            Vector3Int pos = map.WorldToCell(sr.transform.position);

            if (Scheme.GetElement(new Vector3Int(pos.x, pos.y, 1)) == null)
            {
                PlaceTile(Vector3.one, 1);
                switch (type)
                {
                case "Resistor":
                    Resistor newRes = new Resistor(new Vector3Int(pos.x, pos.y, 1), (int)angle);
                    if (!String.IsNullOrEmpty(this.label))
                    {
                        newRes.SetName(this.label);
                        newRes.FixLabel();
                        this.label = null;
                    }

                    AddElementToScheme(newRes);
                    break;

                case "Conductor":
                    Conductor newCon = new Conductor(new Vector3Int(pos.x, pos.y, 1), (int)angle);
                    if (!String.IsNullOrEmpty(this.label))
                    {
                        newCon.SetName(this.label);
                        newCon.FixLabel();
                        this.label = null;
                    }

                    AddElementToScheme(newCon);
                    break;

                case "Nullator":
                    AddElementToScheme(new Nullator(new Vector3Int(pos.x, pos.y, 1), (int)angle));
                    isInfinite = false;
                    break;

                case "Norator":
                    AddElementToScheme(new Norator(new Vector3Int(pos.x, pos.y, 1), (int)angle));
                    isInfinite = false;
                    break;
                }
            }

            Destroy(empty);

            if (isInfinite)
            {
                Init(elementTile.name, 0, true);
            }
            else
            {
                GameObject.Find("MainMenu").GetComponent <Map>().enabled = true;
                mapObject.GetComponent <TilePlacer>().enabled            = false;
            }
        }
        else if (Input.GetMouseButtonDown(0) && PressedUnderButton())
        {
            Destroy(empty);
            GameObject.Find("MainMenu").GetComponent <Map>().enabled = true;
            mapObject.GetComponent <TilePlacer>().enabled            = false;
        }
    }