FxSprite Select(Rect rect, FxAtlas atlas)
        {
            var evt = Event.current;

            if (evt.type == EventType.MouseUp)
            {
                var norCenterPos = Rect.PointToNormalized(rect, evt.mousePosition);

                if (!new Rect(0, 0, 1, 1).Contains(norCenterPos))
                {
                    return(default);
        public static bool SaveAtlas(FxAtlasAssembler assembler)
        {
            if (!assembler)
            {
                return(false);
            }

            string    atlasAssetPath;
            string    atlasTexturePath;
            FxAtlas   atlasAsset = assembler.AtlasAsset;
            Texture2D atlasTexture;

            //没有atlas的时候,新建一个
            if (atlasAsset == null)
            {
                atlasAssetPath = EditorUtility.SaveFilePanel("Save", "Assets", "atlas.asset", "asset");
                if (string.IsNullOrEmpty(atlasAssetPath))
                {
                    return(false);
                }
                else if (atlasAssetPath.EndsWith(".asset") == false)
                {
                    Debug.LogError("must has .asset extension");
                    return(false);
                }

                atlasAssetPath = FileUtil.GetProjectRelativePath(atlasAssetPath);

                atlasAsset = ScriptableObject.CreateInstance <FxAtlas>();
                AssetDatabase.CreateAsset(atlasAsset, atlasAssetPath);
                AssetDatabase.ImportAsset(atlasAssetPath, ImportAssetOptions.ForceUpdate);
                atlasAsset = AssetDatabase.LoadAssetAtPath <FxAtlas>(atlasAssetPath);
            }
            else
            {
                //得到当前atlas的路径
                atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
            }

            atlasTexturePath = atlasAssetPath.Replace(".asset", ".png");

            atlasTexture = GeneratePackedTexture(assembler);

            SavePackedTexture(atlasTexturePath, ref atlasTexture);

            Undo.RecordObjects(new Object[] { assembler, atlasAsset }, "Save Atlas");
            EditorUtility.SetDirty(assembler);
            EditorUtility.SetDirty(atlasAsset);

            atlasAsset.AtlasTexture = atlasTexture;

            var sprites = new FxSprite[assembler.Sprites.Length];

            for (int i = 0; i < assembler.Sprites.Length; i++)
            {
                sprites[i] = new FxSprite()
                {
                    id          = assembler.Sprites[i].ID,
                    name        = assembler.Sprites[i].IdentityName,
                    scaleOffset = assembler.Sprites[i].GetUVRect(assembler.AtlasWidth, assembler.AtlasHeight)
                };
            }

            atlasAsset.Sprites = sprites;

            assembler.AtlasAsset = atlasAsset;

            return(true);
        }