源战役客户端
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.

49 lines
950 B

  1. local rawget = rawget
  2. local setmetatable = setmetatable
  3. local Ray = {}
  4. local get = tolua.initget(Ray)
  5. Ray.__index = function(t,k)
  6. local var = rawget(Ray, k)
  7. if var == nil then
  8. var = rawget(get, k)
  9. if var ~= nil then
  10. return var(t)
  11. end
  12. end
  13. return var
  14. end
  15. Ray.__call = function(t, direction, origin)
  16. return Ray.New(direction, origin)
  17. end
  18. function Ray.New(direction, origin)
  19. local ray = {}
  20. ray.direction = direction:Normalize()
  21. ray.origin = origin
  22. setmetatable(ray, Ray)
  23. return ray
  24. end
  25. function Ray:GetPoint(distance)
  26. local dir = self.direction * distance
  27. dir:Add(self.origin)
  28. return dir
  29. end
  30. function Ray:Get()
  31. return self.origin, self.direction
  32. end
  33. Ray.__tostring = function(self)
  34. return string.format("Origin:(%f,%f,%f),Dir:(%f,%f, %f)", self.origin.x, self.origin.y, self.origin.z, self.direction.x, self.direction.y, self.direction.z)
  35. end
  36. UnityEngine.Ray = Ray
  37. setmetatable(Ray, Ray)
  38. return Ray