Siento que este código esta desordenado, que tiene varias cosas que se pueden simplificar y que su lectura es dificil, podrías mejorarlo?

using System.Collections.Generic;
using Cards;
using Game;
using Game.Systems;
using Game.Systems.Buildings;
using TGS;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;

public class ObjectPlacer : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    [SerializeField] private GameObject objectPrefab;
    [SerializeField] private GameObject smokeParticleSystem;
    [SerializeField] private GameObject grid;
    [SerializeField] private LayerMask layerMaskTerrain;
    [SerializeField] private LayerMask layerMaskBuildings;
    [SerializeField] private GridObjectRelation gridObjectRelation;

    private bool isDragging = false;
    private GameObject instantiatedObject;
    private bool objectPlaced = true;
    private Vector3 hitPosition;
    private TerrainGridSystem tgs;
    private CardBase currentCard;
    private bool buttonUp;
    private float currentTimeScale;

    private void Start()
    {
        tgs = TerrainGridSystem.instance;
    }

    public void Setup(GameObject prefab, CardBase card)
    {
        this.objectPrefab = prefab;
        this.currentCard = card;
        objectPlaced = false;
        
        if (gridObjectRelation.BuildingTexture.ContainsKey(objectPrefab))
        {
            tgs.gridMask = gridObjectRelation.BuildingTexture[objectPrefab];
        }
        else
        {
            tgs.gridMask = gridObjectRelation.DefaultTexture;
        }
        
        tgs.Redraw();
        
        GameManager.Instance.CardSpaceEnablerDisabler.EnableCardBuildingSpace(false);
        currentTimeScale = GameManager.Instance.TimeScaleManager.GetCurrentTimeScale();
        GameManager.Instance.TimeScaleManager.Pause();
    }

    private void Update()
    {
        if (!objectPlaced)
        {
            PlaceObject();
        }
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        isDragging = true;
    }

    public void OnDrag(PointerEventData eventData) { }

    private void PlaceObject()
    {
        if (!buttonUp)
        {
            buttonUp = !Input.GetMouseButton(0);
            return;
        }

        if (RaycastHelper.TryGetTerrainHit(out RaycastHit hit, layerMaskTerrain))
        {
            HandleRaycastHit(hit);
        }
    }

    private void HandleRaycastHit(RaycastHit hit)
    {
        tgs.showCells = true;

        Cell cell = tgs.CellGetAtPosition(hit.point, true);
        
        if (instantiatedObject == null)
        {
            instantiatedObject = Instantiate(objectPrefab);
        }

        Vector3 position = GetPlacementPosition(hit, cell);
        bool allAvailable, noCollisions;
        UpdatePlacerHelperState(out allAvailable, out noCollisions);

        instantiatedObject.transform.position = new Vector3(position.x, 0, position.z);
        hitPosition = hit.point;

        if (allAvailable && noCollisions)
        {
            FinalizePlacement();
        }

        if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Escape))
        {
            CancelPlacement();
        }
    }

    private Vector3 GetPlacementPosition(RaycastHit hit, Cell cell)
    {
        return cell == null ? tgs.CellGetNearestAtPosition(hit.point) : tgs.CellGetPosition(cell);
    }

    private void UpdatePlacerHelperState(out bool allAvailable, out bool noCollisions)
    {
        PlacerHelper placerHelper = instantiatedObject.GetComponent<PlacerHelper>();
        
        Bounds boundsColliderBounds = instantiatedObject.GetComponent<BuildingBase>().boundsCollider.bounds;
        List<int> objectIndices = new List<int>();
        
        var corners = GetGlobalBoundsCorners(boundsColliderBounds, transform);

        bool allCornersInArea = true;
        
        foreach (var corner in corners)
        {
            if (!tgs.Contains(corner))
            {
                allCornersInArea = false;
            }
        }

        tgs.CellGetInArea(boundsColliderBounds, objectIndices);
        
        allAvailable = AreAllCellsAvailable(objectIndices);
        noCollisions = allAvailable && CheckNoCollisions(objectIndices);

        if (!allCornersInArea) allAvailable = false;

        if (allAvailable && noCollisions)
        {
            placerHelper.EnableCorrectArea();
        }
        else
        {
            placerHelper.DisableCorrectArea();
        }
    }
    
    Vector3[] GetGlobalBoundsCorners(Bounds bounds, Transform transform)
    {
        Vector3[] corners = new Vector3[8];
        
        Vector3 min = bounds.min;
        Vector3 max = bounds.max;

        // Calcular las esquinas del Bounds en espacio local
        corners[0] = new Vector3(min.x, min.y, min.z); // Inferior izquierda delantera
        corners[1] = new Vector3(max.x, min.y, min.z); // Inferior derecha delantera
        corners[2] = new Vector3(min.x, max.y, min.z); // Superior izquierda delantera
        corners[3] = new Vector3(max.x, max.y, min.z); // Superior derecha delantera
        corners[4] = new Vector3(min.x, min.y, max.z); // Inferior izquierda trasera
        corners[5] = new Vector3(max.x, min.y, max.z); // Inferior derecha trasera
        corners[6] = new Vector3(min.x, max.y, max.z); // Superior izquierda trasera
        corners[7] = new Vector3(max.x, max.y, max.z); // Superior derecha trasera

        // Convertir a coordenadas globales
        for (int i = 0; i < corners.Length; i++)
        {
            corners[i] = transform.TransformPoint(corners[i]);
        }

        return corners;
    }

    private bool AreAllCellsAvailable(List<int> objectIndices)
    {
        foreach (var index in objectIndices)
        {
            if (!tgs.cells[index].visible)
            {
                return false;
            }
        }
        return true;
    }

    private bool CheckNoCollisions(List<int> objectIndices)
    {
        BuildingBase building = instantiatedObject.GetComponent<BuildingBase>();
        Collider[] colliders = Physics.OverlapBox(building.pivot.position, building.boundsCollider.bounds.extents, building.transform.rotation, layerMaskBuildings);

        foreach (var collider in colliders)
        {
            if (collider.GetComponentInParent<BuildingBase>() != building)
            {
                return false;
            }
        }
        return true;
    }

    private void FinalizePlacement()
    {
        if (Input.GetMouseButtonDown(0))
        {
            PlacerHelper placerHelper = instantiatedObject.GetComponent<PlacerHelper>();
            placerHelper.EnableSoil();

            objectPlaced = true;
            instantiatedObject.GetComponent<BuildingBase>().Init();
            instantiatedObject = null;

            BuildingCard buildingCard = (BuildingCard)currentCard;
            
            GameManager.Instance.CardSelector.CardPlacedOnBoard(buildingCard.id);

            tgs.showCells = false;
            UpdateResources(buildingCard);
            Destroy(currentCard);

            GameManager.Instance.CardSpaceEnablerDisabler.EnableCardBuildingSpace(true);
            GameManager.Instance.DeckController.CardUsed();
            GameManager.Instance.TimeScaleManager.SetTimeScale(currentTimeScale);
        }
    }

    private void UpdateResources(BuildingCard buildingCard)
    {
        GameManager.Instance.StatsManager.Gold -= buildingCard.gold;
        GameManager.Instance.StatsManager.Stone -= buildingCard.stone;
        GameManager.Instance.StatsManager.Wood -= buildingCard.wood;
    }

    private void CancelPlacement()
    {
        currentCard.gameObject.SetActive(true);
        Transform drawTransform = GameManager.Instance.DeckController.handController.drawTransform;
        currentCard.gameObject.GetComponent<RectTransform>().position = drawTransform.position;
        currentCard.gameObject.GetComponent<RectTransform>().rotation = Quaternion.identity;

        BuildingCard buildingCard = (BuildingCard)currentCard;

        if (buildingCard.turn == GameManager.Instance.DeckController.turn)
        {
            GameManager.Instance.DeckController.handController.AddCardToHand(currentCard);
        }

        Destroy(instantiatedObject);
        instantiatedObject = null;
        objectPlaced = true;
        
        GameManager.Instance.CardSpaceEnablerDisabler.EnableCardBuildingSpace(true);
        GameManager.Instance.TimeScaleManager.SetTimeScale(currentTimeScale);
        tgs.showCells = false;
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        isDragging = false;
    }

    private void OnDrawGizmos()
    {
        Gizmos.color = Color.blue;
        Gizmos.DrawWireSphere(hitPosition, 1);
    }
}

public static class RaycastHelper
{
    public static bool TryGetTerrainHit(out RaycastHit hit, LayerMask layerMaskTerrain)
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        return Physics.Raycast(ray, out hit, Mathf.Infinity, layerMaskTerrain);
    }
}