我在另一个脚本中的布尔值不会更改状态

时间:2018-11-24 20:45:04

标签: c# unity3d boolean

感谢您阅读本文。我很困惑,为什么由于某种原因,这段代码不会在产生激光时将实时回合设置为true,而是将产生源设置为正确的游戏对象,并将其与父对象分离,否则任何人都会得到任何东西?在您问之前,不,除非我销毁激光器本身,否则我不会在任何地方将live round设置为false。 谢谢您的帮助!

from PyQt5 import QtCore, QtGui, QtWidgets

class CallbackEllipse(QtWidgets.QGraphicsEllipseItem):
    def __init__(self, light, *args, **kwargs):
        super(CallbackEllipse, self).__init__(*args, **kwargs)
        self._fill_brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        self._percentage = 0
        self._light = light

    def setFillBrush(self, brush):
        self._fill_brush = brush
        self.update()

    def fillBrush(self):
        return self._fill_brush

    def setPercentage(self, percentage):
        self._percentage = percentage
        self.update()

    def percentage(self):
        return self._percentage

    def paint(self, painter, option, widget=None):
        painter.setPen(self.pen())
        r_in = QtCore.QRectF(QtCore.QPointF(), self.rect().size())
        r_out = QtCore.QRectF(r_in)
        r_out.setTop((1-self.percentage())*r_in.height())

        p1 = QtGui.QPixmap(r_in.size().toSize())
        p1.fill(QtCore.Qt.transparent)
        p_1 = QtGui.QPainter(p1)
        p_1.setRenderHints(painter.renderHints())
        p_1.fillRect(r_out, self.fillBrush())
        p_1.end()

        p2 = QtGui.QPixmap(r_in.size().toSize())
        p2.fill(QtCore.Qt.transparent)
        p_2 = QtGui.QPainter(p2)
        p_2.setRenderHints(painter.renderHints())
        p_2.setPen(painter.pen())
        p_2.setBrush(self.brush())
        p_2.drawEllipse(r_in)
        p_2.end()

        pixmap = QtGui.QPixmap(r_in.size().toSize())
        pixmap.fill(QtCore.Qt.transparent)
        p = QtGui.QPainter(pixmap)
        p.setRenderHints(painter.renderHints())
        p.drawPixmap(QtCore.QPointF(), p1)
        p.setCompositionMode(QtGui.QPainter.CompositionMode_DestinationAtop)
        p.drawPixmap(QtCore.QPointF(), p2)
        p.end()

        painter.drawPixmap(option.rect.topLeft(), pixmap)
        painter.setPen(self.pen())
        painter.drawEllipse(option.rect)

class GraphicsView(QtWidgets.QGraphicsView):
    def __init__(self, parent=None):
        super(GraphicsView, self).__init__(parent)
        self.setScene(QtWidgets.QGraphicsScene(self))
        self.setRenderHints(self.renderHints() | QtGui.QPainter.Antialiasing)
        light = {"status": True, "name": "myname"}
        it = CallbackEllipse(light, 100, 100, 100, 100)
        it.setPercentage(0.4)
        it.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.lightGray).darker(150)))
        it.setBrush(QtGui.QBrush(QtGui.QColor(QtCore.Qt.white)))
        it.setFillBrush(QtGui.QBrush(QtGui.QColor("#4471C4")))
        self.scene().addItem(it)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = GraphicsView()
    w.resize(640, 480)
    w.show()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:0)

如果您确定没有更改代码中的变量,我认为这里的问题是您得到的组件spawnOrigin不正确。只需检查spawnOrigin是要通过Debug.Log获取的正确组件,或在Visual Studio中设置断点即可。