本文整理汇总了C#中SiliconStudio.Xenko.Engine.Game.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Game.Run方法的具体用法?C# Game.Run怎么用?C# Game.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiliconStudio.Xenko.Engine.Game
的用法示例。
在下文中一共展示了Game.Run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
using (var game = new Game())
{
game.Run();
}
}
示例2: Main
static void Main(string[] args)
{
// Profiler.EnableAll();
using (game = new Game())
{
game.GraphicsDeviceManager.DeviceCreated += GraphicsDeviceManager_DeviceCreated;
game.Run();
}
}
示例3: RunGameTest
public static void RunGameTest(Game game)
{
#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
using (game)
{
game.Run();
}
#elif SILICONSTUDIO_PLATFORM_UWP
throw new NotImplementedException();
#elif SILICONSTUDIO_PLATFORM_IOS || SILICONSTUDIO_PLATFORM_ANDROID
lock(uniThreadLock)
{
// Prepare finish callback
var tcs = new TaskCompletionSource<bool>();
EventHandler<EventArgs> gameFinishedCallback = (sender, e) =>
{
// Notify waiter that game has exited
Logger.Info("Game finished.");
tcs.TrySetResult(true);
};
EventHandler<GameUnhandledExceptionEventArgs> exceptionhandler = (sender, e) =>
{
Logger.Info("Game finished with exception ={0}.", e);
tcs.TrySetException((Exception)e.ExceptionObject);
};
// Transmit data to activity
// TODO: Avoid static with string intent + Dictionary?
try
{
game.UnhandledException += exceptionhandler;
Logger.Info(@"Starting activity");
#if SILICONSTUDIO_PLATFORM_IOS
game.Exiting += gameFinishedCallback;
UIApplication.SharedApplication.InvokeOnMainThread(() =>
{
var window = UIApplication.SharedApplication.KeyWindow;
var rootNavigationController = (UINavigationController)window.RootViewController;
// create the xenko game view
var bounds = UIScreen.MainScreen.Bounds;
var xenkoGameView = new iOSXenkoView((System.Drawing.RectangleF)bounds) { ContentScaleFactor = UIScreen.MainScreen.Scale };
// create the view controller used to display the xenko game
var xenkoGameController = new iOSGameTestController(game) { View = xenkoGameView };
// create the game context
var gameContext = new GameContextiOS(new iOSWindow(window, xenkoGameView, xenkoGameController));
// push view
rootNavigationController.PushViewController(gameContext.Control.GameViewController, false);
// launch the game
game.Run(gameContext);
});
#elif SILICONSTUDIO_PLATFORM_ANDROID
// Start activity
AndroidGameTestActivity.GameToStart = game;
AndroidGameTestActivity.Destroyed += gameFinishedCallback;
PlatformAndroid.Context.StartActivity(typeof(AndroidGameTestActivity));
#endif
// Wait for completion of task
// TODO: Should we put a timeout and issue a Game.Exit() in main thread if too long?
tcs.Task.Wait();
Logger.Info(@"Activity ended");
}
catch (AggregateException e)
{
// Unwrap aggregate exceptions
if (e.InnerExceptions.Count == 1)
ExceptionDispatchInfo.Capture(e.InnerException).Throw();
}
finally
{
#if SILICONSTUDIO_PLATFORM_IOS
// iOS Cleanup
UIApplication.SharedApplication.InvokeOnMainThread(() =>
{
var window = UIApplication.SharedApplication.KeyWindow;
var rootNavigationController = (UINavigationController)window.RootViewController;
rootNavigationController.PopViewController(false);
});
#elif SILICONSTUDIO_PLATFORM_ANDROID
AndroidGameTestActivity.Destroyed -= gameFinishedCallback;
AndroidGameTestActivity.GameToStart = null;
#endif
}
}
#endif
}
示例4: GameLaunch
/// <inheritdoc/>
public void GameLaunch(string gameTypeName)
{
try
{
Log.Info("Running game with type {0}", gameTypeName);
Type gameType;
lock (loadedAssemblies)
{
gameType = GameEnumerateTypesHelper().FirstOrDefault(x => x.FullName == gameTypeName);
}
if (gameType == null)
throw new InvalidOperationException(string.Format("Could not find type [{0}] in project [{1}]", gameTypeName, projectName));
game = (Game)Activator.CreateInstance(gameType);
// TODO: Bind database
Task.Run(() =>
{
gameFinished.Reset();
try
{
using (game)
{
// Allow scripts to crash, we will still restart them
game.Script.Scheduler.PropagateExceptions = false;
game.Run();
}
}
catch (Exception e)
{
Log.Error("Exception while running game", e);
}
host.OnGameExited();
// Notify we are done
gameFinished.Set();
});
}
catch (Exception ex)
{
Log.Error("Game [{0}] from project [{1}] failed to run", ex, gameTypeName, projectName);
}
}