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);
        }
Esempio n. 2
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();
                        }
                    }
                }
            }
        }