예제 #1
0
        public void OnData(int connectionId, int channelId, int receiveSize, int msgId)
        {
            NetworkMessageID iMsgId = (NetworkMessageID)msgId;

            switch (iMsgId)
            {
            case (NetworkMessageID.SceneLoading):
                SceneLoadingMsg slm = new SceneLoadingMsg();
                slm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleLoadSceneMsg(ref slm, connectionId);
                break;

            case (NetworkMessageID.TickSync):
                TickSyncMsg tsm = new TickSyncMsg();
                tsm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleTickSyncMsg(ref tsm, connectionId);
                break;

            case (NetworkMessageID.SimpleEvent):
                SimpleEventMsg sem = new SimpleEventMsg();
                sem.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleSimpleEventMsg(connectionId, sem.Event);
                break;

            case (NetworkMessageID.SpawnPlayer):
                SpawnPlayerMsg spm = new SpawnPlayerMsg();
                spm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleSpawnPlayerMsg(ref spm, connectionId);
                break;

            case (NetworkMessageID.SpawnCharacter):
                SpawnCharacterMsg scm = new SpawnCharacterMsg();
                scm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleSpawnCharacterMsg(ref scm);
                break;

            case (NetworkMessageID.LazerHit):
                LazerFireMsg lhm = new LazerFireMsg();
                lhm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleLazerFireMsg(ref lhm);
                break;
            }
        }
예제 #2
0
        public void Fire(Quaternion rotation)
        {
            // Lazer beam
            Destroy(Instantiate(LazerBeamPrefab, transform.position, rotation), 0.2f);

            // Check for hit
            RaycastHit            hit;
            MyCharacterController hitCC = null;

            if (Physics.Raycast(transform.position, rotation * Vector3.forward, out hit, 100, -1, QueryTriggerInteraction.Ignore))
            {
                // Spawn visual feedback
                Destroy(Instantiate(ImpactPrefab, hit.point, Quaternion.identity), 5f);

                // Authoritative logic
                if (!GameStatics.OnlineSession.IsClient())
                {
                    Rigidbody hitR = hit.collider.attachedRigidbody;
                    if (hitR)
                    {
                        hitCC = hitR.GetComponent <MyCharacterController>();
                        if (hitCC)
                        {
                            hitCC.OnHitFX();
                            GameStatics.GameManager.SimulationSystem.AddSimulationEvent(new LazerHitEvent(hitCC), GameStatics.GameManager.SimulationSystem.SimulationTick);
                        }
                    }
                }
            }

            if (GameStatics.OnlineSession.IsServer())
            {
                // Send lazer msg event
                LazerFireMsg lhm = new LazerFireMsg();
                lhm.AtTick         = GameStatics.GameManager.SimulationSystem.SimulationTick;
                lhm.FiringPlayerId = OwningCharacter.OwningPlayer.GetId();
                lhm.FiringRotation = rotation;
                lhm.HitCharacterId = (hitCC == null) ? -1 : hitCC.GetId();
                lhm.Serialize(GameStatics.OnlineSession.NetBuffer);
                GameStatics.OnlineSession.SendBufferToAllClients(OnlineSession.ReliableSequencedChannelId);
            }
        }
예제 #3
0
        public void HandleLazerFireMsg(ref LazerFireMsg msg)
        {
            // Show other players firing
            MyPlayerController firingPlayer;

            if (SimulationSystem.RegisteredPlayerControllers.TryGetValue(msg.FiringPlayerId, out firingPlayer))
            {
                if (!firingPlayer.GetIsLocal())
                {
                    firingPlayer.Character.LazerGun.Fire(msg.FiringRotation);
                }
            }

            // Handle real hit logic
            if (msg.HitCharacterId >= 0)
            {
                MyCharacterController hitCC;
                if (KinematicCharacterSubsystem.Characters.TryGetValue(msg.HitCharacterId, out hitCC))
                {
                    hitCC.OnHitFX();
                }
            }
        }