TestOutArg.cs

  1. using UnityEngine;
  2. using System.Collections;
  3. using LuaInterface;
  4. using System;
  5. public class TestOutArg : MonoBehaviour
  6. {
  7. string script =
  8. @"
  9. print('start')
  10. local box = UnityEngine.BoxCollider
  11. function TestPick(ray)
  12. local _layer = 2 ^ LayerMask.NameToLayer('Default')
  13. local flag, hit = UnityEngine.Physics.Raycast(ray, nil, 5000, _layer)
  14. --local flag, hit = UnityEngine.Physics.Raycast(ray, RaycastHit.out, 5000, _layer)
  15. if flag then
  16. print('pick from lua, point: '..tostring(hit.point))
  17. end
  18. end
  19. ";
  20. LuaState state = null;
  21. LuaFunction func = null;
  22. void Start ()
  23. {
  24. new LuaResLoader();
  25. state = new LuaState();
  26. LuaBinder.Bind(state);
  27. state.Start();
  28. state.DoString(script, "TestOutArg.cs");
  29. func = state.GetFunction("TestPick");
  30. }
  31. void Update()
  32. {
  33. if (Input.GetMouseButtonDown(0))
  34. {
  35. Camera camera = Camera.main;
  36. Ray ray = camera.ScreenPointToRay(Input.mousePosition);
  37. RaycastHit hit;
  38. bool flag = Physics.Raycast(ray, out hit, 5000, 1 << LayerMask.NameToLayer("Default"));
  39. if (flag)
  40. {
  41. Debugger.Log("pick from c#, point: [{0}, {1}, {2}]", hit.point.x, hit.point.y, hit.point.z);
  42. }
  43. func.BeginPCall();
  44. func.Push(ray);
  45. func.PCall();
  46. func.EndPCall();
  47. }
  48. state.CheckTop();
  49. state.Collect();
  50. }
  51. void OnDestroy()
  52. {
  53. func.Dispose();
  54. func = null;
  55. state.Dispose();
  56. state = null;
  57. }
  58. }

?