Skip to content

Instantly share code, notes, and snippets.

@ekhart
Created June 22, 2021 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekhart/9f859ffdebfb7bdabee55bd4936716dc to your computer and use it in GitHub Desktop.
Save ekhart/9f859ffdebfb7bdabee55bd4936716dc to your computer and use it in GitHub Desktop.
<!-- za pomocą editor-extension-mode="False" dajemy znać, że tego widoku używamy w runtimie gry -->
<ui:UXML xmlns:ui="UnityEngine.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<!-- podciągamy style zdefiniowane w pliku Test.uss -->
<Style src="/Assets/UI/Uss/Styles.uss" />
<!-- poniżej definiujemy własny bardziej skomplikowany element znajdujący się w innym pliku .uxml -->
<ui:Template name="character-template" src="CharacterTemplate.uxml" />
<!-- pełna klasyfikacja klasy C# (włącznie z namespace'em) -->
<Project.Views.CharacterElement>
<!-- możemy też nadpisywać domyślne stylowanie za pomocą atrybutu style -->
<ui:Label name="main-label" text="Label" class="one-third-width dialog-font" style="-unity-text-align: middle-center;" />
<!-- VisualElement to element bazowy ~ odpowiednik div w HTML -->
<ui:VisualElement class="one-third-width" />
<ui:Button name="close-button" label="Name" text="test" />
<!-- class to wymyślona przez nas nazwa używana jako .character-field w .uss -->
<!-- aby móc użyć zarezerwowanych przez definicję XML znaków np. < > musimy użyć ciągów specjalnych np. &lt; == < -->
<ui:TextField name="name-text" label="&gt; Name" text="test" readonly="true" class="character-field one-fifth-width" />
<!-- name to identyfikator elementu - czyli w .uss będzie to #name-text -->
<ui:SliderInt name="health-slider" label="Health" show-input-field="true" class="character-field" />
<!-- jeśli lista nie wyświetla nam się - to znaczy, że może nie mieć ustawionej wysokości - trzeba na to zwrócić uwagę -->
<!-- stylowanie możemy również zapisywać w .uxml jako atrybut style elementu - acz lepiej to przenieść potem do .uss -->
<ui:VisualElement style="height: 40%; width: 33%;">
<!-- elementy listy również muszą mieć ustawioną poprawną wysokość (item-height) - domyślnie (bez tego atrybutu) to 30px -->
<ui:ListView focusable="true" item-height="20" class="full-height" />
</ui:VisualElement>
<!-- konkretne instancja customowego elementu -->
<ui:Instance template="character-template" name="first-person" />
<ui:Instance template="character-template" name="second-person" class="half-width">
<!-- nadpisywanie atrybutów w instancji szablonu -->
<AttributeOverrides element-name="person-name" text="Alice" tooltip="Tooltip 1" />
</ui:Instance>
</Project.Views.CharacterElement>
</ui:UXML>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment