예제 #1
0
    void BuildingTapCheck()
    {
        Debug.Log("BuildingTapCheck");
        RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

        if (hit.collider != null && (hit.transform.tag == "Tile" || hit.transform.tag == "Building"))
        {
            Debug.Log(hit.transform.tag);
            //якщо відкрито вікно оновлення - закриваєм його
            if (upgradingWindow.selectedBuilding)
            {
                /*if (hit.collider != null && hit.transform.tag == "Building")
                 * {
                 *  var building = hit.transform.GetComponent<Building>();
                 *  if (upgradingWindow.selectedBuilding == building)
                 *  {
                 *      if (!(building is HumanInputer))
                 *      {
                 *          WindowManager.Instance.GetWindow<WindowProductCreation>().Open(building);
                 *          WindowManager.Instance.GetWindow<GUI>().Close(false);
                 *          upgradingWindow.SetSelectedBuilding(null);
                 *      }
                 *  }
                 * }*/
                upgradingWindow.SetSelectedBuilding(null);
            }
            if (creatingWindow.selectedBuilding)
            {
                Point point = CoordinateConvertor.IsoToSimple(hit.point);
                creatingWindow.SetPosition(CoordinateConvertor.SimpleToIso(point));
            }
        }
        // якщо начого не строїмо
        if (!creatingWindow.selectedBuilding)
        {
            // і натискаєм на побудований будинок
            if (hit.collider != null && hit.transform.tag == "Building")
            {
                var building = hit.transform.GetComponent <Building>();
                upgradingWindow.SetSelectedBuilding(building);
                Point point = CoordinateConvertor.IsoToSimple(building.transform.position);
                upgradingWindow.SetPosition(CoordinateConvertor.SimpleToIso(point));
            }
        }
    }