void SyncCustomizer(int weaponID, string line, PhotonMessageInfo info) { if (photonView.ViewID != info.photonView.ViewID) { return; } bl_NetworkGun ng = NetworkGuns.Find(x => x.LocalGun.GunID == weaponID); if (ng != null) { if (ng.GetComponent <bl_CustomizerWeapon>() != null) { ng.GetComponent <bl_CustomizerWeapon>().ApplyAttachments(line); } else { Debug.LogWarning("You have not setup the attachments in the TPWeapon: " + weaponID); } } }
void UpdateAttachemtns() { bl_Customizer[] all = customizerManager.transform.GetComponentsInChildren <bl_Customizer>(true); for (int i = 0; i < all.Length; i++) { if (all[i].WeaponID == script.WeaponID) { _CustomizerWeapon = all[i]; customizerSelected = i; } } int gunID = script.GetComponent <bl_Gun>().GunID; bl_NetworkGun ngun = script.transform.root.GetComponentInChildren <bl_PlayerNetwork>().NetworkGuns.Find(x => x.LocalGun.GunID == gunID); bl_CustomizerWeapon networkScript = ngun.GetComponent <bl_CustomizerWeapon>(); CompareLists(_CustomizerWeapon.Attachments.Foregrips, ref script.Attachments.Foregrips, ref networkScript.Attachments.Foregrips); CompareLists(_CustomizerWeapon.Attachments.Magazines, ref script.Attachments.Magazines, ref networkScript.Attachments.Magazines); CompareLists(_CustomizerWeapon.Attachments.Sights, ref script.Attachments.Sights, ref networkScript.Attachments.Sights); CompareLists(_CustomizerWeapon.Attachments.Suppressers, ref script.Attachments.Suppressers, ref networkScript.Attachments.Suppressers); EditorUtility.SetDirty(networkScript); EditorUtility.SetDirty(target); }
void Transfer() { Transform oldRig = _CustomizerWeapon.Positions.BarrelRoot.transform.parent; GameObject clone = Instantiate(oldRig.gameObject) as GameObject; clone.name = "Attachments [FP]"; Dictionary <string, string> paths = new Dictionary <string, string>(); _CustomizerWeapon.Attachments.Sights.ForEach(x => { if (x.Model != null) { paths.Add(x.Name, AnimationUtility.CalculateTransformPath(x.Model.transform, oldRig)); } }); _CustomizerWeapon.Attachments.Suppressers.ForEach(x => { if (x.Model != null) { paths.Add(x.Name, AnimationUtility.CalculateTransformPath(x.Model.transform, oldRig)); } }); _CustomizerWeapon.Attachments.Magazines.ForEach(x => { if (x.Model != null) { paths.Add(x.Name, AnimationUtility.CalculateTransformPath(x.Model.transform, oldRig)); } }); _CustomizerWeapon.Attachments.Foregrips.ForEach(x => { if (x.Model != null) { paths.Add(x.Name, AnimationUtility.CalculateTransformPath(x.Model.transform, oldRig)); } }); clone.transform.parent = oldRig.parent; clone.transform.localPosition = oldRig.localPosition; clone.transform.localEulerAngles = oldRig.localEulerAngles; clone.transform.localScale = oldRig.localScale; clone.transform.parent = _CustomizerMesh; Vector3[] data = new Vector3[3]; data[0] = clone.transform.localPosition; data[1] = clone.transform.localEulerAngles; data[2] = clone.transform.localScale; clone.transform.parent = _TargetMesh; clone.transform.localPosition = data[0]; clone.transform.localEulerAngles = data[1]; clone.transform.localScale = data[2]; script.Attachments.Sights.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); script.Attachments.Suppressers.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); script.Attachments.Foregrips.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); script.Attachments.Magazines.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); if (script.isFPWeapon) { //clone.layer = LayerMask.NameToLayer("Weapon"); foreach (Transform t in clone.GetComponentsInChildren <Transform>(true)) { t.gameObject.layer = LayerMask.NameToLayer("Weapons"); } } EditorUtility.SetDirty(target); //TP int gunID = script.GetComponent <bl_Gun>().GunID; bl_NetworkGun ngun = script.transform.root.GetComponentInChildren <bl_PlayerNetwork>().NetworkGuns.Find(x => { if (x.LocalGun == null) { return(false); } return(x.LocalGun.GunID == gunID); }); if (ngun != null) { bl_CustomizerWeapon networkCustomizer = ngun.GetComponent <bl_CustomizerWeapon>(); if (networkCustomizer == null) { networkCustomizer = ngun.gameObject.AddComponent <bl_CustomizerWeapon>(); } networkCustomizer.isFPWeapon = false; networkCustomizer.WeaponID = script.WeaponID; networkCustomizer.WeaponName = script.WeaponName; networkCustomizer.BuildAttachments(); if (networkCustomizer.CamoRender == null) { networkCustomizer.CamoRender = new CustomizerCamoRender(); } networkCustomizer.CamoRender.MaterialID = script.CamoRender.MaterialID; //Transform networkTarget = ngun MeshFilter[] meshes = ngun.GetComponentsInChildren <MeshFilter>(); Mesh mesh = script.CamoRender.Render.GetComponent <MeshFilter>().sharedMesh; Transform networkTarget = null; for (int i = 0; i < meshes.Length; i++) { if (meshes[i].sharedMesh == mesh) { networkCustomizer.CamoRender.Render = meshes[i].GetComponent <MeshRenderer>(); networkTarget = networkCustomizer.CamoRender.Render.transform; } } clone = Instantiate(oldRig.gameObject) as GameObject; clone.name = "Attachments [TP]"; clone.transform.parent = networkTarget; clone.transform.localPosition = data[0]; clone.transform.localEulerAngles = data[1]; clone.transform.localScale = data[2]; networkCustomizer.Attachments.Sights.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); networkCustomizer.Attachments.Suppressers.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); networkCustomizer.Attachments.Foregrips.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); networkCustomizer.Attachments.Magazines.ForEach(x => { if (paths.ContainsKey(x.Name)) { x.Model = FindChild(clone, paths[x.Name]); } }); EditorUtility.SetDirty(networkCustomizer); Debug.Log("All done!"); } else { Debug.Log("Could not find the network gun with GunID: " + gunID); } ActiveEditorTracker.sharedTracker.isLocked = false; }