-
Notifications
You must be signed in to change notification settings - Fork 575
(Cleanup) (feedback needed) Remove redundant list of ServerCharacters #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7813920
Remove redundant list of ServerCharacters
eheimburg 5b7c1bf
added missing Using
eheimburg 5fe91fa
Revert and cleanup comments
eheimburg a025873
Removing need for ServerCharacter list by iterating on player connect…
eheimburg 455b87b
remove unneeded usings
eheimburg 1ab6c66
Refactoring to use a static list of player ServerCharacters
eheimburg aaec37b
simplifying diff
eheimburg 7f5e8ff
Update Assets/BossRoom/Scripts/Server/Game/Character/PlayerServerChar…
fernando-cortez 341a6de
moving to serialized field rather than GetComponent, and acting prope…
dwoodruffsf 96c2c1d
Merge branch 'feature/servercharacter_cleanup' of https://github.com/…
dwoodruffsf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Assets/BossRoom/Scripts/Server/Game/Character/PlayerServerCharacter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using MLAPI; | ||
| using UnityEngine; | ||
|
|
||
| namespace BossRoom.Server | ||
| { | ||
| /// <summary> | ||
| /// Attached to the player-characters' prefab, this maintains a list of active ServerCharacter objects for players. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This is an optimization. In server code you can already get a list of players' ServerCharacters by | ||
| /// iterating over the active connections and calling GetComponent() on their PlayerObject. But we need | ||
| /// to iterate over all players quite often -- the monsters' IdleAIState does so in every Update() -- | ||
| /// and all those GetComponent() calls add up! So this optimization lets us iterate without calling | ||
| /// GetComponent(). This will be refactored with a ScriptableObject-based approach on player collection. | ||
| /// </remarks> | ||
| [RequireComponent(typeof(ServerCharacter))] | ||
| public class PlayerServerCharacter : NetworkBehaviour | ||
| { | ||
| static List<ServerCharacter> s_ActivePlayers = new List<ServerCharacter>(); | ||
|
|
||
| [SerializeField] | ||
| ServerCharacter m_CachedServerCharacter; | ||
|
|
||
| public override void NetworkStart() | ||
| { | ||
| if( !IsServer ) | ||
| { | ||
| enabled = false; | ||
| } | ||
| } | ||
|
|
||
| void OnEnable() | ||
| { | ||
| s_ActivePlayers.Add(m_CachedServerCharacter); | ||
| } | ||
|
|
||
| void OnDisable() | ||
| { | ||
| s_ActivePlayers.Remove(m_CachedServerCharacter); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a list of all active players' ServerCharacters. Treat the list as read-only! | ||
| /// The list will be empty on the client. | ||
| /// </summary> | ||
| public static List<ServerCharacter> GetPlayerServerCharacters() | ||
| { | ||
|
|
||
| return s_ActivePlayers; | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
Assets/BossRoom/Scripts/Server/Game/Character/PlayerServerCharacter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.