I am using Unity Editor and trying to open Logitech webcam to take photo. But everything look so weird.
First I am call my `start_webcam()` method in `ProMainPagePreview.cs`, it should print all webcam and open webcam with my config. Here is the code:
>
for (int i = 0; i < WebCamTexture.devices.Length; i++)
{
Debug.Log("(" + i + ")\tWebCam " + WebCamTexture.devices[i].name);
}
string tmpDevName = WebCamTexture.devices[getConfig().USE_WEBCAM_INDEX % WebCamTexture.devices.Length].name;
Debug.Log("Webcam [" + getConfig().USE_WEBCAM_INDEX + "%" + WebCamTexture.devices.Length + "=" + (getConfig().USE_WEBCAM_INDEX % WebCamTexture.devices.Length) +
"] <<" + tmpDevName + ">> resolution : (" + getConfig().webcam_resolution_width + "x" + getConfig().webcam_resolution_height + ")");
mWebCamTexture = new WebCamTexture(
tmpDevName,
getConfig().webcam_resolution_width,
getConfig().webcam_resolution_height
);
mWebCamTexture.Play();
Debug.Log(mWebCamTexture.deviceName + "\twidth x height = " + mWebCamTexture.width + "X" + mWebCamTexture.height + "\tIS PLAYING = " + mWebCamTexture.isPlaying);
But the Debug Log show that the webcam cannot open with my requested resolution and not running at all. DebugLog:
>> (0) WebCam Logitech HD Webcam C270
UnityEngine.Debug:Log(Object)
ProMainPagePreview:setup(ProController) (at Assets/_Photobooth Pro/Scripts/ProMainPagePreview.cs:194)
ProMainPage:show() (at Assets/_Photobooth Pro/Scripts/ProMainPage.cs:113)
ProController:setUI_MainPage() (at Assets/_Photobooth Pro/Scripts/ProController.cs:130)c__AnonStorey0:<>m__0() (at Assets/_Photobooth Pro/Scripts/ProFirstPage.cs:32)
UnityEngine.EventSystems.EventSystem:Update()>> (1) WebCam Integrated Webcam
UnityEngine.Debug:Log(Object)
ProMainPagePreview:setup(ProController) (at Assets/_Photobooth Pro/Scripts/ProMainPagePreview.cs:194)
ProMainPage:show() (at Assets/_Photobooth Pro/Scripts/ProMainPage.cs:113)
ProController:setUI_MainPage() (at Assets/_Photobooth Pro/Scripts/ProController.cs:130)c__AnonStorey0:<>m__0() (at Assets/_Photobooth Pro/Scripts/ProFirstPage.cs:32)
UnityEngine.EventSystems.EventSystem:Update()>> (2) WebCam Logi Capture
UnityEngine.Debug:Log(Object)
ProMainPagePreview:setup(ProController) (at Assets/_Photobooth Pro/Scripts/ProMainPagePreview.cs:194)
ProMainPage:show() (at Assets/_Photobooth Pro/Scripts/ProMainPage.cs:113)
ProController:setUI_MainPage() (at Assets/_Photobooth Pro/Scripts/ProController.cs:130)c__AnonStorey0:<>m__0() (at Assets/_Photobooth Pro/Scripts/ProFirstPage.cs:32)
UnityEngine.EventSystems.EventSystem:Update()>> Webcam [0%3=0] <> resolution : (640x480)
UnityEngine.Debug:Log(Object)
ProMainPagePreview:setup(ProController) (at Assets/_Photobooth Pro/Scripts/ProMainPagePreview.cs:197)
ProMainPage:show() (at Assets/_Photobooth Pro/Scripts/ProMainPage.cs:113)
ProController:setUI_MainPage() (at Assets/_Photobooth Pro/Scripts/ProController.cs:130)c__AnonStorey0:<>m__0() (at Assets/_Photobooth Pro/Scripts/ProFirstPage.cs:32)
UnityEngine.EventSystems.EventSystem:Update()>> Logitech HD Webcam C270 width x height = 16X16 IS PLAYING = False
UnityEngine.Debug:Log(Object)
ProMainPagePreview:setup(ProController) (at Assets/_Photobooth Pro/Scripts/ProMainPagePreview.cs:210)
ProMainPage:show() (at Assets/_Photobooth Pro/Scripts/ProMainPage.cs:113)
ProController:setUI_MainPage() (at Assets/_Photobooth Pro/Scripts/ProController.cs:130)c__AnonStorey0:<>m__0() (at Assets/_Photobooth Pro/Scripts/ProFirstPage.cs:32)
UnityEngine.EventSystems.EventSystem:Update()
It show webcam texture width and height is "16X16" and isPlaying = "False". And you can see there is so many layer between the button click event to `start_webcam()`
(`ProFirstPage` button click event will show `ProMainPage` and it call `ProMainPagePreview.setup()` to start webcam).
----------
Then, I copied the same code to `ProController.cs` and run. the Debug.Log():> (0) WebCam Logitech HD Webcam C270
UnityEngine.Debug:Log(Object)
ProController:Start() (at Assets/_Photobooth Pro/Scripts/ProController.cs:47)> (1) WebCam Integrated Webcam
UnityEngine.Debug:Log(Object)
ProController:Start() (at Assets/_Photobooth Pro/Scripts/ProController.cs:47)> (2) WebCam Logi Capture
UnityEngine.Debug:Log(Object)
ProController:Start() (at Assets/_Photobooth Pro/Scripts/ProController.cs:47)> Webcam [0%3=0] <> resolution : (640x480)
UnityEngine.Debug:Log(Object)
ProController:Start() (at Assets/_Photobooth Pro/Scripts/ProController.cs:50)> Logitech HD Webcam C270 width x height = 640X480 IS PLAYING = True
UnityEngine.Debug:Log(Object)
ProController:Start() (at Assets/_Photobooth Pro/Scripts/ProController.cs:59)
The Code Work!!!! And I don't know why it work I guess it is because my first attempt there are too many layer between the scripts.
Anyone know the correct answer?
↧