用像素设置精灵的大小

我对C#还是比较陌生,但是我了解大多数基本知识。我知道这个问题已经问过很多次了,经过近两个小时的搜索,我似乎仍然找不到有效的答案,因此请耐心等待。

我正在为iOS创建2D Unity游戏,我需要能够获取屏幕尺寸,(我知道如何做到这一点,它是Screen.width / Screen.height),然后设置精灵的大小。我正在尝试在屏幕上获取7个精灵(沿宽度方向),但我需要通过设备进行调整。硬编码数字在这里不起作用。因此,要实现这一点,我需要一种按像素缩放的方法,我不确定该怎么做,或者不确定是否可以使用Unity。如果还有其他方法,请告诉我。

(是的,我已经尝试过使用Rect和RectTransform,它可能无法满足我的需要,或者我使用的是错误的。可能是。)

renbogoushi 回答:用像素设置精灵的大小

我弄清楚了,我不得不使用确定屏幕宽度的数学函数组合,我必须从那里完善一些数字。

以下是有效方法的一般概念:

override func touchesMoved(_ touches: Set<UITouch>,with event: UIEvent?) {
    if let touch = touches.first {
        let location = touch.location(in: timeCircle)
        let extraGrip: CGFloat = -25.0
        if let last = lastLocation,location.x > extraGrip,location.y > extraGrip {
            let rad = radiansBetweenPoint(location,last)
            let value = (CGFloat(rad)/CGFloat.pi)*180
            let currentAngle: CGFloat = ((radiansBetweenPoint(lineCenter,linePoint!)/CGFloat.pi)*180.0)-90.0
            let newValue = value+currentAngle+180.0
            var index: CGFloat = (newValue/360.0)*12
            if roundf(Float(index)) <= 0 {
                index += 12
            }

            //skip 2 o clock
            if roundf(Float(index)) == 2 {
                index += 1

            }

            setLineToPoint(pointForArcByIndex(index: index))
            setTimeFromIndex(index)
            lastIndex = index
        }
    }
}
本文链接:https://www.f2er.com/3091829.html

大家都在问