Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity3D的UGUI,当pivot不是(0.5,0.5)时,使用focus不是预期的结果 #164

Open
magicedy opened this issue Mar 20, 2019 · 0 comments

Comments

@magicedy
Copy link

相关截图
image

image

描述问题bug
比如上面focus=[0,0]和focus=[0.5,0.5],当pivot不是(0.5,0.5)的时候,focus就不是预期想要的左上角focus=[0,0]点和图形中心点focus=[0.5,0.5]了

预期效果
下面是把Anchor修改成固定返回(0.5,0.5),感觉这样的结果才是正确的,望解答下疑问

image

相关代码
例如get_position里使用focus参数时,anchorPoint属性值会参与计算,当anchor不是0.5,0.5时,结果不符合预期

    def get_position(self, focus=None):
        focus = focus or self._focus or 'anchor'
        if focus == 'anchor':
            pos = self.attr('pos')
        elif focus == 'center':
            x, y = self.attr('pos')
            w, h = self.get_size()
            ap_x, ap_y = self.attr("anchorPoint")
            fx, fy = 0.5, 0.5
            pos = [x + w * (fx - ap_x), y + h * (fy - ap_y)]
        elif type(focus) in (list, tuple):
            x, y = self.attr('pos')
            w, h = self.get_size()
            ap_x, ap_y = self.attr("anchorPoint")
            fx, fy = focus
            pos = [x + w * (fx - ap_x), y + h * (fy - ap_y)]
        else:
            raise TypeError('Unsupported focus type {}. '
                            'Only "anchor/center" or 2-list/2-tuple available.'.format(type(focus)))
        return pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant