コード例 #1
0
    public static void PostProcess(BuildOptions options, string installPath, string downloadWebplayerUrl, int width, int height)
    {
        string fileName = FileUtil.UnityGetFileName(installPath);
        string path1    = installPath;
        string str1     = "Temp/BuildingWebplayerTemplate";

        FileUtil.DeleteFileOrDirectory(str1);
        if (PlayerSettings.webPlayerTemplate == null || !PlayerSettings.webPlayerTemplate.Contains(":"))
        {
            Debug.LogError((object)"Invalid WebPlayer template selection! Select a template in player settings.");
        }
        else
        {
            string[] strArray = PlayerSettings.webPlayerTemplate.Split(':');
            string   str2     = Path.Combine(Path.Combine(!strArray[0].Equals("PROJECT") ? Path.Combine(EditorApplication.applicationContentsPath, "Resources") : Application.dataPath, "WebPlayerTemplates"), strArray[1]);
            if (!Directory.Exists(str2))
            {
                Debug.LogError((object)"Invalid WebPlayer template path! Select a template in player settings.");
            }
            else if (Directory.GetFiles(str2, "index.*").Length < 1)
            {
                Debug.LogError((object)"Invalid WebPlayer template selection! Select a template in player settings.");
            }
            else
            {
                FileUtil.CopyDirectoryRecursive(str2, str1);
                string file      = Directory.GetFiles(str1, "index.*")[0];
                string extension = Path.GetExtension(file);
                string str3      = Path.Combine(str1, fileName + extension);
                FileUtil.MoveFileOrDirectory(file, str3);
                string[] files = Directory.GetFiles(str1, "thumbnail.*");
                if (files.Length > 0)
                {
                    FileUtil.DeleteFileOrDirectory(files[0]);
                }
                bool          flag       = (options & BuildOptions.WebPlayerOfflineDeployment) != BuildOptions.None;
                string        str4       = !flag ? downloadWebplayerUrl + "/3.0/uo/UnityObject2.js" : "UnityObject2.js";
                string        str5       = string.Format("<script type='text/javascript' src='{0}'></script>", !flag ? (object)"https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.min.js" : (object)"jquery.min.js");
                List <string> stringList = new List <string>();
                stringList.Add("%UNITY_UNITYOBJECT_DEPENDENCIES%");
                stringList.Add(str5);
                stringList.Add("%UNITY_UNITYOBJECT_URL%");
                stringList.Add(str4);
                stringList.Add("%UNITY_WIDTH%");
                stringList.Add(width.ToString());
                stringList.Add("%UNITY_HEIGHT%");
                stringList.Add(height.ToString());
                stringList.Add("%UNITY_PLAYER_PARAMS%");
                stringList.Add(PostProcessWebPlayer.GeneratePlayerParamsString(options));
                stringList.Add("%UNITY_WEB_NAME%");
                stringList.Add(PlayerSettings.productName);
                stringList.Add("%UNITY_WEB_PATH%");
                stringList.Add(fileName + ".unity3d");
                if (InternalEditorUtility.IsUnityBeta())
                {
                    stringList.Add("%UNITY_BETA_WARNING%");
                    stringList.Add("\r\n\t\t<p style=\"color: #c00; font-size: small; font-style: italic;\">Built with beta version of Unity. Will only work on your computer!</p>");
                    stringList.Add("%UNITY_SET_BASE_DOWNLOAD_URL%");
                    stringList.Add(",baseDownloadUrl: \"" + downloadWebplayerUrl + "/\"");
                }
                else
                {
                    stringList.Add("%UNITY_BETA_WARNING%");
                    stringList.Add(string.Empty);
                    stringList.Add("%UNITY_SET_BASE_DOWNLOAD_URL%");
                    stringList.Add(string.Empty);
                }
                foreach (string templateCustomKey in PlayerSettings.templateCustomKeys)
                {
                    stringList.Add("%UNITY_CUSTOM_" + templateCustomKey.ToUpper() + "%");
                    stringList.Add(PlayerSettings.GetTemplateCustomValue(templateCustomKey));
                }
                FileUtil.ReplaceText(str3, stringList.ToArray());
                if (flag)
                {
                    string str6 = Path.Combine(str1, "UnityObject2.js");
                    FileUtil.DeleteFileOrDirectory(str6);
                    FileUtil.UnityFileCopy(EditorApplication.applicationContentsPath + "/Resources/UnityObject2.js", str6);
                    string str7 = Path.Combine(str1, "jquery.min.js");
                    FileUtil.DeleteFileOrDirectory(str7);
                    FileUtil.UnityFileCopy(EditorApplication.applicationContentsPath + "/Resources/jquery.min.js", str7);
                }
                FileUtil.CopyDirectoryRecursive(str1, installPath, true);
                string str8 = Path.Combine(path1, fileName + ".unity3d");
                FileUtil.DeleteFileOrDirectory(str8);
                FileUtil.MoveFileOrDirectory("Temp/unitystream.unity3d", str8);
                if (!Directory.Exists("Assets/StreamingAssets"))
                {
                    return;
                }
                FileUtil.CopyDirectoryRecursiveForPostprocess("Assets/StreamingAssets", Path.Combine(path1, "StreamingAssets"), true);
            }
        }
    }
コード例 #2
0
    public static void PostProcess(BuildOptions options, string installPath, string downloadWebplayerUrl, int width, int height)
    {
        string str  = FileUtil.UnityGetFileName(installPath);
        string text = "Temp/BuildingWebplayerTemplate";

        FileUtil.DeleteFileOrDirectory(text);
        if (PlayerSettings.webPlayerTemplate == null || !PlayerSettings.webPlayerTemplate.Contains(":"))
        {
            Debug.LogError("Invalid WebPlayer template selection! Select a template in player settings.");
            return;
        }
        string[] array = PlayerSettings.webPlayerTemplate.Split(new char[]
        {
            ':'
        });
        string text2;

        if (array[0].Equals("PROJECT"))
        {
            text2 = Application.dataPath;
        }
        else
        {
            text2 = Path.Combine(EditorApplication.applicationContentsPath, "Resources");
        }
        text2 = Path.Combine(Path.Combine(text2, "WebPlayerTemplates"), array[1]);
        if (!Directory.Exists(text2))
        {
            Debug.LogError("Invalid WebPlayer template path! Select a template in player settings.");
            return;
        }
        string[] files = Directory.GetFiles(text2, "index.*");
        if (files.Length < 1)
        {
            Debug.LogError("Invalid WebPlayer template selection! Select a template in player settings.");
            return;
        }
        FileUtil.CopyDirectoryRecursive(text2, text);
        files = Directory.GetFiles(text, "index.*");
        string text3     = files[0];
        string extension = Path.GetExtension(text3);
        string text4     = Path.Combine(text, str + extension);

        FileUtil.MoveFileOrDirectory(text3, text4);
        string[] files2 = Directory.GetFiles(text, "thumbnail.*");
        if (files2.Length > 0)
        {
            FileUtil.DeleteFileOrDirectory(files2[0]);
        }
        bool          flag  = (options & BuildOptions.WebPlayerOfflineDeployment) != BuildOptions.None;
        string        item  = (!flag) ? (downloadWebplayerUrl + "/3.0/uo/UnityObject2.js") : "UnityObject2.js";
        string        item2 = string.Format("<script type='text/javascript' src='{0}'></script>", (!flag) ? "https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.min.js" : "jquery.min.js");
        List <string> list  = new List <string>();

        list.Add("%UNITY_UNITYOBJECT_DEPENDENCIES%");
        list.Add(item2);
        list.Add("%UNITY_UNITYOBJECT_URL%");
        list.Add(item);
        list.Add("%UNITY_WIDTH%");
        list.Add(width.ToString());
        list.Add("%UNITY_HEIGHT%");
        list.Add(height.ToString());
        list.Add("%UNITY_PLAYER_PARAMS%");
        list.Add(PostProcessWebPlayer.GeneratePlayerParamsString(options));
        list.Add("%UNITY_WEB_NAME%");
        list.Add(PlayerSettings.productName);
        list.Add("%UNITY_WEB_PATH%");
        list.Add(str + ".unity3d");
        if (InternalEditorUtility.IsUnityBeta())
        {
            list.Add("%UNITY_BETA_WARNING%");
            list.Add("\r\n\t\t<p style=\"color: #c00; font-size: small; font-style: italic;\">Built with beta version of Unity. Will only work on your computer!</p>");
            list.Add("%UNITY_SET_BASE_DOWNLOAD_URL%");
            list.Add(",baseDownloadUrl: \"" + downloadWebplayerUrl + "/\"");
        }
        else
        {
            list.Add("%UNITY_BETA_WARNING%");
            list.Add(string.Empty);
            list.Add("%UNITY_SET_BASE_DOWNLOAD_URL%");
            list.Add(string.Empty);
        }
        string[] templateCustomKeys = PlayerSettings.templateCustomKeys;
        for (int i = 0; i < templateCustomKeys.Length; i++)
        {
            string text5 = templateCustomKeys[i];
            list.Add("%UNITY_CUSTOM_" + text5.ToUpper() + "%");
            list.Add(PlayerSettings.GetTemplateCustomValue(text5));
        }
        FileUtil.ReplaceText(text4, list.ToArray());
        if (flag)
        {
            string text6 = Path.Combine(text, "UnityObject2.js");
            FileUtil.DeleteFileOrDirectory(text6);
            FileUtil.UnityFileCopy(EditorApplication.applicationContentsPath + "/Resources/UnityObject2.js", text6);
            text6 = Path.Combine(text, "jquery.min.js");
            FileUtil.DeleteFileOrDirectory(text6);
            FileUtil.UnityFileCopy(EditorApplication.applicationContentsPath + "/Resources/jquery.min.js", text6);
        }
        FileUtil.CopyDirectoryRecursive(text, installPath, true);
        string text7 = Path.Combine(installPath, str + ".unity3d");

        FileUtil.DeleteFileOrDirectory(text7);
        FileUtil.MoveFileOrDirectory("Temp/unitystream.unity3d", text7);
        if (Directory.Exists("Assets/StreamingAssets"))
        {
            FileUtil.CopyDirectoryRecursiveForPostprocess("Assets/StreamingAssets", Path.Combine(installPath, "StreamingAssets"), true);
        }
    }