void UpdateTransformMatrix() { Matrix4x4 matrix = Matrix4x4.identity; if (_skew.x != 0 || _skew.y != 0) { ToolSet.SkewMatrix(ref matrix, _skew.x, _skew.y); } if (_perspective) { matrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(_rotation), Vector3.one); } Vector3 camPos = Vector3.zero; if (matrix.isIdentity) { _transformMatrix = null; } else { _transformMatrix = matrix; camPos = new Vector3(_pivot.x * _contentRect.width, -_pivot.y * _contentRect.height, _focalLength); } //组件的transformMatrix是通过paintingMode实现的,因为全部通过矩阵变换的话,和unity自身的变换混杂在一起,无力理清。 if (_transformMatrix != null) { if (this is Container) { this.EnterPaintingMode(4, null); } } else { if (this is Container) { this.LeavePaintingMode(4); } } if (this._paintingMode > 0) { this.paintingGraphics.cameraPosition = camPos; this.paintingGraphics.vertexMatrix = _transformMatrix; this._paintingFlag = 1; } else if (this.graphics != null) { this.graphics.cameraPosition = camPos; this.graphics.vertexMatrix = _transformMatrix; _requireUpdateMesh = true; } _outlineChanged = true; }