예제 #1
0
 protected bool ConstraintIsFixedType(RectConstraintType type)
 {
     return
         (type == RectConstraintType.FixedGroupLength ||
          type == RectConstraintType.FixedElementLength ||
          type == RectConstraintType.FixedPadding
         );
 }
예제 #2
0
 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"
                           );
             }
         }
     }
 }
예제 #3
0
        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);
        }