How to use different font families for the same unicode block in ucharclases?

I can offer you a “family-aware” switching command.

\documentclass{article}
\usepackage{fontspec}
\usepackage[Sinhala,Latin]{ucharclasses}

\setmainfont{Noto Serif}[NFSSFamily=standardserif]
\setsansfont{Noto Sans}[NFSSFamily=standardsans]

\newfontfamily\sinhalaserif{Noto Serif Sinhala}[
  NFSSFamily=sinhalaserif,
]
\newfontfamily\sinhalasans{Noto Sans Sinhala}[
  NFSSFamily=sinhalasans,
]

\setDefaultTransitions{\switchto{standard}}{}
\setTransitionTo{Sinhala}{\switchto{sinhala}}

\ExplSyntaxOn
\NewDocumentCommand{\switchto}{m}
 {
  \str_case_e:vnF {f@family}
   {
    { standardsans } { \fontfamily{#1sans}\selectfont }
    { sinhalasans } { \fontfamily{#1sans}\selectfont }
   }
   { \fontfamily{#1serif}\selectfont }
 }
\cs_generate_variant:Nn \str_case_e:nnF { v }
\ExplSyntaxOff

\begin{document}

a word මගේ වායුපායානයේ

\textsf{a word  ආඳන් පිරී ඇත.}

\end{document}

enter image description here


Here is another approach, which exploits what xeCJK can do with other languages beyond CJK:

% !TeX program = XeLaTeX
\documentclass{article}
\usepackage[no-math]{xeCJK}% loads fontspec
\xeCJKDeclareCharClass{HangulJamo}{"200D,"0D80 -> "0DFF}
% https://en.wikipedia.org/wiki/Sinhala_(Unicode_block)+ZWJ
% https://en.wikipedia.org/wiki/Zero-width_joiner
% The HangulJamo class has the property that no additional code is inserted
% between characters within this class.
\xeCJKsetup{CJKspace=true}
% Keep spaces between characters.
\xeCJKDeclareCharClass{HalfLeft}{"2018, "201C}
\xeCJKDeclareCharClass{HalfRight}{%
  "00B7, "2019, "201D, "2013, "2014, "2025, "2026, "2027, "2E3A}
% In Unicode, some Latin and CJK punctuation marks share the same code points.
% We make sure that these punctuation marks are the Latin ones.

\setmainfont{NotoSerif-Regular.ttf}
\setsansfont{NotoSans-Regular.ttf}
\setCJKmainfont{NotoSerifSinhala-Regular.ttf}
\setCJKsansfont{NotoSansSinhala-Regular.ttf}

\newcommand\test{%
  My hovercraft is full of eels.\par % ;-)
  මාගේ වායු පා යානයේ ආඳන් පිරී ඇත.\par
}
\begin{document}
\test
\medskip
{\sffamily
\test}
\end{document}

example

Drawbacks? Well, the documentation of xeCJK is only available in Chinese…