Exemplo n.º 1
0
        private void OnGUI()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
                return;
            }

            //Get current event
            Event e = ProcessEvents();

            if (isLoaded)
            {
                GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2)));
                GUILayout.BeginVertical();


                if (curWindow != null && curWindow.textureAtlas != null)
                {
                    //Export options
                    GUILayout.Box("Note: No custom export options right now.. :<", EditorStyles.helpBox);

                    //Export
                    GUILayout.BeginVertical(EditorStyles.helpBox);

                    GUILayout.Label("Meshes: OBJ | Textures: PNG");
                    if (GUILayout.Button("Export Atlas", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
                    }

                    GUILayout.EndVertical();
                }
                else if (curWindow == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: Link with the Texture Atlas Editor lost!", EditorStyles.helpBox);
                    if (GUILayout.Button("Link Atlas Editor", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        curWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow <MA_TextureAtlasserProWindow>();
                    }
                    GUI.backgroundColor = Color.white;
                }
                else if (curWindow.textureAtlas == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: No Texture Atlas found make sure to open one!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            if (e.type == EventType.Repaint)
            {
                isLoaded = true;
            }
        }
Exemplo n.º 2
0
        private static void CreateViews()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
            }

            thisWindow.settings      = MA_TextureAtlasserProUtils.LoadSettings();
            thisWindow.workView      = new MA_TextureAtlasserProWorkView(thisWindow, "workView");
            thisWindow.menuView      = new MA_TextureAtlasserProMenuView(thisWindow, "menuView");
            thisWindow.inspectorView = new MA_TextureAtlasserProInspectorView(thisWindow, "inspectorView");
            thisWindow.debugView     = new MA_TextureAtlasserProDebugView(thisWindow, "debugView");
        }
        private void DrawExportMenu()
        {
            GUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Height(44));

            if (GUILayout.Button(MA_TextureAtlasserProGuiLoader.createExportSettingsGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
            {
                MA_TextureAtlasserProCreateExportWindow.InitWindow(curWindow);
            }

            bool wasEnabled = GUI.enabled;

            if (curWindow.textureAtlas.exportSettings != null)
            {
                GUI.enabled = true;
            }
            else
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
            {
                string[] textures = null;
                string   material = null;
                string[] models   = null;

                if (curWindow.textureAtlas.exportSettings.exportTextures)
                {
                    textures = MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.textureExportSettings);
                }

                if (curWindow.textureAtlas.exportSettings.exportMaterials)
                {
                    material = MA_TextureAtlasserProUtils.ExportAtlasMaterial(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.materialExportSettings, textures: textures);
                }

                if (curWindow.textureAtlas.exportSettings.exportModels)
                {
                    models = MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings, materialPath: material);
                }
            }

            GUI.enabled = wasEnabled;

            GUILayout.EndHorizontal();
        }
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, MA_TextureAtlasserProUtils.VIEW_OFFSET, position.width - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2)));
            GUILayout.BeginVertical();

            //Input options
            settingsName = EditorGUILayout.TextField("Settings name", settingsName, GUILayout.ExpandWidth(true));
            if (settingsName == "Settings name" || string.IsNullOrEmpty(settingsName))
            {
                nameError           = true;
                GUI.backgroundColor = Color.red;
                GUILayout.Box("Error: Enter a valid settings name!", EditorStyles.helpBox);
                GUI.backgroundColor = Color.white;
            }
            else
            {
                nameError = false;
            }

            //Create
            if (!nameError)
            {
                if (GUILayout.Button("Create!", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                {
                    MA_TextureAtlasserProExportSettings exportSettings = MA_TextureAtlasserProUtils.CreateExportSettings(settingsName, true);

                    if (curWindow != null && curWindow.textureAtlas != null)
                    {
                        curWindow.textureAtlas.exportSettings = exportSettings;
                    }

                    this.Close();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
Exemplo n.º 5
0
        public override void UpdateView(Event e, Rect editorViewRect)
        {
            //Update base derived class
            base.UpdateView(e, editorViewRect);

            if (isLoaded)
            {
                //Draw inspector
                if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
                {
                    //Deselect GUI elements when we are focusing on a new quad
                    if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad)
                    {
                        lastSelectedQuad = curWindow.textureAtlas.selectedTextureQuad;
                        GUI.FocusControl(null);
                    }

                    GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
                    GUILayout.BeginVertical(GUILayout.ExpandWidth(true));

                    GUILayout.Label("Quad Name");
                    curWindow.textureAtlas.selectedTextureQuad.name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.name);

                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);

                    //Textures
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Textures", GUILayout.ExpandWidth(true));
                    if (GUILayout.Button(MA_TextureAtlasserProGuiLoader.editGC, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
                    {
                        isEditing = !isEditing;
                    }
                    GUILayout.EndHorizontal();
                    if (curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0)
                    {
                        if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
                        {
                            MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
                        }
                    }
                    for (int i = 0; i < curWindow.textureAtlas.textureGroupRegistration.Count; i++)
                    {
                        if (isEditing)
                        {
                            curWindow.textureAtlas.textureGroupRegistration[i].name = curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.textureGroupRegistration[i].name);
                        }
                        else
                        {
                            GUILayout.Label(curWindow.textureAtlas.textureGroupRegistration[i].name);
                        }
                        GUILayout.BeginHorizontal();
                        curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture = (Texture)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture, typeof(Texture), false);
                        if (isEditing && GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
                        {
                            MA_TextureAtlasserProUtils.RemoveTextureGroup(curWindow.textureAtlas, i);
                        }
                        if (isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
                        {
                            MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
                        }
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);

                    //Models
                    GUILayout.Label("Models");

                    SerializedObject serializedObject = new SerializedObject(curWindow.textureAtlas.selectedTextureQuad);
                    serializedObject.Update();

                    if (curWindow.textureAtlas.selectedTextureQuad.modelGroups != null)
                    {
                        SerializedProperty modelGroupsSP = serializedObject.FindProperty("modelGroups");

                        for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.modelGroups.Count; i++)
                        {
                            using (new GUILayout.VerticalScope(EditorStyles.helpBox))
                            {
                                using (new GUILayout.HorizontalScope())
                                {
                                    curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name);
                                    if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
                                    {
                                        curWindow.textureAtlas.selectedTextureQuad.modelGroups.RemoveAt(i);
                                        break;
                                    }
                                }

                                SerializedProperty meshesSP = modelGroupsSP.GetArrayElementAtIndex(i).FindPropertyRelative("meshes");
                                EditorGUILayout.PropertyField(meshesSP, false, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(editorViewRect.width * 0.5f));

                                if (meshesSP.isExpanded)
                                {
                                    for (int j = 0; j < curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Count; j++)
                                    {
                                        using (new GUILayout.HorizontalScope())
                                        {
                                            curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j], typeof(Mesh), false);
                                            if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
                                            {
                                                curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.RemoveAt(j);
                                                break;
                                            }
                                        }
                                    }
                                }

                                if (GUILayout.Button("+", EditorStyles.miniButton))
                                {
                                    curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Add(null);
                                }
                            }
                        }

                        if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
                        {
                            curWindow.textureAtlas.selectedTextureQuad.modelGroups.Add(new MA_ModelGroup()
                            {
                                name = MA_StringUtils.RandomAlphabetString(6)
                            });
                        }
                    }
                    else
                    {
                        curWindow.textureAtlas.selectedTextureQuad.modelGroups = new List <MA_ModelGroup>();
                    }

                    serializedObject.ApplyModifiedProperties();

                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);

                    //x, y, w, h.
                    GUILayout.FlexibleSpace();
                    if (!MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.width) || !MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.height))
                    {
                        labelStyle.normal.textColor = Color.red;
                    }
                    else
                    {
                        labelStyle.normal.textColor = GUI.skin.label.normal.textColor;
                    }

                    GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString());
                    GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString(), labelStyle);

                    GUILayout.EndVertical();
                    GUILayout.EndArea();
                }
            }

            if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
            {
                ProcessEvents(e, editorViewRect);
            }
        }
Exemplo n.º 6
0
        public override void UpdateView(Event e, Rect editorViewRect)
        {
            //Update base derived class
            base.UpdateView(e, editorViewRect);

            if (isLoaded)
            {
                //Draw inspector
                if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
                {
                    //Deselect GUI elements when we are focusing on a new quad
                    if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad)
                    {
                        lastSelectedQuad = curWindow.textureAtlas.selectedTextureQuad;
                        GUI.FocusControl(null);
                    }

                    GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
                    GUILayout.BeginVertical(GUILayout.ExpandWidth(true));

                    GUILayout.Label("Quad Name");
                    curWindow.textureAtlas.selectedTextureQuad.name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.name);

                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET / 2);

                    //Textures
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Textures", GUILayout.ExpandWidth(true));
                    if (GUILayout.Button(MA_TextureAtlasserProIcons.editIcon, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
                    {
                        isEditing = !isEditing;
                    }
                    GUILayout.EndHorizontal();
                    if (curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0)
                    {
                        if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
                        {
                            MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
                        }
                    }
                    for (int i = 0; i < curWindow.textureAtlas.textureGroupRegistration.Count; i++)
                    {
                        if (isEditing)
                        {
                            curWindow.textureAtlas.textureGroupRegistration[i].name = curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.textureGroupRegistration[i].name);
                        }
                        else
                        {
                            GUILayout.Label(curWindow.textureAtlas.textureGroupRegistration[i].name);
                        }
                        GUILayout.BeginHorizontal();
                        curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture = (Texture)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture, typeof(Texture), false);
                        if (isEditing && GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
                        {
                            MA_TextureAtlasserProUtils.RemoveTextureGroup(curWindow.textureAtlas, i);
                        }
                        if (isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
                        {
                            MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
                        }
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET / 2);

                    //Meshes
                    GUILayout.Label("Meshes");
                    if (curWindow.textureAtlas.selectedTextureQuad.meshes != null)
                    {
                        if (curWindow.textureAtlas.selectedTextureQuad.meshes.Count == 0)
                        {
                            if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
                            {
                                curWindow.textureAtlas.selectedTextureQuad.meshes.Add(null);
                            }
                        }
                        for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.meshes.Count; i++)
                        {
                            GUILayout.BeginHorizontal();
                            curWindow.textureAtlas.selectedTextureQuad.meshes[i] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.meshes[i], typeof(Mesh), false);
                            if (GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
                            {
                                curWindow.textureAtlas.selectedTextureQuad.meshes.RemoveAt(i);
                            }
                            if (GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
                            {
                                curWindow.textureAtlas.selectedTextureQuad.meshes.Insert(i, null);
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        curWindow.textureAtlas.selectedTextureQuad.meshes = new List <Mesh>();
                    }

                    GUILayout.FlexibleSpace();
                    GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString());
                    GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString());

                    GUILayout.EndVertical();
                    GUILayout.EndArea();
                }
            }

            if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
            {
                ProcessEvents(e, editorViewRect);
            }
        }
Exemplo n.º 7
0
        private void OnGUI()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
                return;
            }

            //Get current event
            Event e = ProcessEvents();

            if (isLoaded)
            {
                GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2)));
                GUILayout.BeginVertical();


                if (curWindow != null && curWindow.textureAtlas != null)
                {
                    //Export
                    GUILayout.BeginVertical();

                    DrawExportModeEditor();
                    DrawAdvancedEditor();

                    GUILayout.BeginHorizontal(EditorStyles.helpBox);

                    GUI.enabled = _selectedExportMode != ExportMode.None;
                    if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        if (exportObjDefault)
                        {
                            MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas);
                        }

                        if (_replaceMeshes)
                        {
                            MA_TextureAtlasserProUtils.ModifyMeshes(curWindow.textureAtlas);
                        }

                        if (exportPngDefault)
                        {
                            if (exportSprite)
                            {
                                MA_TextureAtlasserProUtils.ExportAtlasSpritesPNG(curWindow.textureAtlas, exportSliceSprite);
                            }
                            else
                            {
                                MA_TextureAtlasserProUtils.ExportAtlasTexturesPNG(curWindow.textureAtlas);
                            }
                        }
                    }

                    GUI.enabled = true;

                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
                else if (curWindow == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: Link with the Texture Atlas Editor lost!", EditorStyles.helpBox);
                    if (GUILayout.Button("Link Atlas Editor", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        curWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow <MA_TextureAtlasserProWindow>();
                    }
                    GUI.backgroundColor = Color.white;
                }
                else if (curWindow.textureAtlas == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: No Texture Atlas found make sure to open one!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            if (e.type == EventType.Repaint)
            {
                isLoaded = true;
            }
        }
        public override void UpdateView(Event e, Rect editorViewRect)
        {
            //Update base derived class
            base.UpdateView(e, editorViewRect);

            //Draw Menu
            if (isLoaded)
            {
                GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));

                if (GUILayout.Button(MA_TextureAtlasserProIcons.createAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                {
                    MA_TextureAtlasserProCreateWindow.InitEditorWindow(curWindow);
                }
                if (GUILayout.Button(MA_TextureAtlasserProIcons.loadAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                {
                    curWindow.textureAtlas = MA_TextureAtlasserProUtils.LoadTextureAtlas();
                }

                if (curWindow.textureAtlas != null)
                {
                    if (GUILayout.Button(MA_TextureAtlasserProIcons.exportAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        MA_TextureAtlasserProExportWindow.InitEditorWindow(curWindow);
                        //MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
                    }
                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET);
                    if (curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOnIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        curWindow.textureAtlas.showTextures = false;
                    }
                    else if (!curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOffIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        curWindow.textureAtlas.showTextures = true;
                    }
                    GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET);
                    if (GUILayout.Button(MA_TextureAtlasserProIcons.createQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus);
                    }
                    if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.removeQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        if (curWindow.textureAtlas.selectedTextureQuad != null)
                        {
                            MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus);
                        }
                    }
                    if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.duplicateQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        if (curWindow.textureAtlas.selectedTextureQuad != null)
                        {
                            MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
                        }
                    }
                }

                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }

            ProcessEvents(e, editorViewRect);
        }
Exemplo n.º 9
0
        protected override void ProcessEvents(Event e, Rect editorViewRect)
        {
            base.ProcessEvents(e, editorViewRect);

            // Allow adjusting the zoom with the mouse wheel as well. In this case, use the mouse coordinates
            // as the zoom center instead of the top left corner of the zoom area. This is achieved by
            // maintaining an origin that is used as offset when drawing any GUI elements in the zoom area.
            if (e.type == EventType.ScrollWheel)
            {
                Vector2 screenCoordsMousePos = e.mousePosition;
                Vector2 delta = e.delta;
                Vector2 zoomCoordsMousePos = ConvertScreenCoordsToZoomCoords(screenCoordsMousePos);
                float   zoomDelta          = -delta.y / 100.0f;
                float   oldZoom            = zoom;
                zoom += zoomDelta;
                zoom  = Mathf.Clamp(zoom, kZoomMin, kZoomMax);
                if (zoom < 1.025f && zoom > 0.995f)
                {
                    zoom = 1;
                }
                zoomCoordsOrigin += (zoomCoordsMousePos - zoomCoordsOrigin) - (oldZoom / zoom) * (zoomCoordsMousePos - zoomCoordsOrigin);

                e.Use();
            }

            // Allow moving the zoom area's origin by dragging by dragging with the left mouse button with Alt pressed.
            if (e.type == EventType.MouseDrag && (e.button == 2 || (e.button == 0 && e.modifiers == EventModifiers.Alt)))
            {
                Vector2 delta = Event.current.delta;
                delta            /= zoom;
                zoomCoordsOrigin -= delta;

                e.Use();
            }

            //Hotkeys.
            if (curWindow.settings.useHotkeys)
            {
                if (curWindow.textureAtlas != null)
                {
                    if (e.type == EventType.KeyDown && e.keyCode == curWindow.settings.addQuadHotKey)
                    {
                        MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus);
                        e.Use();
                    }

                    if (curWindow.textureAtlas.selectedTextureQuad != null)
                    {
                        if (e.type == EventType.KeyDown && e.keyCode == curWindow.settings.removeQuadHotKey)
                        {
                            MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus);
                            e.Use();
                        }

                        if (e.type == EventType.KeyDown && e.keyCode == curWindow.settings.duplicateHotKey)
                        {
                            MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
                            e.Use();
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void OnGUI()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
                return;
            }

            //Get current event
            Event e = ProcessEvents();

            if (isLoaded)
            {
                GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2)));
                GUILayout.BeginVertical();


                if (curWindow != null && curWindow.textureAtlas != null)
                {
                    //Export
                    GUILayout.BeginVertical();
                    GUILayout.BeginHorizontal(EditorStyles.helpBox);

                    if (GUILayout.Button("3D", GUILayout.ExpandWidth(false)))
                    {
                        exportObjDefault  = true;
                        exportPngDefault  = true;
                        exportSprite      = false;
                        exportSliceSprite = false;
                    }

                    if (GUILayout.Button("2D", GUILayout.ExpandWidth(false)))
                    {
                        exportObjDefault  = false;
                        exportPngDefault  = true;
                        exportSprite      = true;
                        exportSliceSprite = true;
                    }

                    GUILayout.EndHorizontal();

                    GUILayout.Label("Meshes:");
                    exportObjDefault = GUILayout.Toggle(exportObjDefault, "OBJ default.");

                    GUILayout.Label("Textures:");
                    GUILayout.BeginHorizontal();
                    exportPngDefault = GUILayout.Toggle(exportPngDefault, "PNG default.");
                    if (exportPngDefault)
                    {
                        exportSprite = GUILayout.Toggle(exportSprite, "Sprite.");
                        if (exportSprite)
                        {
                            exportSliceSprite = GUILayout.Toggle(exportSliceSprite, "Slice sprites.");
                        }
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal(EditorStyles.helpBox);

                    if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        if (exportObjDefault)
                        {
                            MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas);
                        }

                        if (exportPngDefault)
                        {
                            if (exportSprite)
                            {
                                MA_TextureAtlasserProUtils.ExportAtlasSpritesPNG(curWindow.textureAtlas, exportSliceSprite);
                            }
                            else
                            {
                                MA_TextureAtlasserProUtils.ExportAtlasTexturesPNG(curWindow.textureAtlas);
                            }
                        }
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
                else if (curWindow == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: Link with the Texture Atlas Editor lost!", EditorStyles.helpBox);
                    if (GUILayout.Button("Link Atlas Editor", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        curWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow <MA_TextureAtlasserProWindow>();
                    }
                    GUI.backgroundColor = Color.white;
                }
                else if (curWindow.textureAtlas == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: No Texture Atlas found make sure to open one!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            if (e.type == EventType.Repaint)
            {
                isLoaded = true;
            }
        }
Exemplo n.º 11
0
        private void OnGUI()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
                return;
            }

            //Get current event
            Event e = ProcessEvents();

            if (isLoaded)
            {
                GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, MA_TextureAtlasserProUtils.VIEW_OFFSET, position.width - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2)));
                GUILayout.BeginVertical();

                //Input options
                textureAtlasName = EditorGUILayout.TextField("Atlas name", textureAtlasName, GUILayout.ExpandWidth(true));
                if (textureAtlasName == "Atlas name" || string.IsNullOrEmpty(textureAtlasName))
                {
                    nameError           = true;
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: Enter a valid atlas name!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }
                else
                {
                    nameError = false;
                }

                textureAtlasSize.x = EditorGUILayout.IntField("Atlas width", (int)textureAtlasSize.x, GUILayout.ExpandWidth(true));
                if (linkedAtlasSize)
                {
                    linkedAtlasSize    = EditorGUILayout.Toggle("link height", linkedAtlasSize, GUILayout.ExpandWidth(true));
                    textureAtlasSize.y = textureAtlasSize.x;
                }
                else
                {
                    textureAtlasSize.y = EditorGUILayout.IntField("Atlas height", (int)textureAtlasSize.y, GUILayout.ExpandWidth(true));
                }
                if (!Mathf.IsPowerOfTwo((int)textureAtlasSize.x) || !Mathf.IsPowerOfTwo((int)textureAtlasSize.y))
                {
                    GUI.backgroundColor = Color.yellow;
                    GUILayout.Box("Warning: Atlas size value isn't a power of two!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }
                if (textureAtlasSize.x < 64 || textureAtlasSize.y < 64)
                {
                    sizeError           = true;
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: The minimum atlas size is 64!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }
                else
                {
                    sizeError = false;
                }

                //Create
                if (!nameError && !sizeError)
                {
                    if (GUILayout.Button("Create Atlas", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        textureAtlas = MA_TextureAtlasserProUtils.CreateTextureAtlas(textureAtlasName, textureAtlasSize);

                        if (curWindow != null)
                        {
                            curWindow.textureAtlas = textureAtlas;
                        }
                        else
                        {
                            Debug.Log("No editor window found");
                        }

                        CloseWindow();
                    }
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            if (e.type == EventType.Repaint)
            {
                isLoaded = true;
            }
        }
Exemplo n.º 12
0
        private void OnGUI()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
                return;
            }

            //Get current event
            Event e = ProcessEvents();

            if (isLoaded)
            {
                GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2)));
                GUILayout.BeginVertical();


                if (curWindow != null && curWindow.textureAtlas != null)
                {
                    //Export
                    GUILayout.BeginVertical();

                    DrawExportPresetMenu();
                    DrawExportAdvancedOptions();

                    GUILayout.BeginHorizontal(EditorStyles.helpBox);

                    switch (exportPreset)
                    {
                    case ExportPreset.Custom:
                        break;

                    case ExportPreset.Default:
                        modelFormat      = ModelFormat.Obj;
                        textureFormat    = TextureFormat.Png;
                        textureType      = TextureType.Default;
                        textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
                        break;

                    case ExportPreset.Sprites:
                        modelFormat      = ModelFormat.None;
                        textureFormat    = TextureFormat.Png;
                        textureType      = TextureType.SpriteSliced;
                        textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
                        break;

                    case ExportPreset.ReplaceObjMeshes:
                        modelFormat      = ModelFormat.ReplaceObj;
                        textureFormat    = TextureFormat.Png;
                        textureType      = TextureType.Default;
                        textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
                        break;

                    default:
                        break;
                    }

                    if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, modelFormat);
                        MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, textureFormat, textureType, textureScaleMode);
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
                else if (curWindow == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: Link with the Texture Atlas Editor lost!", EditorStyles.helpBox);
                    if (GUILayout.Button("Link Atlas Editor", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        curWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow <MA_TextureAtlasserProWindow>();
                    }
                    GUI.backgroundColor = Color.white;
                }
                else if (curWindow.textureAtlas == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: No Texture Atlas found make sure to open one!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            if (e.type == EventType.Repaint)
            {
                isLoaded = true;
            }
        }
        private void DrawExportMenu()
        {
            GUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Height(44));

            if (GUILayout.Button(MA_TextureAtlasserProIcons.createAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
            {
                MA_TextureAtlasserProCreateExportWindow.InitWindow(curWindow);
            }

            bool wasEnabled = GUI.enabled;

            if (curWindow.textureAtlas.exportSettings != null)
            {
                GUI.enabled = true;
            }
            else
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
            {
                bool export = false;

                if (curWindow.textureAtlas.exportSettings.modelExportSettings.modelFormat == ModelFormat.ReplaceMesh)
                {
                    if (EditorUtility.DisplayDialog("Replace original models?", "Are you sure you want to replace the original models, this can't be undone!", "Replace", "Cancel"))
                    {
                        export = true;
                    }
                }
                else
                {
                    export = true;
                }

                if (export)
                {
                    string[] textures = null;
                    string   material = null;
                    string[] models   = null;

                    if (curWindow.textureAtlas.exportSettings.exportTextures)
                    {
                        textures = MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.textureExportSettings);
                    }

                    if (curWindow.textureAtlas.exportSettings.exportMaterials)
                    {
                        material = MA_TextureAtlasserProUtils.ExportAtlasMaterial(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.materialExportSettings, textures: textures);
                    }

                    if (curWindow.textureAtlas.exportSettings.exportModels)
                    {
                        models = MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings, material: material);
                    }
                }
            }

            GUI.enabled = wasEnabled;

            GUILayout.EndHorizontal();
        }