Ejemplo n.º 1
0
 protected void generateNavigationMeshInstances(App.Navigation nav, Godot.Collections.Array nodes)
 {
     for (int i = 0; i < nodes.Count; i++)
     {
         if (nodes[i] is StaticBody staticBody)
         {
             var meshInstance = staticBody.GetNodeOrNull <MeshInstance>("MeshInstance");
             if (meshInstance != null)
             {
                 NavigationMesh navMesh = new NavigationMesh();
                 navMesh.CreateFromMesh(meshInstance.Mesh);
                 nav.NavmeshAdd(navMesh, meshInstance.GetGlobalTransform());
                 var transform       = meshInstance.Transform;
                 var translation     = meshInstance.Translation;
                 var globalTransform = meshInstance.GlobalTransform;
                 GD.Print("created navmesh for meshinstance");
             }
             else
             {
                 GD.Print("[navmesh] meshinstance skipped (no child named 'MeshInstance')");
             }
         }
         else
         {
             GD.Print("[navmesh] meshinstance skipped (no staticbody)");
         }
     }
 }
Ejemplo n.º 2
0
    public override void _Ready()
    {
        GD.Print("This is the same as overriding _Ready()... 2");

        Account account = new Account
        {
            Email       = "*****@*****.**",
            Active      = true,
            CreatedDate = new DateTime(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
            Roles       = new List <string>
            {
                "User",
                "Admin"
            }
        };

        string json = JsonConvert.SerializeObject(account, Formatting.Indented);

        // {
        //   "Email": "*****@*****.**",
        //   "Active": true,
        //   "CreatedDate": "2013-01-20T00:00:00Z",
        //   "Roles": [
        //     "User",
        //     "Admin"
        //   ]
        // }

        GD.Print(json);

        /*var foo = new Triangle3(
         *  new SharpNav.Vector3(0, 0, 0),
         *  new SharpNav.Vector3(0, 1f, 0),
         *  new SharpNav.Vector3(0, 1f, 1f)
         * );*/

        this.mainCamera        = (PlayerCamera)GetNode("Navigation/PlayerCharacter/Camera");
        this.playerCharacter   = (KinematicBody)GetNode("Navigation/PlayerCharacter");
        this.navigation        = new App.Navigation();
        this.immediateGeometry = (ImmediateGeometry)GetNode("ImmediateGeometry");
        this.inventory         = (Control)GetNode("Inventory");
        this.characterScreen   = (Control)GetNode("CharacterScreen");

        var map = (Spatial)GetNode("Navigation/map");

        if (map != null && this.navigation != null)
        {
            //this.generateNavigationMeshInstances(this.navigation, map.GetChildren());
            if (this.playerCharacter != null)
            {
                var closestPoint = this.navigation.GetClosestPoint(this.playerCharacter.Translation);
                closestPoint.y = (float)Math.Round(closestPoint.y);
                closestPoint.y = 0;
                // this.playerCharacter.Translation = closestPoint;
            }
        }

        if (map != null)
        {
            var dummyItemOnTheGround = new App.Inventory.InventoryItem((Texture)GD.Load("res://static/dummy-sword-inventory-1x2.png"), new Vector2(1, 2));
            var groundNode           = dummyItemOnTheGround.getGroundNode();
            groundNode.Translation = new Vector3(12f, -1f, -12f);
            map.AddChild(groundNode);
        }
    }