text 在Unity2019.1.9f1的UIElementの生成时の初期コード

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 在Unity2019.1.9f1的UIElementの生成时の初期コード相关的知识,希望对你有一定的参考价值。

using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;


public class Helloworld : EditorWindow
{
    [MenuItem("Window/UIElements/Helloworld")]
    public static void ShowExample()
    {
        Helloworld wnd = GetWindow<Helloworld>();
        wnd.titleContent = new GUIContent("Helloworld");
    }

    public void OnEnable()
    {
        // Each editor window contains a root VisualElement object
        VisualElement root = rootVisualElement;

        // VisualElements objects can contain other VisualElement following a tree hierarchy.
        VisualElement label = new Label("Hello World! From C#");
        root.Add(label);

        // Import UXML
        var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/Helloworld.uxml");
        VisualElement labelFromUXML = visualTree.CloneTree();
        root.Add(labelFromUXML);

        // A stylesheet can be added to a VisualElement.
        // The style will be applied to the VisualElement and all of its children.
        var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Editor/Helloworld.uss");
        VisualElement labelWithStyle = new Label("Hello World! With Style");
        labelWithStyle.styleSheets.Add(styleSheet);
        root.Add(labelWithStyle);
    }
}
Label {
    font-size: 20;
    font-weight: bold;
    text-color: rgb(68, 138, 255);
}
<?xml version="1.0" encoding="utf-8"?>
<engine:UXML
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:engine="UnityEngine.UIElements"
    xmlns:editor="UnityEditor.UIElements"

xsi:noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd"
xsi:schemaLocation="
                        UnityEngine.UIElements ../../UIElementsSchema/UnityEngine.UIElements.xsd
                        UnityEditor.UIElements ../../UIElementsSchema/UnityEditor.UIElements.xsd
                        UnityEditor.PackageManager.UI ../../UIElementsSchema/UnityEditor.PackageManager.UI.xsd
"
>
    <engine:Label text="Hello World! From UXML" />
</engine:UXML>

以上是关于text 在Unity2019.1.9f1的UIElementの生成时の初期コード的主要内容,如果未能解决你的问题,请参考以下文章

Unity 2020.1.0f1 缺少 UnityEngine.UI

Unity - 将 Unity 更新到 2021.1.18f1 后,EasyAR 3.1.0 网络摄像头黑屏

Unity 2019.3.11.f1 + Unity 输入系统 1.0.0 + Unity Remote 5 + iPhone 8 触摸屏不工作

将 Unity3D 项目从 2019.2.12f1 升级到 2020.3.1f1 后,Visual Studio 项目充斥着 CS518 错误

如何使用Unity 2017.3.1f1和Visual Studio 2017更新脚本?

Unity 2020.1.8f1 无法构建 xcode 项目,因为缺少 plist 键值对