Last active
January 29, 2022 08:58
-
-
Save baobao/5d5204b55323cea4a930f03145edac9f to your computer and use it in GitHub Desktop.
UI Toolkitサンプル:MouseDown・MouseUpショートコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UIElements; | |
// 解説Qiita記事 : https://qiita.com/ohbashunsuke/items/ae1da96e582aef734eee | |
[RequireComponent(typeof(UIDocument))] | |
public class UIToolkit_MouseDownUpTest : MonoBehaviour | |
{ | |
void OnEnable() | |
{ | |
var document = GetComponent<UIDocument>(); | |
var visualTree = document.rootVisualElement; | |
var container = visualTree.Q("container"); | |
container.RegisterCallback<PointerDownEvent>(OnPointerDown); | |
container.RegisterCallback<PointerUpEvent>(OnPointerUp); | |
} | |
private void OnPointerDown(PointerDownEvent evt) | |
{ | |
var ve = (VisualElement) evt.target; | |
ve.style.backgroundColor = Color.red; | |
} | |
private void OnPointerUp(PointerUpEvent evt) | |
{ | |
var ve = (VisualElement) evt.target; | |
ve.style.backgroundColor = Color.yellow; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ui:UXML xmlns:ui="UnityEngine.UIElements" editor-extension-mode="False"> | |
<Style src="TouchTest.uss" /> | |
<ui:VisualElement name="container" style="height: 100%; width: 100%; background-color: rgba(255, 255, 0, 255);" /> | |
</ui:UXML> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment