Night_gua 2024-02-11 22:05 采纳率: 0%
浏览 4
已结题

UnityBepinExAmongUs模组问题

Unity Bepinex6.0.0-be.670 AmongUs模组

using System;
using System.Collections.Generic;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using static UnityEngine.UI.Button;
using Object = UnityEngine.Object;
using UnityEngine.SceneManagement;
using AmongUs.Data;
using Assets.InnerNet;
using System.Linq;

namespace MCI.UI
{
    [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))]
    public class MainMenuPatch
    {
        private static AnnouncementPopUp popUp;

        private static void Prefix(MainMenuManager __instance)
        {
            var template = GameObject.Find("SettingsButton");
            var template2 = GameObject.Find("AcountButton");
            var template3 = GameObject.Find("NewsButton");
            if (template == null || template2 == null || template3 == null) return;
            template.transform.localScale = new Vector3(0.42f, 0.84f, 1f);
            template.GetComponent<AspectPosition>().anchorPoint = new Vector2(0.378f, 0.5f);
            template.transform.FindChild("FontPlacer").transform.localScale = new Vector3(1.8f, 0.9f, 0.9f);
            template.transform.FindChild("FontPlacer").transform.localPosition = new Vector3(-1.1f, 0f, 0f);

            template2.transform.localScale = new Vector3(0.42f, 0.84f, 1f);
            template2.GetComponent<AspectPosition>().anchorPoint = new Vector2(0.378f, 0.5f);
            template2.transform.FindChild("FontPlacer").transform.localScale = new Vector3(1.8f, 0.9f, 0.9f);
            template2.transform.FindChild("FontPlacer").transform.localPosition = new Vector3(-1.1f, 0f, 0f);

            template3.transform.localScale = new Vector3(0.42f, 0.84f, 1f);
            template3.GetComponent<AspectPosition>().anchorPoint = new Vector2(0.378f, 0.5f);
            template3.transform.FindChild("FontPlacer").transform.localScale = new Vector3(1.8f, 0.9f, 0.9f);
            template3.transform.FindChild("FontPlacer").transform.localPosition = new Vector3(-1.1f, 0f, 0f);
            //qq频道
            var buttonDiscord = UnityEngine.Object.Instantiate(template, template.transform.parent);
            buttonDiscord.transform.localScale = new Vector3(0.42f, 0.84f, 1f);
            buttonDiscord.GetComponent<AspectPosition>().anchorPoint = new Vector2(0.542f, 0.5f);

            var textDiscord = buttonDiscord.transform.GetComponentInChildren<TMPro.TMP_Text>();
            __instance.StartCoroutine(Effects.Lerp(0.5f,
                new System.Action<float>((p) => { textDiscord.SetText("QQ频道"); })));
            PassiveButton passiveButtonDiscord = buttonDiscord.GetComponent<PassiveButton>();

            passiveButtonDiscord.OnClick = new Button.ButtonClickedEvent();
            passiveButtonDiscord.OnClick.AddListener((System.Action)(() =>
                Application.OpenURL(
                    "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=1YPTXe2Sh93pAUXv1mwv4unI6J_G1FYK&authKey=%2BPzdgfi%2FpbaxyPTVU1Lx8xU69Zo1X4%2FCih0lTozAbZ0%2FsCiO%2FGe8sQ97p6jxEFlV&noverify=0&group_code=647668527")));
            //DEBUG
            var buttonGITHUB = UnityEngine.Object.Instantiate(template, template3.transform.parent);
            buttonGITHUB.transform.localScale = new Vector3(0.42f, 0.84f, 1f);
            buttonGITHUB.GetComponent<AspectPosition>().anchorPoint = new Vector2(0.542f, 0.5f);

            var textGITHUB = buttonDiscord.transform.GetComponentInChildren<TMPro.TMP_Text>();
            __instance.StartCoroutine(Effects.Lerp(0.5f,
                new System.Action<float>((p) => { textGITHUB.SetText("QQ频道"); })));
            PassiveButton passiveButtonGITHUB = buttonDiscord.GetComponent<PassiveButton>();

            passiveButtonGITHUB.OnClick = new Button.ButtonClickedEvent();
            passiveButtonGITHUB.OnClick.AddListener((System.Action)(() =>
                Application.OpenURL(
                    "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=1YPTXe2Sh93pAUXv1mwv4unI6J_G1FYK&authKey=%2BPzdgfi%2FpbaxyPTVU1Lx8xU69Zo1X4%2FCih0lTozAbZ0%2FsCiO%2FGe8sQ97p6jxEFlV&noverify=0&group_code=647668527")));

            //公告
            if (template == null) return;
            var creditsButton = Object.Instantiate(template, template.transform.parent);

            creditsButton.transform.localScale = new Vector3(0.42f, 0.84f, 1f);
            creditsButton.GetComponent<AspectPosition>().anchorPoint = new Vector2(0.462f, 0.5f);

            var textCreditsButton = creditsButton.transform.GetComponentInChildren<TMPro.TMP_Text>();
            __instance.StartCoroutine(Effects.Lerp(0.5f,
                new System.Action<float>((p) => { textCreditsButton.SetText("TORE公告"); })));
            PassiveButton passiveCreditsButton = creditsButton.GetComponent<PassiveButton>();

            passiveCreditsButton.OnClick = new Button.ButtonClickedEvent();

            passiveCreditsButton.OnClick.AddListener((System.Action)delegate
            {
                // do stuff
                if (popUp != null) Object.Destroy(popUp);
                var popUpTemplate = Object.FindObjectOfType<AnnouncementPopUp>(true);
                if (popUpTemplate == null)
                {
                    return;
                }

                popUp = Object.Instantiate(popUpTemplate);

                popUp.gameObject.SetActive(true);
                string creditsString = @$"<align=""center""><b>Team:</b>
Mallöris    K3ndo    Bavari    Gendelo

<b>团队开发者:</b>
Eisbison (GOAT)    Thunderstorm584    EndOfFile

<b>开发者:</b>
EnoPM    twix    NesTT

<b>Github贡献者:</b>
Alex2911    amsyarasyiq    MaximeGillot
Psynomit    probablyadnf    JustASysAdmin

<b>[https://discord.gg/77RkMJHWsM]Discord[] 贡献者:</b>
Draco Cordraconis    Streamblox (formerly)
感谢所有dicord贡献者的帮助!

感谢miniduikboot & GD对模组的帮助

";
                creditsString += $@"<size=60%> <b>其他贡献 & 资源:</b>
OxygenFilter - 从版本v2.3.0 到v2.6.1, 对TOR有很大帮助
Reactor - 使得我们的模组更好
BepInEx - 使得模组能够运行
Essentials - Custom game options by DorCoMaNdO:
Before v1.6: We used the default Essentials release
v1.6-v1.8: We slightly changed the default Essentials.
v2.0.0 and later: As we were not using Reactor anymore, we are using our own implementation, inspired by the one from DorCoMaNdO
Jackal and Sidekick - Original idea for the Jackal and Sidekick came from Dhalucard
Among-Us-Love-Couple-Mod - Idea for the Lovers modifier comes from Woodi-dev
Jester - Idea for the Jester role came from Maartii
ExtraRolesAmongUs - Idea for the Engineer and Medic role came from NotHunter101. Also some code snippets from their implementation were used.
Among-Us-Sheriff-Mod - Idea for the Sheriff role came from Woodi-dev
TooManyRolesMods - Idea for the Detective and Time Master roles comes from Hardel-DW. Also some code snippets from their implementation were used.
TownOfUs - Idea for the Swapper, Shifter, Arsonist and a similar Mayor role came from Slushiegoose
Ottomated - Idea for the Morphling, Snitch and Camouflager role came from Ottomated
Crowded-Mod - Our implementation for 10+ player lobbies was inspired by the one from the Crowded Mod Team
Goose-Goose-Duck - Idea for the Vulture role came from Slushiegoose
TheEpicRoles - Idea for the first kill shield (partly) and the tabbed option menu (fully + some code), by LaicosVK DasMonschta Nova
TheOtherRolesGMIA - 许多代码来源于此,送葬者等职业也来源于此(感谢imp11的帮助!)[https://github.com/dabao40/TheOtherRolesGMIA]TheOtherRolesGMIA[] 下载传送门
ugackMiner53 - Idea and core code for the Prop Hunt game mode</size>";
                creditsString += "</align>";

                Assets.InnerNet.Announcement creditsAnnouncement = new()
                {
                    Id = "torCredits",
                    Language = 0,
                    Number = 500,
                    Title = "\nThe Other Roles\n贡献 & 资源",
                    ShortTitle = "TOR Credits",
                    SubTitle = "",
                    PinState = false,
                    Date = "02.01.2024",
                    Text = creditsString,
                };
                __instance.StartCoroutine(Effects.Lerp(0.1f, new Action<float>((p) =>
                {
                    if (p == 1)
                    {
                        var backup = DataManager.Player.Announcements.allAnnouncements;
                        DataManager.Player.Announcements.allAnnouncements = new();
                        popUp.Init(false);
                        DataManager.Player.Announcements.SetAnnouncements(
                            new Announcement[] { creditsAnnouncement });
                        popUp.CreateAnnouncementList();
                        popUp.UpdateAnnouncementText(creditsAnnouncement.Number);
                        popUp.visibleAnnouncements._items[0].PassiveButton.OnClick.RemoveAllListeners();
                        DataManager.Player.Announcements.allAnnouncements = backup;
                    }
                })));
            });

        }
    }
}

构建后打开游戏黑屏,无法进入游戏

  • 写回答

4条回答 默认 最新

  • 叫兽-郭老师 新星创作者: Java技术领域 2024-02-11 22:06
    关注

    参考通义千问和郭老师的小迷弟雅思莫了-编写提供,主要是为了帮助您快速解决问题,如下回答,您可以参考下,如有问题,评论区留言。

    根据您提供的代码,这段代码是在为《Among Us》游戏的主菜单添加额外按钮(QQ频道、GitHub和公告)以及处理公告按钮点击事件的逻辑。在游戏加载后黑屏无法进入游戏的问题,可能是由于以下原因:

    1. 脚本错误:尽管代码看起来是修改UI元素,但如果在运行时引发异常(例如找不到GameObject或组件),可能会导致游戏无法正常启动。请确保所有GameObject.Find()调用的对象名称正确无误,并且在预期的时间点存在。

    2. 内存泄漏:如果实例化的新对象没有被适当管理,可能导致内存问题,进而影响游戏启动。不过,从这段代码来看,似乎实例化的对象都已被妥善处理。

    3. Harmony补丁问题:确认Harmony补丁是否正确应用并且兼容当前的Among Us版本及BepInEx版本。

    4. 游戏资源冲突:对游戏原有资源进行大幅度修改可能与游戏内部逻辑产生冲突,导致游戏无法正常初始化。

    5. Unity引擎兼容性:检查所使用的Unity版本与Among Us原版游戏是否匹配。

    要解决这个问题,请尝试以下步骤:

    • 在Unity编辑器中调试模组,查看是否有任何运行时错误信息。
    • 确认所有GameObject名称和组件引用的正确性。
    • 检查游戏日志文件以查找有关错误的具体线索。
    • 分步测试你的修改,先只实现部分功能,逐步排查问题来源。

    若以上方法仍无法解决问题,建议你简化这个补丁,分段测试每一部分功能,找出具体引起黑屏的原因。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月13日
  • 创建了问题 2月11日