The Stagecoach service bus makes very poor connections with the ferries, for various historical reasons. You would have to do Citylink or train to Glasgow, then Stagecoach to Ayr, then Stagecoach to Cairnryan. It would also cost double either of the through options below. Totally not worth it.
Cairnryan is a small village- almost nowhere to stay there overnight -one B and B, the hotel the village had has closed for good. Thus you would have to overshoot to stay in Stranraer then have to get back to Cairnryan next morning.
This is very easy to do in the day-
EITHER on a through Sail-Rail ticket- https://www.scotrail.co.uk/tickets/combined-tickets-travel-passes/rail-and-sail#tbi-buy-tickets Book on Scotrail- 0926 from Edinburgh- train to Glasgow Central, train Glasgow Central to Ayr, coach from outside the station which is a dedicated coach for the sailing, £35 all in, including the ferry. At Belfast you have to catch (at separate cost) a dedicated shuttle bus into the city, Get off at the market hall, short walk to Lanyon Place station for an easy connection into the mid evening train to Dublin.
The Belfast to Dublin train costs £12 if booked in advance (see translink below).
OR- Scottish Citylink Coach- three a day at 0600, 1015 and 1415 arrives at Belfast Europa Bus Station 1415, 1830 and 2230 respectively- https://booking.citylink.co.uk/#/results
Cost £33 if booked 3 days ahead, a bit more last minute. That fare is coach to Glasgow Bus Station, Coach Glasgow direct to the Ferry, embark and disembark as foot passengers, and an included shuttle bus (different to the one for rail passengers) takes you to Europa Bus Station. From there all 3 services (even the late night arrival) have a connection on the Translink X1 coach to Dublin Busaras- https://www.translink.co.uk/timetables?LocationId=&Name=X1&LocationType=&TransportMode=Bus&page=1
If booked ahead that coach costs £9.50.
It all works very smoothly and is super easy. Both the through rail and the through coach routes are guaranteed connections.
In my mind the coach is the easy winner for ease of connections, although with a railcard the train route wins on cost at just over £23.
Stena Ferries will tell you that there are through Scotland to Dublin coach fares, except the memo hasn't reached Citylink!!