Пример #1
0
        /// //////////////////////
        ///

        public static void SettingsForGameobjectGUI()
        {
            GUILayout.Box("SETTINGS FOR GO", headerStyle, GUILayout.ExpandWidth(true), headerHeight);

            GUILayout.Space(10f);

            if (GUILayout.Button("Create child Pivote in center"))
            {
                SetGameObjestSettings.SetPivote();
            }
            if (GUILayout.Button("Create group of GO"))
            {
                SetGameObjestSettings.CreateGroup();
            }

            if (buttonStyle == null)
            {
                buttonStyle = new GUIStyle(GUI.skin.button)
                {
                    richText = true
                };
                headerStyle = new GUIStyle(GUI.skin.box)
                {
                    alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold
                };
            }


            GUILayout.Box("ADJUST PIVOT", headerStyle, GUILayout.ExpandWidth(true), headerHeight);

            Transform selection = Selection.activeTransform;

            if (!IsNull(selection))
            {
                if (!IsNull(selection.parent))
                {
                    if (selection.localPosition != Vector3.zero || selection.localEulerAngles != Vector3.zero)
                    {
                        if (GUILayout.Button("Move and rotate <b>" + selection.parent.name + "</b>'s pivot here", buttonStyle, buttonHeight))
                        {
                            SetParentPivot(selection, false);
                        }

                        if (selection.localEulerAngles != Vector3.zero)
                        {
                            EditorGUILayout.HelpBox("Pivot will also be rotated to match " + selection.name + "'s rotation.", MessageType.None);
                        }

                        if (GUILayout.Button("Move <b>" + selection.parent.name + "</b>'s pivot here", buttonStyle, buttonHeight))
                        {
                            SetParentPivot(selection, true);
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Selected object is at pivot position", buttonStyle, buttonHeight);
                        GUI.enabled = true;
                    }
                }
                else
                {
                    GUI.enabled = false;
                    GUILayout.Button("Selected object has no parent", buttonStyle, buttonHeight);
                    GUI.enabled = true;
                }
            }
            else
            {
                GUI.enabled = false;
                GUILayout.Button("Nothing is selected", buttonStyle, buttonHeight);
                GUI.enabled = true;
            }

            GUILayout.Space(15f);

            auroSaveChangedMesh = EditorGUILayout.ToggleLeft("AutoSave Mesh", auroSaveChangedMesh);

            GUILayout.Space(15f);

            GUILayout.Box("MESH UTILITY", headerStyle, GUILayout.ExpandWidth(true), headerHeight);

            GUILayout.Space(5f);

            GUILayout.Label("Custom path " + pathCustom);

            if (GUILayout.Button("Set default path", buttonStyle, buttonHeight))
            {
                pathCustom = "Assets/__Project__/Models/MeshAssets/";
                Helpful.Debug(pathCustom);
            }
            if (GUILayout.Button("Save custom path", buttonStyle, buttonHeight))
            {
                var temp = pathCustom;
                pathCustom = EditorUtility.SaveFolderPanel("Save custom path", "", string.Empty);
                int      i          = 0;
                bool     normalPath = false;
                string[] tempPath   = Helpful.GetName(pathCustom, '/');
                foreach (var item in tempPath)
                {
                    if (item.Contains("Assets"))
                    {
                        normalPath = true;
                        pathCustom = "";
                        for (int j = i; j < tempPath.Length; j++)
                        {
                            pathCustom += tempPath[j] + "/";
                        }
                        continue;
                    }
                    else
                    {
                        i++;
                    }
                }
                if (!normalPath)
                {
                    Helpful.Debug("Find path in project!!!");
                    pathCustom = temp;
                }
                else
                {
                    Helpful.Debug(pathCustom);
                }
            }

            EditorGUILayout.HelpBox("If an object has a MeshFilter, changing its pivot will modify the mesh. That modified mesh must be saved before it can be applied to prefab.", MessageType.None);

            if (!IsNull(selection))
            {
                MeshFilter meshFilter = selection.GetComponent <MeshFilter>();
                if (!IsNull(meshFilter) && !IsNull(meshFilter.sharedMesh))
                {
                    if (GUILayout.Button("Save <b>" + selection.name + "</b>'s mesh as Asset (Recommended)", buttonStyle, buttonHeight))
                    {
                        if (!Directory.Exists(pathCustom))
                        {
                            Directory.CreateDirectory(pathCustom);
                        }
                        SaveMesh(meshFilter, selection.name, true);
                    }

                    GUILayout.Space(5f);

                    if (GUILayout.Button("Save <b>" + selection.name + "</b>'s mesh as OBJ", buttonStyle, buttonHeight))
                    {
                        if (!Directory.Exists(pathCustom))
                        {
                            Directory.CreateDirectory(pathCustom);
                        }
                        SaveMesh(meshFilter, selection.name, false);
                    }
                }
                else
                {
                    GUI.enabled = false;
                    GUILayout.Button("Selected object has no mesh", buttonStyle, buttonHeight);
                    GUI.enabled = true;
                }

                GUILayout.Space(5f);

                if (GUILayout.Button("Save all meshes as Asset (Recommended)", buttonStyle, buttonHeight))
                {
                    if (!Directory.Exists(pathCustom))
                    {
                        Directory.CreateDirectory(pathCustom);
                    }
                    for (int i = 0; i < Selection.gameObjects.Length; i++)
                    {
                        MeshFilter meshFilterGO = Selection.gameObjects[i].GetComponent <MeshFilter>();
                        if (!IsNull(meshFilterGO) && !IsNull(meshFilterGO.sharedMesh))
                        {
                            SaveMesh(meshFilterGO, Selection.gameObjects[i].name + "" + i, true);
                        }
                    }
                }

                GUILayout.Space(5f);

                if (GUILayout.Button("Save all meshes as OBJ", buttonStyle, buttonHeight))
                {
                    if (!Directory.Exists(pathCustom))
                    {
                        Directory.CreateDirectory(pathCustom);
                    }
                    for (int i = 0; i < Selection.gameObjects.Length; i++)
                    {
                        MeshFilter meshFilterGO = Selection.gameObjects[i].GetComponent <MeshFilter>();
                        if (!IsNull(meshFilterGO) && !IsNull(meshFilterGO.sharedMesh))
                        {
                            SaveMesh(meshFilterGO, Selection.gameObjects[i].name + "" + i, false);
                        }
                    }
                }
            }
            else
            {
                GUI.enabled = false;
                GUILayout.Button("Nothing is selected", buttonStyle, buttonHeight);
                GUI.enabled = true;
            }

            GUILayout.Space(15f);

            GUILayout.Box("SETTINGS", headerStyle, GUILayout.ExpandWidth(true), headerHeight);

            EditorGUI.BeginChangeCheck();
            createColliderObjectOnPivotChange = EditorGUILayout.ToggleLeft("Create Child Collider Object On Pivot Change", createColliderObjectOnPivotChange);
            EditorGUILayout.HelpBox("Note that original collider(s) (if exists) will not be destroyed automatically.", MessageType.None);
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetBool("AdjustPivotCreateColliders", createColliderObjectOnPivotChange);
            }

            GUILayout.Space(10f);

            EditorGUI.BeginChangeCheck();
            createNavMeshObstacleObjectOnPivotChange = EditorGUILayout.ToggleLeft("Create Child NavMesh Obstacle Object On Pivot Change", createNavMeshObstacleObjectOnPivotChange);
            EditorGUILayout.HelpBox("Note that original NavMesh Obstacle (if exists) will not be destroyed automatically.", MessageType.None);
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetBool("AdjustPivotCreateNavMeshObstacle", createNavMeshObstacleObjectOnPivotChange);
            }

            GUILayout.Space(10f);

            if (GUILayout.Button("Tern off rendering shadows for gameObjects"))
            {
                Debug.Log("<color=blue>Kinogoblin Editor</color> Off shadows");
                SetGameObjestSettings.Shadows(false);
            }
            if (GUILayout.Button("Tern on rendering shadows for gameObjects"))
            {
                Debug.Log("<color=blue>Kinogoblin Editor</color> On shadows");
                SetGameObjestSettings.Shadows(true);
            }
        }
Пример #2
0
        public static void ChangeMaterialGUI()
        {
            if (buttonStyle == null)
            {
                buttonStyle = new GUIStyle(GUI.skin.button)
                {
                    richText = true
                };
                headerStyle = new GUIStyle(GUI.skin.box)
                {
                    alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold
                };
            }

            GUILayout.Box("SETTINGS FOR GO", headerStyle, GUILayout.ExpandWidth(true), headerHeight);

            GUILayout.Label("Base settings for new material", EditorStyles.boldLabel);
            GUILayout.Space(10f);

            EditorGUILayout.BeginHorizontal();
            source = EditorGUILayout.ObjectField("Set material", source, typeof(UnityEngine.Object), true);
            EditorGUILayout.EndHorizontal();
            if (GUILayout.Button("Set checked material"))
            {
                Helpful.Debug("Kinogoblin Editor ", "Set checked material");
                if (source != null)
                {
                    try
                    {
                        checkedMaterial = (Material)source;
                    }
                    catch
                    {
                        checkedMaterial = null;
                        Debug.LogError("<color=blue>Kinogoblin Editor</color> This file is not material! I'll look for material by object name");
                    }
                }
                SetMaterialButton.SetCheckMaterial(checkedMaterial);
            }

            GUILayout.Space(10f);

            if (GUILayout.Button("Set new material"))
            {
                Helpful.Debug("Kinogoblin Editor ", "Set new material");
                SetMaterialButton.SetMaterialNew();
            }

            GUILayout.Box("MATERIAL SAVER FROM OBJECTS", headerStyle, GUILayout.ExpandWidth(true), headerHeight);

            GUILayout.Space(5f);

            GUILayout.Label("Custom path " + pathCustom);

            if (GUILayout.Button("Set default path", buttonStyle, buttonHeight))
            {
                pathCustom = "Assets/__Project__/Materials/";
                Helpful.Debug(pathCustom);
            }
            if (GUILayout.Button("Save custom path", buttonStyle, buttonHeight))
            {
                var temp = pathCustom;
                pathCustom = EditorUtility.SaveFolderPanel("Save custom path", "", string.Empty);
                int      i          = 0;
                bool     normalPath = false;
                string[] tempPath   = Helpful.GetName(pathCustom, '/');
                foreach (var item in tempPath)
                {
                    if (item.Contains("Assets"))
                    {
                        normalPath = true;
                        pathCustom = "";
                        for (int j = i; j < tempPath.Length; j++)
                        {
                            pathCustom += tempPath[j] + "/";
                        }
                        continue;
                    }
                    else
                    {
                        i++;
                    }
                }
                if (!normalPath)
                {
                    Helpful.Debug("Find path in project!!!");
                    pathCustom = temp;
                }
                else
                {
                    Helpful.Debug(pathCustom);
                }
            }

            Transform selection = Selection.activeTransform;

            if (!IsNull(selection))
            {
                if (GUILayout.Button("Copy and save <b>" + selection.name + "</b>'s materials!", buttonStyle, buttonHeight))
                {
                    var pathWithName = pathCustom + "/" + selection.name + "/";
                    if (!Directory.Exists(pathWithName))
                    {
                        Directory.CreateDirectory(pathWithName);
                    }
                    SaveMaterialButton.SaveMaterialFromGameObject(pathWithName, selection);
                }

                GUILayout.Space(5f);
            }
            else
            {
                GUI.enabled = false;
                GUILayout.Button("Selected object for save materials", buttonStyle, buttonHeight);
                GUI.enabled = true;
            }
        }