File tree Expand file tree Collapse file tree 5 files changed +19
-76
lines changed Expand file tree Collapse file tree 5 files changed +19
-76
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ GameObject:
28
28
- 114 : {fileID: 11475710}
29
29
- 114 : {fileID: 11415652}
30
30
m_Layer : 0
31
- m_Name : NetworkManager
31
+ m_Name : GameManager
32
32
m_TagString : Untagged
33
33
m_Icon : {fileID: 0}
34
34
m_NavMeshLayer : 0
File renamed without changes.
Original file line number Diff line number Diff line change 9
9
/// </summary>
10
10
public class GameNetworkManager : NetworkManager {
11
11
12
- PlayerManager playerManager ;
13
-
14
- void Awake ( )
15
- {
16
- playerManager = GetComponentInChildren < PlayerManager > ( ) ;
17
-
18
- }
19
-
20
- public override void OnServerAddPlayer ( NetworkConnection conn , short playerControllerId )
21
- {
22
- base . OnServerAddPlayer ( conn , playerControllerId ) ;
23
-
24
- playerManager . AddPlayer ( conn . connectionId , conn . hostId ) ;
25
- }
26
-
27
- public override void OnServerRemovePlayer ( NetworkConnection conn , PlayerController player )
28
- {
29
- playerManager . RemovePlayer ( conn . connectionId , conn . hostId ) ;
30
-
31
- base . OnServerRemovePlayer ( conn , player ) ;
32
- }
33
-
34
- public override void OnServerDisconnect ( NetworkConnection conn )
12
+ private static GameNetworkManager instance ;
13
+ public static GameNetworkManager Instance
35
14
{
36
- base . OnServerDisconnect ( conn ) ;
15
+ get
16
+ {
17
+ if ( instance == null )
18
+ {
19
+ instance = FindObjectOfType < GameNetworkManager > ( ) ;
20
+ }
21
+ return instance ;
22
+ }
37
23
}
38
24
39
25
}
Original file line number Diff line number Diff line change 10
10
[ NetworkSettings ( channel = 0 , sendInterval = 2f ) ]
11
11
public class PlayerManager : NetworkBehaviour {
12
12
13
- [ Serializable ]
14
- public struct PlayerInfo
13
+ private static PlayerManager instance ;
14
+ public static PlayerManager Instance
15
15
{
16
- public string name ;
17
- public short rtt ;
18
-
19
- public int hostID ;
20
- public int connID ;
21
- } ;
22
-
23
- public class SyncListPlayer : SyncListStruct < PlayerInfo > { }
24
- public SyncListPlayer players = new SyncListPlayer ( ) ;
25
-
26
- public void AddPlayer ( int connID , int hostID )
27
- {
28
- PlayerInfo player = new PlayerInfo ( ) ;
29
-
30
- player . name = "?" ;
31
- player . rtt = 999 ;
32
- player . connID = connID ;
33
- player . hostID = hostID ;
34
-
35
- players . Add ( player ) ;
36
- }
37
-
38
- public int GetPlayerIndex ( int connID , int hostID )
39
- {
40
- for ( int i = 0 ; i < players . Count ; i ++ )
16
+ get
41
17
{
42
- if ( players [ i ] . connID == connID && players [ i ] . hostID == hostID )
18
+ if ( instance == null )
43
19
{
44
- return i ;
20
+ instance = FindObjectOfType < PlayerManager > ( ) ;
45
21
}
22
+ return instance ;
46
23
}
47
-
48
- return - 1 ;
49
- }
50
-
51
- public PlayerInfo GetPlayer ( int connID , int hostID )
52
- {
53
- int index = GetPlayerIndex ( connID , hostID ) ;
54
- if ( index == - 1 )
55
- {
56
- throw new Exception ( "Can't find player with connID " + connID ) ;
57
- }
58
- return players [ index ] ;
59
- }
60
-
61
- public void RemovePlayer ( int connID , int hostID )
62
- {
63
- players . Remove ( GetPlayer ( connID , hostID ) ) ;
64
- }
65
-
66
- void Update ( )
67
- {
68
- //TODO update ping
69
24
}
70
25
71
26
}
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ public class RemotePlayer : NetworkBehaviour {
28
28
29
29
void Start ( )
30
30
{
31
+ transform . parent = PlayerManager . Instance . transform ;
31
32
if ( isLocalPlayer )
32
33
{
33
34
CmdSetDisplayName ( "Atrakeur" ) ;
@@ -76,6 +77,7 @@ void Update()
76
77
void CmdSetDisplayName ( string name )
77
78
{
78
79
this . displayName = name ;
80
+ this . gameObject . name = "Player " + name ;
79
81
}
80
82
81
83
/// <summary>
You can’t perform that action at this time.
0 commit comments