From 6aead426176b29fb207c03551c629ce3d316f35e Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Thu, 28 Sep 2017 15:41:29 -0400 Subject: [PATCH] [gameplaykit] Add bindings from Xcode 9.0 (#2798) Re-based from Miguel's PR #2476 including reviewers feedback. [1] https://github.com/xamarin/xamarin-macios/pull/2476 * [spritekit] Add GKSceneRootNodeType to SKScene too and adjust intro tests * [tests][intro][macos] Don't skip protocol checks for SceneKit on 64 bits --- src/gameplaykit.cs | 45 +++++++++++++++++++ src/scenekit.cs | 8 +++- src/spritekit.cs | 6 ++- tests/introspection/ApiProtocolTest.cs | 10 +++++ tests/introspection/Mac/MacApiProtocolTest.cs | 5 ++- 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/gameplaykit.cs b/src/gameplaykit.cs index 10e5af0bc1..412cf93e33 100644 --- a/src/gameplaykit.cs +++ b/src/gameplaykit.cs @@ -12,6 +12,7 @@ using System.ComponentModel; using XamCore.ObjCRuntime; using XamCore.Foundation; using XamCore.SpriteKit; +using XamCore.SceneKit; using Vector2 = global::OpenTK.Vector2; using Vector2d = global::OpenTK.Vector2d; using Vector2i = global::OpenTK.Vector2i; @@ -361,6 +362,16 @@ namespace XamCore.GameplayKit { [Export ("findActionForAnswers:")] [return: NullAllowed] NSObject FindAction (NSDictionary answers); + + [iOS (11,0), TV (11,0)] + [Mac (10,13, onlyOn64: true)] + [Export ("initWithURL:error:")] + IntPtr Constructor (NSUrl url, [NullAllowed] NSError error); + + [iOS (11,0), TV (11,0)] + [Mac (10,13, onlyOn64: true)] + [Export ("exportToURL:error:")] + bool Export (NSUrl url, [NullAllowed] NSError error); } [iOS (9,0), Mac (10,11, onlyOn64 : true)] @@ -1786,6 +1797,12 @@ namespace XamCore.GameplayKit { [return: NullAllowed] GKScene FromFile (string filename); + [iOS (11,0)][TV (11,0)][Mac (10,13, onlyOn64: true)] + [Static] + [Export ("sceneWithFileNamed:rootNode:")] + [return: NullAllowed] + GKScene FromFile (string filename, IGKSceneRootNodeType rootNode); + [Export ("entities")] GKEntity [] Entities { get; } @@ -1808,6 +1825,23 @@ namespace XamCore.GameplayKit { void RemoveGraph (string name); } + [iOS (11,0)] + [TV (11,0)] + [Mac (10,13, onlyOn64: true)] + [BaseType (typeof(GKComponent))] + interface GKSCNNodeComponent : GKAgentDelegate + { + [Static] + [Export ("componentWithNode:")] + GKSCNNodeComponent FromNode (SCNNode node); + + [Export ("initWithNode:")] + IntPtr Constructor (SCNNode node); + + [Export ("node")] + SCNNode Node { get; } + } + [iOS (10,0), TV (10,0), Mac (10,12, onlyOn64: true)] [Category] [BaseType (typeof (SKNode))] @@ -1833,6 +1867,17 @@ namespace XamCore.GameplayKit { void SetEntity (GKEntity entity); } + [iOS (11,0), TV (11,0), Mac (10,13, onlyOn64: true)] + [Category] + [BaseType (typeof (SCNNode))] + interface SCNNode_GameplayKit { + [Export ("entity")] + GKEntity GetEntity (); + + [Export ("setEntity:")] + void SetEntity (GKEntity entity); + } + [iOS (10,0), TV (10,0), Mac (10,12, onlyOn64: true)] [BaseType (typeof (NSObject), Name = "GKQuadtreeNode")] // Renamed to GKQuadtreeNode (lower case t) in Xcode8 [DisableDefaultCtor] // Used as a hint for faster removal via [GKQuadTree removeData:WithNode:] diff --git a/src/scenekit.cs b/src/scenekit.cs index 6fbf2efcc7..436547b2c0 100644 --- a/src/scenekit.cs +++ b/src/scenekit.cs @@ -45,6 +45,7 @@ using XamCore.SpriteKit; #if (XAMCORE_2_0 || !MONOMAC) && !WATCH using XamCore.ModelIO; using XamCore.Metal; +using XamCore.GameplayKit; #endif #if MONOMAC @@ -2029,7 +2030,12 @@ namespace XamCore.SceneKit { [Watch (3,0)] [Mac (10,8), iOS (8,0)] [BaseType (typeof (NSObject))] - interface SCNScene : NSSecureCoding { + interface SCNScene : +#if (XAMCORE_2_0 || !MONOMAC) && !WATCH + GKSceneRootNodeType , +#endif + NSSecureCoding { + [Static] [Export ("scene")] SCNScene Create (); diff --git a/src/spritekit.cs b/src/spritekit.cs index ff6516ca72..b8584ad674 100644 --- a/src/spritekit.cs +++ b/src/spritekit.cs @@ -521,7 +521,11 @@ namespace XamCore.SpriteKit { [Mac (10,9, onlyOn64 : true)] [Since (7,0)] [BaseType (typeof (SKEffectNode))] - partial interface SKScene { + interface SKScene +#if (XAMCORE_2_0 || !MONOMAC) && !WATCH + : GKSceneRootNodeType +#endif + { [Export ("initWithSize:")] IntPtr Constructor (CGSize size); diff --git a/tests/introspection/ApiProtocolTest.cs b/tests/introspection/ApiProtocolTest.cs index 55a708edfd..be467524b3 100644 --- a/tests/introspection/ApiProtocolTest.cs +++ b/tests/introspection/ApiProtocolTest.cs @@ -172,6 +172,16 @@ namespace Introspection { if (!TestRuntime.CheckXcodeVersion (9, 0)) return true; break; + case "GKSceneRootNodeType": + // it's an empty protocol, defined by a category and does not reply as expected + switch (type.Name) { + // GameplayKit.framework/Headers/SceneKit+Additions.h + case "SCNScene": + // GameplayKit.framework/Headers/SpriteKit+Additions.h + case "SKScene": + return true; + } + break; } return false; } diff --git a/tests/introspection/Mac/MacApiProtocolTest.cs b/tests/introspection/Mac/MacApiProtocolTest.cs index 6f9b5b4596..be2f017ee6 100644 --- a/tests/introspection/Mac/MacApiProtocolTest.cs +++ b/tests/introspection/Mac/MacApiProtocolTest.cs @@ -230,7 +230,10 @@ namespace Introspection { switch (type.Namespace) { case "MonoMac.SceneKit": case "SceneKit": - return IntPtr.Size == 4; // 64bits should be fine + // skip on 32 bits but continue otherwise + if (IntPtr.Size == 4) + return true; + break; } return base.Skip (type, protocolName);