/** * IDragAndDropInterface method implementation for PlacementValid * * Determines if a location is valid for placement * * This is the outwardly-facing function, which will take care of any * generic actions common to all towers and then rely on each class's * TowerPlacementValid implementation for actually determining if the * location is valid. */ public bool PlacementValid(RaycastHit primaryHitInfo, List <RaycastHit> secondaryHitInfo) { bool placementValid = TowerPlacementValid(primaryHitInfo, secondaryHitInfo); if (placementValid) { rangeEffect.UpdateEffect(TowerRangeEffect.EffectState.Valid); } else { rangeEffect.UpdateEffect(TowerRangeEffect.EffectState.Invalid); } return(placementValid); }
/** * Check for a tower and apply the effects that selecting a tower should trigger * * @param hitObject GameObject The object that the raycast hit * @param isLeftMouse Bool dictating if the left mouse button was clicked or not */ private void CheckForTower(GameObject hitObject, bool isLeftMouse) { // Flag to tell us later if we actually hit a tower bool hitTower = false; // Attempt to get the TowerBase component from the object if it has one TowerBase towerTemp = hitObject.GetComponent <TowerBase>(); // Make sure that we found a TowerBase component that is active if (towerTemp != null && towerTemp.isActiveAndEnabled) { // Set flag so we know later that we hit a tower hitTower = true; // Turn off previous effect if there was one if (selectedRangeEffect != null && selectedRangeEffect != hitObject.GetComponent <TowerRangeEffect>()) { // Turn the neutral range effect off selectedRangeEffect.UpdateEffect(TowerRangeEffect.EffectState.Off); } // Set as selected tower selectedTower = towerTemp; // Get the range effect component and update it to show the neutral tower range effect selectedRangeEffect = hitObject.GetComponent <TowerRangeEffect>(); selectedRangeEffect.UpdateEffect(selectedRangeEffect.State == TowerRangeEffect.EffectState.Off ? TowerRangeEffect.EffectState.Neutral : TowerRangeEffect.EffectState.Off); } // If we did not hit a tower, remove selected tower if (!hitTower) { // Remove reference if (selectedTower != null) { selectedTower = null; } // Remove references to other components if (selectedRangeEffect != null) { // Turn the neutral range effect off selectedRangeEffect.UpdateEffect(TowerRangeEffect.EffectState.Off); selectedRangeEffect = null; } } }