/// <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="p2p">The NetworkP2P component used for handing this object over.</param>
 /// <param name="offsetPos">Offset position of the object compared to the <c>p2p</c> which is handing it over.</param>
 /// <param name="offsetRot">Offset rotation of the object compared to the <c>p2p</c> which is handing it over.</param>
 public NetworkP2PHandoverInstance(NetworkViewBase networkView, NetworkP2PBase p2p, Vector3 offsetPos, Quaternion offsetRot)
     : this(networkView, p2p)
 {
     position   += offsetPos;
     rotation   *= offsetRot;
     _networkP2P = p2p as P2P;
 }
Beispiel #2
0
        /// <summary>
        /// Sets up a NetworkView with the info in this instance of NetworkInstantiateArgs.
        /// </summary>
        /// <param name="nv">The NetworkView that we want to setup.</param>
        public void SetupNetworkView(NetworkViewBase nv)
        {
            nv.position = position;
            nv.rotation = rotation;

            data.SetupNetworkView(nv);
        }
        internal NetworkViewBase _Create(string localPrefab, NetworkInstantiateArgs args, NetworkMessage msg)
        {
#if UNITY_BUILD
            Profiler.BeginSample("Instantiate prefab: " + localPrefab);
#endif

            // TODO: if server then validate viewID is owned by player!

            if (String.IsNullOrEmpty(localPrefab))
            {
                Log.Debug(NetworkLogFlags.Instantiate, "Skipping instantiate of empty prefab with ", args.viewID, " (in ", args.group, "), owner ", args.owner);

#if UNITY_BUILD
                Profiler.EndSample();
#endif
                return(null);
            }

            Log.Debug(NetworkLogFlags.Instantiate, "Instantiate prefab '", localPrefab, "' with viewID ", args.viewID, " (in ", args.group, "), owner ", args.owner, ", position ", args.position, ", rotation ", args.rotation);

            // TODO: why do we do this? We aren't removing the old instantiate from the RPC buffer so is this even safe?
            NetworkViewBase nv = _FindNetworkView(args.viewID);
            if (nv.IsNotNull())
            {
                _DestroyNetworkView(nv);
            }

            var info = new NetworkMessageInfo(msg, null);
            nv = OnCreate(localPrefab, args, info);

#if UNITY_BUILD
            Profiler.EndSample();
#endif
            return(nv);
        }
Beispiel #4
0
 private static Object _GetComponent(Type type, NetworkViewBase nv)
 {
     if (nv.IsNullOrDestroyed())
     {
         return(null);
     }
     return(type == typeof(GameObject) ? nv.gameObject : nv.GetComponent(type) as Object);
 }
 internal NetworkMessageInfo(NetworkMessage msg, NetworkViewBase nv)
 {
     sender             = msg.sender;
     localTimestamp     = msg.localTimeSent;
     serverTimestamp    = msg.monotonicServerTimeSent;
     rawServerTimestamp = msg.rawServerTimeSent;
     networkView        = nv as NV;
     flags = msg.flags;
 }
 internal NetworkMessageInfo(NetworkBaseLocal network, NetworkFlags flags, NetworkViewBase nv)
 {
     sender             = network._localPlayer;
     localTimestamp     = NetworkTime.localTime;
     serverTimestamp    = network._GetMonotonicServerTime(localTimestamp);
     rawServerTimestamp = network._GetRawServerTime(localTimestamp);
     networkView        = nv as NV;
     this.flags         = flags;
 }
        private static NetworkMessage _GenerateMessage(NetworkViewBase nv, NetworkPlayer target)
        {
            var msgChannel = NetworkMessage.Channel.StateSyncOwner;
            var msgCode    = NetworkMessage.InternalCode.StateSyncOwnerDeltaCompressedInit;
            var sqNr       = (byte)(nv._expectedOwnerStateDeltaCompressedSequenceNr - 1);
            var state      = nv._prevOwnerStateSerialization;

            return(_GenerateMessage(nv, msgChannel, msgCode, sqNr, state, target));
        }
 /// <summary>
 /// Creates a new instance of NetworkMessageInfo using the provided arguments.
 /// The class is initialized using the info parameter, except the networkview property which is initialized using the nv parameter.
 /// </summary>
 public NetworkMessageInfo(NetworkMessageInfo info, NetworkViewBase nv)
 {
     sender             = info.sender;
     localTimestamp     = info.localTimestamp;
     serverTimestamp    = info.serverTimestamp;
     rawServerTimestamp = info.rawServerTimestamp;
     flags       = info.flags;
     networkView = nv as NV;
 }
        protected static NetworkMessage _GenerateMessage(NetworkViewBase nv, NetworkMessage.Channel channel, NetworkMessage.InternalCode msgCode, byte sqNr, BitStream state, NetworkPlayer target)
        {
            var msg = new NetworkMessage(nv._network, nv._syncFlags, channel, String.Empty, msgCode, target, NetworkPlayer.unassigned, nv.viewID);

            msg.stream._buffer.Write(sqNr);
            msg.stream._buffer.Write(state._data, 0, state._buffer.LengthBytes);

            return(msg);
        }
        public bool AddNetworkView(NetworkViewBase nv)
        {
            var viewID = nv.viewID;

            if (viewID == NetworkViewID.unassigned)
            {
                return(false);
            }

            NetworkViewBase other;

            if (_enabledViews.TryGetValue(viewID, out other))
            {
                if (!other.ReferenceEquals(nv))
                {
                    Log.Error(NetworkLogFlags.NetworkView, "Can't subscribe ", nv, " since there already exists one with ", viewID, " at ", other);
                    return(false);
                }
            }
            else
            {
                Log.Debug(NetworkLogFlags.NetworkView, "Subscribing ", nv);

                _enabledViews[viewID] = nv;

                var owner = nv.owner;

                _userViews.GetOrAdd(owner).Add(nv);

                nv._ClearStateSyncData();

                var group = nv.group;
                if (group != NetworkGroup.unassigned)
                {
                    _AddPlayerToGroup(owner, group, viewID);
                }
            }

            return(true);
        }
        public bool RemoveNetworkView(NetworkViewBase nv)
        {
            var viewID = nv.viewID;

            if (viewID == NetworkViewID.unassigned)
            {
                return(false);
            }

            NetworkViewBase other;

            if (!_enabledViews.TryGetValue(viewID, out other) || !other.ReferenceEquals(nv))
            {
                return(false);
            }

            Log.Debug(NetworkLogFlags.NetworkView, "Unsubscribing ", nv);

            _enabledViews.Remove(viewID);

            var owner = nv.owner;

            List <NetworkViewBase> views;

            if (_userViews.TryGetValue(owner, out views))
            {
                views.Remove(nv);
            }

            var group = nv.group;

            if (group != NetworkGroup.unassigned)
            {
                _RemovePlayerFromGroup(owner, group, viewID);
            }

            return(true);
        }
        /// <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;
        }
Beispiel #13
0
        protected override void OnDestroy(NetworkViewBase networkView)
        {
            if (networkView.IsNullOrDestroyed())
            {
                Log.Warning(NetworkLogFlags.Instantiate, "Object is already destroyed, the network destroyer will be skipped. Please call uLink.Network.Destroy instead of Object.Destroy.");
                return;
            }

            var nv        = networkView as NetworkView;
            var destroyer = nv.instantiator.destroyer;

            if (destroyer != null)
            {
                Log.Debug(NetworkLogFlags.Instantiate, "Calling destroyer for ", nv, " with viewID ", nv.viewID, " (in ", nv.group, "), owner ", nv.owner);

                Profiler.BeginSample("Calling Destroyer");
                destroyer(nv);
                Profiler.EndSample();
            }
            else
            {
                Log.Error(NetworkLogFlags.Instantiate, "Missing Destroyer for ", nv);
            }
        }
 protected abstract void OnDestroy(NetworkViewBase networkView);
 public NetworkMessageInfo(NetworkPlayer sender, ulong timestampInMillis, NetworkFlags flags, NetworkViewBase networkView)
 {
     this.sender      = sender;
     localTimestamp   = timestampInMillis * 0.001;
     this.networkView = networkView as NV;
     this.flags       = flags;
 }
        internal void _DestroyNetworkView(NetworkViewBase nv)
        {
            OnDestroy(nv);

            nv.SetUnassignedViewID();
        }
Beispiel #17
0
 private static GameObject _GetGameObject(NetworkViewBase nv)
 {
     return(!nv.IsNullOrDestroyed() ? nv.gameObject : null);
 }
 /// <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="p2p">The NetworkP2P component used for handing this object over.</param>
 public NetworkP2PHandoverInstance(NetworkViewBase networkView, NetworkP2PBase p2p)
     : this(networkView, networkView.position, networkView.rotation, NetworkP2PSpace.NetworkP2P)
 {
     p2p.InverseTransform(ref position, ref rotation);
     _networkP2P = p2p as P2P;
 }
 /// <summary>
 /// Creates and initializes a new instance of NetworkP2PHandoverInstance.
 /// </summary>
 /// <param name="networkView">The network view to use for the object being handovered.</param>
 public NetworkP2PHandoverInstance(NetworkViewBase networkView)
     : this(networkView, networkView.position, networkView.rotation, NetworkP2PSpace.World)
 {
 }
Beispiel #20
0
 private static T _GetComponent <T>(NetworkViewBase nv) where T : Component
 {
     return(!nv.IsNullOrDestroyed() ? nv.GetComponent <T>() : null);
 }
 /// <summary>
 /// Creates a new instance of NetworkMessageInfo using the supplied arguments.
 /// </summary>
 public NetworkMessageInfo(NetworkPlayer sender, double localTimestamp, double serverTimestamp, double rawServerTimestamp, NetworkFlags flags, NetworkViewBase networkView)
 {
     this.sender             = sender;
     this.localTimestamp     = localTimestamp;
     this.serverTimestamp    = serverTimestamp;
     this.rawServerTimestamp = rawServerTimestamp;
     this.networkView        = networkView as NV;
     this.flags = flags;
 }
 internal BufferedStateSyncOwnerDeltaCompressedInit(NetworkViewBase nv, NetworkPlayer target)
     : base(_GenerateMessage(nv, target))
 {
 }