【Unity3D】UI Toolkit数据动态绑定

这篇具有很好参考价值的文章主要介绍了【Unity3D】UI Toolkit数据动态绑定。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1 前言

        本文将实现 cvs 表格数据与 UI Toolkit 元素的动态绑定。

        如果读者对 UI Toolkit 不是太了解,可以参考以下内容。

  • UI Toolkit简介
  • UI Toolkit容器
  • UI Toolkit元素
  • UI Toolkit样式选择器
  • UI Toolkit自定义元素

        本文完整资源见→UI Toolkit数据动态绑定。

2 数据动态绑定案例

2.1 UI 搭建

        样式和 UI 层级结构如下。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

        MainLayout.xml

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <Style src="project://database/Assets/Role/View/StyleSheets/RoleStyle.uss?fileID=7433441132597879392&amp;guid=d93d80f270ec5014c90e97cc8c404d1f&amp;type=3#RoleStyle" />
    <ui:VisualElement name="Background" style="flex-grow: 1; background-image: url(&apos;project://database/Assets/Role/Img/Background_Sky.png?fileID=2800000&amp;guid=02ebb0e77ccd96143911134d6e39e1db&amp;type=3#Background_Sky&apos;); padding-left: 4%; padding-right: 4%; padding-top: 4%; padding-bottom: 4%; -unity-background-scale-mode: scale-and-crop;">
        <ui:Label text="Game Role" display-tooltip-when-elided="true" name="TitleLab" style="height: 10%; margin-bottom: 1%; -unity-text-align: middle-left; font-size: 100px; -unity-font-style: italic; color: rgb(34, 34, 34);" />
        <ui:VisualElement name="Body" style="flex-grow: 1; flex-direction: row;">
            <ui:VisualElement name="RoleTemplate" style="flex-basis: 25%; margin-left: 10px; margin-right: 10px; margin-top: 10px; margin-bottom: 10px; background-color: rgba(0, 0, 0, 0.2); border-top-left-radius: 10px; border-bottom-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px;">
                <ui:VisualElement name="Image" style="flex-basis: 50%; margin-left: 5%; margin-right: 5%; margin-top: 5%; margin-bottom: 0; background-color: rgba(0, 0, 0, 0.39); border-top-left-radius: 10px; border-top-right-radius: 10px; background-image: url(&apos;project://database/Assets/Role/Img/Avatar_1.png?fileID=2800000&amp;guid=95b3aee3bc9bae64f8b70aba356b50b1&amp;type=3#Avatar_1&apos;); -unity-background-scale-mode: scale-and-crop;" />
                <ui:Label text="角色" display-tooltip-when-elided="true" name="NameLab" style="margin-left: 3%; margin-right: 3%; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; background-color: rgb(255, 96, 96); border-top-left-radius: 10px; border-bottom-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; flex-shrink: 1; font-size: 35px; -unity-text-align: middle-center; color: rgb(255, 254, 254);" />
                <ui:VisualElement name="Properties" style="flex-grow: 1; margin-left: 5%; margin-right: 5%; margin-top: 0; margin-bottom: 5%; background-color: rgba(0, 0, 0, 0.39); border-bottom-right-radius: 10px; border-bottom-left-radius: 10px;">
                    <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                        <ui:Label text="等级" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                        <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                    </ui:VisualElement>
                    <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                        <ui:Label text="行动力" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                        <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                    </ui:VisualElement>
                    <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                        <ui:Label text="最大HP" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                        <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                    </ui:VisualElement>
                    <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                        <ui:Label text="最大MP" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                        <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                    </ui:VisualElement>
                    <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                        <ui:Label text="攻击力" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                        <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                    </ui:VisualElement>
                    <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                        <ui:Label text="防御力" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                        <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                    </ui:VisualElement>
                </ui:VisualElement>
            </ui:VisualElement>
        </ui:VisualElement>
    </ui:VisualElement>
</ui:UXML>

        RoleStyle.uss

#RoleTemplate:hover {
    transition-duration: 0.1s;
    translate: 0 -20px;
    border-left-width: 5px;
    border-right-width: 5px;
    border-top-width: 5px;
    border-bottom-width: 5px;
    border-left-color: rgb(248, 242, 242);
    border-right-color: rgb(248, 242, 242);
    border-top-color: rgb(248, 242, 242);
    border-bottom-color: rgb(248, 242, 242);
}

#Property Label {
    font-size: 25px;
    color: rgba(0, 0, 0, 255);
    -unity-text-align: middle-center;
    -unity-font-style: bold;
}

        显示效果如下。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

2.2 创建模板

        在 Hierarchy 窗口选中 RoleTemplate 元素,右键弹出菜单,选择 Create Template,选择 Resources 目录下保存 RoleTemplate.uxml,修改 Grow 为 1。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

        RoleTemplate.xml

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    <ui:VisualElement name="RoleTemplate" style="flex-basis: 25%; margin-left: 10px; margin-right: 10px; margin-top: 10px; margin-bottom: 10px; background-color: rgba(0, 0, 0, 0.2); border-top-left-radius: 10px; border-bottom-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; flex-grow: 1;">
        <ui:VisualElement name="Image" style="flex-basis: 50%; margin-left: 5%; margin-right: 5%; margin-top: 5%; margin-bottom: 0; background-color: rgba(0, 0, 0, 0.39); border-top-left-radius: 10px; border-top-right-radius: 10px; background-image: url(&apos;project://database/Assets/Role/Img/Avatar_1.png?fileID=2800000&amp;guid=95b3aee3bc9bae64f8b70aba356b50b1&amp;type=3#Avatar_1&apos;); -unity-background-scale-mode: scale-and-crop;" />
        <ui:Label text="角色" display-tooltip-when-elided="true" name="NameLab" style="margin-left: 3%; margin-right: 3%; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; background-color: rgb(255, 96, 96); border-top-left-radius: 10px; border-bottom-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; flex-shrink: 1; font-size: 35px; -unity-text-align: middle-center; color: rgb(255, 254, 254);" />
        <ui:VisualElement name="Properties" style="flex-grow: 1; margin-left: 5%; margin-right: 5%; margin-top: 0; margin-bottom: 5%; background-color: rgba(0, 0, 0, 0.39); border-bottom-right-radius: 10px; border-bottom-left-radius: 10px;">
            <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                <ui:Label text="等级" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
            </ui:VisualElement>
            <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                <ui:Label text="行动力" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
            </ui:VisualElement>
            <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                <ui:Label text="最大HP" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
            </ui:VisualElement>
            <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                <ui:Label text="最大MP" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
            </ui:VisualElement>
            <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                <ui:Label text="攻击力" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
            </ui:VisualElement>
            <ui:VisualElement name="Property" style="flex-direction: row; margin-left: 5px; margin-right: 5px; margin-top: 5px; margin-bottom: 5px; flex-grow: 0; justify-content: center;">
                <ui:Label text="防御力" display-tooltip-when-elided="true" name="Name" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(185, 251, 192); border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
                <ui:Label text="1" display-tooltip-when-elided="true" name="Value" style="flex-basis: 50%; flex-shrink: 1; background-color: rgb(255, 200, 200); border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0;" />
            </ui:VisualElement>
        </ui:VisualElement>
    </ui:VisualElement>
</ui:UXML>

        保存模板后,删除 Hierarchy 窗口中的 RoleTemplate 元素,后面会通过脚本加载 RoleTemplate。

2.3 自定义元素

        RoleView.cs

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
 
public class RoleView : VisualElement {
    // 便于在UI Builder中导入自定义UI, 需要有无参构造函数
    public new class UxmlFactory : UxmlFactory<RoleView> {}
    private TemplateContainer container; // 模板容器
    private List<VisualElement> properties; // 角色属性

    public RoleView() {
        container = Resources.Load<VisualTreeAsset>("RoleTemplate").Instantiate();
        container.style.flexGrow = 1;
        hierarchy.Add(container);
        properties = container.Query("Property").ToList();
    }

    public RoleView(RoleData roleData) : this() {
        userData = roleData;
        UpdateRoleData();
        container.RegisterCallback<MouseDownEvent>(OnClick);
    }

    private void OnClick(MouseDownEvent mouseDownEvent) { // 单击角色模板回调函数
        RoleData roleData = (RoleData) userData;
        if (mouseDownEvent.button == 0) { // 按下鼠标左键
            roleData.RoleLevel++;
        } else if (mouseDownEvent.button == 1) { // 按下鼠标右键
            roleData.RoleLevel--;
        }
        UpdateRoleData();
    }

    private void UpdateRoleData() { // 更新角色数据
        RoleData roleData = (RoleData) userData;
        container.Q<VisualElement>("Image").style.backgroundImage = roleData.RoleImage;
        container.Q<Label>("NameLab").text = roleData.RoleName;
        SetProperty(properties[0], roleData.RoleLevel);
        SetProperty(properties[1], roleData.LevelData.initiative);
        SetProperty(properties[2], roleData.LevelData.maxHp);
        SetProperty(properties[3], roleData.LevelData.maxMp);
        SetProperty(properties[4], roleData.LevelData.attack);
        SetProperty(properties[5], roleData.LevelData.defense);
    }

    private void SetProperty(VisualElement property, int value) { // 更新角色属性
        property.Q<Label>("Value").text = value.ToString();
    }
}

2.4 自定义数据

        LevelData.cs

public class LevelData { // 等级属性数据
    public int initiative; // 主动权(行动力/速度)
    public int maxHp; // 最大生命值
    public int maxMp; // 最大魔法值
    public int attack; // 攻击力
    public int defense; // 防御力
}

        RoleData.cs

using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = ("RoleData"), fileName = ("RoleData_"))]
public class RoleData : ScriptableObject { // 角色属性数据
    private const int roleMaxLevel = 10; // 最大等级
    [SerializeField]
    private TextAsset levelDataFile; // 等级数据csv文件
    [SerializeField]
    private Texture2D roleImage; // 角色头像
    [SerializeField]
    private string roleName; // 角色名
    [SerializeField, Range(1, roleMaxLevel)]
    private int roleStartLevel = 1; // 角色开始等级
    [SerializeField]
    private List<LevelData> levelDatas; // 等级数据
    private int roleLevel; // 角色当前等级

    public Texture2D RoleImage => roleImage; // 获取角色头像

    public string RoleName => roleName; // 获取角色名

    public int RoleLevel { // 获取/设置角色等级
        get => roleLevel;
        set {
            if (roleLevel == value || value < 1 || value > roleMaxLevel) {
                return;
            }
            roleLevel = value;
        }
    }

    public LevelData LevelData => levelDatas[roleLevel - 1]; // 获取角色等级数据

    private void OnEnable() {
        roleLevel = roleStartLevel;
    }

    private void OnValidate() {
        if (levelDataFile == null) {
            return;
        }
        if (levelDatas == null) {
            levelDatas = new List<LevelData>();
        }
        levelDatas.Clear();
        string[] textInLines = levelDataFile.text.Split('\n');
        for (int i = 1; i < textInLines.Length; i++) {
            string[] statsValues = textInLines[i].Split(",");
            LevelData levelData = new LevelData();
            levelData.initiative = int.Parse(statsValues[0]);
            levelData.maxHp = int.Parse(statsValues[1]);
            levelData.maxMp = int.Parse(statsValues[2]);
            levelData.attack = int.Parse(statsValues[3]);
            levelData.defense = int.Parse(statsValues[4]);
            levelDatas.Add(levelData);
        }
    }
}

        编译后,在 Assets 窗口右键,依次选择【Create→RoleData】,创建 4 个对象,对应 4 个角色的配置,分别重命名为 RoleData_1.asset、RoleData_2.asset、RoleData_3.asset、RoleData_4.asset。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

        选中 ScriptableObject 配置文件后,在 Inspector 窗口配置角色属性。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

        其中 LevelDataFile 是角色每个等级的属性 cvs 表,内容如下。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

2.5 元素加载

        RoleLoader.cs

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
 
public class RoleLoader : MonoBehaviour {
    [SerializeField]
    private List<RoleData> roleDatas; // 角色数据
    private VisualElement root; // 根容器
 
    private void Awake() {
        root = GetComponent<UIDocument>().rootVisualElement;
        var bodyContainer = root.Q("Body");
        bodyContainer.Clear();
        for(int i = 0; i < roleDatas.Count; i++) {
            RoleView roleView = new RoleView(roleDatas[i]);
            roleView.style.flexBasis = Length.Percent(25.0f);
            bodyContainer.Add(roleView);
        }
    }
}

        说明:RoleLoader 脚本组件挂在 UIDocument 对象上,并且需要将 RoleData_1.asset、RoleData_2.asset、RoleData_3.asset、RoleData_4.asset 赋给 RoleDatas,如下。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS

2.6 运行效果

        运行效果如下,单击卡片,角色的等级会升 1 级,等级属性也会按照 cvs 表格中的策略数据同步更新。

【Unity3D】UI Toolkit数据动态绑定,Unity3D,# Unity基础,数据绑定,Data Binding,UI Toolkit,CVS文章来源地址https://www.toymoban.com/news/detail-719772.html

到了这里,关于【Unity3D】UI Toolkit数据动态绑定的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【Unity3D】UI Toolkit样式选择器

            UI Toolkit简介 中介绍了样式属性,UI Toolkit容器 和 UI Toolkit元素 中介绍了容器和元素,本文将介绍样式选择器(Selector),主要包含样式类选择器(Class Selector)、C# 类选择器(Type Selector)、名称选择器(Name Selector)、通用选择器(Universal Selector)、后代选择器

    2024年02月03日
    浏览(30)
  • 【Unity3D小功能】Unity3D中实现点击‘文字’出现‘UI面板’

    推荐阅读 CSDN主页 GitHub开源地址 Unity3D插件分享 简书地址 QQ群:398291828 大家好,我是佛系工程师 ☆恬静的小魔龙☆ ,不定时更新Unity开发技巧,觉得有用记得一键三连哦。 宠粉博主又来了,今天有粉丝问我如何实现点击一段文字然后出现的面板在那段文字附近显示: 深入了

    2024年04月13日
    浏览(42)
  • unity3D之UI

    1.canvas介绍 (1)Canvas属于Unity的UGUI,UGUI提供了强大的可视化编辑,大大提高了GUI的开发效率。 (2)Canvas是所有UI组件的父物体,也就是说每一个UI组件都必须在Canvas下,作为Canvas的子物体,当你创建一个UI控件时,如果在Hierarchy下没有Canvas组件的话,Unity会帮你自动创建一个Canva

    2024年02月04日
    浏览(95)
  • 【Unity3D小功能】Unity3D中实现UI擦除效果、刮刮卡功能

    推荐阅读 CSDN主页 GitHub开源地址 Unity3D插件分享 简书地址 我的个人博客 大家好,我是佛系工程师 ☆恬静的小魔龙☆ ,不定时更新Unity开发技巧,觉得有用记得一键三连哦。 使用Unity3D实现UI的擦拭效果、刮刮卡功能的效果实现方式比较多,比如说用Shader、Texture渲染都是可以

    2024年02月04日
    浏览(200)
  • Unity3D 连接 SQLite 作为数据库基础功能【详细图文教程】

    轻量级: SQLite是一个嵌入式数据库引擎,它的库文件非常小巧,没有独立的服务器进程,适用于嵌入到其他应用程序中,对于轻量级的项目或移动应用程序非常适用。 零配置: 使用SQLite不需要进行复杂的配置或管理,你只需要简单地创建一个文件即可开始使用,减少了额外的

    2024年02月10日
    浏览(27)
  • unity3D基础操作之01--unity3d窗口界面介绍

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 1、Scene场景编辑窗口; 2、Game游戏运行窗口; 3、Hierarchy场景物体列表窗口; 4、Project项目资源列表窗口; 5、Inspector属性编辑列表窗口; 6、其他常调节窗口 在屏幕左上方为场景编辑窗口Scene,在场景编

    2024年02月06日
    浏览(51)
  • 使用Unity生成UI预制体 (Unity3D)

    在Unity中,预制体(Prefab)是一种非常有用的工具,用于生成可重复使用的UI元素。预制体使得UI的创建和管理变得更加简单和高效。在本文中,我们将详细介绍如何使用Unity生成UI预制体,并提供相应的源代码示例。 步骤1:创建UI元素 首先,我们需要创建UI元素,例如按钮、

    2024年02月05日
    浏览(42)
  • 【Unity3D】实现UI点击事件穿透

              注意:EventSystem.current.RaycastAll获取到的对象列表是能够接受事件的,假如你的按钮Button自己身上没有Image,而是Button的子物体有,那么你就要给这个子物体也加上标签Tag才能响应到。 如果ExecuteEvents.Execute不管用,可以试试ExecuteEvents.ExecuteHierarchy

    2024年02月04日
    浏览(34)
  • Unity3D学习之UI系统——GUI

    设置Screen Type和Center Type 最终实现效果: 3.1.1 GUI 共同点 3.1.2 文本控件 可以传图片 在unity中拖入图片 可以把Rect 设置成public 的变量,在控件中设置 文字和图片均显示 toolTip 获取当前选中的空间的附带信息 GUI Style 控制样式 3.1.3 按钮控件 必须要按下并抬起才算被点击 长按按钮

    2024年01月22日
    浏览(51)
  • Unity3D学习之UI系统——NGUI

    资源商店搜索 学习版自行搜索 导入即可 创建UI 创建NGUI后,挂载在UI Root 和其 子Camera的脚本 分辨率自适应模式的基础 3.1.1 分辨率概念 3.1.2 Root的作用 3.1.3 root脚本各组件 Minimun Height 和 Maximum Height 用于拖动窗口时,如果窗口变得很小了,UI不缩放的话,会挡住游戏,使用Flex

    2024年03月17日
    浏览(72)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包