调用父类成员

CallCSParent.lua.txt

  1. local camera = CS.UnityEngine.Camera.main
  2. if camera ~= nil then
  3. print("Find Camera")
  4. end
  5. local callParent = camera.transform:GetComponent(typeof(CS.shenjun.CallParent))
  6. if nil ~= callParent then
  7. print("GetComponent CallParent")
  8. else
  9. print("Not Find Component CallParent")
  10. end
  11. --调用父类的静态字段
  12. print(CS.shenjun.CallParent.index)
  13. --调用父类的非静态字段
  14. print(callParent.tag)
  15. --调用父类的静态方法
  16. CS.shenjun.CallParent.SetIndex()
  17. --调用父类的非静态方法
  18. print(callParent:CompareTag("Player"))

CallParent.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 CallParent : Parent {
  11. void Start () {
  12. LuaEnv luaEnv = new LuaEnv();
  13. luaEnv.DoString("require 'CallCSParent'");
  14. luaEnv.Dispose();
  15. }
  16. void Update () {
  17. }
  18. }
  19. public class Parent : MonoBehaviour
  20. {
  21. public static int index = 0;
  22. public static void SetIndex()
  23. {
  24. index++;
  25. Debug.Log("index : " + index);
  26. }
  27. }
  28. }

?