/// <summary> /// Spawn lootable item on world. /// </summary> /// <param name="value">Incoming message</param> private void OnSpawn_Item(string[] value) { SNet_Network.Spawn_Item readMessage = SNet_Network.SNetMessage.ReadMessage <SNet_Network.Spawn_Item>(value[0]); readMessage.s = ulong.Parse(value[1]); if (!SNet_Network.instance.isHost(readMessage.s)) { return; // Only the host can send this } SNet_Identity go = null; if (SNet_Identity.find(readMessage.i, out go)) { if (readMessage.a > 0) { go.GetComponent <Item>().item.ammo = readMessage.a; } // Already have that identity. return; } Transform prefab = ResourcesLoader.prefabs.Find(x => x.name == readMessage.b); prefab = Instantiate(prefab, readMessage.p, readMessage.r); if (readMessage.c != Vector3.zero) { prefab.localScale = readMessage.c; } SNet_Identity identity = prefab.GetComponent <SNet_Identity>(); identity.Set(readMessage.i, readMessage.b); if (readMessage.a > 0) // or it has default ammo { identity.GetComponent <Item>().item.ammo = readMessage.a; } Collider cldr = prefab.GetComponent <Collider>(); if (cldr != null) { cldr.enabled = true; } Rigidbody rb = prefab.GetComponent <Rigidbody>(); if (rb != null) { rb.isKinematic = false; } DestroyIn dIn = prefab.GetComponent <DestroyIn>(); if (dIn != null) { dIn.enabled = true; } }
public void Equip(string prefabName) { if (prefab != null) { if (prefab.item.prefabName == prefabName) { return; } prefab.SendMessage("Detach"); Destroy(prefab.gameObject); } if (string.IsNullOrEmpty(prefabName)) { if (prefab != null) { Destroy(prefab.gameObject); } } Item.PlayerItem willEquip = inv.l.Find(x => x.prefabName == prefabName); if (willEquip == null) { willEquip = new Item.PlayerItem(); } inv.ci = willEquip; identity.controller.isShooting = false; prefab = null; if (!string.IsNullOrEmpty(prefabName)) { Transform Tprefab = ResourcesLoader.prefabs.Find(x => x.name == prefabName); Transform tBone = identity.animator.animator.GetBoneTransform(Tprefab.GetComponent <Item>().item.targetBone); prefab = Instantiate(Tprefab, tBone).GetComponent <Item>(); prefab.name = prefabName; Destroy(prefab.GetComponent <CustomScale>()); Destroy(prefab.GetComponent <Snet_SceneObject_AutoSpawn>()); Collider cldr = prefab.GetComponent <Collider>(); if (cldr != null) { cldr.enabled = false; } Rigidbody rb = prefab.GetComponent <Rigidbody>(); if (rb != null) { rb.isKinematic = true; } DestroyIn dIn = prefab.GetComponent <DestroyIn>(); if (dIn != null) { dIn.enabled = false; } IKWeapon attacher = prefab.GetComponent <IKWeapon>(); if (attacher != null) { attacher.Attach(); } } SetState(); if (isLocalPlayer) { if (Crosshair.instance == null || Crosshair.instance.normal == null) { return; } foreach (Transform t in Crosshair.instance.normal.transform) { t.GetComponent <UIVisibility>().Open(t.name == inv.ci.crossHair_Normal); } foreach (Transform t in Crosshair.instance.aimed.transform) { t.GetComponent <UIVisibility>().Open(t.name == inv.ci.crossHair_Aimed); } if (!UpdateCurrentAmmo()) { SyncInventory(); } } }