private void XShrink(Vector3 mouseWorldCoord) { float xBound = _horizontalOrientation == Orientation.EAST ? _maxPlacedX : _minPlacedX; PlacementData placementData = _subPlacerPrefab.toPlace; int placersToRemove = (int)(Mathf.Abs(mouseWorldCoord.x - xBound) / placementData.unitsWidth); for (int i = 1; i <= placersToRemove; i++) { foreach (LinkedList <BuildingPlacer> line in _allPlacers) { if (line.Count != 0)//La première ligne sera dans ce cas de temps à autre, puisque le placeur d'origine n'est pas dans les données de placement multiple { BuildingPlacer toDelete = line.Last.Value; line.RemoveLast(); GameManager.instance.DestroyGameObject(toDelete.gameObject); _placersNber--; } } int placementWidth = _subPlacerPrefab.toPlace.unitsWidth; if (_horizontalOrientation == Orientation.EAST) { _maxPlacedX -= placementWidth; } else if (_horizontalOrientation == Orientation.WEST) { _minPlacedX += placementWidth; } } }
private void ManageXOverflow(Vector3 mouseWorldCoord, string orientation, float xBound) { if (_horizontalOrientation != orientation) { DeletePlacers(); _horizontalOrientation = orientation; } int xMultiplier = _horizontalOrientation == Orientation.EAST ? 1 : -1; int yMultiplier = _verticalOrientation == Orientation.NORTH ? 1 : -1; PlacementData placementData = _subPlacerPrefab.toPlace; int placersToAdd = (int)(Mathf.Abs(mouseWorldCoord.x - xBound) / placementData.unitsWidth); /* * La condition de cette boucle vérifie qu'il faut encore ajouter une colonne * de placeurs et qu'on ne viole pas la limite de placeurs en l'ajoutant. */ for (int i = 1; i <= placersToAdd && _placersNber + _allPlacers.Count < maxPlacersNber; i++) { for (int y = 0; y < _allPlacers.Count; y++) { Vector3 newPosition = new Vector3(xBound + i * xMultiplier * placementData.unitsWidth, _initialPlacementCoord.y + y * yMultiplier * placementData.unitsHeight, _subPlacerPrefab.transform.position.z); BuildingPlacer newPlacer = CreateNewPlacer(newPosition); Enumerable.ElementAt(_allPlacers, y).AddLast(newPlacer); TakePlacerIntoAccount(newPlacer); } } }
private void ManageYOverflow(Vector3 mouseWorldCoord, string orientation, float yBound) { if (_verticalOrientation != orientation) { DeletePlacers(); _verticalOrientation = orientation; } int xMultiplier = _horizontalOrientation == Orientation.EAST ? 1 : -1; int yMultiplier = _verticalOrientation == Orientation.NORTH ? 1 : -1; PlacementData placementData = _subPlacerPrefab.toPlace; int placersToAdd = (int)(Mathf.Abs(mouseWorldCoord.y - yBound) / placementData.unitsHeight); /* * La condition de cette boucle vérifie qu'il faut encore ajouter une ligne * de placeurs et qu'on ne viole pas la limite de placeurs en l'ajoutant. */ for (int i = 1; i <= placersToAdd && _placersNber + _allPlacers.First.Value.Count < maxPlacersNber; i++) { LinkedList <BuildingPlacer> newLine = new LinkedList <BuildingPlacer>(); _allPlacers.AddLast(newLine); for (int x = 0; x <= _allPlacers.First.Value.Count; x++)//<= et pas <, car le placeur de départ occupe une case mais n'est pas compris dans les collections (pou éviter de le supprimer), il faut donc compenser ça ! { Vector3 newPosition = new Vector3(_initialPlacementCoord.x + x * xMultiplier * placementData.unitsWidth, yBound + i * yMultiplier * placementData.unitsHeight, _subPlacerPrefab.transform.position.z); BuildingPlacer newPlacer = CreateNewPlacer(newPosition); newLine.AddLast(newPlacer); TakePlacerIntoAccount(newPlacer); } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 pos = BuildingPlacer.mouseToTile(); //Debug.Log("Tile at: (" + pos.x + "," + pos.y + ") Biome: " + getTile(pos.x, pos.y).getBiome()); } }
void Update() { //if this building is not current building in building placer then turn this building to grey if (BuildingPlacer.GetInstance().getCurrentBuilding() != this.transform) { MarkGrey(); } }
public void StartPlaning(GameObject currentBuildingPlacerGO) { if (currentBuildingPlacer != null) { Destroy(currentBuildingPlacer.gameObject); } currentBuildingPlacer = Instantiate(currentBuildingPlacerGO).GetComponent <BuildingPlacer>(); }
private void Start() { _renderer = GetComponent <Renderer>(); _placer = FindObjectOfType <BuildingPlacer>(); _previousPosition = transform.position; _previousRotation = transform.rotation; _previousLocalScale = transform.localScale; UpdateCells(); }
public void Init( BuildingsTypesList buildingsTypesList, BuildingPlacer buildingPlacer, Canvas canvas ) { _buildingsTypesList = buildingsTypesList; _buildingPlacer = buildingPlacer; _canvas = canvas; }
/** * Set controls */ private void Update() { TutorialUtils.ShowTutorial(TutorialCanvas, Settings); EnvironmentRender.Get().SetSkyBox(); BuildingPlacer.PlaceNewBuildingListener(); MenuController.Get().SetCanvasListener(TutorialCanvas, BuildingPickerCanvas, BuildingNameLabel, ExitCanvasDialog); Movement.SetKeyboard(CameraTransform); Movement.SetMouse(CameraTransform); Movement.SetGamePad(CameraTransform); }
public void OnPointerExit(PointerEventData eventData) { //handle on pinter exit event if (BuildingPlacer.GetInstance().currentSelectedPanelItem != null && BuildingPlacer.GetInstance().hasPlaced) { BuildingPlacer.GetInstance().currentSelectedPanelItem.RemoveBuilding(); //remove a building from currently selected scroll panel item BuildingPlacer.GetInstance().currentSelectedPanelItem = null; BuildingPlacer.GetInstance().pointerInScrollBar = false; } }
void Start() { Vector3 dim = gameObject.GetComponent<Terrain>().terrainData.size; Object[] structure = Resources.LoadAll("wrak_budova",typeof(Object)); if(MapPropertiesHelper.SET.spawn_buildings()){ bp = new BuildingPlacer(structure,gameObject); bp.place_buildings_recursively(); } add_allocator(dim); }
private void constructOnGameStart() { foreach (var building in settings.BuildingsToAdd) { if (building.BuildingPrefab != null) { BuildingPlacer.PlaceInstantly(building.BuildingPrefab, building.TileIDToPlace, building.Direction); } } }
void Update() { UpdateList(); UpdateVisibleButtonCount(); //if buttons exceed the screen or pointer is not inside scroll bar then stop scrolling if ((visibleButtonCount - 1) * buttonDistance < (rightBoundary.anchoredPosition.x - leftBoundary.anchoredPosition.x) || !BuildingPlacer.GetInstance().pointerInScrollBar) { scrollable = false; } else { scrollable = true; } if (scrollable) { scrollPanel.parent.GetComponent <ScrollRect>().horizontal = true; if (!dragging) { //if not dragging, lerp the scroll bar to appropriate position based on the boundaries //if scroll bar dragged such that first scroll bar item crossed left boundary then lerp it back if (scrollPanelItems[0].transform.position.x > leftBoundary.transform.position.x) { scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, leftBoundary.GetComponent <RectTransform>().anchoredPosition.x, Time.deltaTime * 10f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y); } //if scroll bar dragged such that last visible scroll bar item crossed right boundary then lerp it forward if (scrollPanelItems[visibleButtonCount - 1].transform.position.x < rightBoundary.transform.position.x) { scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, rightBoundary.GetComponent <RectTransform>().anchoredPosition.x - buttonDistance * (visibleButtonCount - 1), Time.deltaTime * 10f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y); } } } else { scrollPanel.parent.GetComponent <ScrollRect>().horizontal = false; if (scrollPanelItems.Count != 0) { //if not scrollable and still scroll panel items visible then lerp scroll bar such that first scroll panel item is at start of scroll panel if (scrollPanelItems[0].transform.position.x > leftBoundary.transform.position.x) { scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, leftBoundary.GetComponent <RectTransform>().anchoredPosition.x, Time.deltaTime * 7f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y); } if (scrollPanelItems[0].transform.position.x < leftBoundary.transform.position.x) { scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, leftBoundary.GetComponent <RectTransform>().anchoredPosition.x, Time.deltaTime * 7f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y); } } } }
void OnGUI() { if (IsSelected) { EntityProperties[] entitiesAvailableOnThisUnit = EntitiesHolder.LoadEntitiesAvailableOnId(base.id); for (int i = 0; i < entitiesAvailableOnThisUnit.Length; i++) { EntityProperties current = entitiesAvailableOnThisUnit[i]; if (GUI.Button(new Rect(0, 40 * i, 400, 40), current.Name + ", " + current.Description)) { BuildingPlacer.Create(current.Id); } } } }
void Awake() { if (buildingPlacer == null) { buildingPlacer = GameObject.FindGameObjectWithTag("Manager").GetComponent <BuildingPlacer>(); } else if (buildingPlacer != this) { Destroy(gameObject); } floorMask = LayerMask.GetMask("Floor"); ceilingMask = LayerMask.GetMask("Ceiling"); buildingMask = LayerMask.GetMask("Building"); mainCamera = Camera.main; hasPlaced = true; }
// Start is called before the first frame update void Start() { buildPlacer = FindObjectOfType <BuildingPlacer>(); grid = buildPlacer.GetComponent <GridR>(); request = gameObject.GetComponent <Requester>(); mesh = gameObject.GetComponent <MeshRenderer>(); notConstructed = buildPlacer.notConstructed; finishedConstructing = buildPlacer.finishedConstructing; children = new List <Transform>(); foreach (Transform child in gameObject.transform) { children.Add(child); } changeMesh(notConstructed); RoundManager.OnRoundTick += onTick; //Get a list of the actual physical buildings gameobjects }
private void TakePlacerIntoAccount(BuildingPlacer placer) { Vector3 position = placer.transform.position; _placersNber++; if (position.x > _maxPlacedX) { _maxPlacedX = position.x; } else if (position.x < _minPlacedX) { _minPlacedX = position.x; } if (position.y > _maxPlacedY) { _maxPlacedY = position.y; } else if (position.y < _minPlacedY) { _minPlacedY = position.y; } }
public void OnClick() { BuildingPlacer.StartPlacing(buildingPrefab); }
void Awake () { inst = this; }
public void OnPointerEnter(PointerEventData eventData) { BuildingPlacer.GetInstance().pointerInScrollBar = true; }
public MultiplePlacementData(BuildingPlacer subPlacerPrefab) { _subPlacerPrefab = subPlacerPrefab; }
protected void Awake() { _controlledPlacer = GetComponent <BuildingPlacer>(); _multiplePlacementData = new MultiplePlacementData(subPlacerPrefab); }
/// <summary> /// Add uConstruct demo into the scene. /// </summary> public static void GX_ApplyDemoToSelectedPlayer() { #if UNITY_EDITOR GameObject player = Selection.activeGameObject; if (player == null) { Debug.LogError("No player is chosen, ABORT."); return; } else { try { GameObject demoPlayerPrefab = Resources.Load <GameObject>("Players/DemoPlayer"); if (demoPlayerPrefab != null) { BuildingPlacer placer = player.GetComponent <BuildingPlacer>(); BaseAOIFinder finder = player.GetComponent <BaseAOIFinder>(); BuildingPlacer demoPlacer = demoPlayerPrefab.GetComponent <BuildingPlacer>(); if (demoPlacer == null) { Debug.LogError("Cant find building placer on CubesDemo player, Buildings cannot be automatically assigned"); } if (placer == null) { placer = player.AddComponent <BuildingPlacer>(); } if (finder == null) { finder = player.AddComponent <BaseAOIFinder>(); } if (demoPlacer != null) { placer.buildings = demoPlacer.buildings; placer.playerCamera = player.GetComponentInChildren <Camera>(); } } else { Debug.LogError("Cant find demo player on CubesDemo, Buildings cannot be automatically assigned"); } } catch (Exception) { Debug.LogError("Applying demo scripts failed."); } } Terrain[] terrains = Terrain.activeTerrains; Terrain terrain; BaseSocket socket; for (int i = 0; i < terrains.Length; i++) { terrain = terrains[i]; if (terrain.GetComponent <BaseSocket>() == null) { socket = terrain.gameObject.AddComponent <BaseSocket>(); socket.receiveType = (BuildingType)Enum.Parse(typeof(BuildingType), "Foundation", true); socket.placingType = PlacingRestrictionType.FreelyBased; socket.usePhysics = false; } } if (GameObject.FindObjectOfType <DemoUI>() == null) { GameObject canvas = Resources.Load <GameObject>("Canvas"); var canvasGO = GameObject.Instantiate(canvas); canvasGO.name = canvas.name; // remove the "Clone" thingy from the name } #endif }
void Start() { buildingPlacer = FindObjectOfType <BuildingPlacer>(); }
public void RemoveBuilding() { buildingCount--; //remove building from scroll panel item but add to BuildigPlacer BuildingPlacer.GetInstance().SetCurrentBuilding(buildingPrefab, gameObject); }
private void Awake() { BL = this; Controlls = new InputMaster(); Controlls.Player.PlaceBuilding.performed += _ => PlaceB(); }
// Use this for initialization void Start() { m_BuildingPlacer = FindObjectOfType <BuildingPlacer>(); m_grid = FindObjectOfType <Grid>(); m_placeableBuilding = FindObjectOfType <PlaceableBuilding>(); }
public void OnPointerDown(PointerEventData eventData) { //handle pointer down event on scroll panel item BuildingPlacer.GetInstance().currentSelectedPanelItem = this; }
public Bot() { buildingPlacer = new BuildingPlacer(this); Main = this; }