private SpawnPlayerConfig LoadPlayerConfig(List<HeroInfo> heroInfos, int deckIndex) {…
- User
private SpawnPlayerConfig LoadPlayerConfig(List heroInfos, int deckIndex) { PlayerDeck playerDeck; if (this.GetModel().playerDecks.Count + this.GetModel().botDecks.Count < 2) { playerDeck = GameManager.Instance.playerDecks[deckIndex]; } else { // 2v2两个真人匹配到2个电脑的场景 if (this.GetModel().playerDecks.Count == 2 && this.GetModel().botDecks.Count == 2) { int adjustedIndex = deckIndex / 2; if (deckIndex % 2 == 0) { playerDeck = this.GetModel().playerDecks[adjustedIndex]; } else { playerDeck = this.GetModel().botDecks[adjustedIndex]; playerDeck.isbot = true; } } else { if (deckIndex > this.GetModel().playerDecks.Count - 1) { playerDeck = this.GetModel() .botDecks[deckIndex - this.GetModel().playerDecks.Count]; playerDeck.isbot = true; } else { playerDeck = this.GetModel().playerDecks[deckIndex]; } } }
codevar spawnPlayerConfig = new SpawnPlayerConfig { CardDecks = new List<BaseCard>() }; for (var i = 0; i < playerDeck.cards.Count; i++) { for (var j = 0; j < playerDeck.cards[i].amount; j++) { spawnPlayerConfig.CardDecks.Add(playerDeck.cards[i].card); } } var heroInfo = heroInfos.First(x => x.heroType == playerDeck.heroType); spawnPlayerConfig.skillAvatar = heroInfo.skill.name; spawnPlayerConfig.heroAvatar = heroInfo.avatar.name; spawnPlayerConfig.playerName = playerDeck.playerName; spawnPlayerConfig.heroType = playerDeck.heroType; spawnPlayerConfig.heroTalent = heroInfo.talents[playerDeck.heroTalent]; spawnPlayerConfig.heroSkillName = heroInfo.skillName; spawnPlayerConfig.heroSkillDescription = heroInfo.skillDescription; spawnPlayerConfig.profession = playerDeck.profession; spawnPlayerConfig.isBot = playerDeck.isbot; return spawnPlayerConfig; } 帮忙优化这个方法 - Assistant
- User
if (GetHeroTalentDisPlayer()!= null && !GetGameMode().GetIsInDrawCardPhase() && GetHeroTalentDisPlayer().isActiveAndEnabled) { if (Input.GetMouseButton(0)) { GetHeroTalentDisPlayer().SetTalentInfoVisible(false); } } 这个判断鼠标左键按下的事件,会导致,我点击到一个按钮上面也触发,就会触发两次,导致setactive不生效,怎么避免点击到按钮上不算左键点击事件呢
- Assistant
The issue you're encountering is due to mouse event propagation, where clicking on a UI element like a button causes both the button's event handler and your global mouse event handler to be triggered. To avoid this, you can use the Unity Event System to check if the pointer is over a UI element before proceeding with your logic.
You can utilize the
EventSystem.current.IsPointerOverGameObject()method to determine if the mouse is currently over a UI element. This method returnstrueif the pointer is over any UI element, which allows you to conditionally execute your logic only when it's not over a UI element.Here’s how you can modify your code:
csharp - User
public void Merge(StepFrame other) { if (other.InputEvents != null && other.InputEvents.Count > 0) { if (InputEvents == null) { InputEvents = new List(); }
codeforeach (var item in other.InputEvents) { InputEvents.Add(item); } } } 帮忙优化一下这个代码 - Assistant
Certainly! The code snippet you have provided involves merging input events from another
StepFrameinto the current one. To optimize it, we can streamline the logic and improve readability. Here's how you can refactor the method:csharppublic void Merge(StepFrame other) { if (other.InputEvents == null || other.InputEvents.Count == 0) return; InputEvents ??= new List<CommonGamePlayerInputEvent>(); InputEvents.AddRange(other.InputEvents); }Key Changes:
-
Null-conditional Check Simplification: I consolidated the check for
other.InputEventsbeing null or empty into a singleifstatement. If either condition is true, the method returns early, avoiding unnecessary operations. -
Null-coalescing Assignment: Used the null-coalescing assignment operator () to initialize only if it is currently , making the code more concise and expressive.
-
- User
- Assistant
- User
- Assistant