public void Place() { if (!_placingMode) { Debug.LogError("placing mode not enabled"); } if (_materialChanger != null) { _materialChanger.RevertMaterials(); //Destroy(_materialChanger); } //удаляем Rigidbody, если он бы добавлен ранее в StartPlacing() if (!_hasDefaultRigidbody) { var objectRigidbody = PlaceableObjectGrid.GetComponent <Rigidbody>(); Destroy(objectRigidbody); } PlaceableObjectGrid.collider.isTrigger = false;//включаем влияение объекта на физику в игре var objectAI = PlaceableObjectGrid.GetComponent <BaseObjectAI>(); if (objectAI != null) { objectAI.enabled = true; } GameObjectManager.AddToPlayerObjectsList(_player, PlaceableObjectGrid.transform); _player.Money -= PlaceableObjectPrice; //вычесть стоимость объекта из денег игрока PlaceableObjectGrid.DoUpdateGraphs(GridTags.Buildings); //обновление сетки PlaceableObjectGrid.IsGhost = false; RuntimeBatching.DoStaticBatching(PlaceableObjectGrid.transform); PlaceableObjectGrid = null; PlaceableObjectPrice = 0; _player.CursorState = CursorStates.Default; _placingMode = false; }
/// <summary> /// проверяет возможность размещения объекта и также меняет цвет объекта в зависимости - можно или нет размещать объект в текущей позиции /// </summary> public bool PlacementIsAvailable() { if (!_placingMode) { Debug.LogError("Placing mode not enabled"); } bool isAvailable = true; if (PlaceableObjectGrid.CurrentCollisionAmount > 0) { isAvailable = false; } else { Node[] nodes = PlaceableObjectGrid.FindNodes(); foreach (Node node in nodes) { if (node.tags == (int)GridTags.Buildings || !node.walkable) { isAvailable = false; break; } } } if (_materialChanger != null) { if (isAvailable) { _materialChanger.SetAsAvailable(); } else { _materialChanger.SetAsBanned(2.0f); } } return(isAvailable); }