示例#1
0
    public void InputTransform()
    {
        Matrix4x4 parentMatrix = Matrix4x4.TRS(parent.position, parent.rotation, parent.lossyScale);
        int       childCount   = child.Length;

        for (int i = 0; i < childCount; ++i)
        {
            FlexibleTransform childFlexible  = GetChild(i);
            Transform         childTransform = childFlexible.transform;

            Matrix4x4 m = MatrixConversion.GetLocalMatrix(parentMatrix, childTransform.position, childTransform.rotation, childTransform.lossyScale);

            childFlexible.position = MatrixConversion.PositionFromMatrix(m);
            childFlexible.rotation = MatrixConversion.RotationFromMatrix(m);
            childFlexible.scale    = MatrixConversion.ScaleFromMatrix(m);
        }
    }
示例#2
0
    public void SyncTransform()
    {
        int       childCount   = child.Length;
        Matrix4x4 parentMatrix = Matrix4x4.TRS(parent.position, parent.rotation, parent.lossyScale);

        for (int i = 0; i < childCount; ++i)
        {
            FlexibleTransform childFlexible  = GetChild(i);
            Transform         childTransform = childFlexible.transform;

            Matrix4x4 m = MatrixConversion.GetWorldMatrix(parentMatrix, childFlexible.position, childFlexible.rotation, childFlexible.scale);

            childTransform.position = MatrixConversion.PositionFromMatrix(m);
            childTransform.rotation = MatrixConversion.RotationFromMatrix(m);
            Vector3 scale = MatrixConversion.ScaleFromMatrix(m);
            childTransform.localScale = childTransform.parent == null ?scale:new Vector3(scale.x * childTransform.localScale.x, scale.y * childTransform.localScale.y, scale.z * childTransform.localScale.z);
        }
    }