You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

CalcerVector.cs 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. public class CalcerVector : Calcer<Vector3>
  7. {
  8. private Vector3 internalValue;
  9. private int dimensions;
  10. public CalcerVector()
  11. {
  12. }
  13. public CalcerVector(Vector3 value)
  14. {
  15. internalValue = value;
  16. dimensions = 3;
  17. }
  18. public CalcerVector(Vector2 value)
  19. {
  20. internalValue = value;
  21. dimensions = 2;
  22. }
  23. public override Vector3 value
  24. {
  25. get
  26. {
  27. switch (dimensions)
  28. {
  29. case 3:
  30. return (Vector3)internalValue;
  31. case 2:
  32. return (Vector2)internalValue;
  33. default:
  34. return internalValue;
  35. }
  36. }
  37. }
  38. public static implicit operator CalcerVector(Vector3 val)
  39. {
  40. return new CalcerVector(val);
  41. }
  42. public static implicit operator CalcerVector(Vector2 val)
  43. {
  44. return new CalcerVector(val);
  45. }
  46. public static implicit operator Vector3(CalcerVector calc)
  47. {
  48. return calc.value;
  49. }
  50. public static CalcerVector operator +(CalcerVector first, CalcerVector second)
  51. {
  52. return new CalcerVectorCalc(first, second, CalcerVectorCalc.Operation.Add);
  53. }
  54. public static CalcerVector operator -(CalcerVector first, CalcerVector second)
  55. {
  56. return new CalcerVectorCalc(first, second, CalcerVectorCalc.Operation.Sub);
  57. }
  58. }
  59. }