首页 > 代码库 > Unity 源码(伪)
Unity 源码(伪)
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A:
B:
C:
D:
E:
F:
G:
H:
I:
J:
K:
L:
M:
1 using System; 2 using System.Runtime.CompilerServices; 3 using UnityEngine.Internal; 4 using UnityEngine.Scripting; 5 using UnityEngineInternal; 6 7 namespace UnityEngine 8 { 9 /// <summary> 10 /// <para>A collection of common math functions.</para> 11 /// </summary> 12 public struct Mathf 13 { 14 /// <summary> 15 /// <para>The infamous 3.14159265358979... value (Read Only).</para> 16 /// </summary> 17 public const float PI = 3.14159274f; 18 19 /// <summary> 20 /// <para>A representation of positive infinity (Read Only).</para> 21 /// </summary> 22 public const float Infinity = float.PositiveInfinity; 23 24 /// <summary> 25 /// <para>A representation of negative infinity (Read Only).</para> 26 /// </summary> 27 public const float NegativeInfinity = float.NegativeInfinity; 28 29 /// <summary> 30 /// <para>Degrees-to-radians conversion constant (Read Only).</para> 31 /// </summary> 32 public const float Deg2Rad = 0.0174532924f; 33 34 /// <summary> 35 /// <para>Radians-to-degrees conversion constant (Read Only).</para> 36 /// </summary> 37 public const float Rad2Deg = 57.29578f; 38 39 /// <summary> 40 /// <para>A tiny floating point value (Read Only).</para> 41 /// </summary> 42 public static readonly float Epsilon = (!MathfInternal.IsFlushToZeroEnabled) ? MathfInternal.FloatMinDenormal : MathfInternal.FloatMinNormal; 43 44 /// <summary> 45 /// <para>Returns the closest power of two value.</para> 46 /// </summary> 47 /// <param name="value"></param> 48 [GeneratedByOldBindingsGenerator, ThreadAndSerializationSafe] 49 [MethodImpl(MethodImplOptions.InternalCall)] 50 public static extern int ClosestPowerOfTwo(int value); 51 52 /// <summary> 53 /// <para>Converts the given value from gamma (sRGB) to linear color space.</para> 54 /// </summary> 55 /// <param name="value"></param> 56 [GeneratedByOldBindingsGenerator] 57 [MethodImpl(MethodImplOptions.InternalCall)] 58 public static extern float GammaToLinearSpace(float value); 59 60 /// <summary> 61 /// <para>Converts the given value from linear to gamma (sRGB) color space.</para> 62 /// </summary> 63 /// <param name="value"></param> 64 [GeneratedByOldBindingsGenerator] 65 [MethodImpl(MethodImplOptions.InternalCall)] 66 public static extern float LinearToGammaSpace(float value); 67 68 /// <summary> 69 /// <para>Convert a color temperature in Kelvin to RGB color.</para> 70 /// </summary> 71 /// <param name="kelvin">Temperature in Kelvin. Range 1000 to 40000 Kelvin.</param> 72 /// <returns> 73 /// <para>Correlated Color Temperature as floating point RGB color.</para> 74 /// </returns> 75 public static Color CorrelatedColorTemperatureToRGB(float kelvin) 76 { 77 Color result; 78 Mathf.INTERNAL_CALL_CorrelatedColorTemperatureToRGB(kelvin, out result); 79 return result; 80 } 81 82 [GeneratedByOldBindingsGenerator] 83 [MethodImpl(MethodImplOptions.InternalCall)] 84 private static extern void INTERNAL_CALL_CorrelatedColorTemperatureToRGB(float kelvin, out Color value); 85 86 /// <summary> 87 /// <para>Returns true if the value is power of two.</para> 88 /// </summary> 89 /// <param name="value"></param> 90 [GeneratedByOldBindingsGenerator] 91 [MethodImpl(MethodImplOptions.InternalCall)] 92 public static extern bool IsPowerOfTwo(int value); 93 94 /// <summary> 95 /// <para>Returns the next power of two value.</para> 96 /// </summary> 97 /// <param name="value"></param> 98 [GeneratedByOldBindingsGenerator] 99 [MethodImpl(MethodImplOptions.InternalCall)] 100 public static extern int NextPowerOfTwo(int value); 101 102 /// <summary> 103 /// <para>Generate 2D Perlin noise.</para> 104 /// </summary> 105 /// <param name="x">X-coordinate of sample point.</param> 106 /// <param name="y">Y-coordinate of sample point.</param> 107 /// <returns> 108 /// <para>Value between 0.0 and 1.0.</para> 109 /// </returns> 110 [GeneratedByOldBindingsGenerator] 111 [MethodImpl(MethodImplOptions.InternalCall)] 112 public static extern float PerlinNoise(float x, float y); 113 114 [GeneratedByOldBindingsGenerator] 115 [MethodImpl(MethodImplOptions.InternalCall)] 116 public static extern ushort FloatToHalf(float val); 117 118 [GeneratedByOldBindingsGenerator] 119 [MethodImpl(MethodImplOptions.InternalCall)] 120 public static extern float HalfToFloat(ushort val); 121 122 /// <summary> 123 /// <para>Returns the sine of angle f in radians.</para> 124 /// </summary> 125 /// <param name="f">The argument as a radian.</param> 126 /// <returns> 127 /// <para>The return value between -1 and +1.</para> 128 /// </returns> 129 public static float Sin(float f) 130 { 131 return (float)Math.Sin((double)f); 132 } 133 134 /// <summary> 135 /// <para>Returns the cosine of angle f in radians.</para> 136 /// </summary> 137 /// <param name="f"></param> 138 public static float Cos(float f) 139 { 140 return (float)Math.Cos((double)f); 141 } 142 143 /// <summary> 144 /// <para>Returns the tangent of angle f in radians.</para> 145 /// </summary> 146 /// <param name="f"></param> 147 public static float Tan(float f) 148 { 149 return (float)Math.Tan((double)f); 150 } 151 152 /// <summary> 153 /// <para>Returns the arc-sine of f - the angle in radians whose sine is f.</para> 154 /// </summary> 155 /// <param name="f"></param> 156 public static float Asin(float f) 157 { 158 return (float)Math.Asin((double)f); 159 } 160 161 /// <summary> 162 /// <para>Returns the arc-cosine of f - the angle in radians whose cosine is f.</para> 163 /// </summary> 164 /// <param name="f"></param> 165 public static float Acos(float f) 166 { 167 return (float)Math.Acos((double)f); 168 } 169 170 /// <summary> 171 /// <para>Returns the arc-tangent of f - the angle in radians whose tangent is f.</para> 172 /// </summary> 173 /// <param name="f"></param> 174 public static float Atan(float f) 175 { 176 return (float)Math.Atan((double)f); 177 } 178 179 /// <summary> 180 /// <para>Returns the angle in radians whose Tan is y/x.</para> 181 /// </summary> 182 /// <param name="y"></param> 183 /// <param name="x"></param> 184 public static float Atan2(float y, float x) 185 { 186 return (float)Math.Atan2((double)y, (double)x); 187 } 188 189 /// <summary> 190 /// <para>Returns square root of f.</para> 191 /// </summary> 192 /// <param name="f"></param> 193 public static float Sqrt(float f) 194 { 195 return (float)Math.Sqrt((double)f); 196 } 197 198 /// <summary> 199 /// <para>Returns the absolute value of f.</para> 200 /// </summary> 201 /// <param name="f"></param> 202 public static float Abs(float f) 203 { 204 return Math.Abs(f); 205 } 206 207 /// <summary> 208 /// <para>Returns the absolute value of value.</para> 209 /// </summary> 210 /// <param name="value"></param> 211 public static int Abs(int value) 212 { 213 return Math.Abs(value); 214 } 215 216 /// <summary> 217 /// <para>Returns the smallest of two or more values.</para> 218 /// </summary> 219 /// <param name="a"></param> 220 /// <param name="b"></param> 221 /// <param name="values"></param> 222 public static float Min(float a, float b) 223 { 224 return (a >= b) ? b : a; 225 } 226 227 /// <summary> 228 /// <para>Returns the smallest of two or more values.</para> 229 /// </summary> 230 /// <param name="a"></param> 231 /// <param name="b"></param> 232 /// <param name="values"></param> 233 public static float Min(params float[] values) 234 { 235 int num = values.Length; 236 float result; 237 if (num == 0) 238 { 239 result = 0f; 240 } 241 else 242 { 243 float num2 = values[0]; 244 for (int i = 1; i < num; i++) 245 { 246 if (values[i] < num2) 247 { 248 num2 = values[i]; 249 } 250 } 251 result = num2; 252 } 253 return result; 254 } 255 256 /// <summary> 257 /// <para>Returns the smallest of two or more values.</para> 258 /// </summary> 259 /// <param name="a"></param> 260 /// <param name="b"></param> 261 /// <param name="values"></param> 262 public static int Min(int a, int b) 263 { 264 return (a >= b) ? b : a; 265 } 266 267 /// <summary> 268 /// <para>Returns the smallest of two or more values.</para> 269 /// </summary> 270 /// <param name="a"></param> 271 /// <param name="b"></param> 272 /// <param name="values"></param> 273 public static int Min(params int[] values) 274 { 275 int num = values.Length; 276 int result; 277 if (num == 0) 278 { 279 result = 0; 280 } 281 else 282 { 283 int num2 = values[0]; 284 for (int i = 1; i < num; i++) 285 { 286 if (values[i] < num2) 287 { 288 num2 = values[i]; 289 } 290 } 291 result = num2; 292 } 293 return result; 294 } 295 296 /// <summary> 297 /// <para>Returns largest of two or more values.</para> 298 /// </summary> 299 /// <param name="a"></param> 300 /// <param name="b"></param> 301 /// <param name="values"></param> 302 public static float Max(float a, float b) 303 { 304 return (a <= b) ? b : a; 305 } 306 307 /// <summary> 308 /// <para>Returns largest of two or more values.</para> 309 /// </summary> 310 /// <param name="a"></param> 311 /// <param name="b"></param> 312 /// <param name="values"></param> 313 public static float Max(params float[] values) 314 { 315 int num = values.Length; 316 float result; 317 if (num == 0) 318 { 319 result = 0f; 320 } 321 else 322 { 323 float num2 = values[0]; 324 for (int i = 1; i < num; i++) 325 { 326 if (values[i] > num2) 327 { 328 num2 = values[i]; 329 } 330 } 331 result = num2; 332 } 333 return result; 334 } 335 336 /// <summary> 337 /// <para>Returns the largest of two or more values.</para> 338 /// </summary> 339 /// <param name="a"></param> 340 /// <param name="b"></param> 341 /// <param name="values"></param> 342 public static int Max(int a, int b) 343 { 344 return (a <= b) ? b : a; 345 } 346 347 /// <summary> 348 /// <para>Returns the largest of two or more values.</para> 349 /// </summary> 350 /// <param name="a"></param> 351 /// <param name="b"></param> 352 /// <param name="values"></param> 353 public static int Max(params int[] values) 354 { 355 int num = values.Length; 356 int result; 357 if (num == 0) 358 { 359 result = 0; 360 } 361 else 362 { 363 int num2 = values[0]; 364 for (int i = 1; i < num; i++) 365 { 366 if (values[i] > num2) 367 { 368 num2 = values[i]; 369 } 370 } 371 result = num2; 372 } 373 return result; 374 } 375 376 /// <summary> 377 /// <para>Returns f raised to power p.</para> 378 /// </summary> 379 /// <param name="f"></param> 380 /// <param name="p"></param> 381 public static float Pow(float f, float p) 382 { 383 return (float)Math.Pow((double)f, (double)p); 384 } 385 386 /// <summary> 387 /// <para>Returns e raised to the specified power.</para> 388 /// </summary> 389 /// <param name="power"></param> 390 public static float Exp(float power) 391 { 392 return (float)Math.Exp((double)power); 393 } 394 395 /// <summary> 396 /// <para>Returns the logarithm of a specified number in a specified base.</para> 397 /// </summary> 398 /// <param name="f"></param> 399 /// <param name="p"></param> 400 public static float Log(float f, float p) 401 { 402 return (float)Math.Log((double)f, (double)p); 403 } 404 405 /// <summary> 406 /// <para>Returns the natural (base e) logarithm of a specified number.</para> 407 /// </summary> 408 /// <param name="f"></param> 409 public static float Log(float f) 410 { 411 return (float)Math.Log((double)f); 412 } 413 414 /// <summary> 415 /// <para>Returns the base 10 logarithm of a specified number.</para> 416 /// </summary> 417 /// <param name="f"></param> 418 public static float Log10(float f) 419 { 420 return (float)Math.Log10((double)f); 421 } 422 423 /// <summary> 424 /// <para>Returns the smallest integer greater to or equal to f.</para> 425 /// </summary> 426 /// <param name="f"></param> 427 public static float Ceil(float f) 428 { 429 return (float)Math.Ceiling((double)f); 430 } 431 432 /// <summary> 433 /// <para>Returns the largest integer smaller to or equal to f.</para> 434 /// </summary> 435 /// <param name="f"></param> 436 public static float Floor(float f) 437 { 438 return (float)Math.Floor((double)f); 439 } 440 441 /// <summary> 442 /// <para>Returns f rounded to the nearest integer.</para> 443 /// </summary> 444 /// <param name="f"></param> 445 public static float Round(float f) 446 { 447 return (float)Math.Round((double)f); 448 } 449 450 /// <summary> 451 /// <para>Returns the smallest integer greater to or equal to f.</para> 452 /// </summary> 453 /// <param name="f"></param> 454 public static int CeilToInt(float f) 455 { 456 return (int)Math.Ceiling((double)f); 457 } 458 459 /// <summary> 460 /// <para>Returns the largest integer smaller to or equal to f.</para> 461 /// </summary> 462 /// <param name="f"></param> 463 public static int FloorToInt(float f) 464 { 465 return (int)Math.Floor((double)f); 466 } 467 468 /// <summary> 469 /// <para>Returns f rounded to the nearest integer.</para> 470 /// </summary> 471 /// <param name="f"></param> 472 public static int RoundToInt(float f) 473 { 474 return (int)Math.Round((double)f); 475 } 476 477 /// <summary> 478 /// <para>Returns the sign of f.</para> 479 /// </summary> 480 /// <param name="f"></param> 481 public static float Sign(float f) 482 { 483 return (f < 0f) ? -1f : 1f; 484 } 485 486 /// <summary> 487 /// <para>Clamps a value between a minimum float and maximum float value.</para> 488 /// </summary> 489 /// <param name="value"></param> 490 /// <param name="min"></param> 491 /// <param name="max"></param> 492 public static float Clamp(float value, float min, float max) 493 { 494 if (value < min) 495 { 496 value =http://www.mamicode.com/ min; 497 } 498 else if (value > max) 499 { 500 value =http://www.mamicode.com/ max; 501 } 502 return value; 503 } 504 505 /// <summary> 506 /// <para>Clamps value between min and max and returns value.</para> 507 /// </summary> 508 /// <param name="value"></param> 509 /// <param name="min"></param> 510 /// <param name="max"></param> 511 public static int Clamp(int value, int min, int max) 512 { 513 if (value < min) 514 { 515 value =http://www.mamicode.com/ min; 516 } 517 else if (value > max) 518 { 519 value =http://www.mamicode.com/ max; 520 } 521 return value; 522 } 523 524 /// <summary> 525 /// <para>Clamps value between 0 and 1 and returns value.</para> 526 /// </summary> 527 /// <param name="value"></param> 528 public static float Clamp01(float value) 529 { 530 float result; 531 if (value < 0f) 532 { 533 result = 0f; 534 } 535 else if (value > 1f) 536 { 537 result = 1f; 538 } 539 else 540 { 541 result = value; 542 } 543 return result; 544 } 545 546 /// <summary> 547 /// <para>Linearly interpolates between a and b by t.</para> 548 /// </summary> 549 /// <param name="a">The start value.</param> 550 /// <param name="b">The end value.</param> 551 /// <param name="t">The interpolation value between the two floats.</param> 552 /// <returns> 553 /// <para>The interpolated float result between the two float values.</para> 554 /// </returns> 555 public static float Lerp(float a, float b, float t) 556 { 557 return a + (b - a) * Mathf.Clamp01(t); 558 } 559 560 /// <summary> 561 /// <para>Linearly interpolates between a and b by t with no limit to t.</para> 562 /// </summary> 563 /// <param name="a">The start value.</param> 564 /// <param name="b">The end value.</param> 565 /// <param name="t">The interpolation between the two floats.</param> 566 /// <returns> 567 /// <para>The float value as a result from the linear interpolation.</para> 568 /// </returns> 569 public static float LerpUnclamped(float a, float b, float t) 570 { 571 return a + (b - a) * t; 572 } 573 574 /// <summary> 575 /// <para>Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.</para> 576 /// </summary> 577 /// <param name="a"></param> 578 /// <param name="b"></param> 579 /// <param name="t"></param> 580 public static float LerpAngle(float a, float b, float t) 581 { 582 float num = Mathf.Repeat(b - a, 360f); 583 if (num > 180f) 584 { 585 num -= 360f; 586 } 587 return a + num * Mathf.Clamp01(t); 588 } 589 590 /// <summary> 591 /// <para>Moves a value current towards target.</para> 592 /// </summary> 593 /// <param name="current">The current value.</param> 594 /// <param name="target">The value to move towards.</param> 595 /// <param name="maxDelta">The maximum change that should be applied to the value.</param> 596 public static float MoveTowards(float current, float target, float maxDelta) 597 { 598 float result; 599 if (Mathf.Abs(target - current) <= maxDelta) 600 { 601 result = target; 602 } 603 else 604 { 605 result = current + Mathf.Sign(target - current) * maxDelta; 606 } 607 return result; 608 } 609 610 /// <summary> 611 /// <para>Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.</para> 612 /// </summary> 613 /// <param name="current"></param> 614 /// <param name="target"></param> 615 /// <param name="maxDelta"></param> 616 public static float MoveTowardsAngle(float current, float target, float maxDelta) 617 { 618 float num = Mathf.DeltaAngle(current, target); 619 float result; 620 if (-maxDelta < num && num < maxDelta) 621 { 622 result = target; 623 } 624 else 625 { 626 target = current + num; 627 result = Mathf.MoveTowards(current, target, maxDelta); 628 } 629 return result; 630 } 631 632 /// <summary> 633 /// <para>Interpolates between min and max with smoothing at the limits.</para> 634 /// </summary> 635 /// <param name="from"></param> 636 /// <param name="to"></param> 637 /// <param name="t"></param> 638 public static float SmoothStep(float from, float to, float t) 639 { 640 t = Mathf.Clamp01(t); 641 t = -2f * t * t * t + 3f * t * t; 642 return to * t + from * (1f - t); 643 } 644 645 public static float Gamma(float value, float absmax, float gamma) 646 { 647 bool flag = false; 648 if (value < 0f) 649 { 650 flag = true; 651 } 652 float num = Mathf.Abs(value); 653 float result; 654 if (num > absmax) 655 { 656 result = ((!flag) ? num : (-num)); 657 } 658 else 659 { 660 float num2 = Mathf.Pow(num / absmax, gamma) * absmax; 661 result = ((!flag) ? num2 : (-num2)); 662 } 663 return result; 664 } 665 666 /// <summary> 667 /// <para>Compares two floating point values and returns true if they are similar.</para> 668 /// </summary> 669 /// <param name="a"></param> 670 /// <param name="b"></param> 671 public static bool Approximately(float a, float b) 672 { 673 return Mathf.Abs(b - a) < Mathf.Max(1E-06f * Mathf.Max(Mathf.Abs(a), Mathf.Abs(b)), Mathf.Epsilon * 8f); 674 } 675 676 [ExcludeFromDocs] 677 public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed) 678 { 679 float deltaTime = Time.deltaTime; 680 return Mathf.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 681 } 682 683 [ExcludeFromDocs] 684 public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime) 685 { 686 float deltaTime = Time.deltaTime; 687 float maxSpeed = float.PositiveInfinity; 688 return Mathf.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 689 } 690 691 public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, [DefaultValue("Mathf.Infinity")] float maxSpeed, [DefaultValue("Time.deltaTime")] float deltaTime) 692 { 693 smoothTime = Mathf.Max(0.0001f, smoothTime); 694 float num = 2f / smoothTime; 695 float num2 = num * deltaTime; 696 float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2); 697 float num4 = current - target; 698 float num5 = target; 699 float num6 = maxSpeed * smoothTime; 700 num4 = Mathf.Clamp(num4, -num6, num6); 701 target = current - num4; 702 float num7 = (currentVelocity + num * num4) * deltaTime; 703 currentVelocity = (currentVelocity - num * num7) * num3; 704 float num8 = target + (num4 + num7) * num3; 705 if (num5 - current > 0f == num8 > num5) 706 { 707 num8 = num5; 708 currentVelocity = (num8 - num5) / deltaTime; 709 } 710 return num8; 711 } 712 713 [ExcludeFromDocs] 714 public static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed) 715 { 716 float deltaTime = Time.deltaTime; 717 return Mathf.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 718 } 719 720 [ExcludeFromDocs] 721 public static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime) 722 { 723 float deltaTime = Time.deltaTime; 724 float maxSpeed = float.PositiveInfinity; 725 return Mathf.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 726 } 727 728 public static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime, [DefaultValue("Mathf.Infinity")] float maxSpeed, [DefaultValue("Time.deltaTime")] float deltaTime) 729 { 730 target = current + Mathf.DeltaAngle(current, target); 731 return Mathf.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 732 } 733 734 /// <summary> 735 /// <para>Loops the value t, so that it is never larger than length and never smaller than 0.</para> 736 /// </summary> 737 /// <param name="t"></param> 738 /// <param name="length"></param> 739 public static float Repeat(float t, float length) 740 { 741 return t - Mathf.Floor(t / length) * length; 742 } 743 744 /// <summary> 745 /// <para>PingPongs the value t, so that it is never larger than length and never smaller than 0.</para> 746 /// </summary> 747 /// <param name="t"></param> 748 /// <param name="length"></param> 749 public static float PingPong(float t, float length) 750 { 751 t = Mathf.Repeat(t, length * 2f); 752 return length - Mathf.Abs(t - length); 753 } 754 755 /// <summary> 756 /// <para>Calculates the linear parameter t that produces the interpolant value within the range [a, b].</para> 757 /// </summary> 758 /// <param name="a"></param> 759 /// <param name="b"></param> 760 /// <param name="value"></param> 761 public static float InverseLerp(float a, float b, float value) 762 { 763 float result; 764 if (a != b) 765 { 766 result = Mathf.Clamp01((value - a) / (b - a)); 767 } 768 else 769 { 770 result = 0f; 771 } 772 return result; 773 } 774 775 /// <summary> 776 /// <para>Calculates the shortest difference between two given angles given in degrees.</para> 777 /// </summary> 778 /// <param name="current"></param> 779 /// <param name="target"></param> 780 public static float DeltaAngle(float current, float target) 781 { 782 float num = Mathf.Repeat(target - current, 360f); 783 if (num > 180f) 784 { 785 num -= 360f; 786 } 787 return num; 788 } 789 790 internal static bool LineIntersection(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, ref Vector2 result) 791 { 792 float num = p2.x - p1.x; 793 float num2 = p2.y - p1.y; 794 float num3 = p4.x - p3.x; 795 float num4 = p4.y - p3.y; 796 float num5 = num * num4 - num2 * num3; 797 bool result2; 798 if (num5 == 0f) 799 { 800 result2 = false; 801 } 802 else 803 { 804 float num6 = p3.x - p1.x; 805 float num7 = p3.y - p1.y; 806 float num8 = (num6 * num4 - num7 * num3) / num5; 807 result = new Vector2(p1.x + num8 * num, p1.y + num8 * num2); 808 result2 = true; 809 } 810 return result2; 811 } 812 813 internal static bool LineSegmentIntersection(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, ref Vector2 result) 814 { 815 float num = p2.x - p1.x; 816 float num2 = p2.y - p1.y; 817 float num3 = p4.x - p3.x; 818 float num4 = p4.y - p3.y; 819 float num5 = num * num4 - num2 * num3; 820 bool result2; 821 if (num5 == 0f) 822 { 823 result2 = false; 824 } 825 else 826 { 827 float num6 = p3.x - p1.x; 828 float num7 = p3.y - p1.y; 829 float num8 = (num6 * num4 - num7 * num3) / num5; 830 if (num8 < 0f || num8 > 1f) 831 { 832 result2 = false; 833 } 834 else 835 { 836 float num9 = (num6 * num2 - num7 * num) / num5; 837 if (num9 < 0f || num9 > 1f) 838 { 839 result2 = false; 840 } 841 else 842 { 843 result = new Vector2(p1.x + num8 * num, p1.y + num8 * num2); 844 result2 = true; 845 } 846 } 847 } 848 return result2; 849 } 850 851 internal static long RandomToLong(System.Random r) 852 { 853 byte[] array = new byte[8]; 854 r.NextBytes(array); 855 return (long)(BitConverter.ToUInt64(array, 0) & 9223372036854775807uL); 856 } 857 } 858 }
N:
O:
P:
Q:
R:
S:
T:
U:
V:
1 using System; 2 using UnityEngine.Scripting; 3 4 namespace UnityEngine 5 { 6 /// <summary> 7 /// <para>Representation of 2D vectors and points.</para> 8 /// </summary> 9 [UsedByNativeCode] 10 public struct Vector2 11 { 12 /// <summary> 13 /// <para>X component of the vector.</para> 14 /// </summary> 15 public float x; 16 17 /// <summary> 18 /// <para>Y component of the vector.</para> 19 /// </summary> 20 public float y; 21 22 public const float kEpsilon = 1E-05f; 23 24 public float this[int index] 25 { 26 get 27 { 28 float result; 29 if (index != 0) 30 { 31 if (index != 1) 32 { 33 throw new IndexOutOfRangeException("Invalid Vector2 index!"); 34 } 35 result = this.y; 36 } 37 else 38 { 39 result = this.x; 40 } 41 return result; 42 } 43 set 44 { 45 if (index != 0) 46 { 47 if (index != 1) 48 { 49 throw new IndexOutOfRangeException("Invalid Vector2 index!"); 50 } 51 this.y = value; 52 } 53 else 54 { 55 this.x = value; 56 } 57 } 58 } 59 60 /// <summary> 61 /// <para>Returns this vector with a magnitude of 1 (Read Only).</para> 62 /// </summary> 63 public Vector2 normalized 64 { 65 get 66 { 67 Vector2 result = new Vector2(this.x, this.y); 68 result.Normalize(); 69 return result; 70 } 71 } 72 73 /// <summary> 74 /// <para>Returns the length of this vector (Read Only).</para> 75 /// </summary> 76 public float magnitude 77 { 78 get 79 { 80 return Mathf.Sqrt(this.x * this.x + this.y * this.y); 81 } 82 } 83 84 /// <summary> 85 /// <para>Returns the squared length of this vector (Read Only).</para> 86 /// </summary> 87 public float sqrMagnitude 88 { 89 get 90 { 91 return this.x * this.x + this.y * this.y; 92 } 93 } 94 95 /// <summary> 96 /// <para>Shorthand for writing Vector2(0, 0).</para> 97 /// </summary> 98 public static Vector2 zero 99 { 100 get 101 { 102 return new Vector2(0f, 0f); 103 } 104 } 105 106 /// <summary> 107 /// <para>Shorthand for writing Vector2(1, 1).</para> 108 /// </summary> 109 public static Vector2 one 110 { 111 get 112 { 113 return new Vector2(1f, 1f); 114 } 115 } 116 117 /// <summary> 118 /// <para>Shorthand for writing Vector2(0, 1).</para> 119 /// </summary> 120 public static Vector2 up 121 { 122 get 123 { 124 return new Vector2(0f, 1f); 125 } 126 } 127 128 /// <summary> 129 /// <para>Shorthand for writing Vector2(0, -1).</para> 130 /// </summary> 131 public static Vector2 down 132 { 133 get 134 { 135 return new Vector2(0f, -1f); 136 } 137 } 138 139 /// <summary> 140 /// <para>Shorthand for writing Vector2(-1, 0).</para> 141 /// </summary> 142 public static Vector2 left 143 { 144 get 145 { 146 return new Vector2(-1f, 0f); 147 } 148 } 149 150 /// <summary> 151 /// <para>Shorthand for writing Vector2(1, 0).</para> 152 /// </summary> 153 public static Vector2 right 154 { 155 get 156 { 157 return new Vector2(1f, 0f); 158 } 159 } 160 161 /// <summary> 162 /// <para>Constructs a new vector with given x, y components.</para> 163 /// </summary> 164 /// <param name="x"></param> 165 /// <param name="y"></param> 166 public Vector2(float x, float y) 167 { 168 this.x = x; 169 this.y = y; 170 } 171 172 /// <summary> 173 /// <para>Set x and y components of an existing Vector2.</para> 174 /// </summary> 175 /// <param name="newX"></param> 176 /// <param name="newY"></param> 177 public void Set(float newX, float newY) 178 { 179 this.x = newX; 180 this.y = newY; 181 } 182 183 /// <summary> 184 /// <para>Linearly interpolates between vectors a and b by t.</para> 185 /// </summary> 186 /// <param name="a"></param> 187 /// <param name="b"></param> 188 /// <param name="t"></param> 189 public static Vector2 Lerp(Vector2 a, Vector2 b, float t) 190 { 191 t = Mathf.Clamp01(t); 192 return new Vector2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); 193 } 194 195 /// <summary> 196 /// <para>Linearly interpolates between vectors a and b by t.</para> 197 /// </summary> 198 /// <param name="a"></param> 199 /// <param name="b"></param> 200 /// <param name="t"></param> 201 public static Vector2 LerpUnclamped(Vector2 a, Vector2 b, float t) 202 { 203 return new Vector2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); 204 } 205 206 /// <summary> 207 /// <para>Moves a point current towards target.</para> 208 /// </summary> 209 /// <param name="current"></param> 210 /// <param name="target"></param> 211 /// <param name="maxDistanceDelta"></param> 212 public static Vector2 MoveTowards(Vector2 current, Vector2 target, float maxDistanceDelta) 213 { 214 Vector2 a = target - current; 215 float magnitude = a.magnitude; 216 Vector2 result; 217 if (magnitude <= maxDistanceDelta || magnitude == 0f) 218 { 219 result = target; 220 } 221 else 222 { 223 result = current + a / magnitude * maxDistanceDelta; 224 } 225 return result; 226 } 227 228 /// <summary> 229 /// <para>Multiplies two vectors component-wise.</para> 230 /// </summary> 231 /// <param name="a"></param> 232 /// <param name="b"></param> 233 public static Vector2 Scale(Vector2 a, Vector2 b) 234 { 235 return new Vector2(a.x * b.x, a.y * b.y); 236 } 237 238 /// <summary> 239 /// <para>Multiplies every component of this vector by the same component of scale.</para> 240 /// </summary> 241 /// <param name="scale"></param> 242 public void Scale(Vector2 scale) 243 { 244 this.x *= scale.x; 245 this.y *= scale.y; 246 } 247 248 /// <summary> 249 /// <para>Makes this vector have a magnitude of 1.</para> 250 /// </summary> 251 public void Normalize() 252 { 253 float magnitude = this.magnitude; 254 if (magnitude > 1E-05f) 255 { 256 this /= magnitude; 257 } 258 else 259 { 260 this = Vector2.zero; 261 } 262 } 263 264 /// <summary> 265 /// <para>Returns a nicely formatted string for this vector.</para> 266 /// </summary> 267 /// <param name="format"></param> 268 public override string ToString() 269 { 270 return UnityString.Format("({0:F1}, {1:F1})", new object[] 271 { 272 this.x, 273 this.y 274 }); 275 } 276 277 /// <summary> 278 /// <para>Returns a nicely formatted string for this vector.</para> 279 /// </summary> 280 /// <param name="format"></param> 281 public string ToString(string format) 282 { 283 return UnityString.Format("({0}, {1})", new object[] 284 { 285 this.x.ToString(format), 286 this.y.ToString(format) 287 }); 288 } 289 290 public override int GetHashCode() 291 { 292 return this.x.GetHashCode() ^ this.y.GetHashCode() << 2; 293 } 294 295 /// <summary> 296 /// <para>Returns true if the given vector is exactly equal to this vector.</para> 297 /// </summary> 298 /// <param name="other"></param> 299 public override bool Equals(object other) 300 { 301 bool result; 302 if (!(other is Vector2)) 303 { 304 result = false; 305 } 306 else 307 { 308 Vector2 vector = (Vector2)other; 309 result = (this.x.Equals(vector.x) && this.y.Equals(vector.y)); 310 } 311 return result; 312 } 313 314 /// <summary> 315 /// <para>Reflects a vector off the vector defined by a normal.</para> 316 /// </summary> 317 /// <param name="inDirection"></param> 318 /// <param name="inNormal"></param> 319 public static Vector2 Reflect(Vector2 inDirection, Vector2 inNormal) 320 { 321 return -2f * Vector2.Dot(inNormal, inDirection) * inNormal + inDirection; 322 } 323 324 /// <summary> 325 /// <para>Dot Product of two vectors.</para> 326 /// </summary> 327 /// <param name="lhs"></param> 328 /// <param name="rhs"></param> 329 public static float Dot(Vector2 lhs, Vector2 rhs) 330 { 331 return lhs.x * rhs.x + lhs.y * rhs.y; 332 } 333 334 /// <summary> 335 /// <para>Returns the angle in degrees between from and to.</para> 336 /// </summary> 337 /// <param name="from"></param> 338 /// <param name="to"></param> 339 public static float Angle(Vector2 from, Vector2 to) 340 { 341 return Mathf.Acos(Mathf.Clamp(Vector2.Dot(from.normalized, to.normalized), -1f, 1f)) * 57.29578f; 342 } 343 344 /// <summary> 345 /// <para>Returns the distance between a and b.</para> 346 /// </summary> 347 /// <param name="a"></param> 348 /// <param name="b"></param> 349 public static float Distance(Vector2 a, Vector2 b) 350 { 351 return (a - b).magnitude; 352 } 353 354 /// <summary> 355 /// <para>Returns a copy of vector with its magnitude clamped to maxLength.</para> 356 /// </summary> 357 /// <param name="vector"></param> 358 /// <param name="maxLength"></param> 359 public static Vector2 ClampMagnitude(Vector2 vector, float maxLength) 360 { 361 Vector2 result; 362 if (vector.sqrMagnitude > maxLength * maxLength) 363 { 364 result = vector.normalized * maxLength; 365 } 366 else 367 { 368 result = vector; 369 } 370 return result; 371 } 372 373 public static float SqrMagnitude(Vector2 a) 374 { 375 return a.x * a.x + a.y * a.y; 376 } 377 378 public float SqrMagnitude() 379 { 380 return this.x * this.x + this.y * this.y; 381 } 382 383 /// <summary> 384 /// <para>Returns a vector that is made from the smallest components of two vectors.</para> 385 /// </summary> 386 /// <param name="lhs"></param> 387 /// <param name="rhs"></param> 388 public static Vector2 Min(Vector2 lhs, Vector2 rhs) 389 { 390 return new Vector2(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y)); 391 } 392 393 /// <summary> 394 /// <para>Returns a vector that is made from the largest components of two vectors.</para> 395 /// </summary> 396 /// <param name="lhs"></param> 397 /// <param name="rhs"></param> 398 public static Vector2 Max(Vector2 lhs, Vector2 rhs) 399 { 400 return new Vector2(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y)); 401 } 402 403 public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed, float deltaTime) 404 { 405 smoothTime = Mathf.Max(0.0001f, smoothTime); 406 float num = 2f / smoothTime; 407 float num2 = num * deltaTime; 408 float d = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2); 409 Vector2 vector = current - target; 410 Vector2 vector2 = target; 411 float maxLength = maxSpeed * smoothTime; 412 vector = Vector2.ClampMagnitude(vector, maxLength); 413 target = current - vector; 414 Vector2 vector3 = (currentVelocity + num * vector) * deltaTime; 415 currentVelocity = (currentVelocity - num * vector3) * d; 416 Vector2 vector4 = target + (vector + vector3) * d; 417 if (Vector2.Dot(vector2 - current, vector4 - vector2) > 0f) 418 { 419 vector4 = vector2; 420 currentVelocity = (vector4 - vector2) / deltaTime; 421 } 422 return vector4; 423 } 424 425 public static Vector2 operator +(Vector2 a, Vector2 b) 426 { 427 return new Vector2(a.x + b.x, a.y + b.y); 428 } 429 430 public static Vector2 operator -(Vector2 a, Vector2 b) 431 { 432 return new Vector2(a.x - b.x, a.y - b.y); 433 } 434 435 public static Vector2 operator -(Vector2 a) 436 { 437 return new Vector2(-a.x, -a.y); 438 } 439 440 public static Vector2 operator *(Vector2 a, float d) 441 { 442 return new Vector2(a.x * d, a.y * d); 443 } 444 445 public static Vector2 operator *(float d, Vector2 a) 446 { 447 return new Vector2(a.x * d, a.y * d); 448 } 449 450 public static Vector2 operator /(Vector2 a, float d) 451 { 452 return new Vector2(a.x / d, a.y / d); 453 } 454 455 public static bool operator ==(Vector2 lhs, Vector2 rhs) 456 { 457 return (lhs - rhs).sqrMagnitude < 9.99999944E-11f; 458 } 459 460 public static bool operator !=(Vector2 lhs, Vector2 rhs) 461 { 462 return !(lhs == rhs); 463 } 464 465 public static implicit operator Vector2(Vector3 v) 466 { 467 return new Vector2(v.x, v.y); 468 } 469 470 public static implicit operator Vector3(Vector2 v) 471 { 472 return new Vector3(v.x, v.y, 0f); 473 } 474 } 475 }
1 using System; 2 using System.Runtime.CompilerServices; 3 using UnityEngine.Internal; 4 using UnityEngine.Scripting; 5 6 namespace UnityEngine 7 { 8 /// <summary> 9 /// <para>Representation of 3D vectors and points.</para> 10 /// </summary> 11 [UsedByNativeCode] 12 public struct Vector3 13 { 14 public const float kEpsilon = 1E-05f; 15 16 /// <summary> 17 /// <para>X component of the vector.</para> 18 /// </summary> 19 public float x; 20 21 /// <summary> 22 /// <para>Y component of the vector.</para> 23 /// </summary> 24 public float y; 25 26 /// <summary> 27 /// <para>Z component of the vector.</para> 28 /// </summary> 29 public float z; 30 31 public float this[int index] 32 { 33 get 34 { 35 float result; 36 switch (index) 37 { 38 case 0: 39 result = this.x; 40 break; 41 case 1: 42 result = this.y; 43 break; 44 case 2: 45 result = this.z; 46 break; 47 default: 48 throw new IndexOutOfRangeException("Invalid Vector3 index!"); 49 } 50 return result; 51 } 52 set 53 { 54 switch (index) 55 { 56 case 0: 57 this.x = value; 58 break; 59 case 1: 60 this.y = value; 61 break; 62 case 2: 63 this.z = value; 64 break; 65 default: 66 throw new IndexOutOfRangeException("Invalid Vector3 index!"); 67 } 68 } 69 } 70 71 /// <summary> 72 /// <para>Returns this vector with a magnitude of 1 (Read Only).</para> 73 /// </summary> 74 public Vector3 normalized 75 { 76 get 77 { 78 return Vector3.Normalize(this); 79 } 80 } 81 82 /// <summary> 83 /// <para>Returns the length of this vector (Read Only).</para> 84 /// </summary> 85 public float magnitude 86 { 87 get 88 { 89 return Mathf.Sqrt(this.x * this.x + this.y * this.y + this.z * this.z); 90 } 91 } 92 93 /// <summary> 94 /// <para>Returns the squared length of this vector (Read Only).</para> 95 /// </summary> 96 public float sqrMagnitude 97 { 98 get 99 { 100 return this.x * this.x + this.y * this.y + this.z * this.z; 101 } 102 } 103 104 /// <summary> 105 /// <para>Shorthand for writing Vector3(0, 0, 0).</para> 106 /// </summary> 107 public static Vector3 zero 108 { 109 get 110 { 111 return new Vector3(0f, 0f, 0f); 112 } 113 } 114 115 /// <summary> 116 /// <para>Shorthand for writing Vector3(1, 1, 1).</para> 117 /// </summary> 118 public static Vector3 one 119 { 120 get 121 { 122 return new Vector3(1f, 1f, 1f); 123 } 124 } 125 126 /// <summary> 127 /// <para>Shorthand for writing Vector3(0, 0, 1).</para> 128 /// </summary> 129 public static Vector3 forward 130 { 131 get 132 { 133 return new Vector3(0f, 0f, 1f); 134 } 135 } 136 137 /// <summary> 138 /// <para>Shorthand for writing Vector3(0, 0, -1).</para> 139 /// </summary> 140 public static Vector3 back 141 { 142 get 143 { 144 return new Vector3(0f, 0f, -1f); 145 } 146 } 147 148 /// <summary> 149 /// <para>Shorthand for writing Vector3(0, 1, 0).</para> 150 /// </summary> 151 public static Vector3 up 152 { 153 get 154 { 155 return new Vector3(0f, 1f, 0f); 156 } 157 } 158 159 /// <summary> 160 /// <para>Shorthand for writing Vector3(0, -1, 0).</para> 161 /// </summary> 162 public static Vector3 down 163 { 164 get 165 { 166 return new Vector3(0f, -1f, 0f); 167 } 168 } 169 170 /// <summary> 171 /// <para>Shorthand for writing Vector3(-1, 0, 0).</para> 172 /// </summary> 173 public static Vector3 left 174 { 175 get 176 { 177 return new Vector3(-1f, 0f, 0f); 178 } 179 } 180 181 /// <summary> 182 /// <para>Shorthand for writing Vector3(1, 0, 0).</para> 183 /// </summary> 184 public static Vector3 right 185 { 186 get 187 { 188 return new Vector3(1f, 0f, 0f); 189 } 190 } 191 192 [Obsolete("Use Vector3.forward instead.")] 193 public static Vector3 fwd 194 { 195 get 196 { 197 return new Vector3(0f, 0f, 1f); 198 } 199 } 200 201 /// <summary> 202 /// <para>Creates a new vector with given x, y, z components.</para> 203 /// </summary> 204 /// <param name="x"></param> 205 /// <param name="y"></param> 206 /// <param name="z"></param> 207 public Vector3(float x, float y, float z) 208 { 209 this.x = x; 210 this.y = y; 211 this.z = z; 212 } 213 214 /// <summary> 215 /// <para>Creates a new vector with given x, y components and sets z to zero.</para> 216 /// </summary> 217 /// <param name="x"></param> 218 /// <param name="y"></param> 219 public Vector3(float x, float y) 220 { 221 this.x = x; 222 this.y = y; 223 this.z = 0f; 224 } 225 226 /// <summary> 227 /// <para>Spherically interpolates between two vectors.</para> 228 /// </summary> 229 /// <param name="a"></param> 230 /// <param name="b"></param> 231 /// <param name="t"></param> 232 [ThreadAndSerializationSafe] 233 public static Vector3 Slerp(Vector3 a, Vector3 b, float t) 234 { 235 Vector3 result; 236 Vector3.INTERNAL_CALL_Slerp(ref a, ref b, t, out result); 237 return result; 238 } 239 240 [GeneratedByOldBindingsGenerator] 241 [MethodImpl(MethodImplOptions.InternalCall)] 242 private static extern void INTERNAL_CALL_Slerp(ref Vector3 a, ref Vector3 b, float t, out Vector3 value); 243 244 /// <summary> 245 /// <para>Spherically interpolates between two vectors.</para> 246 /// </summary> 247 /// <param name="a"></param> 248 /// <param name="b"></param> 249 /// <param name="t"></param> 250 public static Vector3 SlerpUnclamped(Vector3 a, Vector3 b, float t) 251 { 252 Vector3 result; 253 Vector3.INTERNAL_CALL_SlerpUnclamped(ref a, ref b, t, out result); 254 return result; 255 } 256 257 [GeneratedByOldBindingsGenerator] 258 [MethodImpl(MethodImplOptions.InternalCall)] 259 private static extern void INTERNAL_CALL_SlerpUnclamped(ref Vector3 a, ref Vector3 b, float t, out Vector3 value); 260 261 private static void Internal_OrthoNormalize2(ref Vector3 a, ref Vector3 b) 262 { 263 Vector3.INTERNAL_CALL_Internal_OrthoNormalize2(ref a, ref b); 264 } 265 266 [GeneratedByOldBindingsGenerator] 267 [MethodImpl(MethodImplOptions.InternalCall)] 268 private static extern void INTERNAL_CALL_Internal_OrthoNormalize2(ref Vector3 a, ref Vector3 b); 269 270 private static void Internal_OrthoNormalize3(ref Vector3 a, ref Vector3 b, ref Vector3 c) 271 { 272 Vector3.INTERNAL_CALL_Internal_OrthoNormalize3(ref a, ref b, ref c); 273 } 274 275 [GeneratedByOldBindingsGenerator] 276 [MethodImpl(MethodImplOptions.InternalCall)] 277 private static extern void INTERNAL_CALL_Internal_OrthoNormalize3(ref Vector3 a, ref Vector3 b, ref Vector3 c); 278 279 public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent) 280 { 281 Vector3.Internal_OrthoNormalize2(ref normal, ref tangent); 282 } 283 284 public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent, ref Vector3 binormal) 285 { 286 Vector3.Internal_OrthoNormalize3(ref normal, ref tangent, ref binormal); 287 } 288 289 /// <summary> 290 /// <para>Rotates a vector current towards target.</para> 291 /// </summary> 292 /// <param name="current"></param> 293 /// <param name="target"></param> 294 /// <param name="maxRadiansDelta"></param> 295 /// <param name="maxMagnitudeDelta"></param> 296 public static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta) 297 { 298 Vector3 result; 299 Vector3.INTERNAL_CALL_RotateTowards(ref current, ref target, maxRadiansDelta, maxMagnitudeDelta, out result); 300 return result; 301 } 302 303 [GeneratedByOldBindingsGenerator] 304 [MethodImpl(MethodImplOptions.InternalCall)] 305 private static extern void INTERNAL_CALL_RotateTowards(ref Vector3 current, ref Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta, out Vector3 value); 306 307 [Obsolete("Use Vector3.ProjectOnPlane instead.")] 308 public static Vector3 Exclude(Vector3 excludeThis, Vector3 fromThat) 309 { 310 return fromThat - Vector3.Project(fromThat, excludeThis); 311 } 312 313 /// <summary> 314 /// <para>Linearly interpolates between two vectors.</para> 315 /// </summary> 316 /// <param name="a"></param> 317 /// <param name="b"></param> 318 /// <param name="t"></param> 319 public static Vector3 Lerp(Vector3 a, Vector3 b, float t) 320 { 321 t = Mathf.Clamp01(t); 322 return new Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t); 323 } 324 325 /// <summary> 326 /// <para>Linearly interpolates between two vectors.</para> 327 /// </summary> 328 /// <param name="a"></param> 329 /// <param name="b"></param> 330 /// <param name="t"></param> 331 public static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t) 332 { 333 return new Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t); 334 } 335 336 /// <summary> 337 /// <para>Moves a point current in a straight line towards a target point.</para> 338 /// </summary> 339 /// <param name="current"></param> 340 /// <param name="target"></param> 341 /// <param name="maxDistanceDelta"></param> 342 public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta) 343 { 344 Vector3 a = target - current; 345 float magnitude = a.magnitude; 346 Vector3 result; 347 if (magnitude <= maxDistanceDelta || magnitude == 0f) 348 { 349 result = target; 350 } 351 else 352 { 353 result = current + a / magnitude * maxDistanceDelta; 354 } 355 return result; 356 } 357 358 [ExcludeFromDocs] 359 public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed) 360 { 361 float deltaTime = Time.deltaTime; 362 return Vector3.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 363 } 364 365 [ExcludeFromDocs] 366 public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime) 367 { 368 float deltaTime = Time.deltaTime; 369 float maxSpeed = float.PositiveInfinity; 370 return Vector3.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); 371 } 372 373 public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, [DefaultValue("Mathf.Infinity")] float maxSpeed, [DefaultValue("Time.deltaTime")] float deltaTime) 374 { 375 smoothTime = Mathf.Max(0.0001f, smoothTime); 376 float num = 2f / smoothTime; 377 float num2 = num * deltaTime; 378 float d = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2); 379 Vector3 vector = current - target; 380 Vector3 vector2 = target; 381 float maxLength = maxSpeed * smoothTime; 382 vector = Vector3.ClampMagnitude(vector, maxLength); 383 target = current - vector; 384 Vector3 vector3 = (currentVelocity + num * vector) * deltaTime; 385 currentVelocity = (currentVelocity - num * vector3) * d; 386 Vector3 vector4 = target + (vector + vector3) * d; 387 if (Vector3.Dot(vector2 - current, vector4 - vector2) > 0f) 388 { 389 vector4 = vector2; 390 currentVelocity = (vector4 - vector2) / deltaTime; 391 } 392 return vector4; 393 } 394 395 /// <summary> 396 /// <para>Set x, y and z components of an existing Vector3.</para> 397 /// </summary> 398 /// <param name="new_x"></param> 399 /// <param name="new_y"></param> 400 /// <param name="new_z"></param> 401 public void Set(float new_x, float new_y, float new_z) 402 { 403 this.x = new_x; 404 this.y = new_y; 405 this.z = new_z; 406 } 407 408 /// <summary> 409 /// <para>Multiplies two vectors component-wise.</para> 410 /// </summary> 411 /// <param name="a"></param> 412 /// <param name="b"></param> 413 public static Vector3 Scale(Vector3 a, Vector3 b) 414 { 415 return new Vector3(a.x * b.x, a.y * b.y, a.z * b.z); 416 } 417 418 /// <summary> 419 /// <para>Multiplies every component of this vector by the same component of scale.</para> 420 /// </summary> 421 /// <param name="scale"></param> 422 public void Scale(Vector3 scale) 423 { 424 this.x *= scale.x; 425 this.y *= scale.y; 426 this.z *= scale.z; 427 } 428 429 /// <summary> 430 /// <para>Cross Product of two vectors.</para> 431 /// </summary> 432 /// <param name="lhs"></param> 433 /// <param name="rhs"></param> 434 public static Vector3 Cross(Vector3 lhs, Vector3 rhs) 435 { 436 return new Vector3(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x); 437 } 438 439 public override int GetHashCode() 440 { 441 return this.x.GetHashCode() ^ this.y.GetHashCode() << 2 ^ this.z.GetHashCode() >> 2; 442 } 443 444 /// <summary> 445 /// <para>Returns true if the given vector is exactly equal to this vector.</para> 446 /// </summary> 447 /// <param name="other"></param> 448 public override bool Equals(object other) 449 { 450 bool result; 451 if (!(other is Vector3)) 452 { 453 result = false; 454 } 455 else 456 { 457 Vector3 vector = (Vector3)other; 458 result = (this.x.Equals(vector.x) && this.y.Equals(vector.y) && this.z.Equals(vector.z)); 459 } 460 return result; 461 } 462 463 /// <summary> 464 /// <para>Reflects a vector off the plane defined by a normal.</para> 465 /// </summary> 466 /// <param name="inDirection"></param> 467 /// <param name="inNormal"></param> 468 public static Vector3 Reflect(Vector3 inDirection, Vector3 inNormal) 469 { 470 return -2f * Vector3.Dot(inNormal, inDirection) * inNormal + inDirection; 471 } 472 473 /// <summary> 474 /// <para></para> 475 /// </summary> 476 /// <param name="value"></param> 477 public static Vector3 Normalize(Vector3 value) 478 { 479 float num = Vector3.Magnitude(value); 480 Vector3 result; 481 if (num > 1E-05f) 482 { 483 result = value / num; 484 } 485 else 486 { 487 result = Vector3.zero; 488 } 489 return result; 490 } 491 492 /// <summary> 493 /// <para>Makes this vector have a magnitude of 1.</para> 494 /// </summary> 495 public void Normalize() 496 { 497 float num = Vector3.Magnitude(this); 498 if (num > 1E-05f) 499 { 500 this /= num; 501 } 502 else 503 { 504 this = Vector3.zero; 505 } 506 } 507 508 /// <summary> 509 /// <para>Dot Product of two vectors.</para> 510 /// </summary> 511 /// <param name="lhs"></param> 512 /// <param name="rhs"></param> 513 public static float Dot(Vector3 lhs, Vector3 rhs) 514 { 515 return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z; 516 } 517 518 /// <summary> 519 /// <para>Projects a vector onto another vector.</para> 520 /// </summary> 521 /// <param name="vector"></param> 522 /// <param name="onNormal"></param> 523 public static Vector3 Project(Vector3 vector, Vector3 onNormal) 524 { 525 float num = Vector3.Dot(onNormal, onNormal); 526 Vector3 result; 527 if (num < Mathf.Epsilon) 528 { 529 result = Vector3.zero; 530 } 531 else 532 { 533 result = onNormal * Vector3.Dot(vector, onNormal) / num; 534 } 535 return result; 536 } 537 538 /// <summary> 539 /// <para>Projects a vector onto a plane defined by a normal orthogonal to the plane.</para> 540 /// </summary> 541 /// <param name="vector"></param> 542 /// <param name="planeNormal"></param> 543 public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal) 544 { 545 return vector - Vector3.Project(vector, planeNormal); 546 } 547 548 /// <summary> 549 /// <para>Returns the angle in degrees between from and to.</para> 550 /// </summary> 551 /// <param name="from">The angle extends round from this vector.</param> 552 /// <param name="to">The angle extends round to this vector.</param> 553 public static float Angle(Vector3 from, Vector3 to) 554 { 555 return Mathf.Acos(Mathf.Clamp(Vector3.Dot(from.normalized, to.normalized), -1f, 1f)) * 57.29578f; 556 } 557 558 /// <summary> 559 /// <para>Returns the distance between a and b.</para> 560 /// </summary> 561 /// <param name="a"></param> 562 /// <param name="b"></param> 563 public static float Distance(Vector3 a, Vector3 b) 564 { 565 Vector3 vector = new Vector3(a.x - b.x, a.y - b.y, a.z - b.z); 566 return Mathf.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z); 567 } 568 569 /// <summary> 570 /// <para>Returns a copy of vector with its magnitude clamped to maxLength.</para> 571 /// </summary> 572 /// <param name="vector"></param> 573 /// <param name="maxLength"></param> 574 public static Vector3 ClampMagnitude(Vector3 vector, float maxLength) 575 { 576 Vector3 result; 577 if (vector.sqrMagnitude > maxLength * maxLength) 578 { 579 result = vector.normalized * maxLength; 580 } 581 else 582 { 583 result = vector; 584 } 585 return result; 586 } 587 588 public static float Magnitude(Vector3 a) 589 { 590 return Mathf.Sqrt(a.x * a.x + a.y * a.y + a.z * a.z); 591 } 592 593 public static float SqrMagnitude(Vector3 a) 594 { 595 return a.x * a.x + a.y * a.y + a.z * a.z; 596 } 597 598 /// <summary> 599 /// <para>Returns a vector that is made from the smallest components of two vectors.</para> 600 /// </summary> 601 /// <param name="lhs"></param> 602 /// <param name="rhs"></param> 603 public static Vector3 Min(Vector3 lhs, Vector3 rhs) 604 { 605 return new Vector3(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y), Mathf.Min(lhs.z, rhs.z)); 606 } 607 608 /// <summary> 609 /// <para>Returns a vector that is made from the largest components of two vectors.</para> 610 /// </summary> 611 /// <param name="lhs"></param> 612 /// <param name="rhs"></param> 613 public static Vector3 Max(Vector3 lhs, Vector3 rhs) 614 { 615 return new Vector3(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y), Mathf.Max(lhs.z, rhs.z)); 616 } 617 618 public static Vector3 operator +(Vector3 a, Vector3 b) 619 { 620 return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z); 621 } 622 623 public static Vector3 operator -(Vector3 a, Vector3 b) 624 { 625 return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z); 626 } 627 628 public static Vector3 operator -(Vector3 a) 629 { 630 return new Vector3(-a.x, -a.y, -a.z); 631 } 632 633 public static Vector3 operator *(Vector3 a, float d) 634 { 635 return new Vector3(a.x * d, a.y * d, a.z * d); 636 } 637 638 public static Vector3 operator *(float d, Vector3 a) 639 { 640 return new Vector3(a.x * d, a.y * d, a.z * d); 641 } 642 643 public static Vector3 operator /(Vector3 a, float d) 644 { 645 return new Vector3(a.x / d, a.y / d, a.z / d); 646 } 647 648 public static bool operator ==(Vector3 lhs, Vector3 rhs) 649 { 650 return Vector3.SqrMagnitude(lhs - rhs) < 9.99999944E-11f; 651 } 652 653 public static bool operator !=(Vector3 lhs, Vector3 rhs) 654 { 655 return !(lhs == rhs); 656 } 657 658 /// <summary> 659 /// <para>Returns a nicely formatted string for this vector.</para> 660 /// </summary> 661 /// <param name="format"></param> 662 public override string ToString() 663 { 664 return UnityString.Format("({0:F1}, {1:F1}, {2:F1})", new object[] 665 { 666 this.x, 667 this.y, 668 this.z 669 }); 670 } 671 672 /// <summary> 673 /// <para>Returns a nicely formatted string for this vector.</para> 674 /// </summary> 675 /// <param name="format"></param> 676 public string ToString(string format) 677 { 678 return UnityString.Format("({0}, {1}, {2})", new object[] 679 { 680 this.x.ToString(format), 681 this.y.ToString(format), 682 this.z.ToString(format) 683 }); 684 } 685 686 [Obsolete("Use Vector3.Angle instead. AngleBetween uses radians instead of degrees and was deprecated for this reason")] 687 public static float AngleBetween(Vector3 from, Vector3 to) 688 { 689 return Mathf.Acos(Mathf.Clamp(Vector3.Dot(from.normalized, to.normalized), -1f, 1f)); 690 } 691 } 692 }
1 using System; 2 using UnityEngine.Scripting; 3 4 namespace UnityEngine 5 { 6 /// <summary> 7 /// <para>Representation of four-dimensional vectors.</para> 8 /// </summary> 9 [UsedByNativeCode] 10 public struct Vector4 11 { 12 public const float kEpsilon = 1E-05f; 13 14 /// <summary> 15 /// <para>X component of the vector.</para> 16 /// </summary> 17 public float x; 18 19 /// <summary> 20 /// <para>Y component of the vector.</para> 21 /// </summary> 22 public float y; 23 24 /// <summary> 25 /// <para>Z component of the vector.</para> 26 /// </summary> 27 public float z; 28 29 /// <summary> 30 /// <para>W component of the vector.</para> 31 /// </summary> 32 public float w; 33 34 public float this[int index] 35 { 36 get 37 { 38 float result; 39 switch (index) 40 { 41 case 0: 42 result = this.x; 43 break; 44 case 1: 45 result = this.y; 46 break; 47 case 2: 48 result = this.z; 49 break; 50 case 3: 51 result = this.w; 52 break; 53 default: 54 throw new IndexOutOfRangeException("Invalid Vector4 index!"); 55 } 56 return result; 57 } 58 set 59 { 60 switch (index) 61 { 62 case 0: 63 this.x = value; 64 break; 65 case 1: 66 this.y = value; 67 break; 68 case 2: 69 this.z = value; 70 break; 71 case 3: 72 this.w = value; 73 break; 74 default: 75 throw new IndexOutOfRangeException("Invalid Vector4 index!"); 76 } 77 } 78 } 79 80 /// <summary> 81 /// <para>Returns this vector with a magnitude of 1 (Read Only).</para> 82 /// </summary> 83 public Vector4 normalized 84 { 85 get 86 { 87 return Vector4.Normalize(this); 88 } 89 } 90 91 /// <summary> 92 /// <para>Returns the length of this vector (Read Only).</para> 93 /// </summary> 94 public float magnitude 95 { 96 get 97 { 98 return Mathf.Sqrt(Vector4.Dot(this, this)); 99 } 100 } 101 102 /// <summary> 103 /// <para>Returns the squared length of this vector (Read Only).</para> 104 /// </summary> 105 public float sqrMagnitude 106 { 107 get 108 { 109 return Vector4.Dot(this, this); 110 } 111 } 112 113 /// <summary> 114 /// <para>Shorthand for writing Vector4(0,0,0,0).</para> 115 /// </summary> 116 public static Vector4 zero 117 { 118 get 119 { 120 return new Vector4(0f, 0f, 0f, 0f); 121 } 122 } 123 124 /// <summary> 125 /// <para>Shorthand for writing Vector4(1,1,1,1).</para> 126 /// </summary> 127 public static Vector4 one 128 { 129 get 130 { 131 return new Vector4(1f, 1f, 1f, 1f); 132 } 133 } 134 135 /// <summary> 136 /// <para>Creates a new vector with given x, y, z, w components.</para> 137 /// </summary> 138 /// <param name="x"></param> 139 /// <param name="y"></param> 140 /// <param name="z"></param> 141 /// <param name="w"></param> 142 public Vector4(float x, float y, float z, float w) 143 { 144 this.x = x; 145 this.y = y; 146 this.z = z; 147 this.w = w; 148 } 149 150 /// <summary> 151 /// <para>Creates a new vector with given x, y, z components and sets w to zero.</para> 152 /// </summary> 153 /// <param name="x"></param> 154 /// <param name="y"></param> 155 /// <param name="z"></param> 156 public Vector4(float x, float y, float z) 157 { 158 this.x = x; 159 this.y = y; 160 this.z = z; 161 this.w = 0f; 162 } 163 164 /// <summary> 165 /// <para>Creates a new vector with given x, y components and sets z and w to zero.</para> 166 /// </summary> 167 /// <param name="x"></param> 168 /// <param name="y"></param> 169 public Vector4(float x, float y) 170 { 171 this.x = x; 172 this.y = y; 173 this.z = 0f; 174 this.w = 0f; 175 } 176 177 /// <summary> 178 /// <para>Set x, y, z and w components of an existing Vector4.</para> 179 /// </summary> 180 /// <param name="new_x"></param> 181 /// <param name="new_y"></param> 182 /// <param name="new_z"></param> 183 /// <param name="new_w"></param> 184 public void Set(float new_x, float new_y, float new_z, float new_w) 185 { 186 this.x = new_x; 187 this.y = new_y; 188 this.z = new_z; 189 this.w = new_w; 190 } 191 192 /// <summary> 193 /// <para>Linearly interpolates between two vectors.</para> 194 /// </summary> 195 /// <param name="a"></param> 196 /// <param name="b"></param> 197 /// <param name="t"></param> 198 public static Vector4 Lerp(Vector4 a, Vector4 b, float t) 199 { 200 t = Mathf.Clamp01(t); 201 return new Vector4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); 202 } 203 204 /// <summary> 205 /// <para>Linearly interpolates between two vectors.</para> 206 /// </summary> 207 /// <param name="a"></param> 208 /// <param name="b"></param> 209 /// <param name="t"></param> 210 public static Vector4 LerpUnclamped(Vector4 a, Vector4 b, float t) 211 { 212 return new Vector4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); 213 } 214 215 /// <summary> 216 /// <para>Moves a point current towards target.</para> 217 /// </summary> 218 /// <param name="current"></param> 219 /// <param name="target"></param> 220 /// <param name="maxDistanceDelta"></param> 221 public static Vector4 MoveTowards(Vector4 current, Vector4 target, float maxDistanceDelta) 222 { 223 Vector4 a = target - current; 224 float magnitude = a.magnitude; 225 Vector4 result; 226 if (magnitude <= maxDistanceDelta || magnitude == 0f) 227 { 228 result = target; 229 } 230 else 231 { 232 result = current + a / magnitude * maxDistanceDelta; 233 } 234 return result; 235 } 236 237 /// <summary> 238 /// <para>Multiplies two vectors component-wise.</para> 239 /// </summary> 240 /// <param name="a"></param> 241 /// <param name="b"></param> 242 public static Vector4 Scale(Vector4 a, Vector4 b) 243 { 244 return new Vector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); 245 } 246 247 /// <summary> 248 /// <para>Multiplies every component of this vector by the same component of scale.</para> 249 /// </summary> 250 /// <param name="scale"></param> 251 public void Scale(Vector4 scale) 252 { 253 this.x *= scale.x; 254 this.y *= scale.y; 255 this.z *= scale.z; 256 this.w *= scale.w; 257 } 258 259 public override int GetHashCode() 260 { 261 return this.x.GetHashCode() ^ this.y.GetHashCode() << 2 ^ this.z.GetHashCode() >> 2 ^ this.w.GetHashCode() >> 1; 262 } 263 264 /// <summary> 265 /// <para>Returns true if the given vector is exactly equal to this vector.</para> 266 /// </summary> 267 /// <param name="other"></param> 268 public override bool Equals(object other) 269 { 270 bool result; 271 if (!(other is Vector4)) 272 { 273 result = false; 274 } 275 else 276 { 277 Vector4 vector = (Vector4)other; 278 result = (this.x.Equals(vector.x) && this.y.Equals(vector.y) && this.z.Equals(vector.z) && this.w.Equals(vector.w)); 279 } 280 return result; 281 } 282 283 /// <summary> 284 /// <para></para> 285 /// </summary> 286 /// <param name="a"></param> 287 public static Vector4 Normalize(Vector4 a) 288 { 289 float num = Vector4.Magnitude(a); 290 Vector4 result; 291 if (num > 1E-05f) 292 { 293 result = a / num; 294 } 295 else 296 { 297 result = Vector4.zero; 298 } 299 return result; 300 } 301 302 /// <summary> 303 /// <para>Makes this vector have a magnitude of 1.</para> 304 /// </summary> 305 public void Normalize() 306 { 307 float num = Vector4.Magnitude(this); 308 if (num > 1E-05f) 309 { 310 this /= num; 311 } 312 else 313 { 314 this = Vector4.zero; 315 } 316 } 317 318 /// <summary> 319 /// <para>Dot Product of two vectors.</para> 320 /// </summary> 321 /// <param name="a"></param> 322 /// <param name="b"></param> 323 public static float Dot(Vector4 a, Vector4 b) 324 { 325 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; 326 } 327 328 /// <summary> 329 /// <para>Projects a vector onto another vector.</para> 330 /// </summary> 331 /// <param name="a"></param> 332 /// <param name="b"></param> 333 public static Vector4 Project(Vector4 a, Vector4 b) 334 { 335 return b * Vector4.Dot(a, b) / Vector4.Dot(b, b); 336 } 337 338 /// <summary> 339 /// <para>Returns the distance between a and b.</para> 340 /// </summary> 341 /// <param name="a"></param> 342 /// <param name="b"></param> 343 public static float Distance(Vector4 a, Vector4 b) 344 { 345 return Vector4.Magnitude(a - b); 346 } 347 348 public static float Magnitude(Vector4 a) 349 { 350 return Mathf.Sqrt(Vector4.Dot(a, a)); 351 } 352 353 /// <summary> 354 /// <para>Returns a vector that is made from the smallest components of two vectors.</para> 355 /// </summary> 356 /// <param name="lhs"></param> 357 /// <param name="rhs"></param> 358 public static Vector4 Min(Vector4 lhs, Vector4 rhs) 359 { 360 return new Vector4(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y), Mathf.Min(lhs.z, rhs.z), Mathf.Min(lhs.w, rhs.w)); 361 } 362 363 /// <summary> 364 /// <para>Returns a vector that is made from the largest components of two vectors.</para> 365 /// </summary> 366 /// <param name="lhs"></param> 367 /// <param name="rhs"></param> 368 public static Vector4 Max(Vector4 lhs, Vector4 rhs) 369 { 370 return new Vector4(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y), Mathf.Max(lhs.z, rhs.z), Mathf.Max(lhs.w, rhs.w)); 371 } 372 373 public static Vector4 operator +(Vector4 a, Vector4 b) 374 { 375 return new Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); 376 } 377 378 public static Vector4 operator -(Vector4 a, Vector4 b) 379 { 380 return new Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); 381 } 382 383 public static Vector4 operator -(Vector4 a) 384 { 385 return new Vector4(-a.x, -a.y, -a.z, -a.w); 386 } 387 388 public static Vector4 operator *(Vector4 a, float d) 389 { 390 return new Vector4(a.x * d, a.y * d, a.z * d, a.w * d); 391 } 392 393 public static Vector4 operator *(float d, Vector4 a) 394 { 395 return new Vector4(a.x * d, a.y * d, a.z * d, a.w * d); 396 } 397 398 public static Vector4 operator /(Vector4 a, float d) 399 { 400 return new Vector4(a.x / d, a.y / d, a.z / d, a.w / d); 401 } 402 403 public static bool operator ==(Vector4 lhs, Vector4 rhs) 404 { 405 return Vector4.SqrMagnitude(lhs - rhs) < 9.99999944E-11f; 406 } 407 408 public static bool operator !=(Vector4 lhs, Vector4 rhs) 409 { 410 return !(lhs == rhs); 411 } 412 413 public static implicit operator Vector4(Vector3 v) 414 { 415 return new Vector4(v.x, v.y, v.z, 0f); 416 } 417 418 public static implicit operator Vector3(Vector4 v) 419 { 420 return new Vector3(v.x, v.y, v.z); 421 } 422 423 public static implicit operator Vector4(Vector2 v) 424 { 425 return new Vector4(v.x, v.y, 0f, 0f); 426 } 427 428 public static implicit operator Vector2(Vector4 v) 429 { 430 return new Vector2(v.x, v.y); 431 } 432 433 /// <summary> 434 /// <para>Returns a nicely formatted string for this vector.</para> 435 /// </summary> 436 /// <param name="format"></param> 437 public override string ToString() 438 { 439 return UnityString.Format("({0:F1}, {1:F1}, {2:F1}, {3:F1})", new object[] 440 { 441 this.x, 442 this.y, 443 this.z, 444 this.w 445 }); 446 } 447 448 /// <summary> 449 /// <para>Returns a nicely formatted string for this vector.</para> 450 /// </summary> 451 /// <param name="format"></param> 452 public string ToString(string format) 453 { 454 return UnityString.Format("({0}, {1}, {2}, {3})", new object[] 455 { 456 this.x.ToString(format), 457 this.y.ToString(format), 458 this.z.ToString(format), 459 this.w.ToString(format) 460 }); 461 } 462 463 public static float SqrMagnitude(Vector4 a) 464 { 465 return Vector4.Dot(a, a); 466 } 467 468 public float SqrMagnitude() 469 { 470 return Vector4.Dot(this, this); 471 } 472 } 473 }
W:
X:
Y:
Z:
Unity 源码(伪)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。