Where is the startup cs file?


#1

I want to work entirely inside Visual Studio. The Xenko Studio looks nice, but it’s not for me.

I added a new file- GameScript.cs to the MyGame.Game project and made a SyncScript.

using SiliconStudio.Xenko.Engine;
using System;

namespace MyGame
{
    public class GameScript : SyncScript
    {
        public override void Start()
        {
            throw new Exception("Get here at least?");
        }

        public override void Update()
        {
            
        }
    }
}

I put a breakpoint inside the Start method but it never hits. I see in the documentation that the script files needs to be dragged to the scene but it can also be done programatically-

myEntity.Add(new myAsyncScript());

However, I don’t know what the entry file is. I looked at the sample projects like JumpyJet and see they have scripts, but I don’t see how those scripts are added, I assume through the drag-and-drop method.

How do I add scripts to the game outside of the xenko studio?


#2

Look for your Main method. You can create your own class extending Game and instantiating it there instead of using the one from the library.


#3

Script will be executed only if they are added to an entity.

See http://doc.xenko.com/latest/en/manual/scripts/use-a-script.html


#4

Entry points for games are in the platform specific projects. For example if you created a game called MyGame for Windows there would be a project called MyGame.Windows and there would be a MyGameApp.cs in there that looked like:

class MyGameApp
{
    static void Main(string[] args)
    {
        using (var game = new Game())
        {
           //Setup Game stuff here:

            game.Run();
        }
    }
}

You could do all your setup in there per platform. But I think the easiest solution is just to use Game Studio setup a single MainScene with 1 Entity in it with a StartupScript called something like Bootstrap on it. Then close Game Studio and code away:

public class Bootstrap : StartupScript
{
    public override void Start()
    {
        // Do all your game startup code in here
    }
}

You may also need a camera in your startup screen.