Exemplo n.º 1
0
        public void TryPlaceBuild()
        {
            if (Input.GetButtonDown("RMB"))
            {
                Destroy(obj);
                place = false;
            }
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            Physics.Raycast(ray, out hit, 10000);
            for (int x = 0; x < build.cost.Length; x++)
            {
                if (build.cost[x] == 0 || ResourceManagerPlayerOnly.resourceTypes[x].amount >= build.cost[x])
                {
                    continue;
                }
                Destroy(obj);
                place = false;
            }
            if (!hit.collider)
            {
                return;
            }
            int i = uGrid.DetermineLocation(hit.point, gridI);

            if (!uGrid.IsValidLocation(i))
            {
                return;
            }
            if (uGrid.grids[gridI].points[i].state != 2)
            {
                loc = i;
                obj.transform.position = uGrid.grids[gridI].points[i].loc;
            }
            if (!Input.GetButtonDown("LMB"))
            {
                return;
            }
            try
            {
                Actor.Create <Game.Actors.Buildings.Building>(
                    BuildingHelper.DetermineBuildingType(BuildingHelper.PrefabToType(build.obj)),
                    PlaceProgressBuilding(
                        build,
                        unitSelect.curSelectedS,
                        GameManager.Instance.GuiPlayer.FactionIndex,
                        new Position(loc),
                        obj.transform.rotation,
                        ResourceManagerPlayerOnly),
                    GameManager.Instance.GuiPlayer);
            }
            catch (InvalidOperationException)
            {
                return;
            }
            if (!Input.GetButton("ContinuePlace"))
            {
                Destroy(obj);
                place  = false;
                placed = true;
            }
        }