Change the way to get pixels and finish the implementation of the APIs 🎉

This commit is contained in:
hecomi
2016-12-01 22:29:52 +09:00
parent 7e3df8ec2e
commit 583af4ff46
15 changed files with 185 additions and 159 deletions
@@ -1,15 +0,0 @@
using UnityEngine;
using System.Collections;
public class GetPixels : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: bc0250b1a79f38b48bfddf1e05bda638
timeCreated: 1480420057
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -14,15 +14,15 @@ public class GetPixelsExample : MonoBehaviour
void Start()
{
// must be called (performance will be slightly down).
uDesktopDuplication.Manager.useGetPixels = true;
texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
GetComponent<Renderer>().material.mainTexture = texture;
}
void Update()
{
// must be called (performance will be slightly down).
uDesktopDuplication.Manager.primary.useGetPixels = true;
var monitor = uddTexture.monitor;
if (!monitor.hasBeenUpdated) return;
+1 -5
View File
@@ -172,7 +172,7 @@ public static class Lib
[DllImport("uDesktopDuplication")]
public static extern bool HasBeenUpdated(int id);
[DllImport("uDesktopDuplication")]
public static extern bool UseGetPixels(bool use);
public static extern bool UseGetPixels(int id, bool use);
public static string GetName(int id)
{
@@ -216,10 +216,6 @@ public static class Lib
public static bool GetPixels(int id, Color32[] colors, int x, int y, int width, int height)
{
if (!Mathf.IsPowerOfTwo(width) || !Mathf.IsPowerOfTwo(height)) {
Debug.LogErrorFormat("width and height must be power of two.");
return false;
}
if (colors.Length < width * height) {
Debug.LogErrorFormat("colors is small.", id, x, y, width, height);
return false;
@@ -52,14 +52,6 @@ public class Manager : MonoBehaviour
}
}
static public bool useGetPixels
{
set
{
Lib.UseGetPixels(value);
}
}
[Tooltip("Debug mode is not applied while running.")]
[SerializeField] DebugMode debugMode = DebugMode.File;
@@ -169,7 +161,8 @@ public class Manager : MonoBehaviour
state == MonitorState.NotSet ||
state == MonitorState.AccessLost ||
state == MonitorState.AccessDenied ||
state == MonitorState.SessionDisconnected
state == MonitorState.SessionDisconnected ||
state == MonitorState.Unknown
) {
reinitializeNeeded = true;
break;
@@ -237,6 +237,20 @@ public class Monitor
get { return Lib.HasBeenUpdated(id); }
}
bool useGetPixels_ = false;
public bool useGetPixels
{
get
{
return useGetPixels_;
}
set
{
useGetPixels_ = value;
Lib.UseGetPixels(id, value);
}
}
public bool shouldBeUpdated
{
get;
@@ -325,16 +339,28 @@ public class Monitor
public Color32[] GetPixels(int x, int y, int width, int height)
{
if (!useGetPixels_) {
Debug.LogErrorFormat("Please set Monitor[{0}].useGetPixels as true.", id);
return null;
}
return Lib.GetPixels(id, x, y, width, height);
}
public bool GetPixels(Color32[] colors, int x, int y, int width, int height)
{
if (!useGetPixels_) {
Debug.LogErrorFormat("Please set Monitor[{0}].useGetPixels as true.", id);
return false;
}
return Lib.GetPixels(id, colors, x, y, width, height);
}
public Color32 GetPixel(int x, int y)
{
if (!useGetPixels_) {
Debug.LogErrorFormat("Please set Monitor[{0}].useGetPixels as true.", id);
return Color.black;
}
return Lib.GetPixel(id, x, y);
}
}