/// <summary> /// A player interacts to a networked object. /// </summary> /// <param name="value">Incoming message</param> private void OnInteract(string[] value) { Interactor.Interact readMessage = SNet_Network.SNetMessage.ReadMessage <Interactor.Interact>(value[0]); readMessage.s = ulong.Parse(value[1]); SNet_Identity id = null; if ( SNet_Identity.find(readMessage.i, out id)) { // sender interacts the item. SNet_Identity sender = null; if (SNet_Identity.find(readMessage.s, out sender)) { switch (id.gameObject.tag) { case "Item": // Loot weapon or something Item item = id.GetComponent <Item>(); if (item != null && sender.controller != null) { Item.PlayerItem pi = sender.controller.GetComponent <PlayerInventory>().inv.l.Find(x => x.prefabName == item.item.prefabName); if (pi != null && pi.maxammo <= pi.ammo) { return; // Maximum ammo reached. } item.item.looter = sender.controller.GetComponent <SNet_Identity>().identity; SNet_Network.instance.Send_Message(item.item); Destroy(item.gameObject); } break; case "Vehicle": // Get into a vehicle SNet_Vehicle vehicle = id.GetComponent <SNet_Vehicle>(); int vIndex = vehicle.vehicle.p.FindIndex(x => x == sender.identity); if (vIndex != -1) { vehicle.vehicle.p [vIndex] = 0; vehicle.VehicleUpdate(); return; } vIndex = vehicle.vehicle.p.FindIndex(x => x == 0); // Empty seat if (!sender.controller.isDead && vIndex != -1 && !vehicle.vehicle.p.Contains(sender.identity)) { vehicle.vehicle.p[vIndex] = sender.identity; vehicle.VehicleUpdate(); } break; } } } }
public void Set(ulong _identity, string _prefab) { identity = _identity; prefab = _prefab; animator = GetComponent <SNet_Animator>(); rbody = GetComponent <SNet_Rigidbody>(); tform = GetComponent <SNet_Transform>(); controller = GetComponent <SNet_Controller>(); ragdoll = GetComponent <RagdollHelper>(); explosive = GetComponent <Explosive>(); vehicle = GetComponent <SNet_Vehicle>(); asource = GetComponent <AudioSource>(); if (_identity < 1000000 && identity > SNet_Network.SNetMessage.idStep) { SNet_Network.SNetMessage.idStep = identity; } /* * MAX REALTIME NETWORK OBJECTS LIMIT is 1.000.000 * */ set = true; }