PLUG Unity Guide

Quick Start

Download latest version

1. Project settings

In order to use PLUG SDK, development environment should be set as following from unity..

  • From unity menu, click on Asset > Import package and select NaverCafeSDK-x.x.x.unityPackage file you have downloaded from Custom Package dialog box.

  • If you click on Import from Custom Package dialog box, NCSDK folder and Plugins folder are generated.

  • Drag the NCSDK.Prefabs in Sample folder in NCSDK folder to desired scene. Button that is provided as default in plugin is generated.

  • Enter the cafe ID, client ID, and client secret to GLinkConfig file in Scripts folder in NCSDK folder.

//NCSDK/Scripts/GLinkConfig 
static class GLinkConfig
{
     public const string NaverLoginConsumerKey = "Consumer ID";
     public const string NaverLoginConsumerSecret = "Secret ID";
     public const int CafeId = 00000000;
}

Run PLUG SDK button is provided as default in PLUG SDK for development. It can be directly generated. Sample code is written in SampleBehaviour.cs file.

Refer to GitHub archive for details about PLUG SDK for each operating system..

2. Initialization

Initialize PLUG SDK according to the language that is being supported, as explained below.

2.1 PLUG SDK initialization (only supports Korean - Naver cafe)

When initializing PLUG SDK that only supports Korean, initialization information should be set and items related to foreign language support in script file should be processed as note.

Apply initialization information setting to GLinkConfig.cs file in Scripts folder in NCSDK folder.

  • NaverLoginClientId: Client ID received when registering application on the login developer center using Naver ID

  • NaverLoginClientSecret: Client secret received when registering application on the login developer center using Naver ID

  • CafeId: Cafe ID received by opening a Naver café

Items that are related to foreign language support in script file for each operating system in Script folder in NCSDK folder are processed as note. Following items in GlinkAndroid.cs file, which is the script file for Android, are processed as note.

glinkClass.CallStatic ("initGlobal", currentActivity, GLinkConfig.ConsumerKey, GLinkConfig.ConsumerSecureKey, GLinkConfig.CommunityNo, GLinkConfig.LoungeNo);

Following items in GlinkiOS.cs file, which is the script file for iOS, are processed as note.

_InitGLinkForGlobal(GLinkConfig.ConsumerKey, GLinkConfig.ConsumerSecureKey, GLinkConfig.CommunityNo, GLinkConfig.LoungeNo);

2.2 PLUG SDK initialization (only supports a foreign language)

When initializing PLUG SDK that only supports foreign language, initialization information should be set and items related to foreign language support in script file should be removed from note.

Apply initialization information setting to GLinkConfig.cs file in Scripts folder in NCSDK folder.

  • NeoIdConsumerKey: Consumer key received by opening the community

  • CommunityId: Community ID received by opening the community

Items that are related to foreign language support in script file for each operating system in Script folder in NCSDK folder are removed from note.

Following items in GlinkAndroid.cs file, which is the script file for Android, are removed from note.

glinkClass.CallStatic ("initGlobal", currentActivity, GLinkConfig.ConsumerKey, GLinkConfig.ConsumerSecureKey, GLinkConfig.CommunityNo, GLinkConfig.LoungeNo);

Following items in GlinkiOS.cs file, which is the script file for iOS, are removed from note.

_InitGLinkForGlobal(GLinkConfig.ConsumerKey, GLinkConfig.ConsumerSecureKey, GLinkConfig.CommunityNo, GLinkConfig.LoungeNo);

3. Start PLUG SDK

Run PLUG SDK after initialization is complete.

GLink.cs GLink.cs file is a script file where there is a method for controlling PLUG SDK.

3.1 executeHome() method

It is a method for starting executeHome() method plugin.

GLink.sharedInstance().executeHome();

3.2 executeArticlePost() method

executeArticlePost() method is used for opening article post screen. Deliver article ID to parameter.

GLink.sharedInstance().executeArticlePost("Content");

4. Additional iOS setting

When developing iOS game, following items should be set additionally.

4.1 Vertical mode setting

When developing game that is carried out in vertical mode, NCSDKManager.setOrientationIsLandscape properties for NCSDKUnityManager.mm file in NCSDK/Plugins/iOS folder should be set as No.

- (void)setGLRootViewController {
_mainViewcontroller = UnityGetGLViewController();

[[NCSDKManager getSharedInstance] setParentViewController:_mainViewcontroller];
[[NCSDKManager getSharedInstance] setNcSDKDelegate:self];
[[NCSDKManager getSharedInstance] setOrientationIsLandscape:NO];
}

4.2 .bundle file link

In unity 5.4.0f3 version or above, .bundle file is not linked when building iOS application. You should select iOS from Select for plugin to link the NaverAuth.bundle file and NaverCafeSDK.bundle file.

4.3 Xcode setting

Development environment should be set as following in XCode.

  1. Add -ObjC option to Other Link Flags from Build Settings.

  2. Add the following library to Link Binary With Libraries on Build Phases. Set the Status of the library to be added to Required.

  • MobileCoreServices.framework

  • SystemConfiguration.framework

  • MediaPlayer.framework

  • AVFoundation.framework

  • CoreMedia.framework

  • AssetsLibrary.framework

  • Security.framework

  • ImageIO.framework

  • QuartzCore.framework

  • ReplayKit.framework(Set library status to optional)

  • SafariServices.framework

  • Webkit.framework

Initialization of a plugin that supports the global community and a domestic Naver cafe

When it supports both global community and domestic Naver cafe, initialization information setting should be applied to GLinkConfig.cs file.

  • NaverLoginClientId: Client ID received when registering application on the login developer center using Naver ID

  • NaverLoginClientSecret: : Client secret received when registering application on the login developer center using Naver ID

  • CafeId: Cafe ID that has been received by opening a Naver cafe

  • ConsumerKey: Consumer key received by opening the community

  • ConsumerSecureKey: Consumer secret key received by opening the community

static class GLinkConfig
{
	public const string NaverLoginClientId = "197CymaStozo7X5r2qR5";
	public const string NaverLoginClientSecret = "evCgKH1kJL";
	public const int CafeId = 28290504;
	
	public const string ConsumerKey = "PLUGTESTKEY";
	public const string ConsumerSecureKey = "PLUGTESTSECRET";
	public const int CommunityNo = 1;
	public const int LoungeNo = 58;
}

Android

Remove the following items from note in GlinkAndroid.cs file, which is the script file for Android, in order to initialize information in global community and domestic Naver cafe.

public GLinkAndroid () {
     ...
    glinkClass.CallStatic ("init", currentActivity, GLinkConfig.NaverLoginClientId, GLinkConfig.NaverLoginClientSecret, GLinkConfig.CafeId);
    glinkClass.CallStatic ("initGlobal", currentActivity, GLinkConfig.ConsumerKey, GLinkConfig.ConsumerSecureKey, GLinkConfig.CommunityNo, GLinkConfig.LoungeNo);
    ...
}

iOS

Remove the following items from note in GlinkiOS.cs file, which is the script file for iOS, in order to initialize information in global community and domestic Naver cafe.

public GLinkiOS () {
     ...
     _InitGLink(GLinkConfig.NaverLoginClientId, GLinkConfig.NaverLoginClientSecret, GLinkConfig.CafeId);
     _InitGLinkForGlobal(GLinkConfig.ConsumerKey, GLinkConfig.ConsumerSecureKey, GLinkConfig.CommunityNo, GLinkConfig.LoungeNo);
     ...
}

Start / Close

Start or close the plugin while a certain tab is selected.

executeHome() method

Start the plugin while home tab is selected.

public void executeHome()

The following is an example of the executeHome() method.

   /**
   * Start with the home tab
   */
  Glink.sharedInstance().executeHome()

executeArticle() method

Start the plugin while a certain post is shown in the bulletin board tab.

public void executeArticle(int articleId)

The following is an example of the executeArticle() method.

   /**
   * Start with reading the article
   */
  Glink.sharedInstance().startArticle(121);

Horizontal mode, vertical mode

The plugin supports both horizontal and vertical modes.

Android

In the Android environment, horizontal and vertical modes are automatically applied without having to apply the setting separately.

iOS

In the iOS environment, setOrientationIsLandscape: method is applied for both the horizontal and vertical modes.

The following is an example of using the horizontal mode on the plugin.

// Default value is Yes
// Horizontal mode
[[NCSDKManager getSharedInstance] setOrientationIsLandscape:YES];

The following is an example of using the vertical mode on the plugin.

// Vertical mode
[[NCSDKManager getSharedInstance] setOrientationIsLandscape:NO];

Adjust transparency

If you adjust transparency using the adjustment slider on the upper left side of the plugin screen, you can use the game and the cafe at the same time.

Android

You can set the setTransparentable() method to enable the transparency adjustment slider in the Android environment.

public static void setTransparentable(Activity activity, boolean isTransparentable)

If you set "true" for the isTransparentable parameter value, you can use the transparency adjustment slider (default value: true).

The following is an example of using the transparency adjustment slider.

  /**
   * You can apply setting for using transparency adjustment slider.
   *
   * Boolean type value for enabling @param isTransparentable transparency adjustment   
   */
  Glink.setTransparentable(activity, true)

iOS

Apply the disableTransparentSlider: method setting to use transparency adjustment slider in iOS environment.

(void)disableTransparentSlider:(BOOL)disable;

If you set YES as the disable parameter value, you can use the transparency adjustment slider (default value: YES).

The following is an example of using the transparency adjustment slider.

/*
 Remove the function for adjusting transparency
 default : YES
 */
//Use the transparency function
[[NCSDKManager getSharedInstance] disableTransparentSlider:YES];

The following is an example of not using the transparency adjustment slider.

// Remove the transparency function
[[NCSDKManager getSharedInstance] disableTransparentSlider:NO];

Widget

A widget is an element that is automatically displayed on the screen when the fold button is pressed on the plugin. You can use the plugin anywhere in the game by using a widget.

Widget display

You can apply the showWidgetWhenUnloadSDK() method setting in order to display the widget when the fold button is pressed on the plugin.

void setShowWidgetWhenUnloadSDK(boolean useWidget)

If you set true on useWidget parameter value, widget is displayed when plug window is folded (default value: true).

The following is an example of displaying the widget.

  /**
   * You can decide whether or not to display the widget when the plugin window is folded.
   *
   * Boolean type value for displaying @param useWidget widget
   */
  Glink.sharedInstance().setShowWidgetWhenUnloadSDK(true);

Run widget

Use the startWidget() method for running the widget.

public static void startWidget()

The following is an example of running the widget.

  /**
   * Run the widget.
   */
  Glink.sharedInstance().startWidget();

Close widget

Use the stopWidget() method to close the widget.

public static void stopWidget()

The following is an example of force closing the widget.

  /**
   * Close the widget.
   */
  Glink.sharedInstance().stopWidget();

Default position settings for the widget

When the widget is first run, it is displayed on the center-left part of the screen. If you wish to set the default position settings when the widget is first run, use the setWidgetStartPosition() method.

However, when the widget is run again after the user has moved the widget, the widget will be displayed in the position where the user last moved it.

void setWidgetStartPosition(bool isLeft, int heightPercentage)

The following is an example for setting the widget's default position to 20% from top, on the right side of the screen.

    /**
    * Apply default position setting for widget.
    * isLeft: If the value is true, it is displayed on the left. If the value is false, it is displayed on the right.
    * heightPercentage: You can designate the vertical position using %.
    **/

    GLink.sharedInstance().setWidgetStartPosition(false, 20);

Screen capture

You can capture the game screen by pressing the screen capture button on the widget.

Screen capture button

Screen capture function is run by registering widget screen capture button click listener.

Android

In Android environment, widget screen capture button click listener is registered on following callback function.

glinkClass.CallStatic ("setOnWidgetScreenshotClickListener", new OnWidgetScreenshotClickListener ());

The following is an example of using screen capture button click listener on GlinkAndroid.cs file, which is the script file for Android.

class OnWidgetScreenshotClickListener : AndroidJavaProxy {
    public OnWidgetScreenshotClickListener () : base("com.naver.glink.android.sdk.Glink$OnWidgetScreenshotClickListener") { /* empty. */ }

    void onScreenshotClick() {
        string name = "CafeSdkController";

        GameObject obj = GameObject.Find (name);
        if (obj == null) {
            obj = new GameObject ("CafeSdkController");
            obj.AddComponent<SampleBehaviour> ();
        }

        SampleBehaviour behaviour = obj.GetComponent<SampleBehaviour> ();
        behaviour.OnClickScreenShotButton ();
    }
}

iOS

In iOS environment, screen capture button click listener is used on GlinkiOS.cs file, which is the script file for iOS, as indicated on the example below.

public void executeCaptureScreenshopAndPostArticle(string dummy) {
    // For iOS , For Widget
    // Game ScreenShot Code
    StartCoroutine (this.CoFunction ());
    Texture2D image = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
    image.ReadPixels (new Rect (0, 0, Screen.width, Screen.height), 0, 0, true);
    image.Apply ();

    byte[] bytes = image.EncodeToPNG();
    string path = Application.persistentDataPath + "/GLShareImage.png";
    File.WriteAllBytes(path, bytes);        

    GLink.sharedInstance().executeArticlePostWithImage(5, "", "", path);

}

Screen capture settings

You can use the setUseWidgetScreenShot() method to enable screen capture functionality.

void setUseWidgetScreenShot(bool useScreenShot);

If you set useScreenShot parameter value as true, screen capture button is displayed on the widget (default value: true).

The following is an example of not using screen capture function.

    /**
    * Screen capture button is not displayed on the widget.
    **/

    GLink.sharedInstance().setUseWidgetScreenShot(false);

Video recording

If you press the video recording button, you can record the game screen while playing the game.

  • The video recording function is supported on Android 5.0 or above.

  • Video recording functionality is supported on iOS 9.0 or above.

Use the video recording function on the widget

If you press the video recording button on the widget, you can record the game screen while playing the game.

Video recording settings

You can use setUseWidgetVideoRecord() method for using video recording function.

public void setUseWidgetVideoRecord(bool useVideoRecord)

If you set the useVideoRecord parameter value as true, the video recording button will be displayed on the widget (default value: false).

Video recording button is not displayed on the widget from the device that is using Android 5.0 or below and iOS 9.0 or below even if you set useVideoRecord parameter value as true.

The following is an example of using the video recording function.

  /**
   * You can decide whether to use video recording function.
   *
   * Boolean type value for using @param useVideoRecord video recording function
   */
  GLink.sharedInstance().setUseWidgetVideoRecord(true)

Recording ended callback listener

Tasks that should be processed when video recording is complete are carried out by registering callback listener. Android

Android

In Android environment, recording complete click listener is registered on following callback function.

glinkClass.CallStatic ("setOnRecordFinishListener", new OnRecordFinishListener ());

The following is an example of using the recording ended listener on GlinkAndroid.cs file, which is the script file for Android.

class OnRecordFinishListener : AndroidJavaProxy {
    public OnRecordFinishListener () : base("com.naver.glink.android.sdk.Glink$OnRecordFinishListener") { /* empty. */ }

    void onRecordFinished(String uri) {
        GLinkAndroid glink = (GLinkAndroid) GLink.sharedInstance ();
        glink.executeArticlePostWithVideo (-1, "", "", uri);
    }
}

iOS

In the iOS environment, the recording ended listener is registered with the ncSDKWidgetSuccessVideoRecord method.

 (void)ncSDKWidgetSuccessVideoRecord;

The following is an example of using the recording ended listener.

...
[[NCSDKManager getSharedInstance] setNcSDKDelegate:self];
...
- (void)ncSDKWidgetSuccessVideoRecord {
    NSLog(@"동영상 녹화 완료");
}

Use the video recording function on the game

You can run the video recording button from the game developer to record the game screen.

Start / Stop video recording

Use the startRecord() method to start video recording.

/*
Start video recording.
*/


GLinkRecord.sharedInstance().startRecord();

Use stoptRecord() method for finishing video recording.

/*
Stop video recording.
*/

GLinkRecord.sharedInstance().stoptRecord();

Video recording callback listener

Callback listener that processes event that is occurred from video recording using the button on game developer should be registered for use.

Android

Android callback listener that is provided in GLinkRecord.cs, which is the script file using video recording function, is indicated as below.

class OnRecordManagerListener : AndroidJavaProxy {
    void onStartRecord() {
    // TODO: startRecord callback.
    showToast ("start record");
    }

    void onErrorRecord() {
    //TODO: record error callback.+
    showToast ("record error");
    }

    void onFinishRecord(string uri) {
    //TODO: record finish callback.+
    // GLinkAndroid glink = (GLinkAndroid) GLink.sharedInstance ();
    // glink.executeArticlePostWithVideo (uri);
    }
}

iOS

iOS callback listener that is provided in GLinkRecord.cs, which is the script file using video recording function, is indicated as below.

public class GLinkRecordiOS : IGLinkRecord {

    // Start video recording
    delegate void RecordStartDelegate();
    [MonoPInvokeCallback(typeof(RecordStartDelegate))]
    public static void _RecordStartCallback () {
        Debug.Log("Record Started.");
    }

    // Error occurs in video recording
    delegate void RecordErrorDelegate(string result);
    [MonoPInvokeCallback(typeof(RecordErrorDelegate))]
    public static void _RecordErrorCallback (string result) {
        Debug.Log("Record Error : " + result);
    }

       // Stop video recording
    delegate void RecordFinishDelegate();
    [MonoPInvokeCallback(typeof(RecordFinishDelegate))]
    public static void _RecordFinishCallback () {
        Debug.Log("Record Finish.");
    }

    // Close preview window after video recording
    delegate void RecordFinishWithPreviewDelegate();
    [MonoPInvokeCallback(typeof(RecordFinishWithPreviewDelegate))]
    public static void _RecordFinishWithPreviewCallback () {
        Debug.Log("Record Finish With Preview.");
    }
}

App scheme processing

When you press the banner image that is displayed on the home screen of the game plugin, you can go to the App scheme to run game functions.

You can register the banner image for moving to the App scheme from the cafe management menu.

Android

In order to use App scheme processing when touch event is occurred in banner image that is moving to App scheme in Android environment, listener should be set in GlinkAndroid.cs file, which is the script file for Android, as indicated below.

class OnClickAppSchemeBannerListener : AndroidJavaProxy {
    public OnClickAppSchemeBannerListener () : base("com.naver.glink.android.sdk.Glink$OnClickAppSchemeBannerListener") { /* empty. */ }

    void onClickAppSchemeBanner (string appScheme) {
        showToast ("tapped:" + appScheme);
    }
}

iOS

In order to use App scheme processing when touch event is occurred in banner image that is moving to App scheme in iOS environment, listener should be in GLinkiOS.cs file, which is the script file for iOS, as indicated below.

delegate void NCSDKAppSchemeBannerDelegate(string appScheme);
[MonoPInvokeCallback(typeof(NCSDKAppSchemeBannerDelegate))]
public static void _NCSDKAppSchemeBannerCallback (string appScheme) {
    Debug.Log("AppSceme : " + appScheme);
    _ShowMessageToast ("AppScheme" + appScheme);
}

Game ID linkage

By linking the user’s game ID and cafe ID, they can be managed. You can check for the list of linked game ID and cafe IDs from cafe management menu.

In order to link a game ID and cafe ID, the syncGameUserId() method should be used.

void syncGameUserId(string gameUserId)

The following is an example of linking the game ID and cafe ID.

  /**
   * Link the game ID and cafe ID.
   *
   * @param gameUserId game ID
   */
  GLink.sharedInstance().syncGameUserId("usergameid");

Change theme color

You can change the theme color of the plugin.

In order to change the theme color, the setThemeColor() method is used.

/** 
 * The default value for the themeColorCSSString parameter is ‘#00c73c.’
 * The default value for backgroundCSSString parameter is ‘#44484e.’
 * It is recommended that you use the default value for the backgroundCSSString parameter.
 **/

void setThemeColor(string themeColorCSSString, string backgroundCSSString);
  • themeColorCSSString: The default color that is used on the theme (default value: #00c73c)

  • backgroundCSSString: the background color for the tab menu (default value: #44484e). It is recommended that you use the default value.

Caution Do not apply alpha values for the CSS color value.

  • Correct example: #ff9800

  • Incorrect example: #e2ff9800

The following is an example of changing the theme color.

GLink.sharedInstance().setThemeColor("#00c73c", "#44484e");

Change resource image

The resource image that is included in Naver cafe plugin library can be changed as indicated below.

Android

The resource image that is included in Naver cafe plugin library from Android environment can be changed as indicated below.

  1. Unzip the Naver cafe plugin library file (.aar file).

  2. Change the image in the /res/drawable-xhdpi folder to the desired image.

  3. Compress the unzipped folder to a library file (.aar file).

  4. Apply the new Naver cafe plugin library to build the project.

Caution When changing the image, the new image's size should be identical with the previous image.

iOS

The resource image that is included in Naver cafe plugin library in an iOS environment can be changed as indicated below.

  1. Change the image in the NaverCafeSDK.bundle package to the desired image.

  2. Apply the new package to the Naver cafe plugin library and build the project.

Caution When changing the image, the new image's size should be identical with the previous image.

Naver login

Enable login with Naver ID in the application.

  • GLinkNaverId.cs file is used for Naver login function.

init() method

Use the following initialization information to initialize the Naver login functionality.

  • Client ID received when registering application on the login developer center using Naver ID

  • Client secret received when registering application on the login developer center using Naver ID

The following is an example of initializing the Naver login function.

    GLinkNaverId.sharedInstance().init("197CymaStozo7x5r2qR5", "evCgKH1kJL");

login() method

Login with Naver ID.

    GLinkNaverId.sharedInstance().login();

로그인 완료 후 리스너가 호출된다.

Android

Listener is requested after login is complete.

class OnLoggedInListener : AndroidJavaProxy {
        public OnLoggedInListener () : base("com.naver.glink.android.sdk.Glink$OnLoggedInListener") { /* empty. */ }

        void onLoggedIn (bool success) {
            // TODO: login callback.
        }
    }

iOS

The following is an example of calling listener after login is complete in iOS environment.

public static void _NaverIdGetProfileCallback (string result) {
        Debug.Log(" result : " + result);
    }

logout() method

    GLinkNaverId.sharedInstance().logout();

isLogin() method

Check login status.

    BOOL isLogin = GLinkNaverId.sharedInstance().isLogin();

getProfile() method

Search for logged in user’s basic information (mail address, nickname, profile picture, birthday, age). GLinkNaverId.sharedInstance().getProfile();

    GLinkNaverId.sharedInstance().getProfile();

Register listener for the information you wish to search for.

Android

The following is an example of listener that searches for user basic information in Android environment.

    class OnGetProfileListener : AndroidJavaProxy {
        public OnGetProfileListener () : base("com.naver.glink.android.sdk.NaverIdLogin$OnGetProfileListener") { /* empty. */ }

        void onResult(string jsonString) {
            // TODO: get profile callback.
        }
    }

iOS

The following is an example of listener that searches for user basic information in iOS environment.

public static void _NaverIdLoginCallback () {
        Debug.Log("Naver Login Success");
    }

Last updated