퓨즈 + 유니티 애즈[UNITY ADS] 연동 샘플

퓨즈[Fusetools]의 우노[Uno]를 이용해 유니티 애즈를 연동하는 샘플입니다.
현재 iOS만 완료한 상태이며, 안드로이드도 작업중입니다. iOS, Android 모두 완료했습니다.

소스코드 다운로드 (프로젝트 분리된 버전) ::
https://github.com/englekk/Fusetools_UnityAdsSample

하나의 프로젝트로 통합된 버전 ::
http://bit.ly/2eFmQcs

[[ UnoPlayground.uno ]]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Uno.UX;
using Uno;
using Uno.Compiler.ExportTargetInterop;

[Require("Xcode.FrameworkDirectory", "@('iOS_libs':Path)")]
[Require("Xcode.Framework", "@('iOS_libs/UnityAds.framework':Path)")]
[Require("Source.Import", "UnityAdsManager.h")]

public class UnoPlayground : NativeModule
{
    public UnoPlayground()
    {
        AddMember(new NativeFunction("initAds", (NativeCallback)initAds));
        AddMember(new NativeFunction("isReady", (NativeCallback)isReady));
        AddMember(new NativeFunction("showAds", (NativeCallback)showAds));
    }

    object initAds(Context c, object[] args)
    {
        initAds();
       
        return null;
    }

    object isReady(Context c, object[] args)
    {
        bool _b= isReady();
        //debug_log("isReady: " + _b);
        return _b;
    }

    object showAds(Context c, object[] args)
    {
        showAds();

        return null;
    }

    [Foreign(Language.ObjC)]
    static extern(iOS) void initAds()
    @{
        NSLog(@"initAds===");
        [UnityAdsManager init];
        //UnityAdsAndroid ads = new UnityAdsAndroid();
    @}

    [Foreign(Language.ObjC)]
    static extern(iOS) bool isReady()
    @{
        BOOL _b = [UnityAdsManager isReady];
        //NSLog(@"isReady===%d", _b);
        return _b;
    @}

    [Foreign(Language.ObjC)]
    static extern(iOS) void showAds()
    @{
        NSLog(@"showAds===");
        [UnityAdsManager showAds];
    @}

    static extern(!iOS) void initAds()
    {
        debug_log("Not supported!");
    }

    static extern(!iOS) bool isReady()
    {
        debug_log("Not supported!");
        return false;
    }

    static extern(!iOS) void showAds()
    {
        debug_log("Not supported!");
    }
}

[[ MainView.ux ]]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<App Background="#CCC">
    <UnoPlayground ux:Global="UnoPlayground"/>
   
    <StackPanel Alignment="Center" ItemSpacing="10">
        <JavaScript>
            var Environment = require('FuseJS/Environment');
            var readyBtnVisible = Environment.mobile == true ? "Visible" : "Hidden";

            var UnoPlayground = require("UnoPlayground");
            UnoPlayground.initAds();
           
            var Observable = require("FuseJS/Observable");
            var _isReady = Observable(false);

            function isReady()
            {
                _isReady.value = UnoPlayground.isReady();
            }

            var getIsReady = Observable(function ()
            {
                if(readyBtnVisible == "Hidden") return "This sample is for mobile.";
                return "IsReady: " + (_isReady.value == false ? "Tap after 1 second again" : "Ready!");
            });

            function showAds()
            {
                UnoPlayground.showAds();
            }

            var showAdsBtnVisibleStatus = Observable(function ()
            {
                return _isReady.value == true ? "Visible" : "Hidden";
            });

            module.exports = {
                _isReady,
                getIsReady,
                showAds,
                isReady,
                readyBtnVisible,
                showAdsBtnVisibleStatus
            }
        </JavaScript>
        <Text Value="{getIsReady}" TextAlignment="Center" />
        <Basic.Button Text="isReady?" Clicked="{isReady}" Visibility="{readyBtnVisible}" />
        <Basic.Button Text="showAds" Clicked="{showAds}" Visibility="{showAdsBtnVisibleStatus}" />
    </StackPanel>
</App>

[[ 동영상 강좌(재생 목록 버튼을 누르세요) ]]

Was this article helpful?

Related Articles