/// <summary> /// 以反射方式,尝试通过Application读取数据 /// </summary> /// <param name="pathUri"></param> /// <returns></returns> public static System.IO.Stream ApplicationResourceStream(Uri pathUri) { if (!supportApplication) { return(null); } try { if (appType == null) { try { appType = JavaRuntime.ClassforName("System.Windows.Application"); supportApplication = true; } catch { supportApplication = false; } } object o = JavaRuntime.NewInstance(appType); System.Reflection.MethodInfo method = JavaRuntime.GetMethod(appType, "GetResourceStream", pathUri.GetType()); object res = JavaRuntime.Invoke(method, o, pathUri); if (res != null) { System.Reflection.MethodInfo info = res.GetType().GetMethod("get_Stream"); object open = JavaRuntime.Invoke(info, res); return(open as System.IO.Stream); } } catch { } return(null); }
/// <summary> /// 加载并显示Screen到设备屏幕 /// </summary> public void ShowScreen() { if (setupSensors) { Type accelerometer = null; if (accelerometer == null) { try { accelerometer = JavaRuntime.ClassforName("Loon.Core.Input.Sensors.AccelerometerExecute"); supportSensors = true; } catch (Exception) { supportSensors = false; } } if (supportSensors) { try { object o = JavaRuntime.NewInstance(accelerometer); System.Reflection.MethodInfo initialize = JavaRuntime.GetMethod(accelerometer, "Initialize"); initialize.Invoke(o, null); System.Reflection.MethodInfo isActive = JavaRuntime.GetMethod(accelerometer, "IsActive"); supportSensors = (bool)isActive.Invoke(o, null); } catch (Exception) { supportSensors = false; } } } }
public void Register(LSetting setting, Type clazz, params object[] args) { MaxScreen(setting.width, setting.height); Initialization(setting.landscape, setting.mode); SetShowFPS(setting.showFPS); SetShowMemory(setting.showMemory); SetShowLogo(setting.showLogo); SetFPS(setting.fps); if (GamePage != null) { GamePage.Title = setting.title; } if (clazz != null) { if (args != null) { try { int funs = args.Length; if (funs == 0) { SetScreen((Screen)JavaRuntime.NewInstance(clazz)); ShowScreen(); } else { Type[] functions = new Type[funs]; for (int i = 0; i < funs; i++) { functions[i] = GetType(args[i]); } System.Reflection.ConstructorInfo constructor = JavaRuntime.GetConstructor(clazz, functions); Object o = JavaRuntime.Invoke(constructor, args); } } catch (Exception ex) { Log.Exception(ex); } } } }
private void StartElement(string name) { Type clazz = (Type)CollectionUtils.Get(change, name.ToLower()); if (clazz != null) { DefinitionObject childObject = null; try { childObject = (DefinitionObject)JavaRuntime.NewInstance(clazz); if (_source != null) { childObject.fileName = _source; } } catch (Exception e) { Loon.Utils.Debug.Log.Exception(e); } if (this.isCurrentElementDefined) { childObject.InitWithParentObject(this.currentDefinitionObject); } childObject.DefinitionObjectDidInit(); if (childObject.parentDefinitionObject != null) { childObject.parentDefinitionObject.ChildDefinitionObjectDidInit(childObject); } this.curClass = clazz; this.currentDefinitionObject = childObject; this.isCurrentElementDefined = true; } else { this.isCurrentElementDefined = false; if (this.currentDefinitionObject != null) { this.currentDefinitionObject.UndefinedElementDidStart(name); } } }
public void Register(LSetting setting, Type clazz, params object[] args) { XNAConfig.Load(); SetShowFPS(setting.showFPS); SetShowMemory(setting.showMemory); SetShowLogo(setting.showLogo); SetFPS(setting.fps); if (clazz != null) { if (args != null) { try { int funs = args.Length; if (funs == 0) { SetScreen((Screen)JavaRuntime.NewInstance(clazz)); ShowScreen(); } else { Type[] functions = new Type[funs]; for (int i = 0; i < funs; i++) { functions[i] = GetType(args[i]); } System.Reflection.ConstructorInfo constructor = JavaRuntime.GetConstructor(clazz, functions); object o = JavaRuntime.Invoke(constructor, args); } } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); } } } }