コード例 #1
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"
                           );
             }
         }
     }
 }
コード例 #2
0
        IFixedRectConstraintValueData CreateFixedConstraintValueData(
            FixedRectValueType valuType,
            RectTransform referenceRect,
            Vector2 constraintValue
            )
        {
            IFixedRectConstraintValueData result;

            switch (valuType)
            {
            case FixedRectValueType.ConstantValue:
                result = new ConstantFixedRectConstraintValueData(
                    constraintValue
                    );
                break;

            case FixedRectValueType.ReferenceRect:
                result = new ReferenceFixedRectConstraintValueData(
                    referenceRect.sizeDelta,
                    constraintValue
                    );
                break;

            case FixedRectValueType.RelativeToScreen:
                result = new RelativeToScreenRectConstraintValueData(
                    constraintValue
                    );
                break;

            default:
                throw new System.InvalidOperationException(
                          "cannot be anything other than above"
                          );
            }
            return(result);
        }
コード例 #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);
        }