我正在尝试创建一个SDK,其中我有几个图像和.jar文件中的所有类.
我已经为android SDK创建了Unity插件和桥接类.功能在SDK中运行良好.但我面临以下问题,我在这个SDK中以编程方式创建所有视图,
在原生android中它工作正常.使用该context.getClassLoader.getResourceAsStream方法可以访问图像,我可以InputStream很好地获得图像,并在创建视图时显示图像.
但是当我从Unity插件和android-bridge类调用SDK时,我得到null了InputStream.
有没有人对此有任何想法?以及如何解决这个问题.提前致谢.
我正在按照这个教程制作一个步骤计数器,它可以很好地作为一个Android项目但是当我使android项目成为一个库并想在unity3d中使用它时,它崩溃并给我一个错误class not found: exception
我的统一代码如下:
void Start ()
{
#if UNITY_ANDROID
AndroidJNI.AttachCurrentThread();
androidClass = new AndroidJavaClass("com.test.testapp.MainActivity");
#endif
}
#if UNITY_ANDROID
public void checkMyIntOnJava(string message){
if (message == "READY") {
int myInt = androidClass.CallStatic<int>("getMyInt");
guiText.text = "My Int: " + myInt;
}
}
Run Code Online (Sandbox Code Playgroud)
我的android代码如下:
public class MainActivity extends UnityPlayerActivity
implements OnDataPointListener, GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
{
public static void callbackToUnityMethod(int num, String gameObject,String methodName){
_myInt = num;
Log.e("GoogleFit", "in callbackToUnityMethod");
UnityPlayer.UnitySendMessage(gameObject, methodName, "READY");
}
}
Run Code Online (Sandbox Code Playgroud)
制作一个android jar后,我将它保存在unity3d的插件文件夹中.我错过了什么吗?
我的Android Manifest文件如下:
<?xml …Run Code Online (Sandbox Code Playgroud) google-play-services android-studio google-fit unity3d-5 android-unity-plugin
我无法将纹理绑定到a SurfaceTexture以在Unity中显示.
更新4:基于更新1中的管道(表面 - >外部纹理通过表面纹理 - > fbo - >纹理2d)我知道SurfaceTexture没有正确地将其表面转换为纹理.我可以通过pixelcopy从其表面获得正确的绘制图片,我可以确认我的FBO绘图到texture2d管道使用一些测试颜色.所以问题是,为什么SurfaceTexture不能将其表面转换为纹理?
我Texture在Java中生成一个并将其指针传递回Unity:
public void initGLTexture()
{
Log.d("Unity", "initGLTexture");
int textures[] = new int[1];
GLES20.glGenTextures(1, textures, 0);
mTextureId = textures[0];
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureId);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
Run Code Online (Sandbox Code Playgroud)
我SurfaceTexture从id(在Java中)创建一个:
mSurfaceTexture = new SurfaceTexture(mTextureId);
mSurfaceTexture.setDefaultBufferSize(512, 512);
Run Code Online (Sandbox Code Playgroud)
我使用第三方库GeckoView渲染到SurfaceTexture的Surface上.我从Unity调用以下方法OnRenderObject()来保持所有GL渲染在同一个线程上:
mSurfaceTexture.updateTexImage();
Run Code Online (Sandbox Code Playgroud)
我知道上面的代码可以正确地绘制到表面上.
我在Unity中调用以下内容来加载纹理:
_imageTexture2D = Texture2D.CreateExternalTexture(
512,512,TextureFormat.RGBA32,false,true,(IntPtr) mTextureId);
_rawImage.texture = _imageTexture2D;
Run Code Online (Sandbox Code Playgroud)
为什么RawImage应用纹理只显示这个看起来精灵的东西,它应该是一个网页?
更新1:所以我一直在研究以下假设:使用Gecko绘制到Surface,并使用SurfaceTexture将此表面渲染为a GL_TEXTURE_EXTERNAL_OES …
android opengl-es unity-game-engine textureview android-unity-plugin
我创建了一个 Android Unity 插件(.aar 文件),它为我的 Unity 游戏提供了一些自定义定位数据。在我的 Unity 脚本中,我使用,
var x = customClass.CallStatic<float>("getHeadX");
为了得到一些位置数据。每帧调用此方法以获取更新的数据(轮询方法),这使其效率低下。相反,当更新的数据准备好时,我决定从我的 java 代码(插件端)调用我的 Unity 脚本中的 C# 方法。为此,在我的 java 插件中,我写道,
import com.unity3d.player.UnityPlayer;
...
UnityPlayer.UnitySendMessage("Manager", // gameObject name
"PluginCallback", // this is a callback in C#
"Hello from android plugin"); // msg which is not needed actually
Run Code Online (Sandbox Code Playgroud)
但是,编译器抱怨包com.unity3d.player.UnityPlayer不存在。所以我从
C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Release\Classes\ classes.jar
进入我的 android 插件项目的“libs”文件夹。我成功构建了它并将生成的 .aar 文件(mylibrary-release.aar)复制到我的 Unity 项目的 Assets\Plugins\Android 文件夹中。
当我构建 Unity 项目(使用“内部”构建系统)时,它给了我这个错误:
IOException: 无法将文件/目录从 'Temp/StagingArea\android-libraries\mylibrary-release\classes.jar' 移动到 'Temp/StagingArea\android-libraries\mylibrary-release\libs\classes.jar'。UnityEditor.Android.PostProcessor.Tasks.ProcessAAR.Execute ...
发生此错误是因为 classes.jar 依赖项与 classes.jar 名称冲突(由我的插件统一制作)。因此,我将依赖项名称更改为unity_classes.jar …
我最近使用 estimote 信标创建了一个 Android Studio 项目。这就需要修改build.gradle,使其能够访问estimote sdk。我创建了该项目并且效果很好。我还创建了一个简单的 Android 插件来显示来自 Unity 的 Toast 消息(可在此处找到说明: https: //www.thepolyglotdeveloper.com/2014/06/creating-an-android-java-plugin-for-unity3d/)。
现在,因为我们在工作中使用 Unity 来创建应用程序,所以现在我需要为要在 Unity 中使用的信标创建一个插件,我的问题基本上是,如何添加 gradle 依赖项(编译 'com.estimote:sdk: 0.9.7@aar')进入Android的库项目(据我所知,一个库项目不会生成gradle文件)和/或进入unity,以便我可以在unity中使用信标代码?
android unity-game-engine gradle android-library android-unity-plugin
我正在尝试将 Google 的应用内审核功能集成到我的 Unity 应用程序中,并在 logcat 控制台上收到以下运行时错误消息。有谁知道这个问题的解决方案?
AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.play.core.review.ReviewManagerFactory (Filename: currently not available on il2cpp Line: -1)