1. 程式人生 > >Unity3d Android IOS 自動設定 簽名和輸出 路徑

Unity3d Android IOS 自動設定 簽名和輸出 路徑

大家先熟悉 下這個 [InitializeOnLoad] 。 這個標籤 是 Unity3D剛開啟 或者 執行時候的回撥;那我們就給予它開始程式碼

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using BoTing.Updater;

[InitializeOnLoad]
public static class ProjectAutoSetting
{


    static ProjectAutoSetting()
    {
        //EditorUserBuildSettings.activeBuildTargetChanged = delegate () {
        //    if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        //    {
        //        Debug.Log("DoSomeThings");
        //    }
        //};
        //EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
        //EditorUserBuildSettings.activeBuildTargetChanged += OnAutoSetting;
        OnAutoSetting();
    }


    static void OnAutoSetting()
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        {
            OnAndroid();
        }
        else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
        {
            OnIOS();
        }
    }


    static void OnAndroid()
    {

        //Debug.Log("OnAndroid");
        DirectoryInfo dir = Directory.GetParent(Application.dataPath).Parent;

        string path = dir.ToString() + @"\KeyStore\user_Phoenix.keystore";//自己的路徑
        //Debug.Log(path);

        if (File.Exists(path))
        {

            PlayerSettings.Android.keystoreName = path;
            PlayerSettings.Android.keyaliasName = "phoenix";
            PlayerSettings.keystorePass = "youxi9123";
            PlayerSettings.keyaliasPass = "phoenix9123";

            PlayerSettings.applicationIdentifier = "com.fenghuang.yule";

            PlayerSettings.companyName = "912娛樂";
            PlayerSettings.productName = "鳳凰競技娛樂";
            PlayerSettings.bundleVersion = UpdaterConfig.AppVersion;//這裡這幾根據專案設定 我這裡有全域性的
            PlayerSettings.Android.bundleVersionCode = int.Parse(System.DateTime.Now.ToString("yyMMddHHmm"));
        }
        string outPath = Directory.GetParent(Application.dataPath).Parent.ToString() + "/" + PlayerSettings.productName + "_" + System.DateTime.Now.ToString("yyyyMMddHHmm");
        EditorUserBuildSettings.SetBuildLocation(BuildTarget.Android, outPath);
    }
    static void OnIOS()
    {
        //Debug.Log("OnIOS");

        PlayerSettings.applicationIdentifier = "com.fenghuang.yule";
        PlayerSettings.bundleVersion = "1.9.115";
        PlayerSettings.iOS.applicationDisplayName = "鳳凰競技娛樂";
        PlayerSettings.iOS.targetOSVersionString = "8";
        PlayerSettings.iOS.buildNumber = System.DateTime.Now.ToString("yyyyMMddHHmm");
        PlayerSettings.iOS.sdkVersion = iOSSdkVersion.DeviceSDK;
    }

}