Reference other files from UXML
Understand the src and the path attributes used to reference other files from UXML.
阅读时间1 分钟最后更新于 23 天前
In a UXML file, you can use the and the elements to reference other UXML or USS files. The two elements both accept either an attribute or a attribute.
<Template><Style>srcpathThe src
attribute
srcThis is the recommended way to reference other files.
Use the following syntax for the attribute:
srcsrc="<path-to-file>/<file-name-with-extension>"
Any errors during import, such as missing files, trigger an error message.
You can use a relative or an absolute path:
- Absolute paths start from the project's folder and begin with a
Assetsor/. For example,project://database/or/Assets/myFolder/myFile.uss.project://database/Assets/myFolder/myFile.uss - Relative paths start from the current file and exclude the . For example,
/.../myFolder/myFile.uss
The path
attribute
pathThe attribute uses the Unity Resources mechanisms, but doesn't offer error reporting at import time and doesn't allow relative paths. This is a legacy way to reference other files and is not recommended. Use it only if you need to reference files that can only be loaded from the folder.
pathResourcesThe attribute accepts files located in either the folder or the folder, with the following rules:
pathResourcesEditor Default Resources- If the file is in the folder, don't include the file extension. For example, write
Resourcesfor a file located atpath="template".Assets/Resources/template.uxml - If the file is in the folder, you must include the file extension. For example, write
Editor Default Resourcesfor a file located atpath="template.uxml".Assets/Editor Default Resources/template.uxml