예제 #1
0
        public override void OnInspectorGUI()
        {
            GUILayout.BeginVertical("box");
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal("box");
            script.WeaponID = EditorGUILayout.Popup("Customizer ID", script.WeaponID, bl_CustomizerData.Instance.GetWeaponStringArray(), EditorStyles.toolbarDropDown);
            GUILayout.Space(5);
            if (GUILayout.Button("Refresh", EditorStyles.toolbarButton, GUILayout.Width(100)))
            {
                script.RefreshAttachments();
            }
            GUILayout.EndHorizontal();
            script.isFPWeapon   = EditorGUILayout.ToggleLeft("is First Person Weapon", script.isFPWeapon, EditorStyles.toolbarButton);
            script.ApplyOnStart = EditorGUILayout.ToggleLeft("Apply On Start", script.ApplyOnStart, EditorStyles.toolbarButton);
            if (GUI.changed)
            {
                script.WeaponName = bl_CustomizerData.Instance.Weapons[script.WeaponID].WeaponName;
                if (script.WeaponName != weaponName)
                {
                    script.BuildAttachments();
                    weaponName = script.WeaponName;
                }
            }

            serializedObject.Update();
            GUILayout.BeginHorizontal("box");
            GUILayout.Space(10);
            EditorGUILayout.PropertyField(camor, true);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal("box");
            GUILayout.Space(10);
            EditorGUILayout.PropertyField(attac, true);
            GUILayout.EndHorizontal();
            serializedObject.ApplyModifiedProperties();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal("box");
            GUI.enabled = customizerManager != null && script.isFPWeapon;
            if (GUILayout.Button("Import", EditorStyles.toolbarButton, GUILayout.Width(100)))
            {
                openImportMenu = !openImportMenu;
                if (openImportMenu)
                {
                    //ActiveEditorTracker.sharedTracker.isLocked = openImportMenu;

                    allCustomizers.Clear();
                    bl_CustomizerManager cm = FindObjectOfType <bl_CustomizerManager>();
                    if (cm != null)
                    {
                        bl_Customizer[] all = cm.transform.GetComponentsInChildren <bl_Customizer>(true);
                        for (int i = 0; i < all.Length; i++)
                        {
                            allCustomizers.Add(all[i].gameObject.name, all[i]);
                            if (all[i].WeaponID == script.WeaponID)
                            {
                                _CustomizerWeapon  = all[i];
                                customizerSelected = i;
                            }
                        }
                        if (script.CamoRender.Render == null)
                        {
                            SetupPlayerWeapons();
                        }
                    }
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Update Attachments", EditorStyles.toolbarButton, GUILayout.Width(200)))
            {
                UpdateAttachemtns();
            }
            GUILayout.EndHorizontal();
            GUI.enabled = true;

            if (openImportMenu)
            {
                GUILayout.BeginVertical("box");
                if (script.CamoRender.Render == null)
                {
                    if (allCustomizers.Count > 0)
                    {
                        if (GUILayout.Button("Setup FP and TP Weapons"))
                        {
                            SetupPlayerWeapons();
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Can't find any customizer weapon in the scene, be sure you're in the Customizer scene", MessageType.Warning);
                    }
                }
                else
                {
                    if (allCustomizers.Count > 0)
                    {
                        customizerSelected = EditorGUILayout.Popup("Customizer Weapon", customizerSelected, allCustomizers.Keys.ToArray());
                        _CustomizerWeapon  = allCustomizers.Values.ElementAt(customizerSelected);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Can't find any customizer weapon in the scene, be sure you're in the Customizer scene", MessageType.Warning);
                    }
                    if (_CustomizerWeapon != null && _CustomizerWeapon.gameObject.name != "***TEMPLATE***")
                    {
                        if (allCustomizersMeshs.Count <= 0)
                        {
                            MeshRenderer[] all = _CustomizerWeapon.Positions.ModelParent.GetComponentsInChildren <MeshRenderer>(true);
                            for (int i = 0; i < all.Length; i++)
                            {
                                allCustomizersMeshs.Add(all[i].name, all[i].transform);
                            }
                        }
                        else
                        {
                            _CustomizerMesh = _CustomizerWeapon.CamoRender.Render.transform;
                            _CustomizerMesh = EditorGUILayout.ObjectField("Customizer Mesh", _CustomizerMesh, typeof(Transform), true) as Transform;
                            if (_CustomizerMesh != null)
                            {
                                if (_TargetMesh == null)
                                {
                                    if (script.CamoRender.Render != null)
                                    {
                                        _TargetMesh = script.CamoRender.Render.transform;
                                    }
                                    else
                                    {
                                        if (GUILayout.Button("Search Mesh"))
                                        {
                                            MeshFilter[] all = script.transform.GetComponentsInChildren <MeshFilter>(true);
                                            Mesh         m   = _CustomizerMesh.GetComponent <MeshFilter>().sharedMesh;
                                            for (int i = 0; i < all.Length; i++)
                                            {
                                                if (all[i].sharedMesh == m)
                                                {
                                                    _TargetMesh = all[i].transform;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _TargetMesh = EditorGUILayout.ObjectField("Target Weapon Mesh", _TargetMesh, typeof(Transform), true) as Transform;
                                }
                            }
                        }
                    }

                    GUI.enabled = (_CustomizerMesh != null && _CustomizerWeapon != null && _TargetMesh != null);
                    if (GUILayout.Button("Transfer", EditorStyles.toolbarButton, GUILayout.Width(100)))
                    {
                        Transfer();
                    }
                    GUI.enabled = true;
                }
                GUILayout.EndVertical();
            }

            EditorGUI.EndChangeCheck();
            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
예제 #2
0
        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;
        }