SHOW:
|
|
- or go back to the newest paste.
| 1 | using UnityEngine; | |
| 2 | using UnityEngine.Networking; | |
| 3 | using System.Collections.Generic; | |
| 4 | ||
| 5 | public class NewNetworkBehaviour : NetworkBehaviour | |
| 6 | {
| |
| 7 | static Dictionary<NetworkInstanceId, NetworkBehaviour> instanceIdToBehavior = new Dictionary<NetworkInstanceId, NetworkBehaviour>(); | |
| 8 | public static T GetBehavior<T>(NetworkInstanceId netId) where T : NetworkBehaviour | |
| 9 | {
| |
| 10 | return instanceIdToBehavior[netId] as T; | |
| 11 | } | |
| 12 | internal void Start() | |
| 13 | {
| |
| 14 | instanceIdToBehavior[this.netId] = this; | |
| 15 | } | |
| 16 | } | |
| 17 | ||
| 18 | public class Player : NewNetworkBehaviour | |
| 19 | {
| |
| 20 | List<Player> suboridnates = new List<Player>(); | |
| 21 | ||
| 22 | internal void Start() | |
| 23 | {
| |
| 24 | base.Start(); | |
| 25 | } | |
| 26 | ||
| 27 | // so to be able to add subordinate to any player from any client we have to do this | |
| 28 | public void AddSubordinate(Player subordinate) | |
| 29 | {
| |
| 30 | Cmd_AddSubordinate(this.netId, subordinate.netId); | |
| 31 | } | |
| 32 | ||
| 33 | [Command] | |
| 34 | void Cmd_AddSubordinate(NetworkInstanceId target, NetworkInstanceId subordinate) | |
| 35 | {
| |
| 36 | GetBehavior<Player>(target).Rpc_AddSubordinate(subordinate); | |
| 37 | } | |
| 38 | ||
| 39 | [ClientRpc] | |
| 40 | void Rpc_AddSubordinate(NetworkInstanceId subordinate) | |
| 41 | {
| |
| 42 | suboridnates.Add(GetBehavior<Player>(subordinate)); | |
| 43 | } | |
| 44 | ||
| 45 | } |