protected GroupData _RemovePlayerFromGroup(NetworkPlayer player, NetworkGroup group, NetworkViewID viewID) { GroupData data; if (_groups.TryGetValue(group, out data)) { HashSet <NetworkViewID> userSet; if (data.users.TryGetValue(player, out userSet)) { if (!userSet.Remove(viewID)) { return(data); } if (userSet.Count == 0) { data.users.Remove(player); } if (viewID != NetworkViewID.unassigned) { data.views.Remove(viewID); } _ServerRemovePlayerFromGroup(player, group, viewID, data, userSet.Count); } if (data.users.Count == 0) { _groups.Remove(group); } return(data); } return(null); }
/// <summary> /// Assigns the specified viewID to this NetworkView. /// </summary> /// <param name="viewID">The viewID you have created via a call to <see cref="O:uLink.Network.AllocateViewID"/></param> /// <param name="owner">Will become the owner of this object</param> /// <param name="group">Will become the group of this object. Default value is unassigned.</param> /// <param name="isInstantiatedRemotely">Will let uLink know this object has been instantiated remotely. Default value is false.</param> /// <remarks> /// Before calling this method, use <see cref="O:uLink.Network.AllocateViewID"/> to get a new allocated and thus /// usable viewID. Use this method on the server and on all clients /// to make them all treat this viewID in the same way. /// </remarks> public bool SetViewID(NetworkViewID viewID, NetworkPlayer owner, NetworkGroup group, bool isInstantiatedRemotely) { if (_parent.IsNotNullOrUnassigned()) { return(_parent.SetViewID(viewID, owner, group, isInstantiatedRemotely)); } Log.Debug(NetworkLogFlags.NetworkView, "Assigning ", this, " to ", viewID, ", owner ", owner, ", group ", group, ", isInstantiatedRemotely", isInstantiatedRemotely); _network.RemoveNetworkView(this); _data.viewID = viewID; _data.owner = owner; _data.group = group; _data.isInstantiatedRemotely = isInstantiatedRemotely; if (!_network.AddNetworkView(this)) { SetUnassignedViewID(); return(false); } // TODO: need to make sure this doesn't cause any weird issues/behavior in all possible scenarios. destroyOnFinalDisconnect = viewID.isAllocated; foreach (var child in _children) { child._data.viewID = viewID; child._data.owner = owner; child._data.group = group; child._data.isInstantiatedRemotely = isInstantiatedRemotely; } return(true); }
internal NetworkP2PHandoverInstance(NetBuffer buffer) { _networkView = null; position = new Vector3(buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat()); rotation = new Quaternion(buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat()); relativeTo = (NetworkP2PSpace)buffer.ReadByte(); remoteViewID = new NetworkViewID(buffer); group = new NetworkGroup(buffer); authFlags = (NetworkAuthFlags)buffer.ReadByte(); isInstantiatedRemotely = buffer.ReadBoolean(); proxyPrefab = buffer.ReadString(); ownerPrefab = buffer.ReadString(); serverPrefab = buffer.ReadString(); cellAuthPrefab = buffer.ReadString(); cellProxyPrefab = buffer.ReadString(); uint initialSize = buffer.ReadVariableUInt32(); _initialData = initialSize != 0 ? buffer.ReadBytes((int)initialSize) : new byte[0]; uint handoverSize = buffer.ReadVariableUInt32(); _handoverData = handoverSize != 0 ? buffer.ReadBytes((int)handoverSize) : new byte[0]; _isInstantiatable = true; _networkP2P = null; }
public GroupData(NetworkGroup group) { if (!NetworkGroup._flags.TryGetValue(group, out flags)) { flags = NetworkGroupFlags.None; } }
internal NetworkViewID[] _FindNetworkViewIDsInGroup(NetworkGroup group) { GroupData data; if (_groups.TryGetValue(group, out data)) { var viewIDs = data.views; var array = new NetworkViewID[viewIDs.Count]; viewIDs.CopyTo(array); return(array); } return(new NetworkViewID[0]); }
internal NetworkPlayer[] _FindPlayersInGroup(NetworkGroup group) { GroupData data; if (_groups.TryGetValue(group, out data)) { var users = data.users; var array = new NetworkPlayer[users.Count]; users.Keys.CopyTo(array, 0); return(array); } return(new NetworkPlayer[0]); }
protected GroupData _AddPlayerToGroup(NetworkPlayer player, NetworkGroup group, NetworkViewID viewID) { var data = _groups.GetOrAdd(group, () => new GroupData(group)); var userSet = data.users.GetOrAdd(player); if (!userSet.Add(viewID)) { return(data); } if (viewID != NetworkViewID.unassigned) { data.views.Add(viewID); } _ServerAddPlayerToGroup(player, group, viewID, data, userSet.Count); return(data); }
// TODO: export find by group w/ owner etc functions to official API! internal NetworkViewBase[] _FindNetworkViewsInGroup(NetworkGroup group) { GroupData data; if (_groups.TryGetValue(group, out data)) { var viewIDs = data.views; var views = new List <NetworkViewBase>(viewIDs.Count); foreach (var viewID in viewIDs) { NetworkViewBase nv; if (_enabledViews.TryGetValue(viewID, out nv)) { views.Add(nv); } } return(views.ToArray()); } return(new NetworkViewBase[0]); }
/// <summary> /// Creates and initializes a new instance of NetworkP2PHandoverInstance. /// </summary> /// <param name="networkView">The network view to use for the object being handovered.</param> /// <param name="position">Position of the object being handovered.</param> /// <param name="rotation">Rotation to use for the object being handovered.</param> /// <param name="relativeTo">The space that position and rotation should be relative to.</param> public NetworkP2PHandoverInstance(NetworkViewBase networkView, Vector3 position, Quaternion rotation, NetworkP2PSpace relativeTo) { this.position = position; this.rotation = rotation; this.relativeTo = relativeTo; _networkView = networkView.root as NV; // make sure it's the parent networkview and not a child remoteViewID = _networkView.viewID; group = _networkView.group; authFlags = _networkView._data.authFlags; // TODO: ugly hack to void authority permission check isInstantiatedRemotely = _networkView.isInstantiatedRemotely; proxyPrefab = _networkView.proxyPrefab; ownerPrefab = _networkView.ownerPrefab; serverPrefab = _networkView.serverPrefab; cellAuthPrefab = _networkView.cellAuthPrefab; cellProxyPrefab = _networkView.cellProxyPrefab; _initialData = null; _handoverData = null; _isInstantiatable = false; _networkP2P = null; }
public Object Instantiate(NetworkPlayer owner, Object prefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { _AssertPrefab(prefab, true); return(_GetComponent(prefab.GetType(), base.Instantiate(owner, prefab.GetName(), position, rotation, group, initialData))); }
public new GameObject Instantiate(NetworkViewID viewID, NetworkPlayer owner, string proxyPrefab, string ownerPrefab, string serverPrefab, string cellAuthPrefab, string cellProxyPrefab, NetworkAuthFlags authFlags, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { return(_GetGameObject(base.Instantiate(viewID, owner, proxyPrefab, ownerPrefab, serverPrefab, cellAuthPrefab, cellProxyPrefab, authFlags, position, rotation, group, initialData))); }
internal bool _DoesGroupHaveAnyNetworkViews(NetworkGroup group) { return(_groups.ContainsKey(group)); }
public GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { _AssertPrefab(prefab, true); return(_GetGameObject(base.Instantiate(prefab.GetName(), position, rotation, group, initialData))); }
public void WriteNetworkGroup(NetworkGroup value) { value._Write(_buffer); }
public GameObject Instantiate(GameObject othersPrefab, GameObject ownerPrefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { _AssertPrefab(othersPrefab, false); _AssertPrefab(ownerPrefab, false); return(_GetGameObject(base.Instantiate(othersPrefab.GetNameNullSafe(), ownerPrefab.GetNameNullSafe(), position, rotation, group, initialData))); }
/// <summary> /// Assigns the specified viewID to this NetworkView. /// </summary> /// <param name="viewID">The view ID you have created via a call to <see cref="O:uLink.Network.AllocateViewID"/></param> /// <param name="info">The sender of <see cref="uLink.NetworkMessageInfo"/> /// will become the owner and the creator for this object</param> /// <param name="group">The group which this NetworkView will belong to</param> /// <remarks> /// Before calling this method, use <see cref="O:uLink.Network.AllocateViewID"/> to get a new allocated and thus /// usable viewID. Use this method on the server and on all clients /// to make them all treat this viewID in the same way. /// </remarks> /// <example> /// Can be used when instantiating NPCs in an MMO game. /// This method is usually called in all clients after receiving the viewID from the server via some /// RPC call. Then the clients will become aware that the server has the owner and creater role for /// this NPC Game Object. /// </example> public bool SetViewID(NetworkViewID viewID, NetworkMessageInfo info, NetworkGroup group) { return(SetViewID(viewID, info.sender, group)); }
public GameObject Instantiate(NetworkViewID viewID, NetworkPlayer owner, GameObject proxyPrefab, GameObject ownerPrefab, GameObject serverPrefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { _AssertPrefab(proxyPrefab, false); _AssertPrefab(ownerPrefab, false); _AssertPrefab(serverPrefab, false); return(_GetGameObject(base.Instantiate(viewID, owner, proxyPrefab.GetNameNullSafe(), ownerPrefab.GetNameNullSafe(), serverPrefab.GetNameNullSafe(), position, rotation, group, initialData))); }
public new GameObject Instantiate(NetworkPlayer owner, string proxyPrefab, string ownerPrefab, string serverPrefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { return(_GetGameObject(base.Instantiate(owner, proxyPrefab, ownerPrefab, serverPrefab, position, rotation, group, initialData))); }
public GameObject Instantiate(NetworkViewID viewID, NetworkPlayer owner, GameObject proxyPrefab, GameObject ownerPrefab, GameObject serverPrefab, GameObject cellAuthPrefab, GameObject cellProxyPrefab, NetworkAuthFlags authFlags, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { return(_GetGameObject(base.Instantiate(viewID, owner, proxyPrefab.GetNameNullSafe(), ownerPrefab.GetNameNullSafe(), serverPrefab.GetNameNullSafe(), cellAuthPrefab.GetNameNullSafe(), cellProxyPrefab.GetNameNullSafe(), authFlags, position, rotation, group, initialData))); }
public TComponent Instantiate <TComponent>(NetworkViewID viewID, NetworkPlayer owner, TComponent proxyPrefab, TComponent ownerPrefab, TComponent serverPrefab, TComponent cellAuthPrefab, TComponent cellProxyPrefab, NetworkAuthFlags authFlags, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) where TComponent : Component { return(_GetComponent <TComponent>(base.Instantiate(viewID, owner, proxyPrefab.GetNameNullSafe(), ownerPrefab.GetNameNullSafe(), serverPrefab.GetNameNullSafe(), cellAuthPrefab.GetNameNullSafe(), cellProxyPrefab.GetNameNullSafe(), authFlags, position, rotation, group, initialData))); }
public TComponent Instantiate <TComponent>(NetworkViewID viewID, NetworkPlayer owner, TComponent proxyPrefab, TComponent ownerPrefab, TComponent serverPrefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) where TComponent : Component { _AssertPrefab(proxyPrefab, false); _AssertPrefab(ownerPrefab, false); _AssertPrefab(serverPrefab, false); return(_GetComponent <TComponent>(base.Instantiate(viewID, owner, proxyPrefab.GetNameNullSafe(), ownerPrefab.GetNameNullSafe(), serverPrefab.GetNameNullSafe(), position, rotation, group, initialData))); }
public TComponent Instantiate <TComponent>(NetworkPlayer owner, TComponent prefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) where TComponent : Component { _AssertPrefab(prefab, true); return(_GetComponent <TComponent>(base.Instantiate(owner, prefab.GetName(), position, rotation, group, initialData))); }
public TComponent Instantiate <TComponent>(TComponent othersPrefab, TComponent ownerPrefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) where TComponent : Component { _AssertPrefab(othersPrefab, false); _AssertPrefab(ownerPrefab, false); return(_GetComponent <TComponent>(base.Instantiate(othersPrefab.GetNameNullSafe(), ownerPrefab.GetNameNullSafe(), position, rotation, group, initialData))); }
/// <summary> /// Creates and initializes a new instance of NetworkInstantiateArgs. /// </summary> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="viewID"></param> /// <param name="owner"></param> /// <param name="group"></param> /// <param name="proxyPrefab"></param> /// <param name="ownerPrefab"></param> /// <param name="serverPrefab"></param> /// <param name="cellAuthPrefab"></param> /// <param name="cellProxyPrefab"></param> /// <param name="authFlags"></param> /// <param name="isInstantiatedRemotely"></param> /// <param name="initialData"></param> public NetworkInstantiateArgs(Vector3 position, Quaternion rotation, NetworkViewID viewID, NetworkPlayer owner, NetworkGroup group, string proxyPrefab, string ownerPrefab, string serverPrefab, string cellAuthPrefab, string cellProxyPrefab, NetworkAuthFlags authFlags, bool isInstantiatedRemotely, BitStream initialData) { this.position = position; this.rotation = rotation; data = new NetworkViewData(viewID, owner, group, authFlags, isInstantiatedRemotely, proxyPrefab, ownerPrefab, serverPrefab, cellAuthPrefab, cellProxyPrefab, initialData); }
/// <summary> /// Assigns the specified viewID to this NetworkView. /// </summary> /// <param name="viewID">The viewID you have created via a call to <see cref="O:uLink.Network.AllocateViewID"/></param> /// <param name="owner">Will become the owner of this object</param> /// <param name="group">Will become the group of this object. Default value is unassigned.</param> /// <remarks> /// Before calling this method, use <see cref="O:uLink.Network.AllocateViewID"/> to get a new allocated and thus /// usable viewID. Use this method on the server and on all clients /// to make them all treat this viewID in the same way. /// </remarks> public bool SetViewID(NetworkViewID viewID, NetworkPlayer owner, NetworkGroup group) { return(SetViewID(viewID, owner, group, false)); }
protected abstract void _ServerRemovePlayerFromGroup(NetworkPlayer player, NetworkGroup group, NetworkViewID viewID, GroupData data, int userSetCount);
public new GameObject Instantiate(NetworkPlayer owner, string prefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { if (!(!String.IsNullOrEmpty(prefab))) { Utility.Exception("prefab must be a non-empty string"); } return(_GetGameObject(base.Instantiate(owner, prefab, position, rotation, group, initialData))); }