Unity:求好评控制器

60 篇文章 2 订阅
9 篇文章 1 订阅
using System;
using System.Runtime.InteropServices;
using UnityEngine;


public class AndroidClick : AndroidJavaProxy
{
    private Action<int> action;
    public AndroidClick(Action<int> action) : base("com.cwgtech.unity.MyPlugin$AlertViewCallback")
    {
        this.action = action;
    }

    public void onButtonTapped(int index)
    {
        if (action != null)
        {
            action(index);
        }
    }
}

public class FiveStartManager : MonoBehaviour
{
    private static FiveStartManager main;

    public static FiveStartManager Main
    {
        get { return main; }
    }

    private void Awake()
    {
        main = this;
        strs = new String [4];
        if (GameManager.Main.ischinese)
        {
            strs[0] = "请给个好评吧";
            strs[1] = "有了大家的支持我们会更加努力的做出更多的精品游戏,动动小手给个好评吧,谢谢!";
            strs[2] = "稍后提醒";
            strs[3] = "前往评价";
        }
        else
        {
            strs[0] = "Rate this game";
            strs[1] = "Rate this game please! We appreciate your comments as they means a lot to us!";
            strs[2] = "Remind Me Later";
            strs[3] = "Rate it Now";
        }
    }

    private string[] strs;
    
    AndroidJavaClass _pluginClass;
    AndroidJavaObject _pluginInstance;

    public AndroidJavaClass PluginClass
    {
        get
        {
            if (_pluginClass == null)
            {
                _pluginClass = new AndroidJavaClass("com.cwgtech.unity.MyPlugin");
                AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
                _pluginClass.SetStatic<AndroidJavaObject>("mainActivity", activity);
            }
            return _pluginClass;
        }
    }

    public AndroidJavaObject PluginInstance
    {
        get
        {
            if (_pluginInstance == null)
            {
                _pluginInstance = PluginClass.CallStatic<AndroidJavaObject>("getInstance");
            }
            return _pluginInstance;
        }
    }
    
    private delegate void intCallback(int result);

    [DllImport("__Internal")]
    private static extern void IOScreateNativeAlert(string[] strings, int stringCount, intCallback callback);


    [AOT.MonoPInvokeCallback(typeof(intCallback))]
    static void nativeAlertHandler(int result)
    {
        if (result == 1)
        {
            Application.OpenURL("itms-apps://itunes.apple.com/us/app/id1521212942?mt=8&action=write-review");
        }
    }

    public void ShowHaoPing()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            PluginInstance.Call("showAlertView",new object[]{strs,new AndroidClick((int i) =>
            {
                if (i == -2)
                {
                    Application.OpenURL("market://details?id=" + Application.identifier + "&showAllReviews=true");
                }
            })});
        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {IOScreateNativeAlert(strs, strs.Length, nativeAlertHandler);}
    }
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值