UrhoSharp from PowerShell

lahellerlaheller USMember ✭✭


If somebody for some reason wants to use UrhoSharp from Windows PowerShell, then I created a sample script, how to do that.

# Set the correct parth here to Urho.dll assembly file
$libUrho = "C:\Users\held\.nuget\packages\urhosharp\1.8.93\lib\net45\Urho.dll"


Add-Type -Path $libUrho #-PassThru

Set-Location -Path "$Env:USERPROFILE"

[Urho.Desktop.DesktopUrhoInitializer]::AssetsDirectory = $null

$ExceptionHandler = {
    # $args[0] -> Sender
    # $args[1] -> EventArgs
    Write-Warning -Message "$($args[1].Exception.Message)`n"
    $args[1].Handled = $true

$ActionStarted = {
    Write-Verbose -Message "Application has started!`n" -Verbose
    if ([Urho.Application]::HasCurrent) {
        # Obtain the instance of current existing SimpleApplication
        $app = [Urho.Application]::Current -as [Urho.SimpleApplication]

        # Change default settings
        $app.Zone.Enabled = $false



        # Create one box and add it to the scene
        $box = [Urho.StaticModel]::new($app.Context)
        $box.Model = [Urho.CoreAssets+Models]::Box
        $mat = [Urho.CoreAssets+Materials]::DefaultGrey
        $box.Material = $mat

$ActionStopped = {
    Write-Verbose -Message "Application has stopped!`n" -Verbose

    # Cleanup


$opts = New-Object -TypeName Urho.ApplicationOptions -Property @{
    AutoloadCoreData = $true
    HighDpi = $true
    NoSound = $true
    Orientation = [Urho.ApplicationOptions+OrientationType]::LandscapeAndPortrait
    Height = 800
    Width = 1280
$app = [Urho.Application]::CreateInstance([Urho.SimpleApplication],$opts)

# At this point a new window with Scene appears and the rest of script is blocked until Esc is not pressed
$r1 = $app.Run()

# Execution continues here when Esc is pressed
$r2 = $app.Exit()

Save the above code to C:\UrhoSharp.ps1 file and from command line run following:

powershell.exe -ExecutionPolicy Unrestricted -File "C:\UrhoSharp.ps1"

The above example just displays one gray box in the scene.



Sign In or Register to comment.