public void SelectTile(TaskableBase tile)
    {
        DeselectTile();

        selectedObject = tile;
        selectedIcon.SetActive(true);
        selectedIcon.transform.parent   = selectedObject.transform;
        selectedIcon.transform.position = selectedObject.transform.position;

        BuildingBase buildingObject = tile.GetComponent <BuildingBase>();
        WallBase     wallObject     = tile.GetComponent <WallBase>();
        HaulableBase haulObject     = tile.GetComponent <HaulableBase>();

        if (buildingObject)
        {
            if (buildingObject.currentTask)
            {
                taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                taskActionBarInstance.Setup(buildingObject);
            }
            else
            {
                buildingActionBarInstance = Instantiate(buildingActionBarPrefab, transform);
                buildingActionBarInstance.Setup(buildingObject);

                FactoryBase factoryObject = buildingObject.GetComponent <FactoryBase>();
                if (factoryObject)
                {
                    factoryActionBarInstance = Instantiate(factoryActionBarPrefab, transform);
                    factoryActionBarInstance.Setup(factoryObject);
                }
            }
        }
        else if (wallObject)
        {
            if (wallObject.currentTask)
            {
                taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                taskActionBarInstance.Setup(wallObject);
            }
            else
            {
                wallActionBarInstance = Instantiate(wallActionBarPrefab, transform);
                wallActionBarInstance.Setup(wallObject);
            }
        }
        else if (haulObject)
        {
            if (haulObject.currentTask)
            {
                taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                taskActionBarInstance.Setup(haulObject);
            }
            else
            {
                haulableActionBarInstance = Instantiate(haulableActionBarPrefab, transform);
                haulableActionBarInstance.Setup(haulObject);
            }
        }
    }
    // Called on events that should refresh the menu
    void RefreshMenus(TaskableBase taskable)
    {
        if (taskable && taskable == selectedObject)
        {
            if (taskable.currentTask)
            {
                // Create or update task action bar
                if (taskActionBarInstance)
                {
                    taskActionBarInstance.RefreshUI();
                }
                else
                {
                    taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                    taskActionBarInstance.Setup(selectedObject);
                }

                // clean up building and wall action bars
                if (buildingActionBarInstance)
                {
                    Destroy(buildingActionBarInstance.gameObject);
                }
                if (wallActionBarInstance)
                {
                    Destroy(wallActionBarInstance.gameObject);
                }
                if (factoryActionBarInstance)
                {
                    Destroy(factoryActionBarInstance.gameObject);
                }
                if (haulableActionBarInstance)
                {
                    Destroy(haulableActionBarInstance.gameObject);
                }
            }
            else
            {
                // Clean up task action bar
                if (taskActionBarInstance)
                {
                    Destroy(taskActionBarInstance.gameObject);
                }

                // refresh building and wall action bars
                BuildingBase buildingObject = taskable.GetComponent <BuildingBase>();
                WallBase     wallObject     = taskable.GetComponent <WallBase>();
                HaulableBase haulObject     = taskable.GetComponent <HaulableBase>();
                if (buildingObject)
                {
                    if (buildingActionBarInstance)
                    {
                        buildingActionBarInstance.RefreshUI();
                    }
                    else
                    {
                        buildingActionBarInstance = Instantiate(buildingActionBarPrefab, transform);
                        buildingActionBarInstance.Setup(buildingObject);
                    }
                    FactoryBase factoryObject = buildingObject.GetComponent <FactoryBase>();
                    if (factoryObject)
                    {
                        if (factoryActionBarInstance)
                        {
                            factoryActionBarInstance.RefreshUI();
                        }
                        else
                        {
                            factoryActionBarInstance = Instantiate(factoryActionBarPrefab, transform);
                            factoryActionBarInstance.Setup(factoryObject);
                        }
                    }
                }
                else if (wallObject)
                {
                    if (wallActionBarInstance)
                    {
                        wallActionBarInstance.RefreshUI();
                    }
                    else
                    {
                        wallActionBarInstance = Instantiate(wallActionBarPrefab, transform);
                        wallActionBarInstance.Setup(wallObject);
                    }
                }
                else if (haulObject)
                {
                    if (haulableActionBarInstance)
                    {
                        haulableActionBarInstance.RefreshUI();
                    }
                    else
                    {
                        haulableActionBarInstance = Instantiate(haulableActionBarPrefab, transform);
                        haulableActionBarInstance.Setup(haulObject);
                    }
                }
            }
        }
    }