1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-12-18 11:55:52 +01:00
MaiDXR/Assets/uWindowCapture/Runtime/UwcIconTexture.cs
2022-01-05 19:44:30 +01:00

74 lines
1.5 KiB
C#

using UnityEngine;
namespace uWindowCapture
{
[RequireComponent(typeof(Renderer))]
public class UwcIconTexture : MonoBehaviour
{
[SerializeField] UwcWindowTexture windowTexture_;
public UwcWindowTexture windowTexture
{
get
{
return windowTexture_;
}
set
{
windowTexture_ = value;
if (windowTexture_) {
window = windowTexture_.window;
}
}
}
UwcWindow window_ = null;
public UwcWindow window
{
get
{
return window_;
}
set
{
window_ = value;
if (window_ != null) {
if (!window_.hasIconTexture) {
window_.onIconCaptured.AddListener(OnIconCaptured);
window_.RequestCaptureIcon();
} else {
OnIconCaptured();
}
}
}
}
bool isValid
{
get
{
return window != null;
}
}
void Update()
{
if (windowTexture != null) {
if (window == null || window != windowTexture_.window) {
window = windowTexture_.window;
}
}
}
void OnIconCaptured()
{
if (!isValid) return;
var renderer = GetComponent<Renderer>();
renderer.material.mainTexture = window.iconTexture;
window.onIconCaptured.RemoveListener(OnIconCaptured);
}
}
}