Exemplo n.º 1
0
        protected virtual void OnHealthChanged()
        {
            var evnt = new UpdateNetworkedBuilding();

            evnt.buildingUID = networkedID;
            evnt.health      = health;
            evnt.Send(NetworkReceivers.Server);
        }
Exemplo n.º 2
0
        public override void DestroyBuilding(BaseBuilding building, RaycastHit hit)
        {
            ForgeBuilding boltBuilding = (ForgeBuilding)building;

            if (boltBuilding == null)
            {
                base.DestroyBuilding(building, hit);
                return;
            }

            var evnt = new UpdateNetworkedBuilding();

            evnt.buildingUID = boltBuilding.networkedID;
            evnt.health      = 0;
            evnt.Send(NetworkReceivers.Server);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update the entity
        /// </summary>
        /// <param name="data">data</param>
        public static void UpdateEntity(UpdateNetworkedBuilding data)
        {
            int id       = data.buildingUID;
            var building = GetEntity(id);

            if (building != null)
            {
                building.AssingNetworkedHealth(data.health);

                if (Networking.PrimarySocket.IsServer)
                {
                    data             = new UpdateNetworkedBuilding();
                    data.buildingUID = id;
                    data.Send(NetworkReceivers.Others);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set up callbacks
        /// </summary>
        /// <param name="socket">our socket</param>
        void Networking_Setup(NetWorker socket)
        {
            Networking.PrimarySocket.AddCustomDataReadEvent(CreateNetworkedBuilding.UID, (NetworkingPlayer player, NetworkingStream stream) =>
            {
                CreateNetworkedBuilding data = new CreateNetworkedBuilding().Deserialize(stream);

                BeardedManStudios.Network.Unity.MainThreadManager.Run(() => CreateNetworkBuildingEvent(data));
            });

            Networking.PrimarySocket.AddCustomDataReadEvent(UpdateNetworkedBuilding.UID, (NetworkingPlayer player, NetworkingStream stream) =>
            {
                UpdateNetworkedBuilding data = new UpdateNetworkedBuilding().Deserialize(stream);

                BeardedManStudios.Network.Unity.MainThreadManager.Run(() => UpdateNetworkedBuildingEvent(data));
            });

            if (Networking.PrimarySocket.IsServer)
            {
                Networking.PrimarySocket.playerConnected += (NetworkingPlayer player) => StartCoroutine(ClientConnected(player));
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Called when the UpdateNetworkedBuildingEvent is called
 /// </summary>
 /// <param name="evnt">the event data</param>
 public void UpdateNetworkedBuildingEvent(UpdateNetworkedBuilding evnt)
 {
     UpdateEntity(evnt);
 }