1 using UnityEngine; 2 using XLua; 3 using System.IO; 4 5 public class HotFixScript : MonoBehaviour 6 { 7 private LuaEnv env; 8 9 private void Awake() 10 { 11 env = new LuaEnv(); 12 env.AddLoader(MyLoader); 13 env.DoString("require 'xxx'"); 14 } 15 16 private byte[] MyLoader(ref string filePath) 17 { 18 string absPath = @"E:\xxx\" + filePath + ".lua.txt"; 19 return System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(absPath)); 20 } 21 22 private void OnDisable() 23 { 24 //置空补丁 25 env.DoString("require 'xxx'"); 26 } 27 28 private void OnDestroy() 29 { 30 //释放 31 env.Dispose(); 32 } 33 }