├── .gitignore ├── Assets ├── Sandbox.meta ├── Sandbox │ ├── sandbox.cs │ ├── sandbox.cs.meta │ ├── sandbox.unity │ └── sandbox.unity.meta ├── WindowCapture.meta └── WindowCapture │ ├── Materials.meta │ ├── Materials │ ├── Unlit.mat │ └── Unlit.mat.meta │ ├── Models.meta │ ├── Models │ ├── Board.fbx │ └── Board.fbx.meta │ ├── Plugins.meta │ ├── Plugins │ ├── x86_64.meta │ └── x86_64 │ │ ├── WindowCapture.dll │ │ └── WindowCapture.dll.meta │ ├── Prefabs.meta │ ├── Prefabs │ ├── Window.prefab │ └── Window.prefab.meta │ ├── Scripts.meta │ ├── Scripts │ ├── ForegroundSwitcher.cs │ ├── ForegroundSwitcher.cs.meta │ ├── Lib.cs │ ├── Lib.cs.meta │ ├── Manager.cs │ ├── Manager.cs.meta │ ├── Texture.cs │ ├── Texture.cs.meta │ ├── Window.cs │ └── Window.cs.meta │ ├── Shaders.meta │ └── Shaders │ ├── Common.cginc │ ├── Common.cginc.meta │ ├── Params.cginc │ ├── Params.cginc.meta │ ├── Unlit.shader │ └── Unlit.shader.meta ├── LICENSE ├── Plugin └── WindowCapture │ ├── build │ ├── WindowCapture.vcxproj │ └── WindowCapture.vcxproj.filters │ ├── include │ ├── IUnityGraphics.h │ ├── IUnityGraphicsD3D11.h │ └── IUnityInterface.h │ └── src │ ├── entrypoint.cpp │ ├── manager.cpp │ ├── manager.h │ ├── window.cpp │ └── window.h ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityConnectSettings.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | Debug/ 9 | Release/ 10 | *.db 11 | *.opendb 12 | 13 | # Autogenerated VS/MD solution and project files 14 | ExportedObj/ 15 | *.csproj 16 | *.unityproj 17 | *.sln 18 | *.suo 19 | *.tmp 20 | *.user 21 | *.userprefs 22 | *.pidb 23 | *.booproj 24 | *.svd 25 | 26 | 27 | # Unity3D generated meta files 28 | *.pidb.meta 29 | 30 | # Unity3D Generated File On Crash Reports 31 | sysinfo.txt 32 | 33 | # Builds 34 | *.apk 35 | *.unitypackage 36 | -------------------------------------------------------------------------------- /Assets/Sandbox.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37bd6d9c44493ce429a95d3fe8375ac0 3 | folderAsset: yes 4 | timeCreated: 1478981231 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Sandbox/sandbox.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public class sandbox : MonoBehaviour { 6 | [DllImport("WindowCapture")] 7 | static extern int GetForegroundWindowID(); 8 | 9 | // Use this for initialization 10 | void Start () { 11 | } 12 | 13 | // Update is called once per frame 14 | void Update () { 15 | Debug.Log(GetForegroundWindowID()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Assets/Sandbox/sandbox.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cebaff201439abd488ee87fd35515fd5 3 | timeCreated: 1478981251 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Sandbox/sandbox.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Assets/Sandbox/sandbox.unity -------------------------------------------------------------------------------- /Assets/Sandbox/sandbox.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f16d04f145d69cd45b3a696ec0a98a65 3 | timeCreated: 1478981240 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/WindowCapture.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b165787e98bc99b45bed8f3924f86d28 3 | folderAsset: yes 4 | timeCreated: 1478946633 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01c3a51e2cb1a68449aef3061d0f831f 3 | folderAsset: yes 4 | timeCreated: 1479057262 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Materials/Unlit.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Assets/WindowCapture/Materials/Unlit.mat -------------------------------------------------------------------------------- /Assets/WindowCapture/Materials/Unlit.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 862ce68b59217a8448f5dffb73056f24 3 | timeCreated: 1479057313 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Models.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58d88724e3969904296481d7dae2df99 3 | folderAsset: yes 4 | timeCreated: 1479034541 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Models/Board.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Assets/WindowCapture/Models/Board.fbx -------------------------------------------------------------------------------- /Assets/WindowCapture/Models/Board.fbx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3c0eaed8116e0b429641b999f75ff91 3 | timeCreated: 1479034546 4 | licenseType: Free 5 | ModelImporter: 6 | serializedVersion: 19 7 | fileIDToRecycleName: 8 | 100000: //RootNode 9 | 400000: //RootNode 10 | 2300000: //RootNode 11 | 3300000: //RootNode 12 | 4300000: uDD_Board 13 | 9500000: //RootNode 14 | materials: 15 | importMaterials: 0 16 | materialName: 0 17 | materialSearch: 1 18 | animations: 19 | legacyGenerateAnimations: 4 20 | bakeSimulation: 0 21 | resampleCurves: 1 22 | optimizeGameObjects: 0 23 | motionNodeName: 24 | animationImportErrors: 25 | animationImportWarnings: 26 | animationRetargetingWarnings: 27 | animationDoRetargetingWarnings: 0 28 | animationCompression: 1 29 | animationRotationError: 0.5 30 | animationPositionError: 0.5 31 | animationScaleError: 0.5 32 | animationWrapMode: 0 33 | extraExposedTransformPaths: [] 34 | clipAnimations: [] 35 | isReadable: 0 36 | meshes: 37 | lODScreenPercentages: [] 38 | globalScale: 1 39 | meshCompression: 0 40 | addColliders: 0 41 | importBlendShapes: 1 42 | swapUVChannels: 0 43 | generateSecondaryUV: 0 44 | useFileUnits: 1 45 | optimizeMeshForGPU: 1 46 | keepQuads: 0 47 | weldVertices: 1 48 | secondaryUVAngleDistortion: 8 49 | secondaryUVAreaDistortion: 15.000001 50 | secondaryUVHardAngle: 88 51 | secondaryUVPackMargin: 4 52 | useFileScale: 1 53 | tangentSpace: 54 | normalSmoothAngle: 60 55 | normalImportMode: 0 56 | tangentImportMode: 2 57 | importAnimation: 0 58 | copyAvatar: 0 59 | humanDescription: 60 | human: [] 61 | skeleton: [] 62 | armTwist: 0.5 63 | foreArmTwist: 0.5 64 | upperLegTwist: 0.5 65 | legTwist: 0.5 66 | armStretch: 0.05 67 | legStretch: 0.05 68 | feetSpacing: 0 69 | rootMotionBoneName: 70 | hasTranslationDoF: 0 71 | lastHumanDescriptionAvatarSource: {instanceID: 0} 72 | animationType: 0 73 | humanoidOversampling: 1 74 | additionalBone: 0 75 | userData: 76 | assetBundleName: 77 | assetBundleVariant: 78 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1607810e1d8abd6428113a37348d44cd 3 | folderAsset: yes 4 | timeCreated: 1478970487 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Plugins/x86_64.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8511fec88e2505a49a9a830a450eaf7c 3 | folderAsset: yes 4 | timeCreated: 1478981134 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Plugins/x86_64/WindowCapture.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Assets/WindowCapture/Plugins/x86_64/WindowCapture.dll -------------------------------------------------------------------------------- /Assets/WindowCapture/Plugins/x86_64/WindowCapture.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7236df3d26850dc40ab5b1751526d85d 3 | timeCreated: 1478981134 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 0 13 | settings: {} 14 | Editor: 15 | enabled: 1 16 | settings: 17 | CPU: x86_64 18 | DefaultValueInitialized: true 19 | OS: Windows 20 | Linux: 21 | enabled: 0 22 | settings: 23 | CPU: None 24 | Linux64: 25 | enabled: 1 26 | settings: 27 | CPU: x86_64 28 | LinuxUniversal: 29 | enabled: 1 30 | settings: 31 | CPU: x86_64 32 | OSXIntel: 33 | enabled: 0 34 | settings: 35 | CPU: None 36 | OSXIntel64: 37 | enabled: 1 38 | settings: 39 | CPU: AnyCPU 40 | OSXUniversal: 41 | enabled: 0 42 | settings: 43 | CPU: x86_64 44 | Win: 45 | enabled: 0 46 | settings: 47 | CPU: None 48 | Win64: 49 | enabled: 1 50 | settings: 51 | CPU: AnyCPU 52 | userData: 53 | assetBundleName: 54 | assetBundleVariant: 55 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e2aaeb0f43fddc449493fa0e72101f0 3 | folderAsset: yes 4 | timeCreated: 1478949479 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Prefabs/Window.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Assets/WindowCapture/Prefabs/Window.prefab -------------------------------------------------------------------------------- /Assets/WindowCapture/Prefabs/Window.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17c27e453e3663745b9e4c3d38e61c47 3 | timeCreated: 1479040664 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7291eb4e06beb3641b1e5ed056908406 3 | folderAsset: yes 4 | timeCreated: 1478970477 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/ForegroundSwitcher.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ForegroundSwitcher : MonoBehaviour { 5 | // Update is called once per frame 6 | void Update () { 7 | var texture = GetComponent(); 8 | var foreground = WindowCapture.Manager.foreground; 9 | if (foreground != null) { 10 | texture.window = foreground; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/ForegroundSwitcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fb3b2dc01e92f64e81ce663e944a84c 3 | timeCreated: 1479433625 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Lib.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace WindowCapture 6 | { 7 | public static class Lib 8 | { 9 | [DllImport("WindowCapture")] 10 | public extern static int GetWindowWidth(int id); 11 | 12 | [DllImport("WindowCapture")] 13 | public extern static int GetWindowHeight(int id); 14 | 15 | [DllImport("WindowCapture")] 16 | public extern static uint GetWindowDPI(int id); 17 | 18 | [DllImport("WindowCapture")] 19 | public extern static int GetWindowIDs(IntPtr ids, int length); 20 | 21 | [DllImport("WindowCapture")] 22 | public extern static int GetNumWindows(); 23 | 24 | [DllImport("WindowCapture")] 25 | public static extern int GetForegroundWindowID(); 26 | 27 | [DllImport("WindowCapture")] 28 | public static extern void SetTexture(int id, IntPtr texture); 29 | 30 | [DllImport("WindowCapture")] 31 | public static extern void UpdateWindowByID(int id); 32 | 33 | [DllImport("WindowCapture")] 34 | public static extern IntPtr GetRenderEventFunc(); 35 | 36 | public static int[] GetWindowIDArray() 37 | { 38 | var ids = new int[GetNumWindows()]; 39 | var gch = GCHandle.Alloc(ids, GCHandleType.Pinned); 40 | var length = GetWindowIDs(gch.AddrOfPinnedObject(), ids.Length); 41 | gch.Free(); 42 | 43 | if (length == 0 || length != ids.Length) { 44 | Debug.LogError("Faild to get window ID array."); 45 | } 46 | 47 | return ids; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Lib.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa00ec219d957c14399c4cfe40d24250 3 | timeCreated: 1478999560 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Manager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace WindowCapture 7 | { 8 | public class Manager : MonoBehaviour 9 | { 10 | private static Manager instance_; 11 | public static Manager instance 12 | { 13 | get { return CreateInstance(); } 14 | } 15 | 16 | private List windows_; 17 | public static List windows 18 | { 19 | get { return instance.windows_; } 20 | } 21 | 22 | public static Window foreground 23 | { 24 | get 25 | { 26 | var id = Lib.GetForegroundWindowID(); 27 | if (id == -1) { 28 | return null; 29 | } 30 | var window = instance.windows_.Find(x => x.id == id); 31 | if (window != null) { 32 | return window; 33 | } 34 | var new_window = new Window(id); 35 | instance.windows_.Add(new_window); 36 | return new_window; 37 | } 38 | } 39 | 40 | private Coroutine renderCoroutine_ = null; 41 | 42 | private static Manager CreateInstance() 43 | { 44 | if (instance_) { 45 | return instance_; 46 | } 47 | 48 | var manager = FindObjectOfType(); 49 | if (manager) { 50 | manager.Awake(); 51 | return manager; 52 | } 53 | 54 | var go = new GameObject("WindowCaptureManager"); 55 | return go.AddComponent(); 56 | } 57 | 58 | void Awake() 59 | { 60 | if (instance_ != null) { 61 | return; 62 | } 63 | instance_ = this; 64 | 65 | Lib.GetForegroundWindowID(); 66 | windows_ = Lib.GetWindowIDArray() 67 | .Select(x => new Window(x)).ToList(); 68 | } 69 | 70 | void OnEnable() 71 | { 72 | renderCoroutine_ = StartCoroutine(OnRender()); 73 | } 74 | 75 | IEnumerator OnRender() 76 | { 77 | for (;;) { 78 | yield return new WaitForEndOfFrame(); 79 | foreach (var window in windows_) { 80 | window.Render(); 81 | } 82 | } 83 | } 84 | 85 | void OnDisable() 86 | { 87 | if (renderCoroutine_ != null) { 88 | StopCoroutine(renderCoroutine_); 89 | renderCoroutine_ = null; 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Manager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab53c296b6543f542ae93da656f84828 3 | timeCreated: 1479002292 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Texture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace WindowCapture 4 | { 5 | [AddComponentMenu("WindowCapture/Texture")] 6 | public class Texture : MonoBehaviour 7 | { 8 | public Material material 9 | { 10 | get; 11 | private set; 12 | } 13 | 14 | private Window window_; 15 | public Window window 16 | { 17 | get { return window_; } 18 | set 19 | { 20 | window_ = value; 21 | material = GetComponent().material; // clone 22 | material.mainTexture = window_.texture; 23 | } 24 | } 25 | 26 | [Header("Invert UVs")] 27 | public bool invertX = false; 28 | public bool invertY = false; 29 | 30 | [Header("Clip")] 31 | public bool useClip = false; 32 | public Vector2 clipPos = Vector2.zero; 33 | public Vector2 clipScale = new Vector2(0.2f, 0.2f); 34 | 35 | public enum Bend 36 | { 37 | Off = 0, 38 | Y = 1, 39 | Z = 2, 40 | } 41 | 42 | public Bend bend 43 | { 44 | get 45 | { 46 | return (Bend)material.GetInt("_Bend"); 47 | } 48 | set 49 | { 50 | switch (value) { 51 | case Bend.Off: 52 | material.SetInt("_Bend", 0); 53 | material.DisableKeyword("_BEND_OFF"); 54 | material.DisableKeyword("_BEND_Y"); 55 | material.DisableKeyword("_BEND_Z"); 56 | break; 57 | case Bend.Y: 58 | material.SetInt("_Bend", 1); 59 | material.DisableKeyword("_BEND_OFF"); 60 | material.EnableKeyword("_BEND_Y"); 61 | material.DisableKeyword("_BEND_Z"); 62 | break; 63 | case Bend.Z: 64 | material.SetInt("_Bend", 2); 65 | material.DisableKeyword("_BEND_OFF"); 66 | material.DisableKeyword("_BEND_Y"); 67 | material.EnableKeyword("_BEND_Z"); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | public float radius 74 | { 75 | get { return material.GetFloat("_Radius"); } 76 | set { material.SetFloat("_Radius", value); } 77 | } 78 | 79 | public float width 80 | { 81 | get { return material.GetFloat("_Width"); } 82 | set { material.SetFloat("_Width", value); } 83 | } 84 | 85 | public float height 86 | { 87 | get { return material.GetFloat("_Height"); } 88 | set { material.SetFloat("_Height", value); } 89 | } 90 | 91 | void OnEnable() 92 | { 93 | if (window == null) { 94 | window = Manager.foreground; 95 | } 96 | } 97 | 98 | void Update() 99 | { 100 | UpdateMaterial(); 101 | } 102 | 103 | void UpdateMaterial() 104 | { 105 | UpdateDimension(); 106 | Invert(); 107 | Clip(); 108 | } 109 | 110 | void UpdateDimension() 111 | { 112 | material.SetFloat("_Width", window_.widthMeter); 113 | material.SetFloat("_Height", window_.heightMeter); 114 | } 115 | 116 | void Invert() 117 | { 118 | if (invertX) { 119 | material.EnableKeyword("INVERT_X"); 120 | } else { 121 | material.DisableKeyword("INVERT_X"); 122 | } 123 | 124 | if (invertY) { 125 | material.EnableKeyword("INVERT_Y"); 126 | } else { 127 | material.DisableKeyword("INVERT_Y"); 128 | } 129 | } 130 | 131 | void Clip() 132 | { 133 | if (useClip) { 134 | material.EnableKeyword("USE_CLIP"); 135 | material.SetVector("_ClipPositionScale", new Vector4(clipPos.x, clipPos.y, clipScale.x, clipScale.y)); 136 | } else { 137 | material.DisableKeyword("USE_CLIP"); 138 | } 139 | } 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Texture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0baab662c79c63249afef13aa25a8e83 3 | timeCreated: 1479038771 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Window.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace WindowCapture 4 | { 5 | public class Window 6 | { 7 | public Window(int id) 8 | { 9 | id_ = id; 10 | } 11 | 12 | private int id_; 13 | public int id 14 | { 15 | get { return id_; } 16 | } 17 | 18 | private int width 19 | { 20 | get { return Lib.GetWindowWidth(id); } 21 | } 22 | 23 | private int height 24 | { 25 | get { return Lib.GetWindowHeight(id); } 26 | } 27 | 28 | public float widthMeter 29 | { 30 | get { return width / Lib.GetWindowDPI(id) * 0.0254f; } 31 | } 32 | 33 | public float heightMeter 34 | { 35 | get { return height / Lib.GetWindowDPI(id) * 0.0254f; } 36 | } 37 | 38 | private Texture2D texture_; 39 | public Texture2D texture 40 | { 41 | get 42 | { 43 | if (!texture_) { 44 | CreateTexture(); 45 | } 46 | return texture_; 47 | } 48 | } 49 | 50 | public void CreateTexture() 51 | { 52 | if (width == 0 || height == 0) { 53 | return; 54 | } 55 | texture_ = new Texture2D( 56 | width, 57 | height, 58 | TextureFormat.BGRA32, 59 | false 60 | ); 61 | Lib.SetTexture(id, texture_.GetNativeTexturePtr()); 62 | } 63 | 64 | public void Render() 65 | { 66 | if (width == 0 || height == 0) { 67 | // 最小化状態からの復帰時はサイズが0になる 68 | return; 69 | } 70 | if (texture.width != width 71 | || texture.height != height) { 72 | CreateTexture(); 73 | } 74 | GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Assets/WindowCapture/Scripts/Window.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5a97ade0e0882b4ea5583c510356cca 3 | timeCreated: 1478999018 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88ff067e61694274e89659e11f0a6fb8 3 | folderAsset: yes 4 | timeCreated: 1479034542 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders/Common.cginc: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_CGINC 2 | #define COMMON_CGINC 3 | 4 | #include "UnityCG.cginc" 5 | #include "./Params.cginc" 6 | 7 | struct appdata 8 | { 9 | float4 vertex : POSITION; 10 | float2 uv : TEXCOORD0; 11 | }; 12 | 13 | struct v2f 14 | { 15 | float4 vertex : SV_POSITION; 16 | float2 uv : TEXCOORD0; 17 | }; 18 | 19 | struct Input 20 | { 21 | float2 uv_MainTex; 22 | }; 23 | 24 | inline float2 InvertUV(float2 uv) 25 | { 26 | #ifdef INVERT_X 27 | uv.x = 1.0 - uv.x; 28 | #endif 29 | #ifdef INVERT_Y 30 | uv.y = 1.0 - uv.y; 31 | #endif 32 | return uv; 33 | } 34 | 35 | inline float2 RotateUV(float2 uv) 36 | { 37 | #ifdef ROTATE90 38 | float2 tmp = uv; 39 | uv.x = tmp.y; 40 | uv.y = 1.0 - tmp.x; 41 | #elif ROTATE180 42 | uv.x = 1.0 - uv.x; 43 | uv.y = 1.0 - uv.y; 44 | #elif ROTATE270 45 | float2 tmp = uv; 46 | uv.x = 1.0 - tmp.y; 47 | uv.y = tmp.x; 48 | #endif 49 | return uv; 50 | } 51 | 52 | inline float2 ClipUV(float2 uv) 53 | { 54 | uv.x = _ClipX + uv.x * _ClipWidth; 55 | uv.y = _ClipY + uv.y * _ClipHeight; 56 | return uv; 57 | } 58 | 59 | inline void ConvertToLinearIfNeeded(inout fixed3 rgb) 60 | { 61 | if (!IsGammaSpace()) { 62 | rgb = GammaToLinearSpace(rgb); 63 | } 64 | } 65 | 66 | inline fixed4 GetScreenTexture(float2 uv) 67 | { 68 | uv = InvertUV(uv); 69 | #ifdef USE_CLIP 70 | uv = ClipUV(uv); 71 | #endif 72 | uv = RotateUV(uv); 73 | fixed4 c = tex2D(_MainTex, uv); 74 | ConvertToLinearIfNeeded(c.rgb); 75 | return c; 76 | } 77 | 78 | inline void ResizeVertex(inout float4 v, half width, half height) 79 | { 80 | v.x *= width; 81 | v.y *= height; 82 | } 83 | 84 | inline void BendVertex(inout float4 v, half radius, half width) 85 | { 86 | #if !defined(_BEND_OFF) 87 | half angle = width * v.x / radius; 88 | #ifdef _BEND_Y 89 | radius -= v.y; 90 | v.y += radius * (1 - cos(angle)); 91 | #elif _BEND_Z 92 | radius -= v.z; 93 | v.z += radius * (1 - cos(angle)); 94 | #endif 95 | v.x = radius * sin(angle) / width; 96 | #endif 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders/Common.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ad1e6dd0c05d7d44ab329478f830490 3 | timeCreated: 1479034544 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders/Params.cginc: -------------------------------------------------------------------------------- 1 | #ifndef _PARAMS_CGINC 2 | #define _PARAMS_CGINC 3 | 4 | sampler2D _MainTex; 5 | fixed4 _Color; 6 | 7 | half4 _ClipPositionScale; 8 | #define _ClipX _ClipPositionScale.x 9 | #define _ClipY _ClipPositionScale.y 10 | #define _ClipWidth _ClipPositionScale.z 11 | #define _ClipHeight _ClipPositionScale.w 12 | 13 | #ifndef SURFACE_SHADER 14 | float4 _MainTex_ST; 15 | #endif 16 | 17 | #endif -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders/Params.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d807dff432552264e8362d90f711da2a 3 | timeCreated: 1479034544 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders/Unlit.shader: -------------------------------------------------------------------------------- 1 | Shader "WindowCapture/Unlit" 2 | { 3 | 4 | Properties 5 | { 6 | _Color ("Color", Color) = (1, 1, 1, 1) 7 | _MainTex ("Texture", 2D) = "white" {} 8 | [KeywordEnum(Off, Y, Z)] _Bend("Bending", Int) = 0 9 | [PowerSlider(10.0)] _Radius("Radius", Range(1, 100)) = 30 10 | [KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2 11 | } 12 | 13 | SubShader 14 | { 15 | 16 | Tags { "RenderType"="Opaque" } 17 | 18 | Cull [_Cull] 19 | 20 | CGINCLUDE 21 | 22 | #include "./Common.cginc" 23 | 24 | half _Radius; 25 | half _Width; 26 | half _Height; 27 | 28 | v2f vert(appdata v) 29 | { 30 | v2f o; 31 | ResizeVertex(v.vertex, _Width, _Height); 32 | BendVertex(v.vertex, _Radius, _Width); 33 | o.vertex = UnityObjectToClipPos(v.vertex); 34 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 35 | return o; 36 | } 37 | 38 | fixed4 frag(v2f i) : SV_Target 39 | { 40 | return GetScreenTexture(i.uv); 41 | } 42 | 43 | ENDCG 44 | 45 | Pass 46 | { 47 | CGPROGRAM 48 | #pragma vertex vert 49 | #pragma fragment frag 50 | #pragma multi_compile ___ INVERT_X 51 | #pragma multi_compile ___ INVERT_Y 52 | #pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270 53 | #pragma multi_compile ___ USE_CLIP 54 | #pragma multi_compile _BEND_OFF _BEND_Y _BEND_Z 55 | ENDCG 56 | } 57 | 58 | } 59 | 60 | Fallback "Unlit/Texture" 61 | 62 | } -------------------------------------------------------------------------------- /Assets/WindowCapture/Shaders/Unlit.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e8ca6d08b7199142850affa740b0864 3 | timeCreated: 1479034545 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Hirotoshi YOSHITAKA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/build/WindowCapture.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | {D3A39973-A8DE-48B9-9813-E577108F44B1} 35 | Win32Proj 36 | WindowCapture 37 | 10.0.14393.0 38 | 39 | 40 | 41 | DynamicLibrary 42 | true 43 | v140 44 | Unicode 45 | 46 | 47 | DynamicLibrary 48 | false 49 | v140 50 | true 51 | Unicode 52 | 53 | 54 | DynamicLibrary 55 | true 56 | v140 57 | Unicode 58 | 59 | 60 | DynamicLibrary 61 | false 62 | v140 63 | true 64 | Unicode 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | true 86 | 87 | 88 | true 89 | 90 | 91 | false 92 | 93 | 94 | false 95 | 96 | 97 | 98 | 99 | 100 | Level3 101 | Disabled 102 | WIN32;_DEBUG;_WINDOWS;_USRDLL;WINDOWCAPTURE_EXPORTS;%(PreprocessorDefinitions) 103 | ..\include;%(AdditionalIncludeDirectories) 104 | 105 | 106 | Windows 107 | true 108 | 109 | 110 | xcopy /Y $(TargetPath) $(ProjectDir)..\..\..\Assets\WindowCapture\Plugins\x86\ 111 | 112 | 113 | 114 | 115 | 116 | 117 | Level3 118 | Disabled 119 | _DEBUG;_WINDOWS;_USRDLL;WINDOWCAPTURE_EXPORTS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 120 | ..\include;%(AdditionalIncludeDirectories) 121 | 122 | 123 | Windows 124 | true 125 | 126 | 127 | xcopy /Y $(TargetPath) $(ProjectDir)..\..\..\Assets\WindowCapture\Plugins\x86_64\ 128 | 129 | 130 | 131 | 132 | Level3 133 | 134 | 135 | MaxSpeed 136 | true 137 | true 138 | WIN32;NDEBUG;_WINDOWS;_USRDLL;WINDOWCAPTURE_EXPORTS;%(PreprocessorDefinitions) 139 | ..\include;%(AdditionalIncludeDirectories) 140 | 141 | 142 | Windows 143 | true 144 | true 145 | true 146 | 147 | 148 | xcopy /Y $(TargetPath) $(ProjectDir)..\..\..\Assets\WindowCapture\Plugins\x86\ 149 | 150 | 151 | 152 | 153 | Level3 154 | 155 | 156 | MaxSpeed 157 | true 158 | true 159 | NDEBUG;_WINDOWS;_USRDLL;WINDOWCAPTURE_EXPORTS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 160 | ..\include;%(AdditionalIncludeDirectories) 161 | 162 | 163 | Windows 164 | true 165 | true 166 | true 167 | 168 | 169 | xcopy /Y $(TargetPath) $(ProjectDir)..\..\..\Assets\WindowCapture\Plugins\x86_64\ 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/build/WindowCapture.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/include/IUnityGraphics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IUnityInterface.h" 3 | 4 | typedef enum UnityGfxRenderer 5 | { 6 | kUnityGfxRendererOpenGL = 0, // Legacy OpenGL 7 | kUnityGfxRendererD3D9 = 1, // Direct3D 9 8 | kUnityGfxRendererD3D11 = 2, // Direct3D 11 9 | kUnityGfxRendererGCM = 3, // PlayStation 3 10 | kUnityGfxRendererNull = 4, // "null" device (used in batch mode) 11 | kUnityGfxRendererXenon = 6, // Xbox 360 12 | kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0 13 | kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0 14 | kUnityGfxRendererGXM = 12, // PlayStation Vita 15 | kUnityGfxRendererPS4 = 13, // PlayStation 4 16 | kUnityGfxRendererXboxOne = 14, // Xbox One 17 | kUnityGfxRendererMetal = 16, // iOS Metal 18 | kUnityGfxRendererOpenGLCore = 17, // OpenGL core 19 | kUnityGfxRendererD3D12 = 18, // Direct3D 12 20 | } UnityGfxRenderer; 21 | 22 | typedef enum UnityGfxDeviceEventType 23 | { 24 | kUnityGfxDeviceEventInitialize = 0, 25 | kUnityGfxDeviceEventShutdown = 1, 26 | kUnityGfxDeviceEventBeforeReset = 2, 27 | kUnityGfxDeviceEventAfterReset = 3, 28 | } UnityGfxDeviceEventType; 29 | 30 | typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType); 31 | 32 | // Should only be used on the rendering thread unless noted otherwise. 33 | UNITY_DECLARE_INTERFACE(IUnityGraphics) 34 | { 35 | UnityGfxRenderer (UNITY_INTERFACE_API * GetRenderer)(); // Thread safe 36 | 37 | // This callback will be called when graphics device is created, destroyed, reset, etc. 38 | // It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time, 39 | // when the graphics device is already created. 40 | void (UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); 41 | void (UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); 42 | }; 43 | UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL,0x8C5AD4926EB17B11ULL,IUnityGraphics) 44 | 45 | 46 | 47 | // Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins. 48 | // Provide them with an address to a function of this signature. 49 | typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId); 50 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/include/IUnityGraphicsD3D11.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IUnityInterface.h" 3 | 4 | // Should only be used on the rendering thread unless noted otherwise. 5 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D11) 6 | { 7 | ID3D11Device* (UNITY_INTERFACE_API * GetDevice)(); 8 | }; 9 | UNITY_REGISTER_INTERFACE_GUID(0xAAB37EF87A87D748ULL,0xBF76967F07EFB177ULL,IUnityGraphicsD3D11) 10 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/include/IUnityInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Unity native plugin API 4 | // Compatible with C99 5 | 6 | #if defined(__CYGWIN32__) 7 | #define UNITY_INTERFACE_API __stdcall 8 | #define UNITY_INTERFACE_EXPORT __declspec(dllexport) 9 | #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WINAPI_FAMILY) 10 | #define UNITY_INTERFACE_API __stdcall 11 | #define UNITY_INTERFACE_EXPORT __declspec(dllexport) 12 | #elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(__QNX__) 13 | #define UNITY_INTERFACE_API 14 | #define UNITY_INTERFACE_EXPORT 15 | #else 16 | #define UNITY_INTERFACE_API 17 | #define UNITY_INTERFACE_EXPORT 18 | #endif 19 | 20 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 21 | // IUnityInterface is a registry of interfaces we choose to expose to plugins. 22 | // 23 | // USAGE: 24 | // --------- 25 | // To retrieve an interface a user can do the following from a plugin, assuming they have the header file for the interface: 26 | // 27 | // IMyInterface * ptr = registry->Get(); 28 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 29 | 30 | // Unity Interface GUID 31 | // Ensures global uniqueness. 32 | // 33 | // Template specialization is used to produce a means of looking up a GUID from its interface type at compile time. 34 | // The net result should compile down to passing around the GUID. 35 | // 36 | // UNITY_REGISTER_INTERFACE_GUID should be placed in the header file of any interface definition outside of all namespaces. 37 | // The interface structure and the registration GUID are all that is required to expose the interface to other systems. 38 | struct UnityInterfaceGUID 39 | { 40 | #ifdef __cplusplus 41 | UnityInterfaceGUID(unsigned long long high, unsigned long long low) 42 | : m_GUIDHigh(high) 43 | , m_GUIDLow(low) 44 | { 45 | } 46 | 47 | UnityInterfaceGUID(const UnityInterfaceGUID& other) 48 | { 49 | m_GUIDHigh = other.m_GUIDHigh; 50 | m_GUIDLow = other.m_GUIDLow; 51 | } 52 | 53 | UnityInterfaceGUID& operator=(const UnityInterfaceGUID& other) 54 | { 55 | m_GUIDHigh = other.m_GUIDHigh; 56 | m_GUIDLow = other.m_GUIDLow; 57 | return *this; 58 | } 59 | 60 | bool Equals(const UnityInterfaceGUID& other) const { return m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow == other.m_GUIDLow; } 61 | bool LessThan(const UnityInterfaceGUID& other) const { return m_GUIDHigh < other.m_GUIDHigh || (m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow < other.m_GUIDLow); } 62 | #endif 63 | unsigned long long m_GUIDHigh; 64 | unsigned long long m_GUIDLow; 65 | }; 66 | #ifdef __cplusplus 67 | inline bool operator==(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.Equals(right); } 68 | inline bool operator!=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !left.Equals(right); } 69 | inline bool operator< (const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.LessThan(right); } 70 | inline bool operator> (const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return right.LessThan(left); } 71 | inline bool operator>=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator< (left,right); } 72 | inline bool operator<=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator> (left,right); } 73 | #else 74 | typedef struct UnityInterfaceGUID UnityInterfaceGUID; 75 | #endif 76 | 77 | 78 | 79 | 80 | #ifdef __cplusplus 81 | #define UNITY_DECLARE_INTERFACE(NAME) \ 82 | struct NAME : IUnityInterface 83 | 84 | // Generic version of GetUnityInterfaceGUID to allow us to specialize it 85 | // per interface below. The generic version has no actual implementation 86 | // on purpose. 87 | // 88 | // If you get errors about return values related to this method then 89 | // you have forgotten to include UNITY_REGISTER_INTERFACE_GUID with 90 | // your interface, or it is not visible at some point when you are 91 | // trying to retrieve or add an interface. 92 | template 93 | inline const UnityInterfaceGUID GetUnityInterfaceGUID(); 94 | 95 | // This is the macro you provide in your public interface header 96 | // outside of a namespace to allow us to map between type and GUID 97 | // without the user having to worry about it when attempting to 98 | // add or retrieve and interface from the registry. 99 | #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ 100 | template<> \ 101 | inline const UnityInterfaceGUID GetUnityInterfaceGUID() \ 102 | { \ 103 | return UnityInterfaceGUID(HASHH,HASHL); \ 104 | } 105 | 106 | // Same as UNITY_REGISTER_INTERFACE_GUID but allows the interface to live in 107 | // a particular namespace. As long as the namespace is visible at the time you call 108 | // GetUnityInterfaceGUID< INTERFACETYPE >() or you explicitly qualify it in the template 109 | // calls this will work fine, only the macro here needs to have the additional parameter 110 | #define UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(HASHH, HASHL, TYPE, NAMESPACE) \ 111 | const UnityInterfaceGUID TYPE##_GUID(HASHH, HASHL); \ 112 | template<> \ 113 | inline const UnityInterfaceGUID GetUnityInterfaceGUID< NAMESPACE :: TYPE >() \ 114 | { \ 115 | return UnityInterfaceGUID(HASHH,HASHL); \ 116 | } 117 | 118 | // These macros allow for C compatibility in user code. 119 | #define UNITY_GET_INTERFACE_GUID(TYPE) GetUnityInterfaceGUID< TYPE >() 120 | 121 | 122 | #else 123 | #define UNITY_DECLARE_INTERFACE(NAME) \ 124 | typedef struct NAME NAME; \ 125 | struct NAME 126 | 127 | // NOTE: This has the downside that one some compilers it will not get stripped from all compilation units that 128 | // can see a header containing this constant. However, it's only for C compatibility and thus should have 129 | // minimal impact. 130 | #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ 131 | const UnityInterfaceGUID TYPE##_GUID = {HASHH, HASHL}; 132 | 133 | // In general namespaces are going to be a problem for C code any interfaces we expose in a namespace are 134 | // not going to be usable from C. 135 | #define UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(HASHH, HASHL, TYPE, NAMESPACE) 136 | 137 | // These macros allow for C compatibility in user code. 138 | #define UNITY_GET_INTERFACE_GUID(TYPE) TYPE##_GUID 139 | #endif 140 | 141 | // Using this in user code rather than INTERFACES->Get() will be C compatible for those places in plugins where 142 | // this may be needed. Unity code itself does not need this. 143 | #define UNITY_GET_INTERFACE(INTERFACES, TYPE) (TYPE*)INTERFACES->GetInterface (UNITY_GET_INTERFACE_GUID(TYPE)); 144 | 145 | 146 | #ifdef __cplusplus 147 | struct IUnityInterface 148 | { 149 | }; 150 | #else 151 | typedef void IUnityInterface; 152 | #endif 153 | 154 | 155 | 156 | typedef struct IUnityInterfaces 157 | { 158 | // Returns an interface matching the guid. 159 | // Returns nullptr if the given interface is unavailable in the active Unity runtime. 160 | IUnityInterface* (UNITY_INTERFACE_API * GetInterface)(UnityInterfaceGUID guid); 161 | 162 | // Registers a new interface. 163 | void (UNITY_INTERFACE_API * RegisterInterface)(UnityInterfaceGUID guid, IUnityInterface* ptr); 164 | 165 | #ifdef __cplusplus 166 | // Helper for GetInterface. 167 | template 168 | INTERFACE* Get() 169 | { 170 | return static_cast(GetInterface(GetUnityInterfaceGUID())); 171 | } 172 | 173 | // Helper for RegisterInterface. 174 | template 175 | void Register(IUnityInterface* ptr) 176 | { 177 | RegisterInterface(GetUnityInterfaceGUID(), ptr); 178 | } 179 | #endif 180 | } IUnityInterfaces; 181 | 182 | 183 | 184 | #ifdef __cplusplus 185 | extern "C" { 186 | #endif 187 | 188 | // If exported by a plugin, this function will be called when the plugin is loaded. 189 | void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); 190 | // If exported by a plugin, this function will be called when the plugin is about to be unloaded. 191 | void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload(); 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/src/entrypoint.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Plugin/WindowCapture/src/entrypoint.cpp -------------------------------------------------------------------------------- /Plugin/WindowCapture/src/manager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Plugin/WindowCapture/src/manager.cpp -------------------------------------------------------------------------------- /Plugin/WindowCapture/src/manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "window.h" 8 | 9 | namespace window_capture { 10 | 11 | class manager 12 | { 13 | public: 14 | using id = int; 15 | static const id invalid_id = -1; 16 | 17 | id get_foreground_window_id(); 18 | id find_id(const HWND hwnd) const; 19 | window& get_window(const id request_id); 20 | std::vector get_ids() const; 21 | size_t get_num_windows() const; 22 | 23 | private: 24 | std::map windows; 25 | id head_id = 0; 26 | }; 27 | 28 | extern std::unique_ptr g_manager; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Plugin/WindowCapture/src/window.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/Plugin/WindowCapture/src/window.cpp -------------------------------------------------------------------------------- /Plugin/WindowCapture/src/window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace window_capture { 8 | 9 | class window 10 | { 11 | public: 12 | window(); 13 | explicit window(HWND hwnd); 14 | 15 | HWND get_hwnd() const { return hwnd; } 16 | void set_texture(ID3D11Resource* texture); 17 | int get_width(); 18 | int get_height(); 19 | UINT get_dpi(); 20 | void render(); 21 | void create_texture(); 22 | 23 | private: 24 | HWND hwnd; 25 | ID3D11Resource* unity_texture = nullptr; 26 | Microsoft::WRL::ComPtr gdi_texture; 27 | std::wstring module_file_name; 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.4.2f2 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyounanMOTI/UnityWindowCapture/85028957d80254f8a8ce18e05b6b376a406a9a7b/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityWindowCapture 2 | Window capture plugin for Unity 3 | 4 | # Acknowledgement 5 | Using a part of assets and code from [uDesktopDuplication](https://github.com/hecomi/uDesktopDuplication) by hecomi. 6 | --------------------------------------------------------------------------------