Пример #1
0
        public virtual VisualElement GetTemplate(string templateFilename, bool shouldThrowException = true)
        {
            m_NestedGetTemplateDepth++;
            var fullTemplatePath = k_TemplateRoot + templateFilename;
            var visualTreeAsset  = m_ApplicationProxy.Load <VisualTreeAsset>(fullTemplatePath);
            var result           = visualTreeAsset?.Instantiate();

            m_NestedGetTemplateDepth--;

            // A `GetTemplate` call could implicitly call itself again, creating nested GetTemplate calls.
            // We only want to call localization in the top level `GetTemplate` call to avoid multiple localization attempts on the same element.
            if (m_NestedGetTemplateDepth == 0)
            {
                LocalizeVisualElement(result, L10n.Tr);
            }

            if (result == null && shouldThrowException)
            {
                throw new ResourceLoaderException($"Unable to load resource {templateFilename}");
            }
            return(result);
        }