Example #1
0
        /// <summary>
        /// Uses <see cref="GUILayoutUtility.GetRect(float, float)"/> to get a <see cref="Rect"/> occupying a single
        /// standard line with the <see cref="StandardSpacing"/> added according to the specified `spacing`.
        /// </summary>
        public static Rect LayoutSingleLineRect(SpacingMode spacing = SpacingMode.None)
        {
            Rect rect;

            switch (spacing)
            {
            case SpacingMode.None:
                return(GUILayoutUtility.GetRect(0, LineHeight));

            case SpacingMode.Before:
                rect       = GUILayoutUtility.GetRect(0, LineHeight + StandardSpacing);
                rect.yMin += StandardSpacing;
                return(rect);

            case SpacingMode.After:
                rect       = GUILayoutUtility.GetRect(0, LineHeight + StandardSpacing);
                rect.yMax -= StandardSpacing;
                return(rect);

            case SpacingMode.BeforeAndAfter:
                rect       = GUILayoutUtility.GetRect(0, LineHeight + StandardSpacing * 2);
                rect.yMin += StandardSpacing;
                rect.yMax -= StandardSpacing;
                return(rect);

            default:
                throw new ArgumentException($"Unknown {nameof(StandardSpacing)}: " + spacing, nameof(spacing));
            }
        }
Example #2
0
        void LineTab()
        {
            _axis        = (Axis)EditorGUILayout.EnumPopup("Axis", _axis);
            _space       = (Space)EditorGUILayout.EnumPopup("Rotation Space", _space);
            _spacingMode = (SpacingMode)EditorGUILayout.EnumPopup("Spacing Mode", _spacingMode);

            if (_spacingMode == SpacingMode.FixedInterval)
            {
                _lineInterval = EditorGUILayout.FloatField("Interval", _lineInterval);
            }
            if (_spacingMode == SpacingMode.BoundsAndSpacing)
            {
                _lineSpacing = EditorGUILayout.FloatField("Spacing", _lineSpacing);
            }

            LayoutButton(LineLayout);
        }
        public void Update()
        {
            PathAttachment attachment = target.Attachment as PathAttachment;

            if (attachment == null)
            {
                return;
            }

            float rotateMix = this.rotateMix, translateMix = this.translateMix;
            bool  translate = translateMix > 0, rotate = rotateMix > 0;

            if (!translate && !rotate)
            {
                return;
            }

            PathConstraintData data = this.data;
            SpacingMode        spacingMode = data.spacingMode;
            bool       lengthSpacing = spacingMode == SpacingMode.Length;
            RotateMode rotateMode = data.rotateMode;
            bool       tangents = rotateMode == RotateMode.Tangent, scale = rotateMode == RotateMode.ChainScale;
            int        boneCount = this.bones.Count, spacesCount = tangents ? boneCount : boneCount + 1;

            Bone[] bonesItems = this.bones.Items;
            ExposedList <float> spaces = this.spaces.Resize(spacesCount), lengths = null;
            float spacing = this.spacing;

            if (scale || lengthSpacing)
            {
                if (scale)
                {
                    lengths = this.lengths.Resize(boneCount);
                }
                for (int i = 0, n = spacesCount - 1; i < n;)
                {
                    Bone  bone        = bonesItems[i];
                    float setupLength = bone.data.length;
                    if (setupLength == 0)
                    {
                        setupLength = 0.000000001f;
                    }
                    float x = setupLength * bone.a, y = setupLength * bone.c;
                    float length = (float)Math.Sqrt(x * x + y * y);
                    if (scale)
                    {
                        lengths.Items[i] = setupLength;
                    }
                    spaces.Items[++i] = (lengthSpacing ? Math.Max(0, setupLength + spacing) : spacing) * length / setupLength;
                }
            }
            else
            {
                for (int i = 1; i < spacesCount; i++)
                {
                    spaces.Items[i] = spacing;
                }
            }

            float[] positions = ComputeWorldPositions(attachment, spacesCount, tangents,
                                                      data.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent);
            float boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
            bool  tip;

            if (offsetRotation == 0)
            {
                tip = rotateMode == RotateMode.Chain;
            }
            else
            {
                tip = false;
                Bone p = target.bone;
                offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.DegRad : -MathUtils.DegRad;
            }
            for (int i = 0, p = 3; i < boneCount; i++, p += 3)
            {
                Bone bone = bonesItems[i];
                bone.worldX += (boneX - bone.worldX) * translateMix;
                bone.worldY += (boneY - bone.worldY) * translateMix;
                float x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
                if (scale)
                {
                    float length = lengths.Items[i];
                    if (length != 0)
                    {
                        float s = ((float)Math.Sqrt(dx * dx + dy * dy) / length - 1) * rotateMix + 1;
                        bone.a *= s;
                        bone.c *= s;
                    }
                }
                boneX = x;
                boneY = y;
                if (rotate)
                {
                    float a = bone.a, b = bone.b, c = bone.c, d = bone.d, r, cos, sin;
                    if (tangents)
                    {
                        r = positions[p - 1];
                    }
                    else if (spaces.Items[i + 1] == 0)
                    {
                        r = positions[p + 2];
                    }
                    else
                    {
                        r = MathUtils.Atan2(dy, dx);
                    }
                    r -= MathUtils.Atan2(c, a);
                    if (tip)
                    {
                        cos = MathUtils.Cos(r);
                        sin = MathUtils.Sin(r);
                        float length = bone.data.length;
                        boneX += (length * (cos * a - sin * c) - dx) * rotateMix;
                        boneY += (length * (sin * a + cos * c) - dy) * rotateMix;
                    }
                    else
                    {
                        r += offsetRotation;
                    }
                    if (r > MathUtils.PI)
                    {
                        r -= MathUtils.PI2;
                    }
                    else if (r < -MathUtils.PI)                     //
                    {
                        r += MathUtils.PI2;
                    }
                    r     *= rotateMix;
                    cos    = MathUtils.Cos(r);
                    sin    = MathUtils.Sin(r);
                    bone.a = cos * a - sin * c;
                    bone.b = cos * b - sin * d;
                    bone.c = sin * a + cos * c;
                    bone.d = sin * b + cos * d;
                }
                bone.appliedValid = false;
            }
        }
Example #4
0
 /// <summary>
 /// Construct a spacing configuration.
 /// </summary>
 /// <param name="mode">How to space this array.</param>
 /// <param name="value">The driving value of the array. (The meaning of this value depends on the choice of spacing mode.)</param>
 public SpacingConfiguration(SpacingMode mode, double value)
 {
     this.SpacingMode = mode;
     this.Value       = value;
 }
Example #5
0
        public void Update()
        {
            PathAttachment path = this.target.Attachment as PathAttachment;

            if (path != null)
            {
                float rotateMix    = this.rotateMix;
                float translateMix = this.translateMix;
                bool  flag         = translateMix > 0f;
                bool  flag2        = rotateMix > 0f;
                if (flag || flag2)
                {
                    bool flag6;
                    PathConstraintData data        = this.data;
                    SpacingMode        spacingMode = data.spacingMode;
                    bool                flag3      = spacingMode == SpacingMode.Length;
                    RotateMode          rotateMode = data.rotateMode;
                    bool                tangents   = rotateMode == RotateMode.Tangent;
                    bool                flag5      = rotateMode == RotateMode.ChainScale;
                    int                 count      = this.bones.Count;
                    int                 newSize    = !tangents ? (count + 1) : count;
                    Bone[]              items      = this.bones.Items;
                    ExposedList <float> list       = this.spaces.Resize(newSize);
                    ExposedList <float> list2      = null;
                    float               spacing    = this.spacing;
                    if (flag5 || flag3)
                    {
                        if (flag5)
                        {
                            list2 = this.lengths.Resize(count);
                        }
                        int num6 = 0;
                        int num7 = newSize - 1;
                        while (num6 < num7)
                        {
                            Bone  bone   = items[num6];
                            float length = bone.data.length;
                            if (length < 1E-05f)
                            {
                                if (flag5)
                                {
                                    list2.Items[num6] = 0f;
                                }
                                list.Items[++num6] = 0f;
                            }
                            else
                            {
                                float num9  = length * bone.a;
                                float num10 = length * bone.c;
                                float num11 = (float)Math.Sqrt((double)((num9 * num9) + (num10 * num10)));
                                if (flag5)
                                {
                                    list2.Items[num6] = num11;
                                }
                                list.Items[++num6] = ((!flag3 ? spacing : (length + spacing)) * num11) / length;
                            }
                        }
                    }
                    else
                    {
                        for (int j = 1; j < newSize; j++)
                        {
                            list.Items[j] = spacing;
                        }
                    }
                    float[] numArray       = this.ComputeWorldPositions(path, newSize, tangents, data.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent);
                    float   num13          = numArray[0];
                    float   num14          = numArray[1];
                    float   offsetRotation = data.offsetRotation;
                    if (offsetRotation == 0f)
                    {
                        flag6 = rotateMode == RotateMode.Chain;
                    }
                    else
                    {
                        flag6 = false;
                        Bone bone = this.target.bone;
                        offsetRotation *= (((bone.a * bone.d) - (bone.b * bone.c)) <= 0f) ? -0.01745329f : 0.01745329f;
                    }
                    int index = 0;
                    for (int i = 3; index < count; i += 3)
                    {
                        Bone bone3 = items[index];
                        bone3.worldX += (num13 - bone3.worldX) * translateMix;
                        bone3.worldY += (num14 - bone3.worldY) * translateMix;
                        float num18 = numArray[i];
                        float num19 = numArray[i + 1];
                        float x     = num18 - num13;
                        float y     = num19 - num14;
                        if (flag5)
                        {
                            float num22 = list2.Items[index];
                            if (num22 >= 1E-05f)
                            {
                                float num23 = (((((float)Math.Sqrt((double)((x * x) + (y * y)))) / num22) - 1f) * rotateMix) + 1f;
                                bone3.a *= num23;
                                bone3.c *= num23;
                            }
                        }
                        num13 = num18;
                        num14 = num19;
                        if (flag2)
                        {
                            float num28;
                            float num29;
                            float num30;
                            float a = bone3.a;
                            float b = bone3.b;
                            float c = bone3.c;
                            float d = bone3.d;
                            if (tangents)
                            {
                                num28 = numArray[i - 1];
                            }
                            else if (list.Items[index + 1] < 1E-05f)
                            {
                                num28 = numArray[i + 2];
                            }
                            else
                            {
                                num28 = MathUtils.Atan2(y, x);
                            }
                            num28 -= MathUtils.Atan2(c, a);
                            if (flag6)
                            {
                                num29 = MathUtils.Cos(num28);
                                num30 = MathUtils.Sin(num28);
                                float length = bone3.data.length;
                                num13 += ((length * ((num29 * a) - (num30 * c))) - x) * rotateMix;
                                num14 += ((length * ((num30 * a) + (num29 * c))) - y) * rotateMix;
                            }
                            else
                            {
                                num28 += offsetRotation;
                            }
                            if (num28 > 3.141593f)
                            {
                                num28 -= 6.283185f;
                            }
                            else if (num28 < -3.141593f)
                            {
                                num28 += 6.283185f;
                            }
                            num28  *= rotateMix;
                            num29   = MathUtils.Cos(num28);
                            num30   = MathUtils.Sin(num28);
                            bone3.a = (num29 * a) - (num30 * c);
                            bone3.b = (num29 * b) - (num30 * d);
                            bone3.c = (num30 * a) + (num29 * c);
                            bone3.d = (num30 * b) + (num29 * d);
                        }
                        bone3.appliedValid = false;
                        index++;
                    }
                }
            }
        }
Example #6
0
        public void Update()
        {
            PathAttachment pathAttachment = this.target.Attachment as PathAttachment;

            if (pathAttachment == null)
            {
                return;
            }
            float num   = this.rotateMix;
            float num2  = this.translateMix;
            bool  flag  = num2 > 0f;
            bool  flag2 = num > 0f;

            if (!flag && !flag2)
            {
                return;
            }
            PathConstraintData pathConstraintData = this.data;
            SpacingMode        spacingMode        = pathConstraintData.spacingMode;
            bool       flag3      = spacingMode == SpacingMode.Length;
            RotateMode rotateMode = pathConstraintData.rotateMode;
            bool       flag4      = rotateMode == RotateMode.Tangent;
            bool       flag5      = rotateMode == RotateMode.ChainScale;
            int        count      = this.bones.Count;
            int        num3       = (!flag4) ? (count + 1) : count;

            Bone[] items = this.bones.Items;
            ExposedList <float> exposedList  = this.spaces.Resize(num3);
            ExposedList <float> exposedList2 = null;
            float num4 = this.spacing;

            if (flag5 || flag3)
            {
                if (flag5)
                {
                    exposedList2 = this.lengths.Resize(count);
                }
                int i    = 0;
                int num5 = num3 - 1;
                while (i < num5)
                {
                    Bone  bone = items[i];
                    float num6 = bone.data.length;
                    float num7 = num6 * bone.a;
                    float num8 = num6 * bone.c;
                    num6 = (float)Math.Sqrt((double)(num7 * num7 + num8 * num8));
                    if (flag5)
                    {
                        exposedList2.Items[i] = num6;
                    }
                    exposedList.Items[++i] = ((!flag3) ? num4 : Math.Max(0f, num6 + num4));
                }
            }
            else
            {
                for (int j = 1; j < num3; j++)
                {
                    exposedList.Items[j] = num4;
                }
            }
            float[]  array          = this.ComputeWorldPositions(pathAttachment, num3, flag4, pathConstraintData.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent);
            Skeleton skeleton       = this.target.Skeleton;
            float    x              = skeleton.x;
            float    y              = skeleton.y;
            float    num9           = array[0];
            float    num10          = array[1];
            float    offsetRotation = pathConstraintData.offsetRotation;
            bool     flag6          = rotateMode == RotateMode.Chain && offsetRotation == 0f;
            int      k              = 0;
            int      num11          = 3;

            while (k < count)
            {
                Bone bone2 = items[k];
                bone2.worldX += (num9 - x - bone2.worldX) * num2;
                bone2.worldY += (num10 - y - bone2.worldY) * num2;
                float num12 = array[num11];
                float num13 = array[num11 + 1];
                float num14 = num12 - num9;
                float num15 = num13 - num10;
                if (flag5)
                {
                    float num16 = exposedList2.Items[k];
                    if (num16 != 0f)
                    {
                        float num17 = ((float)Math.Sqrt((double)(num14 * num14 + num15 * num15)) / num16 - 1f) * num + 1f;
                        bone2.a *= num17;
                        bone2.c *= num17;
                    }
                }
                num9  = num12;
                num10 = num13;
                if (flag2)
                {
                    float a = bone2.a;
                    float b = bone2.b;
                    float c = bone2.c;
                    float d = bone2.d;
                    float num18;
                    if (flag4)
                    {
                        num18 = array[num11 - 1];
                    }
                    else if (exposedList.Items[k + 1] == 0f)
                    {
                        num18 = array[num11 + 2];
                    }
                    else
                    {
                        num18 = MathUtils.Atan2(num15, num14);
                    }
                    num18 -= MathUtils.Atan2(c, a) - offsetRotation * 0.0174532924f;
                    float num19;
                    float num20;
                    if (flag6)
                    {
                        num19 = MathUtils.Cos(num18);
                        num20 = MathUtils.Sin(num18);
                        float length = bone2.data.length;
                        num9  += (length * (num19 * a - num20 * c) - num14) * num;
                        num10 += (length * (num20 * a + num19 * c) - num15) * num;
                    }
                    if (num18 > 3.14159274f)
                    {
                        num18 -= 6.28318548f;
                    }
                    else if (num18 < -3.14159274f)
                    {
                        num18 += 6.28318548f;
                    }
                    num18  *= num;
                    num19   = MathUtils.Cos(num18);
                    num20   = MathUtils.Sin(num18);
                    bone2.a = num19 * a - num20 * c;
                    bone2.b = num19 * b - num20 * d;
                    bone2.c = num20 * a + num19 * c;
                    bone2.d = num20 * b + num19 * d;
                }
                k++;
                num11 += 3;
            }
        }
Example #7
0
        public void Update()
        {
            PathAttachment pathAttachment = target.Attachment as PathAttachment;

            if (pathAttachment == null)
            {
                return;
            }
            float num   = rotateMix;
            float num2  = translateMix;
            bool  flag  = num2 > 0f;
            bool  flag2 = num > 0f;

            if (!flag && !flag2)
            {
                return;
            }
            PathConstraintData pathConstraintData = data;
            SpacingMode        spacingMode        = pathConstraintData.spacingMode;
            bool       flag3      = spacingMode == SpacingMode.Length;
            RotateMode rotateMode = pathConstraintData.rotateMode;
            bool       flag4      = rotateMode == RotateMode.Tangent;
            bool       flag5      = rotateMode == RotateMode.ChainScale;
            int        count      = bones.Count;
            int        num3       = (!flag4) ? (count + 1) : count;

            Bone[] items = bones.Items;
            ExposedList <float> exposedList  = spaces.Resize(num3);
            ExposedList <float> exposedList2 = null;
            float num4 = spacing;

            if (flag5 || flag3)
            {
                if (flag5)
                {
                    exposedList2 = lengths.Resize(count);
                }
                int num5 = 0;
                int num6 = num3 - 1;
                while (num5 < num6)
                {
                    Bone  bone = items[num5];
                    float num7 = bone.data.length;
                    if (num7 == 0f)
                    {
                        num7 = 1E-09f;
                    }
                    float num8  = num7 * bone.a;
                    float num9  = num7 * bone.c;
                    float num10 = (float)Math.Sqrt(num8 * num8 + num9 * num9);
                    if (flag5)
                    {
                        exposedList2.Items[num5] = num7;
                    }
                    exposedList.Items[++num5] = ((!flag3) ? num4 : Math.Max(0f, num7 + num4)) * num10 / num7;
                }
            }
            else
            {
                for (int i = 1; i < num3; i++)
                {
                    exposedList.Items[i] = num4;
                }
            }
            float[] array = ComputeWorldPositions(pathAttachment, num3, flag4, pathConstraintData.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent);
            float   num11 = array[0];
            float   num12 = array[1];
            float   num13 = pathConstraintData.offsetRotation;
            bool    flag6;

            if (num13 == 0f)
            {
                flag6 = (rotateMode == RotateMode.Chain);
            }
            else
            {
                flag6 = false;
                Bone bone2 = target.bone;
                num13 *= ((!(bone2.a * bone2.d - bone2.b * bone2.c > 0f)) ? (-(float)Math.PI / 180f) : ((float)Math.PI / 180f));
            }
            int num14 = 0;
            int num15 = 3;

            while (num14 < count)
            {
                Bone bone3 = items[num14];
                bone3.worldX += (num11 - bone3.worldX) * num2;
                bone3.worldY += (num12 - bone3.worldY) * num2;
                float num16 = array[num15];
                float num17 = array[num15 + 1];
                float num18 = num16 - num11;
                float num19 = num17 - num12;
                if (flag5)
                {
                    float num20 = exposedList2.Items[num14];
                    if (num20 != 0f)
                    {
                        float num21 = ((float)Math.Sqrt(num18 * num18 + num19 * num19) / num20 - 1f) * num + 1f;
                        bone3.a *= num21;
                        bone3.c *= num21;
                    }
                }
                num11 = num16;
                num12 = num17;
                if (flag2)
                {
                    float a     = bone3.a;
                    float b     = bone3.b;
                    float c     = bone3.c;
                    float d     = bone3.d;
                    float num22 = flag4 ? array[num15 - 1] : ((exposedList.Items[num14 + 1] != 0f) ? MathUtils.Atan2(num19, num18) : array[num15 + 2]);
                    num22 -= MathUtils.Atan2(c, a);
                    float num23;
                    float num24;
                    if (flag6)
                    {
                        num23 = MathUtils.Cos(num22);
                        num24 = MathUtils.Sin(num22);
                        float length = bone3.data.length;
                        num11 += (length * (num23 * a - num24 * c) - num18) * num;
                        num12 += (length * (num24 * a + num23 * c) - num19) * num;
                    }
                    else
                    {
                        num22 += num13;
                    }
                    if (num22 > (float)Math.PI)
                    {
                        num22 -= (float)Math.PI * 2f;
                    }
                    else if (num22 < -(float)Math.PI)
                    {
                        num22 += (float)Math.PI * 2f;
                    }
                    num22  *= num;
                    num23   = MathUtils.Cos(num22);
                    num24   = MathUtils.Sin(num22);
                    bone3.a = num23 * a - num24 * c;
                    bone3.b = num23 * b - num24 * d;
                    bone3.c = num24 * a + num23 * c;
                    bone3.d = num24 * b + num23 * d;
                }
                bone3.appliedValid = false;
                num14++;
                num15 += 3;
            }
        }