/// <summary> /// 检查资源是否存在,若不存在则创建并注册 /// </summary> /// <returns></returns> public static void TryRegisterResources() { if (TurnEvent.IsResourcesRegistered()) { return; } string eventImagePath = Path.Combine(Path.Combine(Main.resBasePath, "Texture"), $"{TurnEvent.IMAGE_NAME}.png"); bool isSuccess = ResourceLoader.AppendSprite(ref GetSprites.instance.trunEventImage, eventImagePath); if (!isSuccess) { throw new Exception($"Failed to append sprite: {eventImagePath}"); } TurnEvent.eventId = ResourceLoader.AppendRow(DateFile.instance.trunEventDate, new Dictionary <int, string> { [0] = "太吾管家", [1] = "0", [2] = "0", [98] = "${" + TurnEvent.IMAGE_NAME + "}", [99] = "您的管家禀告了如下收获:", }); }
/// <summary> /// 检查资源是否存在,若不存在则载入并注册 /// </summary> public static void TryRegisterResources() { // 注册入口按钮浮窗信息 if (MajordomoWindowButton.messageId < 0 || !DateFile.instance.massageDate.ContainsKey(MajordomoWindowButton.messageId) || DateFile.instance.massageDate[MajordomoWindowButton.messageId][0] != MajordomoWindowButton.MESSAGE_TITLE) { MajordomoWindowButton.messageId = ResourceLoader.AppendRow(DateFile.instance.massageDate, new Dictionary <int, string> { [0] = MESSAGE_TITLE, [1] = MESSAGE_CONTENT, }); } // 载入并注册管家入口按钮 var windowButtonHolder = BuildingWindow.instance.showQuquBoxButton.transform.parent; if (buttonSprite == null) { string buttonImagePath = Path.Combine(Path.Combine(Main.resBasePath, "Texture"), $"{MajordomoWindowButton.IMAGE_NAME}.png"); buttonSprite = ResourceLoader.CreateSpriteFromImage(buttonImagePath); if (buttonSprite == null) { throw new Exception($"Failed to create sprite: {buttonImagePath}"); } } var goButton = UnityEngine.Object.Instantiate(BuildingWindow.instance.showQuquBoxButton, windowButtonHolder); goButton.name = $"MajordomoWindowButton,{MajordomoWindowButton.messageId}"; var image = goButton.GetComponent <Image>(); image.sprite = buttonSprite; var texts = goButton.GetComponentsInChildren <Text>(); foreach (var text in texts) { text.text = MajordomoWindowButton.MESSAGE_TITLE; } var button = Common.RemoveComponent <Button>(goButton, recreate: true); button.onClick.AddListener(() => MajordomoWindow.instance.Open()); UnityEngine.Debug.Log("Resources of MajordomoWindowButton registered."); }