You've already forked PlanetToursScanner
Add project files.
This commit is contained in:
478
Assets/B83.Win32.cs
Normal file
478
Assets/B83.Win32.cs
Normal file
@@ -0,0 +1,478 @@
|
||||
/* * * * *
|
||||
* This is a collection of Win API helpers. Mainly dealing with window message hooks
|
||||
* and file drag&drop support for Windows standalone Unity applications.
|
||||
*
|
||||
* 2019.11.28 - Changed the "UnityDragAndDropHook" class to a static class. This
|
||||
* has been done for IL2CPP support. IL2CPP can not marshall instance method
|
||||
* callbacks passed to native code. So the callbacks must be static methods.
|
||||
* Therefore all fields involved also need to be static.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Markus Göbel (Bunny83)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* * * * */
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace B83.Win32
|
||||
{
|
||||
public enum HookType : int
|
||||
{
|
||||
WH_JOURNALRECORD = 0,
|
||||
WH_JOURNALPLAYBACK = 1,
|
||||
WH_KEYBOARD = 2,
|
||||
WH_GETMESSAGE = 3,
|
||||
WH_CALLWNDPROC = 4,
|
||||
WH_CBT = 5,
|
||||
WH_SYSMSGFILTER = 6,
|
||||
WH_MOUSE = 7,
|
||||
WH_HARDWARE = 8,
|
||||
WH_DEBUG = 9,
|
||||
WH_SHELL = 10,
|
||||
WH_FOREGROUNDIDLE = 11,
|
||||
WH_CALLWNDPROCRET = 12,
|
||||
WH_KEYBOARD_LL = 13,
|
||||
WH_MOUSE_LL = 14
|
||||
}
|
||||
|
||||
// windows messages
|
||||
public enum WM : uint
|
||||
{
|
||||
NULL = 0x0000,
|
||||
CREATE = 0x0001,
|
||||
DESTROY = 0x0002,
|
||||
MOVE = 0x0003,
|
||||
SIZE = 0x0005,
|
||||
ACTIVATE = 0x0006,
|
||||
SETFOCUS = 0x0007,
|
||||
KILLFOCUS = 0x0008,
|
||||
ENABLE = 0x000A,
|
||||
SETREDRAW = 0x000B,
|
||||
SETTEXT = 0x000C,
|
||||
GETTEXT = 0x000D,
|
||||
GETTEXTLENGTH = 0x000E,
|
||||
PAINT = 0x000F,
|
||||
CLOSE = 0x0010,
|
||||
QUERYENDSESSION = 0x0011,
|
||||
QUERYOPEN = 0x0013,
|
||||
ENDSESSION = 0x0016,
|
||||
QUIT = 0x0012,
|
||||
ERASEBKGND = 0x0014,
|
||||
SYSCOLORCHANGE = 0x0015,
|
||||
SHOWWINDOW = 0x0018,
|
||||
WININICHANGE = 0x001A,
|
||||
SETTINGCHANGE = WININICHANGE,
|
||||
DEVMODECHANGE = 0x001B,
|
||||
ACTIVATEAPP = 0x001C,
|
||||
FONTCHANGE = 0x001D,
|
||||
TIMECHANGE = 0x001E,
|
||||
CANCELMODE = 0x001F,
|
||||
SETCURSOR = 0x0020,
|
||||
MOUSEACTIVATE = 0x0021,
|
||||
CHILDACTIVATE = 0x0022,
|
||||
QUEUESYNC = 0x0023,
|
||||
GETMINMAXINFO = 0x0024,
|
||||
PAINTICON = 0x0026,
|
||||
ICONERASEBKGND = 0x0027,
|
||||
NEXTDLGCTL = 0x0028,
|
||||
SPOOLERSTATUS = 0x002A,
|
||||
DRAWITEM = 0x002B,
|
||||
MEASUREITEM = 0x002C,
|
||||
DELETEITEM = 0x002D,
|
||||
VKEYTOITEM = 0x002E,
|
||||
CHARTOITEM = 0x002F,
|
||||
SETFONT = 0x0030,
|
||||
GETFONT = 0x0031,
|
||||
SETHOTKEY = 0x0032,
|
||||
GETHOTKEY = 0x0033,
|
||||
QUERYDRAGICON = 0x0037,
|
||||
COMPAREITEM = 0x0039,
|
||||
GETOBJECT = 0x003D,
|
||||
COMPACTING = 0x0041,
|
||||
[Obsolete]
|
||||
COMMNOTIFY = 0x0044,
|
||||
WINDOWPOSCHANGING = 0x0046,
|
||||
WINDOWPOSCHANGED = 0x0047,
|
||||
[Obsolete]
|
||||
POWER = 0x0048,
|
||||
COPYDATA = 0x004A,
|
||||
CANCELJOURNAL = 0x004B,
|
||||
NOTIFY = 0x004E,
|
||||
INPUTLANGCHANGEREQUEST = 0x0050,
|
||||
INPUTLANGCHANGE = 0x0051,
|
||||
TCARD = 0x0052,
|
||||
HELP = 0x0053,
|
||||
USERCHANGED = 0x0054,
|
||||
NOTIFYFORMAT = 0x0055,
|
||||
CONTEXTMENU = 0x007B,
|
||||
STYLECHANGING = 0x007C,
|
||||
STYLECHANGED = 0x007D,
|
||||
DISPLAYCHANGE = 0x007E,
|
||||
GETICON = 0x007F,
|
||||
SETICON = 0x0080,
|
||||
NCCREATE = 0x0081,
|
||||
NCDESTROY = 0x0082,
|
||||
NCCALCSIZE = 0x0083,
|
||||
NCHITTEST = 0x0084,
|
||||
NCPAINT = 0x0085,
|
||||
NCACTIVATE = 0x0086,
|
||||
GETDLGCODE = 0x0087,
|
||||
SYNCPAINT = 0x0088,
|
||||
NCMOUSEMOVE = 0x00A0,
|
||||
NCLBUTTONDOWN = 0x00A1,
|
||||
NCLBUTTONUP = 0x00A2,
|
||||
NCLBUTTONDBLCLK = 0x00A3,
|
||||
NCRBUTTONDOWN = 0x00A4,
|
||||
NCRBUTTONUP = 0x00A5,
|
||||
NCRBUTTONDBLCLK = 0x00A6,
|
||||
NCMBUTTONDOWN = 0x00A7,
|
||||
NCMBUTTONUP = 0x00A8,
|
||||
NCMBUTTONDBLCLK = 0x00A9,
|
||||
NCXBUTTONDOWN = 0x00AB,
|
||||
NCXBUTTONUP = 0x00AC,
|
||||
NCXBUTTONDBLCLK = 0x00AD,
|
||||
INPUT_DEVICE_CHANGE = 0x00FE,
|
||||
INPUT = 0x00FF,
|
||||
KEYFIRST = 0x0100,
|
||||
KEYDOWN = 0x0100,
|
||||
KEYUP = 0x0101,
|
||||
CHAR = 0x0102,
|
||||
DEADCHAR = 0x0103,
|
||||
SYSKEYDOWN = 0x0104,
|
||||
SYSKEYUP = 0x0105,
|
||||
SYSCHAR = 0x0106,
|
||||
SYSDEADCHAR = 0x0107,
|
||||
UNICHAR = 0x0109,
|
||||
KEYLAST = 0x0108,
|
||||
IME_STARTCOMPOSITION = 0x010D,
|
||||
IME_ENDCOMPOSITION = 0x010E,
|
||||
IME_COMPOSITION = 0x010F,
|
||||
IME_KEYLAST = 0x010F,
|
||||
INITDIALOG = 0x0110,
|
||||
COMMAND = 0x0111,
|
||||
SYSCOMMAND = 0x0112,
|
||||
TIMER = 0x0113,
|
||||
HSCROLL = 0x0114,
|
||||
VSCROLL = 0x0115,
|
||||
INITMENU = 0x0116,
|
||||
INITMENUPOPUP = 0x0117,
|
||||
MENUSELECT = 0x011F,
|
||||
MENUCHAR = 0x0120,
|
||||
ENTERIDLE = 0x0121,
|
||||
MENURBUTTONUP = 0x0122,
|
||||
MENUDRAG = 0x0123,
|
||||
MENUGETOBJECT = 0x0124,
|
||||
UNINITMENUPOPUP = 0x0125,
|
||||
MENUCOMMAND = 0x0126,
|
||||
CHANGEUISTATE = 0x0127,
|
||||
UPDATEUISTATE = 0x0128,
|
||||
QUERYUISTATE = 0x0129,
|
||||
CTLCOLORMSGBOX = 0x0132,
|
||||
CTLCOLOREDIT = 0x0133,
|
||||
CTLCOLORLISTBOX = 0x0134,
|
||||
CTLCOLORBTN = 0x0135,
|
||||
CTLCOLORDLG = 0x0136,
|
||||
CTLCOLORSCROLLBAR = 0x0137,
|
||||
CTLCOLORSTATIC = 0x0138,
|
||||
MOUSEFIRST = 0x0200,
|
||||
MOUSEMOVE = 0x0200,
|
||||
LBUTTONDOWN = 0x0201,
|
||||
LBUTTONUP = 0x0202,
|
||||
LBUTTONDBLCLK = 0x0203,
|
||||
RBUTTONDOWN = 0x0204,
|
||||
RBUTTONUP = 0x0205,
|
||||
RBUTTONDBLCLK = 0x0206,
|
||||
MBUTTONDOWN = 0x0207,
|
||||
MBUTTONUP = 0x0208,
|
||||
MBUTTONDBLCLK = 0x0209,
|
||||
MOUSEWHEEL = 0x020A,
|
||||
XBUTTONDOWN = 0x020B,
|
||||
XBUTTONUP = 0x020C,
|
||||
XBUTTONDBLCLK = 0x020D,
|
||||
MOUSEHWHEEL = 0x020E,
|
||||
MOUSELAST = 0x020E,
|
||||
PARENTNOTIFY = 0x0210,
|
||||
ENTERMENULOOP = 0x0211,
|
||||
EXITMENULOOP = 0x0212,
|
||||
NEXTMENU = 0x0213,
|
||||
SIZING = 0x0214,
|
||||
CAPTURECHANGED = 0x0215,
|
||||
MOVING = 0x0216,
|
||||
POWERBROADCAST = 0x0218,
|
||||
DEVICECHANGE = 0x0219,
|
||||
MDICREATE = 0x0220,
|
||||
MDIDESTROY = 0x0221,
|
||||
MDIACTIVATE = 0x0222,
|
||||
MDIRESTORE = 0x0223,
|
||||
MDINEXT = 0x0224,
|
||||
MDIMAXIMIZE = 0x0225,
|
||||
MDITILE = 0x0226,
|
||||
MDICASCADE = 0x0227,
|
||||
MDIICONARRANGE = 0x0228,
|
||||
MDIGETACTIVE = 0x0229,
|
||||
MDISETMENU = 0x0230,
|
||||
ENTERSIZEMOVE = 0x0231,
|
||||
EXITSIZEMOVE = 0x0232,
|
||||
DROPFILES = 0x0233,
|
||||
MDIREFRESHMENU = 0x0234,
|
||||
IME_SETCONTEXT = 0x0281,
|
||||
IME_NOTIFY = 0x0282,
|
||||
IME_CONTROL = 0x0283,
|
||||
IME_COMPOSITIONFULL = 0x0284,
|
||||
IME_SELECT = 0x0285,
|
||||
IME_CHAR = 0x0286,
|
||||
IME_REQUEST = 0x0288,
|
||||
IME_KEYDOWN = 0x0290,
|
||||
IME_KEYUP = 0x0291,
|
||||
MOUSEHOVER = 0x02A1,
|
||||
MOUSELEAVE = 0x02A3,
|
||||
NCMOUSEHOVER = 0x02A0,
|
||||
NCMOUSELEAVE = 0x02A2,
|
||||
WTSSESSION_CHANGE = 0x02B1,
|
||||
TABLET_FIRST = 0x02c0,
|
||||
TABLET_LAST = 0x02df,
|
||||
CUT = 0x0300,
|
||||
COPY = 0x0301,
|
||||
PASTE = 0x0302,
|
||||
CLEAR = 0x0303,
|
||||
UNDO = 0x0304,
|
||||
RENDERFORMAT = 0x0305,
|
||||
RENDERALLFORMATS = 0x0306,
|
||||
DESTROYCLIPBOARD = 0x0307,
|
||||
DRAWCLIPBOARD = 0x0308,
|
||||
PAINTCLIPBOARD = 0x0309,
|
||||
VSCROLLCLIPBOARD = 0x030A,
|
||||
SIZECLIPBOARD = 0x030B,
|
||||
ASKCBFORMATNAME = 0x030C,
|
||||
CHANGECBCHAIN = 0x030D,
|
||||
HSCROLLCLIPBOARD = 0x030E,
|
||||
QUERYNEWPALETTE = 0x030F,
|
||||
PALETTEISCHANGING = 0x0310,
|
||||
PALETTECHANGED = 0x0311,
|
||||
HOTKEY = 0x0312,
|
||||
PRINT = 0x0317,
|
||||
PRINTCLIENT = 0x0318,
|
||||
APPCOMMAND = 0x0319,
|
||||
THEMECHANGED = 0x031A,
|
||||
CLIPBOARDUPDATE = 0x031D,
|
||||
DWMCOMPOSITIONCHANGED = 0x031E,
|
||||
DWMNCRENDERINGCHANGED = 0x031F,
|
||||
DWMCOLORIZATIONCOLORCHANGED = 0x0320,
|
||||
DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
|
||||
GETTITLEBARINFOEX = 0x033F,
|
||||
HANDHELDFIRST = 0x0358,
|
||||
HANDHELDLAST = 0x035F,
|
||||
AFXFIRST = 0x0360,
|
||||
AFXLAST = 0x037F,
|
||||
PENWINFIRST = 0x0380,
|
||||
PENWINLAST = 0x038F,
|
||||
APP = 0x8000,
|
||||
USER = 0x0400,
|
||||
CPL_LAUNCH = USER + 0x1000,
|
||||
CPL_LAUNCHED = USER + 0x1001,
|
||||
SYSTIMER = 0x118,
|
||||
}
|
||||
|
||||
// WH_CALLWNDPROC
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CWPSTRUCT
|
||||
{
|
||||
public IntPtr lParam;
|
||||
public IntPtr wParam;
|
||||
public WM message;
|
||||
public IntPtr hwnd;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
public int x, y;
|
||||
public POINT(int aX, int aY)
|
||||
{
|
||||
x = aX;
|
||||
y = aY;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "(" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
//WH_GETMESSAGE
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MSG
|
||||
{
|
||||
public IntPtr hwnd;
|
||||
public WM message;
|
||||
public IntPtr wParam;
|
||||
public IntPtr lParam;
|
||||
public ushort time;
|
||||
public POINT pt;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT
|
||||
{
|
||||
public int Left, Top, Right, Bottom;
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "(" + Left + ", " + Top + ", " + Right + ", " + Bottom + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public delegate IntPtr HookProc(int code, IntPtr wParam, ref MSG lParam);
|
||||
public delegate bool EnumThreadDelegate(IntPtr Hwnd, IntPtr lParam);
|
||||
|
||||
public static class Window
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool EnumThreadWindows(uint dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder lpClassName, int nMaxCount);
|
||||
public static string GetClassName(IntPtr hWnd)
|
||||
{
|
||||
var sb = new System.Text.StringBuilder(256);
|
||||
int count = GetClassName(hWnd, sb, 256);
|
||||
return sb.ToString(0, count);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern int GetWindowTextLength(IntPtr hWnd);
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder lpString, int nMaxCount);
|
||||
public static string GetWindowText(IntPtr hWnd)
|
||||
{
|
||||
int length = GetWindowTextLength(hWnd) + 2;
|
||||
var sb = new System.Text.StringBuilder(length);
|
||||
int count = GetWindowText(hWnd, sb, length);
|
||||
return sb.ToString(0, count);
|
||||
}
|
||||
}
|
||||
|
||||
public static class WinAPI
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern uint GetCurrentThreadId();
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern IntPtr SetWindowsHookEx(HookType hookType, HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref MSG lParam);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern void DragAcceptFiles(IntPtr hwnd, bool fAccept);
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern uint DragQueryFile(IntPtr hDrop, uint iFile, System.Text.StringBuilder lpszFile, uint cch);
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern void DragFinish(IntPtr hDrop);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern void DragQueryPoint(IntPtr hDrop, out POINT pos);
|
||||
}
|
||||
|
||||
public static class UnityDragAndDropHook
|
||||
{
|
||||
public delegate void DroppedFilesEvent(List<string> aPathNames, POINT aDropPoint);
|
||||
public static event DroppedFilesEvent OnDroppedFiles;
|
||||
|
||||
private static uint threadId;
|
||||
private static IntPtr mainWindow = IntPtr.Zero;
|
||||
private static IntPtr m_Hook;
|
||||
private static string m_ClassName = "UnityWndClass";
|
||||
|
||||
// attribute required for IL2CPP, also has to be a static method
|
||||
[AOT.MonoPInvokeCallback(typeof(EnumThreadDelegate))]
|
||||
private static bool EnumCallback(IntPtr W, IntPtr _)
|
||||
{
|
||||
if (Window.IsWindowVisible(W) && (mainWindow == IntPtr.Zero || (m_ClassName != null && Window.GetClassName(W) == m_ClassName)))
|
||||
{
|
||||
mainWindow = W;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void InstallHook()
|
||||
{
|
||||
threadId = WinAPI.GetCurrentThreadId();
|
||||
if (threadId > 0)
|
||||
Window.EnumThreadWindows(threadId, EnumCallback, IntPtr.Zero);
|
||||
|
||||
var hModule = WinAPI.GetModuleHandle(null);
|
||||
m_Hook = WinAPI.SetWindowsHookEx(HookType.WH_GETMESSAGE, Callback, hModule, threadId);
|
||||
// Allow dragging of files onto the main window. generates the WM_DROPFILES message
|
||||
WinAPI.DragAcceptFiles(mainWindow, true);
|
||||
}
|
||||
public static void UninstallHook()
|
||||
{
|
||||
WinAPI.UnhookWindowsHookEx(m_Hook);
|
||||
WinAPI.DragAcceptFiles(mainWindow, false);
|
||||
m_Hook = IntPtr.Zero;
|
||||
}
|
||||
|
||||
// attribute required for IL2CPP, also has to be a static method
|
||||
[AOT.MonoPInvokeCallback(typeof(HookProc))]
|
||||
private static IntPtr Callback(int code, IntPtr wParam, ref MSG lParam)
|
||||
{
|
||||
if (code == 0 && lParam.message == WM.DROPFILES)
|
||||
{
|
||||
POINT pos;
|
||||
WinAPI.DragQueryPoint(lParam.wParam, out pos);
|
||||
|
||||
// 0xFFFFFFFF as index makes the method return the number of files
|
||||
uint n = WinAPI.DragQueryFile(lParam.wParam, 0xFFFFFFFF, null, 0);
|
||||
var sb = new System.Text.StringBuilder(1024);
|
||||
|
||||
List<string> result = new List<string>();
|
||||
for (uint i = 0; i < n; i++)
|
||||
{
|
||||
int len = (int)WinAPI.DragQueryFile(lParam.wParam, i, sb, 1024);
|
||||
result.Add(sb.ToString(0, len));
|
||||
sb.Length = 0;
|
||||
}
|
||||
WinAPI.DragFinish(lParam.wParam);
|
||||
if (OnDroppedFiles != null)
|
||||
OnDroppedFiles(result, pos);
|
||||
}
|
||||
return WinAPI.CallNextHookEx(m_Hook, code, wParam, ref lParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/B83.Win32.cs.meta
Normal file
11
Assets/B83.Win32.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30c5021c0b00eb24e97d49b9e31ee383
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
606
Assets/BmpLoader.cs
Normal file
606
Assets/BmpLoader.cs
Normal file
@@ -0,0 +1,606 @@
|
||||
#region License and Information
|
||||
/*****
|
||||
*
|
||||
* BMPLoader.cs
|
||||
*
|
||||
* This is a simple implementation of a BMP file loader for Unity3D.
|
||||
* Formats it should support are:
|
||||
* - 1 bit monochrome indexed
|
||||
* - 2-8 bit indexed
|
||||
* - 16 / 24 / 32 bit color (including "BI_BITFIELDS")
|
||||
* - RLE-4 and RLE-8 support has been added.
|
||||
*
|
||||
* Unless the type is "BI_ALPHABITFIELDS" the loader does not interpret alpha
|
||||
* values by default, however you can set the "ReadPaletteAlpha" setting to
|
||||
* true to interpret the 4th (usually "00") value as alpha for indexed images.
|
||||
* You can also set "ForceAlphaReadWhenPossible" to true so it will interpret
|
||||
* the "left over" bits as alpha if there are any. It will also force to read
|
||||
* alpha from a palette if it's an indexed image, just like "ReadPaletteAlpha".
|
||||
*
|
||||
* It's not tested well to the bone, so there might be some errors somewhere.
|
||||
* However I tested it with 4 different images created with MS Paint
|
||||
* (1bit, 4bit, 8bit, 24bit) as those are the only formats supported.
|
||||
*
|
||||
* 2017.02.05 - first version
|
||||
* 2017.03.06 - Added RLE4 / RLE8 support
|
||||
* 2021.01.21 - Fixed RLE4 bug; Fixed wrongly reading bit masks for indexed images.
|
||||
* 2021.01.22 - Addes support for negative heights (top-down images) The actual
|
||||
* flipping happens once at the Texture2D conversion.
|
||||
*
|
||||
* Copyright (c) 2017 Markus G<>bel (Bunny83)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
*****/
|
||||
#endregion License and Information
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace B83.Image.BMP
|
||||
{
|
||||
public enum BMPComressionMode : int
|
||||
{
|
||||
BI_RGB = 0x00,
|
||||
BI_RLE8 = 0x01,
|
||||
BI_RLE4 = 0x02,
|
||||
BI_BITFIELDS = 0x03,
|
||||
BI_JPEG = 0x04,
|
||||
BI_PNG = 0x05,
|
||||
BI_ALPHABITFIELDS = 0x06,
|
||||
|
||||
BI_CMYK = 0x0B,
|
||||
BI_CMYKRLE8 = 0x0C,
|
||||
BI_CMYKRLE4 = 0x0D,
|
||||
|
||||
}
|
||||
public struct BMPFileHeader
|
||||
{
|
||||
public ushort magic; // "BM"
|
||||
public uint filesize;
|
||||
public uint reserved;
|
||||
public uint offset;
|
||||
}
|
||||
public struct BitmapInfoHeader
|
||||
{
|
||||
public uint size;
|
||||
public int width;
|
||||
public int height;
|
||||
public ushort nColorPlanes; // always 1
|
||||
public ushort nBitsPerPixel; // [1,4,8,16,24,32]
|
||||
public BMPComressionMode compressionMethod;
|
||||
public uint rawImageSize; // can be "0"
|
||||
public int xPPM;
|
||||
public int yPPM;
|
||||
public uint nPaletteColors;
|
||||
public uint nImportantColors;
|
||||
|
||||
public int absWidth { get { return Mathf.Abs(width); } }
|
||||
public int absHeight { get { return Mathf.Abs(height); } }
|
||||
|
||||
}
|
||||
|
||||
public class BMPImage
|
||||
{
|
||||
public BMPFileHeader header;
|
||||
public BitmapInfoHeader info;
|
||||
public uint rMask = 0x00FF0000;
|
||||
public uint gMask = 0x0000FF00;
|
||||
public uint bMask = 0x000000FF;
|
||||
public uint aMask = 0x00000000;
|
||||
public List<Color32> palette;
|
||||
public Color32[] imageData;
|
||||
public Texture2D ToTexture2D()
|
||||
{
|
||||
var tex = new Texture2D(info.absWidth, info.absHeight);
|
||||
|
||||
if (info.height < 0)
|
||||
FlipImage();
|
||||
|
||||
tex.SetPixels32(imageData);
|
||||
tex.Apply();
|
||||
return tex;
|
||||
}
|
||||
// flip image if height is negative
|
||||
internal void FlipImage()
|
||||
{
|
||||
if (info.height > 0)
|
||||
return;
|
||||
int w = info.absWidth;
|
||||
int h = info.absHeight;
|
||||
int h2 = h / 2;
|
||||
for (int y = 0; y < h2; y++)
|
||||
{
|
||||
for (int x = 0, o1 = y * w, o2 = (h - y - 1) * w; x < w; x++, o1++, o2++)
|
||||
{
|
||||
var tmp = imageData[o1];
|
||||
imageData[o1] = imageData[o2];
|
||||
imageData[o2] = tmp;
|
||||
}
|
||||
}
|
||||
info.height = h;
|
||||
}
|
||||
|
||||
public void ReplaceColor(Color32 aColorToSearch, Color32 aReplacementColor)
|
||||
{
|
||||
var s = aColorToSearch;
|
||||
for (int i = 0; i < imageData.Length; i++)
|
||||
{
|
||||
var c = imageData[i];
|
||||
if (c.r == s.r && c.g == s.g && c.b == s.b && c.a == s.a)
|
||||
imageData[i] = aReplacementColor;
|
||||
}
|
||||
}
|
||||
public void ReplaceFirstPixelColor(Color32 aReplacementColor)
|
||||
{
|
||||
ReplaceColor(imageData[0], aReplacementColor);
|
||||
}
|
||||
public void ReplaceFirstPixelColorWithTransparency()
|
||||
{
|
||||
ReplaceFirstPixelColor(new Color32(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class BMPLoader
|
||||
{
|
||||
const ushort MAGIC = 0x4D42; // "BM" little endian
|
||||
public bool ReadPaletteAlpha = false;
|
||||
public bool ForceAlphaReadWhenPossible = false;
|
||||
|
||||
public BMPImage LoadBMP(string aFileName)
|
||||
{
|
||||
using (var file = File.OpenRead(aFileName))
|
||||
return LoadBMP(file);
|
||||
}
|
||||
public BMPImage LoadBMP(byte[] aData)
|
||||
{
|
||||
using (var stream = new MemoryStream(aData))
|
||||
return LoadBMP(stream);
|
||||
}
|
||||
|
||||
public BMPImage LoadBMP(Stream aData)
|
||||
{
|
||||
using (var reader = new BinaryReader(aData))
|
||||
return LoadBMP(reader);
|
||||
|
||||
}
|
||||
public BMPImage LoadBMP(BinaryReader aReader)
|
||||
{
|
||||
BMPImage bmp = new BMPImage();
|
||||
if (!ReadFileHeader(aReader, ref bmp.header))
|
||||
{
|
||||
Debug.LogError("Not a BMP file");
|
||||
return null;
|
||||
}
|
||||
if (!ReadInfoHeader(aReader, ref bmp.info))
|
||||
{
|
||||
Debug.LogError("Unsupported header format");
|
||||
return null;
|
||||
}
|
||||
if (bmp.info.compressionMethod != BMPComressionMode.BI_RGB
|
||||
&& bmp.info.compressionMethod != BMPComressionMode.BI_BITFIELDS
|
||||
&& bmp.info.compressionMethod != BMPComressionMode.BI_ALPHABITFIELDS
|
||||
&& bmp.info.compressionMethod != BMPComressionMode.BI_RLE4
|
||||
&& bmp.info.compressionMethod != BMPComressionMode.BI_RLE8
|
||||
)
|
||||
{
|
||||
Debug.LogError("Unsupported image format: " + bmp.info.compressionMethod);
|
||||
return null;
|
||||
}
|
||||
long offset = 14 + bmp.info.size;
|
||||
aReader.BaseStream.Seek(offset, SeekOrigin.Begin);
|
||||
if (bmp.info.nBitsPerPixel < 24)
|
||||
{
|
||||
bmp.rMask = 0x00007C00;
|
||||
bmp.gMask = 0x000003E0;
|
||||
bmp.bMask = 0x0000001F;
|
||||
}
|
||||
|
||||
if (bmp.info.nBitsPerPixel > 8 && (bmp.info.compressionMethod == BMPComressionMode.BI_BITFIELDS || bmp.info.compressionMethod == BMPComressionMode.BI_ALPHABITFIELDS))
|
||||
{
|
||||
bmp.rMask = aReader.ReadUInt32();
|
||||
bmp.gMask = aReader.ReadUInt32();
|
||||
bmp.bMask = aReader.ReadUInt32();
|
||||
}
|
||||
if (ForceAlphaReadWhenPossible)
|
||||
bmp.aMask = GetMask(bmp.info.nBitsPerPixel) ^ (bmp.rMask | bmp.gMask | bmp.bMask);
|
||||
|
||||
if (bmp.info.compressionMethod == BMPComressionMode.BI_ALPHABITFIELDS)
|
||||
bmp.aMask = aReader.ReadUInt32();
|
||||
|
||||
if (bmp.info.nPaletteColors > 0 || bmp.info.nBitsPerPixel <= 8)
|
||||
bmp.palette = ReadPalette(aReader, bmp, ReadPaletteAlpha || ForceAlphaReadWhenPossible);
|
||||
|
||||
|
||||
aReader.BaseStream.Seek(bmp.header.offset, SeekOrigin.Begin);
|
||||
bool uncompressed = bmp.info.compressionMethod == BMPComressionMode.BI_RGB ||
|
||||
bmp.info.compressionMethod == BMPComressionMode.BI_BITFIELDS ||
|
||||
bmp.info.compressionMethod == BMPComressionMode.BI_ALPHABITFIELDS;
|
||||
if (bmp.info.nBitsPerPixel == 32 && uncompressed)
|
||||
Read32BitImage(aReader, bmp);
|
||||
else if (bmp.info.nBitsPerPixel == 24 && uncompressed)
|
||||
Read24BitImage(aReader, bmp);
|
||||
else if (bmp.info.nBitsPerPixel == 16 && uncompressed)
|
||||
Read16BitImage(aReader, bmp);
|
||||
else if (bmp.info.compressionMethod == BMPComressionMode.BI_RLE4 && bmp.info.nBitsPerPixel == 4 && bmp.palette != null)
|
||||
ReadIndexedImageRLE4(aReader, bmp);
|
||||
else if (bmp.info.compressionMethod == BMPComressionMode.BI_RLE8 && bmp.info.nBitsPerPixel == 8 && bmp.palette != null)
|
||||
ReadIndexedImageRLE8(aReader, bmp);
|
||||
else if (uncompressed && bmp.info.nBitsPerPixel <= 8 && bmp.palette != null)
|
||||
ReadIndexedImage(aReader, bmp);
|
||||
else
|
||||
{
|
||||
Debug.LogError("Unsupported file format: " + bmp.info.compressionMethod + " BPP: " + bmp.info.nBitsPerPixel);
|
||||
return null;
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
||||
private static void Read32BitImage(BinaryReader aReader, BMPImage bmp)
|
||||
{
|
||||
int w = Mathf.Abs(bmp.info.width);
|
||||
int h = Mathf.Abs(bmp.info.height);
|
||||
Color32[] data = bmp.imageData = new Color32[w * h];
|
||||
if (aReader.BaseStream.Position + w * h * 4 > aReader.BaseStream.Length)
|
||||
{
|
||||
Debug.LogError("Unexpected end of file.");
|
||||
return;
|
||||
}
|
||||
int shiftR = GetShiftCount(bmp.rMask);
|
||||
int shiftG = GetShiftCount(bmp.gMask);
|
||||
int shiftB = GetShiftCount(bmp.bMask);
|
||||
int shiftA = GetShiftCount(bmp.aMask);
|
||||
byte a = 255;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
uint v = aReader.ReadUInt32();
|
||||
byte r = (byte)((v & bmp.rMask) >> shiftR);
|
||||
byte g = (byte)((v & bmp.gMask) >> shiftG);
|
||||
byte b = (byte)((v & bmp.bMask) >> shiftB);
|
||||
if (bmp.bMask != 0)
|
||||
a = (byte)((v & bmp.aMask) >> shiftA);
|
||||
data[i] = new Color32(r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void Read24BitImage(BinaryReader aReader, BMPImage bmp)
|
||||
{
|
||||
int w = Mathf.Abs(bmp.info.width);
|
||||
int h = Mathf.Abs(bmp.info.height);
|
||||
int rowLength = ((24 * w + 31) / 32) * 4;
|
||||
int count = rowLength * h;
|
||||
int pad = rowLength - w * 3;
|
||||
Color32[] data = bmp.imageData = new Color32[w * h];
|
||||
if (aReader.BaseStream.Position + count > aReader.BaseStream.Length)
|
||||
{
|
||||
Debug.LogError("Unexpected end of file. (Have " + (aReader.BaseStream.Position + count) + " bytes, expected " + aReader.BaseStream.Length + " bytes)");
|
||||
return;
|
||||
}
|
||||
int shiftR = GetShiftCount(bmp.rMask);
|
||||
int shiftG = GetShiftCount(bmp.gMask);
|
||||
int shiftB = GetShiftCount(bmp.bMask);
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
uint v = aReader.ReadByte() | ((uint)aReader.ReadByte() << 8) | ((uint)aReader.ReadByte() << 16);
|
||||
byte r = (byte)((v & bmp.rMask) >> shiftR);
|
||||
byte g = (byte)((v & bmp.gMask) >> shiftG);
|
||||
byte b = (byte)((v & bmp.bMask) >> shiftB);
|
||||
data[x + y * w] = new Color32(r, g, b, 255);
|
||||
}
|
||||
for (int i = 0; i < pad; i++)
|
||||
aReader.ReadByte();
|
||||
}
|
||||
}
|
||||
|
||||
private static void Read16BitImage(BinaryReader aReader, BMPImage bmp)
|
||||
{
|
||||
int w = Mathf.Abs(bmp.info.width);
|
||||
int h = Mathf.Abs(bmp.info.height);
|
||||
int rowLength = ((16 * w + 31) / 32) * 4;
|
||||
int count = rowLength * h;
|
||||
int pad = rowLength - w * 2;
|
||||
Color32[] data = bmp.imageData = new Color32[w * h];
|
||||
if (aReader.BaseStream.Position + count > aReader.BaseStream.Length)
|
||||
{
|
||||
Debug.LogError("Unexpected end of file. (Have " + (aReader.BaseStream.Position + count) + " bytes, expected " + aReader.BaseStream.Length + " bytes)");
|
||||
return;
|
||||
}
|
||||
int shiftR = GetShiftCount(bmp.rMask);
|
||||
int shiftG = GetShiftCount(bmp.gMask);
|
||||
int shiftB = GetShiftCount(bmp.bMask);
|
||||
int shiftA = GetShiftCount(bmp.aMask);
|
||||
byte a = 255;
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
uint v = aReader.ReadByte() | ((uint)aReader.ReadByte() << 8);
|
||||
byte r = (byte)((v & bmp.rMask) >> shiftR);
|
||||
byte g = (byte)((v & bmp.gMask) >> shiftG);
|
||||
byte b = (byte)((v & bmp.bMask) >> shiftB);
|
||||
if (bmp.aMask != 0)
|
||||
a = (byte)((v & bmp.aMask) >> shiftA);
|
||||
data[x + y * w] = new Color32(r, g, b, a);
|
||||
}
|
||||
for (int i = 0; i < pad; i++)
|
||||
aReader.ReadByte();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReadIndexedImage(BinaryReader aReader, BMPImage bmp)
|
||||
{
|
||||
int w = Mathf.Abs(bmp.info.width);
|
||||
int h = Mathf.Abs(bmp.info.height);
|
||||
int bitCount = bmp.info.nBitsPerPixel;
|
||||
int rowLength = ((bitCount * w + 31) / 32) * 4;
|
||||
int count = rowLength * h;
|
||||
int pad = rowLength - (w * bitCount + 7) / 8;
|
||||
Color32[] data = bmp.imageData = new Color32[w * h];
|
||||
if (aReader.BaseStream.Position + count > aReader.BaseStream.Length)
|
||||
{
|
||||
Debug.LogError("Unexpected end of file. (Have " + (aReader.BaseStream.Position + count) + " bytes, expected " + aReader.BaseStream.Length + " bytes)");
|
||||
return;
|
||||
}
|
||||
BitStreamReader bitReader = new BitStreamReader(aReader);
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
int v = (int)bitReader.ReadBits(bitCount);
|
||||
if (v >= bmp.palette.Count)
|
||||
{
|
||||
Debug.LogError("Indexed bitmap has indices greater than it's color palette");
|
||||
return;
|
||||
}
|
||||
data[x + y * w] = bmp.palette[v];
|
||||
}
|
||||
bitReader.Flush();
|
||||
for (int i = 0; i < pad; i++)
|
||||
aReader.ReadByte();
|
||||
}
|
||||
}
|
||||
private static void ReadIndexedImageRLE4(BinaryReader aReader, BMPImage bmp)
|
||||
{
|
||||
int w = Mathf.Abs(bmp.info.width);
|
||||
int h = Mathf.Abs(bmp.info.height);
|
||||
Color32[] data = bmp.imageData = new Color32[w * h];
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int yOffset = 0;
|
||||
while (aReader.BaseStream.Position < aReader.BaseStream.Length - 1)
|
||||
{
|
||||
int count = (int)aReader.ReadByte();
|
||||
byte d = aReader.ReadByte();
|
||||
if (count > 0)
|
||||
{
|
||||
for (int i = (count / 2); i > 0; i--)
|
||||
{
|
||||
data[x++ + yOffset] = bmp.palette[(d >> 4) & 0x0F];
|
||||
data[x++ + yOffset] = bmp.palette[d & 0x0F];
|
||||
}
|
||||
if ((count & 0x01) > 0)
|
||||
{
|
||||
data[x++ + yOffset] = bmp.palette[(d >> 4) & 0x0F];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d == 0)
|
||||
{
|
||||
x = 0;
|
||||
y += 1;
|
||||
yOffset = y * w;
|
||||
}
|
||||
else if (d == 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (d == 2)
|
||||
{
|
||||
x += aReader.ReadByte();
|
||||
y += aReader.ReadByte();
|
||||
yOffset = y * w;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = (d / 2); i > 0; i--)
|
||||
{
|
||||
byte d2 = aReader.ReadByte();
|
||||
data[x++ + yOffset] = bmp.palette[(d2 >> 4) & 0x0F];
|
||||
if (x + 1 < w)
|
||||
data[x++ + yOffset] = bmp.palette[d2 & 0x0F];
|
||||
}
|
||||
if ((d & 0x01) > 0)
|
||||
{
|
||||
data[x++ + yOffset] = bmp.palette[(aReader.ReadByte() >> 4) & 0x0F];
|
||||
}
|
||||
if ((((d - 1) / 2) & 1) == 0)
|
||||
{
|
||||
aReader.ReadByte(); // padding (word alignment)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void ReadIndexedImageRLE8(BinaryReader aReader, BMPImage bmp)
|
||||
{
|
||||
int w = Mathf.Abs(bmp.info.width);
|
||||
int h = Mathf.Abs(bmp.info.height);
|
||||
Color32[] data = bmp.imageData = new Color32[w * h];
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int yOffset = 0;
|
||||
while (aReader.BaseStream.Position < aReader.BaseStream.Length - 1)
|
||||
{
|
||||
int count = (int)aReader.ReadByte();
|
||||
byte d = aReader.ReadByte();
|
||||
if (count > 0)
|
||||
{
|
||||
for (int i = count; i > 0; i--)
|
||||
{
|
||||
data[x++ + yOffset] = bmp.palette[d];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d == 0)
|
||||
{
|
||||
x = 0;
|
||||
y += 1;
|
||||
yOffset = y * w;
|
||||
}
|
||||
else if (d == 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (d == 2)
|
||||
{
|
||||
x += aReader.ReadByte();
|
||||
y += aReader.ReadByte();
|
||||
yOffset = y * w;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = d; i > 0; i--)
|
||||
{
|
||||
data[x++ + yOffset] = bmp.palette[aReader.ReadByte()];
|
||||
}
|
||||
if ((d & 0x01) > 0)
|
||||
{
|
||||
aReader.ReadByte(); // padding (word alignment)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static int GetShiftCount(uint mask)
|
||||
{
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if ((mask & 0x01) > 0)
|
||||
return i;
|
||||
mask >>= 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
private static uint GetMask(int bitCount)
|
||||
{
|
||||
uint mask = 0;
|
||||
for (int i = 0; i < bitCount; i++)
|
||||
{
|
||||
mask <<= 1;
|
||||
mask |= 0x01;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
private static bool ReadFileHeader(BinaryReader aReader, ref BMPFileHeader aFileHeader)
|
||||
{
|
||||
aFileHeader.magic = aReader.ReadUInt16();
|
||||
if (aFileHeader.magic != MAGIC)
|
||||
return false;
|
||||
aFileHeader.filesize = aReader.ReadUInt32();
|
||||
aFileHeader.reserved = aReader.ReadUInt32();
|
||||
aFileHeader.offset = aReader.ReadUInt32();
|
||||
return true;
|
||||
}
|
||||
private static bool ReadInfoHeader(BinaryReader aReader, ref BitmapInfoHeader aHeader)
|
||||
{
|
||||
aHeader.size = aReader.ReadUInt32();
|
||||
if (aHeader.size < 40)
|
||||
return false;
|
||||
aHeader.width = aReader.ReadInt32();
|
||||
aHeader.height = aReader.ReadInt32();
|
||||
aHeader.nColorPlanes = aReader.ReadUInt16();
|
||||
aHeader.nBitsPerPixel = aReader.ReadUInt16();
|
||||
aHeader.compressionMethod = (BMPComressionMode)aReader.ReadInt32();
|
||||
aHeader.rawImageSize = aReader.ReadUInt32();
|
||||
aHeader.xPPM = aReader.ReadInt32();
|
||||
aHeader.yPPM = aReader.ReadInt32();
|
||||
aHeader.nPaletteColors = aReader.ReadUInt32();
|
||||
aHeader.nImportantColors = aReader.ReadUInt32();
|
||||
int pad = (int)aHeader.size - 40;
|
||||
if (pad > 0)
|
||||
aReader.ReadBytes(pad);
|
||||
return true;
|
||||
}
|
||||
public static List<Color32> ReadPalette(BinaryReader aReader, BMPImage aBmp, bool aReadAlpha)
|
||||
{
|
||||
uint count = aBmp.info.nPaletteColors;
|
||||
if (count == 0u)
|
||||
count = 1u << aBmp.info.nBitsPerPixel;
|
||||
var palette = new List<Color32>((int)count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
byte b = aReader.ReadByte();
|
||||
byte g = aReader.ReadByte();
|
||||
byte r = aReader.ReadByte();
|
||||
byte a = aReader.ReadByte();
|
||||
if (!aReadAlpha)
|
||||
a = 255;
|
||||
palette.Add(new Color32(r, g, b, a));
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
}
|
||||
public class BitStreamReader
|
||||
{
|
||||
BinaryReader m_Reader;
|
||||
byte m_Data = 0;
|
||||
int m_Bits = 0;
|
||||
|
||||
public BitStreamReader(BinaryReader aReader)
|
||||
{
|
||||
m_Reader = aReader;
|
||||
}
|
||||
public BitStreamReader(Stream aStream) : this(new BinaryReader(aStream)) { }
|
||||
|
||||
public byte ReadBit()
|
||||
{
|
||||
if (m_Bits <= 0)
|
||||
{
|
||||
m_Data = m_Reader.ReadByte();
|
||||
m_Bits = 8;
|
||||
}
|
||||
return (byte)((m_Data >> --m_Bits) & 1);
|
||||
}
|
||||
|
||||
public ulong ReadBits(int aCount)
|
||||
{
|
||||
ulong val = 0UL;
|
||||
if (aCount <= 0 || aCount > 32)
|
||||
throw new System.ArgumentOutOfRangeException("aCount", "aCount must be between 1 and 32 inclusive");
|
||||
for (int i = aCount - 1; i >= 0; i--)
|
||||
val |= ((ulong)ReadBit() << i);
|
||||
return val;
|
||||
}
|
||||
public void Flush()
|
||||
{
|
||||
m_Data = 0;
|
||||
m_Bits = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/BmpLoader.cs.meta
Normal file
11
Assets/BmpLoader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba8dd63641342d24eb9b629682637e1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
108
Assets/CameraOrbit.cs
Normal file
108
Assets/CameraOrbit.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CameraOrbit : MonoBehaviour
|
||||
{
|
||||
public static CameraOrbit Instance;
|
||||
bool controlOn;
|
||||
|
||||
EventSystem eventSystem;
|
||||
|
||||
[Header("Orbit Camera")]
|
||||
public float CamZoomMin = 1, CamZoomMax = 15;
|
||||
|
||||
public float CamZoom = 2.4f;
|
||||
public float MoveSpeed = 1;
|
||||
public float ZoomSpeed = 1f;
|
||||
public Camera Camera;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
Camera = GetComponent<Camera>();
|
||||
eventSystem = EventSystem.current;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
OrbitAround(false);
|
||||
}
|
||||
|
||||
float baseZoom;
|
||||
float baseDist;
|
||||
Vector2 lastMouse;
|
||||
Vector2 lastTouch;
|
||||
int lastTouchCount;
|
||||
bool lastControlOn;
|
||||
|
||||
void OrbitAround(bool aroundCharacter = false)
|
||||
{
|
||||
Vector2 mouse = Input.mousePosition;
|
||||
Vector2 mouseDelta = Vector2.zero;
|
||||
Vector2 touchDelta = Vector2.zero;
|
||||
Vector3 position = transform.position;
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && Input.touchCount == 0 && !eventSystem.IsPointerOverGameObject())
|
||||
{
|
||||
Debug.Log("Mouse");
|
||||
lastControlOn = false;
|
||||
controlOn = true;
|
||||
}
|
||||
if (Input.GetMouseButton(0) && controlOn)
|
||||
{
|
||||
if(lastControlOn == false)
|
||||
{
|
||||
lastControlOn = true;
|
||||
mouseDelta = Vector2.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseDelta = (mouse - lastMouse) * Time.deltaTime;
|
||||
}
|
||||
position -= mouseDelta.x * MoveSpeed * transform.right;
|
||||
position -= mouseDelta.y * MoveSpeed * transform.up;
|
||||
position.x = Mathf.Clamp(position.x, -5, 5);
|
||||
position.y = Mathf.Clamp(position.y, -5, 5);
|
||||
lastMouse = mouse;
|
||||
}
|
||||
else
|
||||
{
|
||||
controlOn = false;
|
||||
}
|
||||
|
||||
if (!eventSystem.IsPointerOverGameObject())
|
||||
{
|
||||
SetZoom(CamZoom - Input.mouseScrollDelta.y * ZoomSpeed);
|
||||
}
|
||||
|
||||
float camDist = CamZoom;
|
||||
Camera.orthographicSize = camDist;
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
public void SetZoom(string value)
|
||||
{
|
||||
SetZoom(float.Parse(value, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public void SetZoom(float value)
|
||||
{
|
||||
value = Mathf.Round(value * 1000) / 1000;
|
||||
CamZoom = Mathf.Clamp(value, CamZoomMin, CamZoomMax);
|
||||
}
|
||||
|
||||
public void SetZoomSpeed(float value)
|
||||
{
|
||||
ZoomSpeed = value;
|
||||
}
|
||||
|
||||
public void SetMoveSpeed(float value)
|
||||
{
|
||||
MoveSpeed = value;
|
||||
}
|
||||
}
|
||||
11
Assets/CameraOrbit.cs.meta
Normal file
11
Assets/CameraOrbit.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 603374773bab5e448bceaac8eaa32a17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
97
Assets/CustomCardReader.cs
Normal file
97
Assets/CustomCardReader.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using B83.Win32;
|
||||
using System;
|
||||
using B83.Image.BMP;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
public class CustomCardReader : MonoBehaviour
|
||||
{
|
||||
public SpriteRenderer Renderer;
|
||||
public float Timer;
|
||||
private BMPLoader _BMPLoader;
|
||||
private Texture2D _tex;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_BMPLoader = new BMPLoader();
|
||||
UnityDragAndDropHook.InstallHook();
|
||||
UnityDragAndDropHook.OnDroppedFiles += OnFiles;
|
||||
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
UnityDragAndDropHook.OnDroppedFiles -= OnFiles;
|
||||
UnityDragAndDropHook.UninstallHook();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(Timer > 0)
|
||||
{
|
||||
Timer -= Time.deltaTime;
|
||||
if(Timer <= 0)
|
||||
{
|
||||
ClearTextures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnFiles(List<string> aFiles, POINT aPos)
|
||||
{
|
||||
ClearTextures();
|
||||
|
||||
string file = "";
|
||||
bool isBmp = false;
|
||||
|
||||
// scan through dropped files and filter out supported image types
|
||||
foreach (var f in aFiles)
|
||||
{
|
||||
var fi = new System.IO.FileInfo(f);
|
||||
var ext = fi.Extension.ToLower();
|
||||
if(ext == ".bmp")
|
||||
{
|
||||
file = f;
|
||||
isBmp = true;
|
||||
break;
|
||||
}
|
||||
else if (ext == ".png" || ext == ".jpg" || ext == ".jpeg")
|
||||
{
|
||||
file = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the user dropped a supported file, create a DropInfo
|
||||
if (file == "") return;
|
||||
|
||||
var data = System.IO.File.ReadAllBytes(file);
|
||||
|
||||
if(isBmp)
|
||||
{
|
||||
BMPImage bmpImg = _BMPLoader.LoadBMP(data);
|
||||
_tex = bmpImg.ToTexture2D();
|
||||
}
|
||||
else
|
||||
{
|
||||
_tex = new Texture2D(1, 1);
|
||||
_tex.LoadImage(data);
|
||||
}
|
||||
|
||||
Timer = 5;
|
||||
Renderer.sprite = Sprite.Create(_tex, new Rect(0.0f, 0.0f, _tex.width, _tex.height), new Vector2(0.5f, 0.5f), 100.0f);
|
||||
}
|
||||
|
||||
private void ClearTextures()
|
||||
{
|
||||
if (_tex != null)
|
||||
{
|
||||
Destroy(_tex);
|
||||
}
|
||||
if (Renderer.sprite != null)
|
||||
{
|
||||
Destroy(Renderer.sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/CustomCardReader.cs.meta
Normal file
11
Assets/CustomCardReader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc3fa307428b2b409ba8578de599e0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Plugins.meta
Normal file
10
Assets/Plugins.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f452a138547dbb34b9edfa5d6695c929
|
||||
folderAsset: yes
|
||||
timeCreated: 1519955869
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Plugins/x86.meta
Normal file
10
Assets/Plugins/x86.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cd051131b4a37240be23bed28adaa6a
|
||||
folderAsset: yes
|
||||
timeCreated: 1519954762
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Plugins/x86/UnityCapturePlugin.dll
Normal file
BIN
Assets/Plugins/x86/UnityCapturePlugin.dll
Normal file
Binary file not shown.
87
Assets/Plugins/x86/UnityCapturePlugin.dll.meta
Normal file
87
Assets/Plugins/x86/UnityCapturePlugin.dll.meta
Normal file
@@ -0,0 +1,87 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27f4f8798f88ca0459e783408e6846a1
|
||||
timeCreated: 1519954762
|
||||
licenseType: Free
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
'': OSXIntel
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
'': OSXIntel64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Plugins/x86_64.meta
Normal file
9
Assets/Plugins/x86_64.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2dd877191f53794b810d198e4f4ac67
|
||||
folderAsset: yes
|
||||
timeCreated: 1460524653
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Plugins/x86_64/UnityCapturePlugin.dll
Normal file
BIN
Assets/Plugins/x86_64/UnityCapturePlugin.dll
Normal file
Binary file not shown.
87
Assets/Plugins/x86_64/UnityCapturePlugin.dll.meta
Normal file
87
Assets/Plugins/x86_64/UnityCapturePlugin.dll.meta
Normal file
@@ -0,0 +1,87 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec414908dccab334fb32e19ccf8879bd
|
||||
timeCreated: 1519867776
|
||||
licenseType: Free
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
'': OSXIntel
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
'': OSXIntel64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
118
Assets/UnityCapture.cs
Normal file
118
Assets/UnityCapture.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Unity Capture
|
||||
Copyright (c) 2018 Bernhard Schelling
|
||||
|
||||
Feature contributors:
|
||||
Brandon J Matthews (low-level interface for custom texture capture)
|
||||
|
||||
Based on UnityCam
|
||||
https://github.com/mrayy/UnityCam
|
||||
Copyright (c) 2016 MHD Yamen Saraiji
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Camera))]
|
||||
public class UnityCapture : MonoBehaviour
|
||||
{
|
||||
public enum ECaptureDevice { CaptureDevice1 = 0, CaptureDevice2 = 1, CaptureDevice3 = 2, CaptureDevice4 = 3, CaptureDevice5 = 4, CaptureDevice6 = 5, CaptureDevice7 = 6, CaptureDevice8 = 7, CaptureDevice9 = 8, CaptureDevice10 = 9 }
|
||||
public enum EResizeMode { Disabled = 0, LinearResize = 1 }
|
||||
public enum EMirrorMode { Disabled = 0, MirrorHorizontally = 1 }
|
||||
public enum ECaptureSendResult { SUCCESS = 0, WARNING_FRAMESKIP = 1, WARNING_CAPTUREINACTIVE = 2, ERROR_UNSUPPORTEDGRAPHICSDEVICE = 100, ERROR_PARAMETER = 101, ERROR_TOOLARGERESOLUTION = 102, ERROR_TEXTUREFORMAT = 103, ERROR_READTEXTURE = 104, ERROR_INVALIDCAPTUREINSTANCEPTR = 200 };
|
||||
|
||||
[SerializeField] [Tooltip("Capture device index")] public ECaptureDevice CaptureDevice = ECaptureDevice.CaptureDevice1;
|
||||
[SerializeField] [Tooltip("Scale image if Unity and capture resolution don't match (can introduce frame dropping, not recommended)")] public EResizeMode ResizeMode = EResizeMode.Disabled;
|
||||
[SerializeField] [Tooltip("How many milliseconds to wait for a new frame until sending is considered to be stopped")] public int Timeout = 1000;
|
||||
[SerializeField] [Tooltip("Mirror captured output image")] public EMirrorMode MirrorMode = EMirrorMode.Disabled;
|
||||
[SerializeField] [Tooltip("Introduce a frame of latency in favor of frame rate")] public bool DoubleBuffering = false;
|
||||
[SerializeField] [Tooltip("Check to enable VSync during capturing")] public bool EnableVSync = false;
|
||||
[SerializeField] [Tooltip("Set the desired render target frame rate")] public int TargetFrameRate = 60;
|
||||
[SerializeField] [Tooltip("Check to disable output of warnings")] public bool HideWarnings = false;
|
||||
|
||||
Interface CaptureInterface;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
QualitySettings.vSyncCount = (EnableVSync ? 1 : 0);
|
||||
Application.targetFrameRate = TargetFrameRate;
|
||||
|
||||
if (Application.runInBackground == false)
|
||||
{
|
||||
Debug.LogWarning("Application.runInBackground switched to enabled for capture streaming");
|
||||
Application.runInBackground = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
CaptureInterface = new Interface(CaptureDevice);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
CaptureInterface.Close();
|
||||
}
|
||||
|
||||
void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
Graphics.Blit(source, destination);
|
||||
switch (CaptureInterface.SendTexture(source, Timeout, DoubleBuffering, ResizeMode, MirrorMode))
|
||||
{
|
||||
case ECaptureSendResult.SUCCESS: break;
|
||||
case ECaptureSendResult.WARNING_FRAMESKIP: if (!HideWarnings) Debug.LogWarning("[UnityCapture] Capture device did skip a frame read, capture frame rate will not match render frame rate."); break;
|
||||
case ECaptureSendResult.WARNING_CAPTUREINACTIVE: if (!HideWarnings) Debug.LogWarning("[UnityCapture] Capture device is inactive"); break;
|
||||
case ECaptureSendResult.ERROR_UNSUPPORTEDGRAPHICSDEVICE: Debug.LogError("[UnityCapture] Unsupported graphics device (only D3D11 supported)"); break;
|
||||
case ECaptureSendResult.ERROR_PARAMETER: Debug.LogError("[UnityCapture] Input parameter error"); break;
|
||||
case ECaptureSendResult.ERROR_TOOLARGERESOLUTION: Debug.LogError("[UnityCapture] Render resolution is too large to send to capture device"); break;
|
||||
case ECaptureSendResult.ERROR_TEXTUREFORMAT: Debug.LogError("[UnityCapture] Render texture format is unsupported (only basic non-HDR (ARGB32) and HDR (FP16/ARGB Half) formats are supported)"); break;
|
||||
case ECaptureSendResult.ERROR_READTEXTURE: Debug.LogError("[UnityCapture] Error while reading texture image data"); break;
|
||||
case ECaptureSendResult.ERROR_INVALIDCAPTUREINSTANCEPTR: Debug.LogError("[UnityCapture] Invalid Capture Instance Pointer"); break;
|
||||
}
|
||||
}
|
||||
|
||||
public class Interface
|
||||
{
|
||||
[System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static System.IntPtr CaptureCreateInstance(int CapNum);
|
||||
[System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static void CaptureDeleteInstance(System.IntPtr instance);
|
||||
[System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static ECaptureSendResult CaptureSendTexture(System.IntPtr instance, System.IntPtr nativetexture, int Timeout, bool UseDoubleBuffering, EResizeMode ResizeMode, EMirrorMode MirrorMode, bool IsLinearColorSpace);
|
||||
System.IntPtr CaptureInstance;
|
||||
|
||||
public Interface(ECaptureDevice CaptureDevice)
|
||||
{
|
||||
CaptureInstance = CaptureCreateInstance((int)CaptureDevice);
|
||||
}
|
||||
|
||||
~Interface()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (CaptureInstance != System.IntPtr.Zero) CaptureDeleteInstance(CaptureInstance);
|
||||
CaptureInstance = System.IntPtr.Zero;
|
||||
}
|
||||
|
||||
public ECaptureSendResult SendTexture(Texture Source, int Timeout = 1000, bool DoubleBuffering = false, EResizeMode ResizeMode = EResizeMode.Disabled, EMirrorMode MirrorMode = EMirrorMode.Disabled)
|
||||
{
|
||||
if (CaptureInstance == System.IntPtr.Zero) return ECaptureSendResult.ERROR_INVALIDCAPTUREINSTANCEPTR;
|
||||
return CaptureSendTexture(CaptureInstance, Source.GetNativeTexturePtr(), Timeout, DoubleBuffering, ResizeMode, MirrorMode, QualitySettings.activeColorSpace == ColorSpace.Linear);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/UnityCapture.cs.meta
Normal file
12
Assets/UnityCapture.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f1106d3744ef824496276c8274506b2
|
||||
timeCreated: 1463481058
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
857
Assets/UnityCaptureExample.unity
Normal file
857
Assets/UnityCaptureExample.unity
Normal file
@@ -0,0 +1,857 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 12
|
||||
m_GIWorkflowMode: 0
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 0
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 1024
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 1
|
||||
m_BakeBackend: 0
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 500
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 0
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_LightingSettings: {fileID: 1177242100}
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 3
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
buildHeightMesh: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &598899120
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 598899124}
|
||||
- component: {fileID: 598899123}
|
||||
- component: {fileID: 598899122}
|
||||
- component: {fileID: 598899121}
|
||||
m_Layer: 5
|
||||
m_Name: Canvas
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &598899121
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 598899120}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_IgnoreReversedGraphics: 1
|
||||
m_BlockingObjects: 0
|
||||
m_BlockingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
--- !u!114 &598899122
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 598899120}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_UiScaleMode: 0
|
||||
m_ReferencePixelsPerUnit: 100
|
||||
m_ScaleFactor: 1
|
||||
m_ReferenceResolution: {x: 800, y: 600}
|
||||
m_ScreenMatchMode: 0
|
||||
m_MatchWidthOrHeight: 0
|
||||
m_PhysicalUnit: 3
|
||||
m_FallbackScreenDPI: 96
|
||||
m_DefaultSpriteDPI: 96
|
||||
m_DynamicPixelsPerUnit: 1
|
||||
m_PresetInfoIsWorld: 0
|
||||
--- !u!223 &598899123
|
||||
Canvas:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 598899120}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_RenderMode: 0
|
||||
m_Camera: {fileID: 0}
|
||||
m_PlaneDistance: 100
|
||||
m_PixelPerfect: 0
|
||||
m_ReceivesEvents: 1
|
||||
m_OverrideSorting: 0
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_VertexColorAlwaysGammaSpace: 0
|
||||
m_AdditionalShaderChannelsFlag: 0
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
--- !u!224 &598899124
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 598899120}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0, y: 0, z: 0}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1104935764}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0, y: 0}
|
||||
--- !u!1 &933076934
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 933076936}
|
||||
- component: {fileID: 933076935}
|
||||
- component: {fileID: 933076937}
|
||||
m_Layer: 0
|
||||
m_Name: Card
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!212 &933076935
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 933076934}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 0
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 7.2, y: 10.28}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 0
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!4 &933076936
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 933076934}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: -1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &933076937
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 933076934}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: afc3fa307428b2b409ba8578de599e0a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Renderer: {fileID: 933076935}
|
||||
Timer: 0
|
||||
--- !u!1 &1104935763
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1104935764}
|
||||
- component: {fileID: 1104935766}
|
||||
- component: {fileID: 1104935765}
|
||||
m_Layer: 5
|
||||
m_Name: Panel
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1104935764
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1104935763}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 2082538870}
|
||||
m_Father: {fileID: 598899124}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 40}
|
||||
m_Pivot: {x: 0.5, y: 0}
|
||||
--- !u!114 &1104935765
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1104935763}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!222 &1104935766
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1104935763}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &1126630849
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1126630855}
|
||||
- component: {fileID: 1126630854}
|
||||
- component: {fileID: 1126630853}
|
||||
- component: {fileID: 1126630851}
|
||||
- component: {fileID: 1126630850}
|
||||
- component: {fileID: 1126630856}
|
||||
m_Layer: 0
|
||||
m_Name: Camera
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1126630850
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1126630849}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5f1106d3744ef824496276c8274506b2, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CaptureDevice: 0
|
||||
ResizeMode: 1
|
||||
Timeout: 1000
|
||||
MirrorMode: 0
|
||||
DoubleBuffering: 0
|
||||
EnableVSync: 0
|
||||
TargetFrameRate: 15
|
||||
HideWarnings: 0
|
||||
--- !u!81 &1126630851
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1126630849}
|
||||
m_Enabled: 1
|
||||
--- !u!124 &1126630853
|
||||
Behaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1126630849}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &1126630854
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1126630849}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 2
|
||||
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_Iso: 200
|
||||
m_ShutterSpeed: 0.005
|
||||
m_Aperture: 16
|
||||
m_FocusDistance: 10
|
||||
m_FocalLength: 50
|
||||
m_BladeCount: 5
|
||||
m_Curvature: {x: 2, y: 11}
|
||||
m_BarrelClipping: 0.25
|
||||
m_Anamorphism: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 5
|
||||
m_Depth: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 0
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &1126630855
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1126630849}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -1, z: -0, w: 0.0000029504295}
|
||||
m_LocalPosition: {x: 0, y: 1.51, z: 6.57}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0}
|
||||
--- !u!114 &1126630856
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1126630849}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 603374773bab5e448bceaac8eaa32a17, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CamZoomMin: 1
|
||||
CamZoomMax: 15
|
||||
CamZoom: 2.4
|
||||
MoveSpeed: 1
|
||||
ZoomSpeed: 1
|
||||
Camera: {fileID: 0}
|
||||
--- !u!850595691 &1177242100
|
||||
LightingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Settings.lighting
|
||||
serializedVersion: 6
|
||||
m_GIWorkflowMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_RealtimeEnvironmentLighting: 1
|
||||
m_BounceScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_UsingShadowmask: 0
|
||||
m_BakeBackend: 0
|
||||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 40
|
||||
m_Padding: 2
|
||||
m_LightmapCompression: 3
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 0
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAO: 0
|
||||
m_MixedBakeMode: 1
|
||||
m_LightmapsBakeMode: 1
|
||||
m_FilterMode: 1
|
||||
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_RealtimeResolution: 2
|
||||
m_ForceWhiteAlbedo: 0
|
||||
m_ForceUpdates: 0
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherRayCount: 1024
|
||||
m_FinalGatherFiltering: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVREnvironmentSampleCount: 512
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_PVRBounces: 2
|
||||
m_PVRMinBounces: 2
|
||||
m_PVREnvironmentImportanceSampling: 0
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_PVRTiledBaking: 0
|
||||
m_NumRaysToShootPerTexel: -1
|
||||
m_RespectSceneVisibilityWhenBakingGI: 0
|
||||
--- !u!1 &1251162945
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1251162947}
|
||||
- component: {fileID: 1251162946}
|
||||
m_Layer: 0
|
||||
m_Name: Directional Light
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!108 &1251162946
|
||||
Light:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1251162945}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 10
|
||||
m_Type: 1
|
||||
m_Shape: 0
|
||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||
m_Intensity: 1
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
m_InnerSpotAngle: 21.80208
|
||||
m_CookieSize: 10
|
||||
m_Shadows:
|
||||
m_Type: 2
|
||||
m_Resolution: -1
|
||||
m_CustomResolution: -1
|
||||
m_Strength: 1
|
||||
m_Bias: 0.05
|
||||
m_NormalBias: 0.4
|
||||
m_NearPlane: 0.2
|
||||
m_CullingMatrixOverride:
|
||||
e00: 1
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 1
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 1
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 1
|
||||
m_UseCullingMatrixOverride: 0
|
||||
m_Cookie: {fileID: 0}
|
||||
m_DrawHalo: 0
|
||||
m_Flare: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingLayerMask: 1
|
||||
m_Lightmapping: 4
|
||||
m_LightShadowCasterMode: 0
|
||||
m_AreaSize: {x: 1, y: 1}
|
||||
m_BounceIntensity: 1
|
||||
m_ColorTemperature: 6570
|
||||
m_UseColorTemperature: 0
|
||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_UseBoundingSphereOverride: 0
|
||||
m_UseViewFrustumForShadowCasterCull: 1
|
||||
m_ShadowRadius: 0
|
||||
m_ShadowAngle: 0
|
||||
--- !u!4 &1251162947
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1251162945}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0.40821797, y: -0.23456974, z: 0.10938168, w: 0.8754261}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1283952071
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1283952074}
|
||||
- component: {fileID: 1283952073}
|
||||
- component: {fileID: 1283952072}
|
||||
m_Layer: 0
|
||||
m_Name: EventSystem
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1283952072
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1283952071}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_HorizontalAxis: Horizontal
|
||||
m_VerticalAxis: Vertical
|
||||
m_SubmitButton: Submit
|
||||
m_CancelButton: Cancel
|
||||
m_InputActionsPerSecond: 10
|
||||
m_RepeatDelay: 0.5
|
||||
m_ForceModuleActive: 0
|
||||
--- !u!114 &1283952073
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1283952071}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_FirstSelected: {fileID: 0}
|
||||
m_sendNavigationEvents: 1
|
||||
m_DragThreshold: 10
|
||||
--- !u!4 &1283952074
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1283952071}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &2082538869
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2082538870}
|
||||
- component: {fileID: 2082538872}
|
||||
- component: {fileID: 2082538871}
|
||||
m_Layer: 5
|
||||
m_Name: Text (Legacy)
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &2082538870
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2082538869}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1104935764}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 30}
|
||||
m_Pivot: {x: 0.5, y: 0}
|
||||
--- !u!114 &2082538871
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2082538869}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_FontData:
|
||||
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_FontSize: 18
|
||||
m_FontStyle: 0
|
||||
m_BestFit: 0
|
||||
m_MinSize: 0
|
||||
m_MaxSize: 40
|
||||
m_Alignment: 1
|
||||
m_AlignByGeometry: 0
|
||||
m_RichText: 1
|
||||
m_HorizontalOverflow: 0
|
||||
m_VerticalOverflow: 0
|
||||
m_LineSpacing: 1
|
||||
m_Text: Drag and drop image to load
|
||||
--- !u!222 &2082538872
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2082538869}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1660057539 &9223372036854775807
|
||||
SceneRoots:
|
||||
m_ObjectHideFlags: 0
|
||||
m_Roots:
|
||||
- {fileID: 1251162947}
|
||||
- {fileID: 1126630855}
|
||||
- {fileID: 933076936}
|
||||
- {fileID: 1283952074}
|
||||
- {fileID: 598899124}
|
||||
8
Assets/UnityCaptureExample.unity.meta
Normal file
8
Assets/UnityCaptureExample.unity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91da01314302a514aa3176f8a4ad8536
|
||||
timeCreated: 1463485542
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user