我正在尝试在 c# 中使用 xamarin 编写一个 android 动态壁纸。
为此,我将此处找到的 GLWallPaperService 代码转换为 c#: http:
//www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/
(直接跳转到java实现在这里:https ://github.com/learnopengles/Learn-OpenGLES-Tutorials/tree/master/android/AndroidOpenGLESLessons/src/com/learnopengles/android/livewallpaper )
编译后,我得到错误:
Mono.android.TypeManager 中的 Activate(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object[]) 无法应用于 (java.lang.String,java.lang.String ,com.[redacted].OpenGLES2WallpaperService.OpenGLES2WallpaperService_OpenGLES2Engine,java.lang.Object[]) mono.android.TypeManager.Activate ("com.[redacted].OpenGLES2WallpaperService/OpenGLES2Engine, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "com.[redacted].WallpaperServiceUtil.OpenGLES2WallpaperService, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", this, new java.lang.Object[] { OpenGLES2WallpaperService.this }); D:\[编辑]\obj\Debug\android\src\com\[编辑]\wallpaperserviceutil\OpenGLES2WallpaperService.java
这是我的 c# 实现...抱歉长度:
public abstract class GLWallpaperService : WallpaperService
{
public class GLEngine : Engine
{
private readonly GLWallpaperService outerInstance;
public GLEngine(GLWallpaperService outerInstance) : base(outerInstance)
{
this.outerInstance = outerInstance;
}
internal class WallpaperGLSurfaceView : GLSurfaceView
{
private readonly GLWallpaperService.GLEngine outerInstance;
ISurfaceHolder _surfaceHolder;
internal WallpaperGLSurfaceView(GLWallpaperService.GLEngine outerInstance, Context context, ISurfaceHolder surfaceHolder)
: base(context)
{
this.outerInstance = outerInstance;
_surfaceHolder = surfaceHolder;
}
public override ISurfaceHolder Holder
{
get
{
return _surfaceHolder;
}
}
public virtual void OnDestroy()
{
base.OnDetachedFromWindow();
}
}
private WallpaperGLSurfaceView glSurfaceView;
private bool rendererHasBeenSet;
public override void OnCreate(ISurfaceHolder surfaceHolder)
{
base.OnCreate(surfaceHolder);
glSurfaceView = new WallpaperGLSurfaceView(this, outerInstance, surfaceHolder);
}
public override void OnVisibilityChanged(bool visible)
{
base.OnVisibilityChanged(visible);
if (rendererHasBeenSet)
{
if (visible)
{
glSurfaceView.OnResume();
}
else
{
if (!IsPreview)
{
glSurfaceView.OnPause();
}
}
}
}
public override void OnDestroy()
{
base.OnDestroy();
glSurfaceView.OnDestroy();
}
protected internal virtual Android.Opengl.GLSurfaceView.IRenderer NewRenderer//was just Renderer
{
set
{
glSurfaceView.SetRenderer(value);
rendererHasBeenSet = true;
}
}
protected internal virtual int EGLContextClientVersion
{
set
{
glSurfaceView.SetEGLContextClientVersion(value);
}
}
}
}
public abstract class OpenGLES2WallpaperService : GLWallpaperService
{
public override Engine OnCreateEngine()
{
return new OpenGLES2Engine(this);
}
internal class OpenGLES2Engine : GLWallpaperService.GLEngine
{
private readonly OpenGLES2WallpaperService outerInstance;
public OpenGLES2Engine(OpenGLES2WallpaperService outerInstance)
: base(outerInstance)
{
this.outerInstance = outerInstance;
}
public override void OnCreate(ISurfaceHolder surfaceHolder)
{
base.OnCreate(surfaceHolder);
// Check if the system supports OpenGL ES 2.0.
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final android.app.ActivityManager activityManager = (android.app.ActivityManager) getSystemService(android.content.Context.ACTIVITY_SERVICE);
ActivityManager activityManager = (ActivityManager)outerInstance.GetSystemService(Context.ActivityService);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final android.content.pm.ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
ConfigurationInfo configurationInfo = activityManager.DeviceConfigurationInfo;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
bool supportsEs2 = configurationInfo.ReqGlEsVersion >= 0x20000;
if (supportsEs2)
{
// Request an OpenGL ES 2.0 compatible context.
EGLContextClientVersion = 2;
// Set the renderer to our user-defined renderer.
NewRenderer = outerInstance.NewRenderer;//was just Renderer
}
else
{
// This is where you could create an OpenGL ES 1.x compatible
// renderer if you wanted to support both ES 1 and ES 2.
return;
}
}
}
internal abstract Android.Opengl.GLSurfaceView.IRenderer NewRenderer { get; }
}
public class LessonThreeWallpaperService : OpenGLES2WallpaperService
{
internal override Android.Opengl.GLSurfaceView.IRenderer NewRenderer
{
get
{
return new LessonThreeRenderer(); // is a GLSurfaceView.IRenderer
}
}
}
我的目标是版本 sdk 版本 8 并使用 Visual Studio 2012。
感谢任何帮助。