예제 #1
0
        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);
                }
            }
        }