public void Init() { //init building pool _gameplayCam = GameObject.FindObjectOfType <GameplayCamera>(); _gameBoard = GameObject.FindObjectOfType <GameBoard>(); _buildHologram = GameObject.Instantiate <BuildHologram>(_buildConfig.buildHologram); GameObject pool = GameObject.FindGameObjectWithTag("ScenePool"); if (!pool) { Debug.LogError("NO SCENE POOL TRANSFORM FOUND IN SCENE"); } _buildingGenerator = new GenericPooler(pool ? pool.transform : null); BuildConfig.BuildableBlueprint[] blueprints = _buildConfig.buildables; for (int i = 0; i < blueprints.Length; i++) { BuildConfig.BuildableBlueprint blueprint = blueprints[i]; _buildingGenerator.InitPool(blueprint.GetKey(), 10, blueprint.prefab); } //UI _buildViewController = new BuildViewController(this, _inventorySystem, _buildConfig); //Build Cam //_buildCam = new BuildCam(_buildConfig,_gameplayCam); //init currenty build type SetBuildType(_buildConfig.startingBuildType); }
private void BuildCoreLoop() { if (_builderRecharging) { return; } int cost = _buildConfig.GetCost(_currentBuildType); bool canBuy = _inventorySystem.CanBuy(Storeable.Type.Coin, cost); //Set our hologram position Ray ray = _gameplayCam.camera.ScreenPointToRay(Input.mousePosition); //IF WE ARE ON THE GAMEBOARD if (Physics.RaycastNonAlloc(ray, _hitResults, 100, _gameBoard.GetLayer()) > 0) { Vector3 hitPoint = _hitResults[0].point; seaLevelPos.x = hitPoint.x; seaLevelPos.z = hitPoint.z; GridPosition gridPos = GetHoloGramPosition(hitPoint); float yOffset = _buildConfig.GetOffset(_currentBuildType); _buildHologram.SetPosition(gridPos, yOffset); Debug.DrawRay(hitPoint, Vector3.up, Color.blue); bool colliding = false; if (_collisionDetectionEnabled) { Collider[] overlap = Physics.OverlapBox(_buildHologram.GetPosition(), (_buildHologram.GetScale() / 2.1f), Quaternion.identity, _buildConfig._collisionLayerMask); colliding = overlap.Length > 0; //if(colliding) //{ // Debug.Log(overlap[0].transform.name); //} } _buildHologram.UpdateHologram(!colliding && canBuy, _buildConfig.hologramData); //TRY TO BUILD if (canBuy && !colliding && Input.GetKey(KeyCode.Mouse1)) { //BUILD! BuildConfig.BuildableBlueprint blueprint = _buildConfig.GetBuildableBlueprint(_currentBuildType); Buildable building = _buildingGenerator.GetPooledObject(blueprint.GetKey()) as Buildable; building.Build(_buildHologram.GetPosition(), blueprint.buildTime, blueprint.fallHeight, blueprint.buildEaseType, blueprint); _builderRecharging = true; BuyBuildable(cost); } } }