protected bool ConstraintIsFixedType(RectConstraintType type) { return (type == RectConstraintType.FixedGroupLength || type == RectConstraintType.FixedElementLength || type == RectConstraintType.FixedPadding ); }
void MakeSureEachConstraintsAreProperlySet( RectConstraintType constraintType, FixedRectValueType fixedRectConstraintValueType, RectTransform referenceRect ) { if ( constraintType == RectConstraintType.FixedGroupLength || constraintType == RectConstraintType.FixedElementLength || constraintType == RectConstraintType.FixedPadding ) { if (fixedRectConstraintValueType == FixedRectValueType.ReferenceRect) { if (referenceRect == null) { throw new System.InvalidOperationException( "Reference rectTransform must be set" ); } } } }
IRectConstraint CreateRectConstraint( RectConstraintType constraintType, FixedRectValueType fixedValueType, RectTransform referenceRect, Vector2 constraintValue ) { IRectConstraint rectConstraint; if (ConstraintIsFixedType(constraintType)) { IFixedRectConstraintValueData fixedConstraintValueData = CreateFixedConstraintValueData( fixedValueType, referenceRect, constraintValue ); switch (constraintType) { case RectConstraintType.FixedGroupLength: rectConstraint = new FixedGroupLengthConstraint( fixedConstraintValueData ); break; case RectConstraintType.FixedElementLength: rectConstraint = new FixedElementLengthConstraint( fixedConstraintValueData ); break; case RectConstraintType.FixedPadding: rectConstraint = new FixedPaddingConstraint( fixedConstraintValueData ); break; default: throw new System.InvalidOperationException( "fixed constraint must be one of the three" ); } } else // first constraint is ratio { switch (constraintType) { case RectConstraintType.GroupToElementRatio: rectConstraint = new GroupToElementRatioRectConstraint( constraintValue ); break; case RectConstraintType.ElementToPaddingRatio: rectConstraint = new ElementToPaddingRatioRectConstraint( constraintValue ); break; case RectConstraintType.GroupToPaddingRatio: rectConstraint = new GroupToPaddingRatioRectConstraint( constraintValue ); break; default: throw new System.InvalidOperationException( "ratio constraint must be one of three" ); } } return(rectConstraint); }