使用运算符重载

LuaCallCSOperator.lua.txt

  1. local operator = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.shenjun.LuaCallCSOperator))
  2. local Quaternion = CS.UnityEngine.Quaternion
  3. local Vector3 = CS.UnityEngine.Vector3
  4. operator.transform.rotation = operator.transform.rotation * Quaternion.AngleAxis(45, Vector3.up)
  5. operator.transform.position = operator.transform.position + Vector3.up * 10

LuaCallCSOperator.cs

  1. /*
  2. * created by shenjun
  3. */
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using XLua;
  8. namespace shenjun
  9. {
  10. public class LuaCallCSOperator : MonoBehaviour {
  11. LuaEnv luaEnv = new LuaEnv();
  12. void Start () {
  13. luaEnv.DoString("require 'LuaCallCSOperator'");
  14. }
  15. void Update () {
  16. if(luaEnv != null)
  17. {
  18. luaEnv.Tick();
  19. }
  20. }
  21. private void OnDestroy()
  22. {
  23. luaEnv.Dispose();
  24. }
  25. }
  26. }

?