コード例 #1
0
        /// <summary>
        /// Gets a point in <paramref name="rint"/> using <paramref name="sortType"/>
        /// </summary>
        /// <param name="rint">The <see cref="RectInt"/> to get the point from.</param>
        /// <param name="sortType">The <see cref="AtlasItemSortType"/> used to get the point.</param>
        /// <returns></returns>
        public static Vector2Int GetPointInRint(this RectInt rint, AtlasItemSortType sortType)
        {
            int rintPointX = (sortType == AtlasItemSortType.ByXAndHeight || sortType == AtlasItemSortType.ByXAndY) ? rint.x : rint.x + rint.width;
            int rintPointY = (sortType == AtlasItemSortType.ByWidthAndY || sortType == AtlasItemSortType.ByXAndY) ? rint.y : rint.y + rint.height;

            return(new Vector2Int(rintPointX, rintPointY));
        }
コード例 #2
0
        /// <summary>
        /// Gets the pixel regions of <paramref name="atlas"/> and sorts them using <paramref name="sortType"/>.
        /// </summary>
        /// <param name="atlas">The <see cref="dfAtlas"/> to get the pixel regions from.</param>
        /// <param name="sortType">The <see cref="AtlasItemSortType"/> used to sort the list of pixel regions.</param>
        /// <returns>A list with all pixel regions in <paramref name="atlas"/> that is sorted using <paramref name="sortType"/></returns>
        public static List <RectInt> GetSortedPixelRegions(this dfAtlas atlas, AtlasItemSortType sortType)
        {
            List <RectInt> rawList    = atlas.GetPixelRegions();
            List <RectInt> sortedList = new List <RectInt>();

            while (sortedList.Count < rawList.Count)
            {
                RectInt rint             = new RectInt(0, 0, 0, 0);
                bool    rintIsUnassigned = true;
                for (int i = 0; i < rawList.Count; i++)
                {
                    if (!sortedList.Contains(rawList[i]))
                    {
                        if (rintIsUnassigned)
                        {
                            rint             = rawList[i];
                            rintIsUnassigned = false;
                        }
                        else
                        {
                            rint = ((rint.GetPointInRint(sortType).x >= rawList[i].GetPointInRint(sortType).x&& rint.GetPointInRint(sortType).y >= rawList[i].GetPointInRint(sortType).y) ? rawList[i] : rint);
                        }
                    }
                }
                sortedList.Add(rint);
            }
            return(sortedList);
        }