CocosCreator 2.2.4
See the version list below for details.
dotnet add package CocosCreator --version 2.2.4
NuGet\Install-Package CocosCreator -Version 2.2.4
<PackageReference Include="CocosCreator" Version="2.2.4" />
paket add CocosCreator --version 2.2.4
#r "nuget: CocosCreator, 2.2.4"
// Install CocosCreator as a Cake Addin #addin nuget:?package=CocosCreator&version=2.2.4 // Install CocosCreator as a Cake Tool #tool nuget:?package=CocosCreator&version=2.2.4
Xamarin.CocosCreator
Packages
Platform/Feature | Package name | Stable | Prerelease | Cocos Creator Version |
---|---|---|---|---|
CocosCreator | CocosCreator |
2.2.0 - 2.2.2 |
Getting Started
Environment
- CocosCreator v2.2.x
- Visual Studio 2017+
Build your Cocos Creator Project
- template: default
- platform: android/iOS
- buildPath: ./build
Xamarin Android
Install nuget CocosCreator
1. Create Android Activity
public class MainActivity : Cocos2dxActivity
2. Override OnCreate
protected override void OnCreate(Bundle savedInstanceState)
{
if (!IsTaskRoot)
{
return;
}
Java.Lang.JavaSystem.LoadLibrary("cocos2djs");
this.Setxxteakey("123456789");
base.OnCreate(savedInstanceState);
app = this;
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
}
NOTE: Make sure the xxteakey is matched with your cocos creator's build setting
3. override Cocos2dxGLSurfaceView OnCreateView()
public override Cocos2dxGLSurfaceView OnCreateView()
{
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
glSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0);
return glSurfaceView;
}
4. Copy Resources
Copy resources in Cocos Creator's build folder to Xamarin.Android Assets folder (except frameworks & js backups folder)
- jsb-adapter
- res
- src
- subpackages
- main.js
- project.json
- ...
5. Add to your android project *.csproj file
<ItemGroup>
<AndroidAsset Include="Assets\**" />
</ItemGroup>
Xamarin iOS
Install nuget CocosCreator
1. Create iOS AppDelegate
public partial class AppDelegate : AppController
2. Override DidFinishLaunchingWithOptions
public override bool DidFinishLaunchingWithOptions(UIApplication app, NSDictionary options)
{
options = new NSDictionary(new NSString("xxtea_key"), new NSString("123456789"));
return base.DidFinishLaunchingWithOptions(app, options);
}
NOTE: Make sure the xxteakey is matched with your cocos creator's build setting
3. Copy Resources
Copy resources in Cocos Creator's build folder to Xamarin.iOS Resources folder (except frameworks & js backups folder)
- jsb-adapter
- res
- src
- subpackages
- main.js
- project.json
- ...
4. Add to your iOS project *.csproj file
<BundleResource Include="Resources\**">
<Optimize>False</Optimize>
</BundleResource>
Please run sample project to check all configuration
NOTE: This package does not support iOS emulator
Advanced topics
1. How to Call Xamarin.Android & Xamarin.iOS C# methods using JavaScript
please refer articles for android & ios first
In cocos creator javascript:
if (cc.sys.os === cc.sys.OS_ANDROID) {
var result = jsb.reflection.callStaticMethod("org/cocos2dx/lib/Cocos2dxActivity",
"paramFromJSStaticString", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
"cocos2d-js",
"Native Call Test");
cc.log(result);
}
else if (cc.sys.os === cc.sys.OS_IOS) {
var ret = jsb.reflection.callStaticMethod("NativeOcClass",
"callNativeWithReturnString:andContent:",
"cocos2d-js",
"Native Call Test");
cc.log(ret);
}
To get the value from js:
- In android, override following methods in MainActivity:
public override void ParamFromJSVoid(string title, string message)
{
System.Diagnostics.Debug.WriteLine($"title: {title}, message: {message}");
}
public override int ParamFromJSInt(string title, string message)
{
return base.ParamFromJSInt(title, message);
}
public override string ParamFromJSString(string title, string message)
{
return base.ParamFromJSString(title, message);
}
- In ios, override following methods in AppDelegate:
public override bool CallNativeWithReturnBool(string title, string content)
{
System.Diagnostics.Debug.WriteLine($"CallNativeWithReturnBool: title: { title} & content: {content}");
return base.CallNativeWithReturnBool(title, content);
}
public override string CallNativeWithReturnString(string title, string content)
{
System.Diagnostics.Debug.WriteLine($"CallNativeWithReturnString: title: { title} & content: {content}");
return base.CallNativeWithReturnString(title, content);
}
2. C# Call Javascript
- Xamarin.Android:
app.RunOnGLThread(new Runnable(() =>
{
Cocos2dxJavascriptJavaBridge.EvalString("cc.TestNativeCallJS()");
}));
- Xamarin.iOS :
AppController.EvalScript("cc.TestNativeCallJS()");
3. Cocos Creator HotUpdate
Of course, it's fully compatible with Xamarin!
4. SDK box integration?
No, don't need anymore, we have Xamarin Community instead!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
MonoAndroid | monoandroid90 is compatible. |
Xamarin.iOS | xamarinios10 is compatible. |
-
MonoAndroid 9.0
- Xamarin.Android.Support.CustomTabs (>= 28.0.0.3)
- Xamarin.Android.Support.Design (>= 28.0.0.3)
- Xamarin.Android.Support.v4 (>= 28.0.0.3)
- Xamarin.Android.Support.v7.AppCompat (>= 28.0.0.3)
- Xamarin.Android.Support.v7.CardView (>= 28.0.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2.4.5.1 | 1,249 | 5/26/2021 | |
2.4.5 | 898 | 5/1/2021 | |
2.4.3.1 | 763 | 1/5/2021 | |
2.4.3 | 793 | 11/7/2020 | |
2.3.5 | 597 | 10/29/2020 | |
2.3.4 | 788 | 4/19/2020 | |
2.3.3 | 842 | 4/17/2020 | |
2.2.8 | 621 | 3/27/2020 | |
2.2.7 | 566 | 3/24/2020 | |
2.2.6 | 724 | 2/18/2020 | |
2.2.5 | 869 | 1/7/2020 | |
2.2.4 | 903 | 1/7/2020 | |
2.2.3 | 597 | 1/6/2020 | |
2.2.2 | 643 | 1/6/2020 | |
2.2.1 | 813 | 1/5/2020 |