Exemplo n.º 1
0
        public override void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, Action <NetworkObject> callback)
        {
            if (NetworkManager.Instance.IsMaster)
            {
                if (frame.Sender != null && frame.Sender != networker.Me)
                {
                    if (!ValidateCreateRequest(networker, identity, id, frame))
                    {
                        return;
                    }
                }
            }

            bool          availableCallback = false;
            NetworkObject obj = null;

            MainThreadManager.Run(() =>
            {
                switch (identity)
                {
                case ChatManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new ChatManagerNetworkObject(networker, id, frame);
                    break;

                case GameModeNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new GameModeNetworkObject(networker, id, frame);
                    break;

                case PlayerNetworkObject.IDENTITY:
                    availableCallback = true;
                    ///obj = new PlayerNetworkObject(networker, id, frame);
                    obj = new PlayerNetworkObject();
                    PlayerNetworkObject playerObj = (PlayerNetworkObject)obj;
                    playerObj.SetupUID((int)id, true);
                    break;

                case WeaponPickupNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new WeaponPickupNetworkObject(networker, id, frame);
                    break;
                }

                if (!availableCallback)
                {
                    base.NetworkCreateObject(networker, identity, id, frame, callback);
                }
                else if (callback != null)
                {
                    callback(obj);
                }
            });
        }
		public override void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, Action<NetworkObject> callback)
		{
			if (networker.IsServer)
			{
				if (frame.Sender != null && frame.Sender != networker.Me)
				{
					if (!ValidateCreateRequest(networker, identity, id, frame))
						return;
				}
			}
			
			bool availableCallback = false;
			NetworkObject obj = null;
			MainThreadManager.Run(() =>
			{
				switch (identity)
				{
					case ChatManagerNetworkObject.IDENTITY:
						availableCallback = true;
						obj = new ChatManagerNetworkObject(networker, id, frame);
						break;
					case GameModeNetworkObject.IDENTITY:
						availableCallback = true;
						obj = new GameModeNetworkObject(networker, id, frame);
						break;
					case PlayerNetworkObject.IDENTITY:
						availableCallback = true;
						obj = new PlayerNetworkObject(networker, id, frame);
						break;
					case WeaponPickupNetworkObject.IDENTITY:
						availableCallback = true;
						obj = new WeaponPickupNetworkObject(networker, id, frame);
						break;
				}

				if (!availableCallback)
					base.NetworkCreateObject(networker, identity, id, frame, callback);
				else if (callback != null)
					callback(obj);
			});
		}
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (WeaponPickupNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("OnPickup", OnPickup, typeof(float));
            networkObject.RegisterRpc("Setup", Setup, typeof(int));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }