Пример #1
0
        private static Vector2 ApplySpriteAlignmentToPivot(Vector2 pivot, Rect rect, SpriteAlignment alignment)
        {
            Vector2 result;

            if (alignment != SpriteAlignment.Custom)
            {
                Vector2[] snapPointsArray = SpriteFrameModuleBase.GetSnapPointsArray(rect);
                Vector2   texturePos      = snapPointsArray[(int)alignment];
                result = SpriteFrameModuleBase.ConvertFromTextureToNormalizedSpace(texturePos, rect);
            }
            else
            {
                result = pivot;
            }
            return(result);
        }
Пример #2
0
        protected void SnapPivot(Vector2 pivot, out Vector2 outPivot, out SpriteAlignment outAlignment)
        {
            Rect    selectedSpriteRect = this.selectedSpriteRect;
            Vector2 a = new Vector2(selectedSpriteRect.xMin + selectedSpriteRect.width * pivot.x, selectedSpriteRect.yMin + selectedSpriteRect.height * pivot.y);

            Vector2[]       snapPointsArray = SpriteFrameModuleBase.GetSnapPointsArray(selectedSpriteRect);
            SpriteAlignment spriteAlignment = SpriteAlignment.Custom;
            float           num             = 3.40282347E+38f;

            for (int i = 0; i < snapPointsArray.Length; i++)
            {
                float num2 = (a - snapPointsArray[i]).magnitude * this.m_Zoom;
                if (num2 < num)
                {
                    spriteAlignment = (SpriteAlignment)i;
                    num             = num2;
                }
            }
            outAlignment = spriteAlignment;
            outPivot     = SpriteFrameModuleBase.ConvertFromTextureToNormalizedSpace(snapPointsArray[(int)spriteAlignment], selectedSpriteRect);
        }