diff --git a/Assets/uDesktopDuplication/Scripts/Cursor.cs b/Assets/uDesktopDuplication/Scripts/Cursor.cs index 1681ef4..a85eb6d 100644 --- a/Assets/uDesktopDuplication/Scripts/Cursor.cs +++ b/Assets/uDesktopDuplication/Scripts/Cursor.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System.Collections.Generic; namespace uDesktopDuplication { @@ -17,6 +18,8 @@ public class Cursor : MonoBehaviour private Texture2D pointerTexture_; private Material cursorMaterial_; + private Dictionary pointerTextures_ = new Dictionary(); + void OnEnable() { uddTexture_ = GetComponent(); @@ -62,10 +65,15 @@ public class Cursor : MonoBehaviour void UpdateTexture() { - pointerTexture_ = new Texture2D(monitor.pointerShapeWidth, monitor.pointerShapeHeight, TextureFormat.BGRA32, false); - pointerTexture_.wrapMode = TextureWrapMode.Clamp; - monitor.UpdatePointerTexture(pointerTexture_.GetNativeTexturePtr()); - cursorMaterial_.SetTexture("_MainTex", pointerTexture_); + var scale = new Vector2(monitor.pointerShapeWidth, monitor.pointerShapeHeight); + if (!pointerTextures_.ContainsKey(scale)) { + var texture = new Texture2D(monitor.pointerShapeWidth, monitor.pointerShapeHeight, TextureFormat.BGRA32, false); + texture.wrapMode = TextureWrapMode.Clamp; + pointerTextures_.Add(scale, texture); + } + var pointerTexture = pointerTextures_[scale]; + monitor.UpdatePointerTexture(pointerTexture.GetNativeTexturePtr()); + cursorMaterial_.SetTexture("_MainTex", pointerTexture); } void UpdateMaterial()