我在从android.hardware.camera.getparameters
获取浮动参数后尝试启动相机并将其放在GUI.Button
上,但是当我在Android上运行应用程序时,我得到一个黑屏。在黑屏上GUI.button
或相机预览。但不是GUI.button
取决于我先调用浮点数还是相机。
有人知道问题出在哪里吗?我是初学者,我不知道在哪里可以找到问题。
这是我的代码:
using UnityEngine;
using System.Collections;
public class Cam : MonoBehaviour {
//variables privadas
public static WebCamDevice[] devices = WebCamTexture.devices;
private static float VerticalViewAngle;
private float mi;
//variables publicas
void Awake () {
//mi = hva ();
Playcam ();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GUI.Button(new Rect(0,0,Screen.width,20),mi.ToString("F4"));
}
void OnGUI () {
}
// funciones
public static Texture Startcamera(){
//WebCamDevice cam = WebCamDevice();
WebCamDevice cam = devices [0];
WebCamTexture webCameraTexture = new WebCamTexture(cam.name);
webCameraTexture.deviceName = cam.name;
webCameraTexture.Play();
return webCameraTexture;
}
//gnereacion de variables
public static float hva ()
{
AndroidJavaClass cameraClass = new AndroidJavaClass ("android.hardware.Camera");
int camID = 0;
AndroidJavaObject camera = cameraClass.CallStatic<AndroidJavaObject> ("open", camID);
AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject> ("getParameters");
VerticalViewAngle = cameraParameters.Call<float>("getFocalLength");
//Debug.Log ("miguel "+ VerticalViewAngle);
//Debug.Log ("fernando "+ VerticalViewAngle);
return VerticalViewAngle;
}
public void Playcam () {
GUITexture BackgroundTexture = gameObject.AddComponent<GUITexture>();
BackgroundTexture.pixelInset = new Rect(0,0,Screen.width,Screen.height);
BackgroundTexture.texture = Startcamera ();
}
}
这是我的androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
android:installLocation="preferExternal"
android:theme="@android:style/Theme.NoTitleBar"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:debuggable="false">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>
<activity android:name="com.unity3d.player.VideoPlayer"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<!--
To support devices using the TI S3D library for stereo mode we must
add the following library.
Devices that require this are: ODG X6
-->
<uses-library android:name="com.ti.s3d" android:required="false" />
<!--
To support the ODG R7 in stereo mode we must add the following library.
-->
<uses-library android:name="com.osterhoutgroup.api.ext" android:required="false" />
</application>
</manifest>
<!-- android:installLocation="preferExternal" -->