Last active
February 24, 2024 14:55
-
-
Save GOROman/d403d39b34d7f99934fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UnityからAndroidのCamera LEDを制御する例 | |
// startPreview() でカメラのプレビューを開始した状態で LEDOn() で光る | |
public class AndroidCamera { | |
AndroidJavaObject camera = null; | |
public AndroidCamera() { | |
WebCamDevice[] devices = WebCamTexture.devices; | |
Debug.Log("Camera Name:"+devices[0].name); | |
open(); | |
} | |
public void open() | |
{ | |
if (camera == null) { | |
#if (UNITY_ANDROID && !UNITY_EDITOR) | |
AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera"); | |
camera = cameraClass.CallStatic<AndroidJavaObject>("open"); | |
#endif | |
} | |
} | |
public void release() | |
{ | |
if (camera != null) { | |
LEDOff(); | |
camera.Call("release"); | |
camera = null; | |
} | |
} | |
public void startPreview() | |
{ | |
if (camera != null) { | |
Debug.Log("AndroidCamera::startPreview()"); | |
camera.Call("startPreview"); | |
} | |
} | |
public void stopPreview() | |
{ | |
if (camera != null) { | |
Debug.Log("AndroidCamera::stopPreview()"); | |
LEDOff(); | |
camera.Call("stopPreview"); | |
} | |
} | |
// Flashモードの設定 | |
private void setFlashMode(string mode) | |
{ | |
if (camera != null) { | |
AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject>("getParameters"); | |
cameraParameters.Call("setFlashMode",mode); | |
camera.Call("setParameters",cameraParameters); | |
} | |
} | |
// LED点灯 | |
public void LEDOn() { | |
setFlashMode("torch"); | |
} | |
// LED消灯 | |
public void LEDOff() { | |
setFlashMode("off"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello It is not working. Do you know the reason?