Application.OpenURL不同平台的使用

using UnityEngine;
using System.Collections;

public class testjar : MonoBehaviour {

    private static readonly int LocalVersion = 1;
    private static readonly int ServerVersion = 2;
    public static string apkURL = "http://da.qq.com/webplat/info/news_version3/1615/1616/1617/2174/m1554/201403/253077.shtml";
    public static string exeURL = "http://baidu.com";

    public interface IPlatformUpdate
    {
        void DoPlatformUpdate();
    }
    public class CPlatfromFactory
    {
        public  IPlatformUpdate CreatePlatfrom(string platfrom)
        {
            IPlatformUpdate platform = null;
            if (platfrom.Equals("Android"))
            {
                platform = new CAndroidUpdate();
            }
            else if (platfrom.Equals("EXE"))
            {
                platform = new CEXEUpdate();
            }
            return platform;
        }
    }
    public class CAndroidUpdate : IPlatformUpdate
    {
        public void DoPlatformUpdate()
        {
            Application.OpenURL(apkURL);
        }
    }
    public class CEXEUpdate : IPlatformUpdate
    {
        public void DoPlatformUpdate()
        {
            Application.OpenURL(exeURL);
        }
    }

    public bool isUpdate()
    {
        if (LocalVersion < ServerVersion)
            return true;
        else
            return false;
    }
    public string GetPlatfom()
    {
      #if UNITY_ANDROID
        return "Android";
      #endif
      #if UNITY_STANDALONE_WIN
        return "EXE";
       #endif
    }
    // Use this for initialization
    void Start () {
        if (isUpdate())
        {
            CPlatfromFactory cp = new CPlatfromFactory();
            IPlatformUpdate iu = cp.CreatePlatfrom(GetPlatfom());
            iu.DoPlatformUpdate();
        }


    }

    // Update is called once per frame
    void Update () {

    }
    void OnGUI()    
    {

    } 


}

APK版本打开的是节奏大师的官网,并下载
EXE版本打开的是百度搜索首页。
操作步骤:新建一个空场景,将脚本挂在Camera之上,分别打包APK以及EXE就可以看到效果。

你可能感兴趣的:(unity3d)