SignatureLoaderTest.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using System.Collections;
  3. using XLua;
  4. using System.IO;
  5. namespace XLuaTest
  6. {
  7. public class SignatureLoaderTest : MonoBehaviour
  8. {
  9. public static string PUBLIC_KEY = "BgIAAACkAABSU0ExAAQAAAEAAQBVDDC5QJ+0uSCJA+EysIC9JBzIsd6wcXa+FuTGXcsJuwyUkabwIiT2+QEjP454RwfSQP8s4VZE1m4npeVD2aDnY4W6ZNJe+V+d9Drt9b+9fc/jushj/5vlEksGBIIC/plU4ZaR6/nDdMIs/JLvhN8lDQthwIYnSLVlPmY1Wgyatw==";
  10. // Use this for initialization
  11. void Start()
  12. {
  13. LuaEnv luaenv = new LuaEnv();
  14. #if UNITY_EDITOR
  15. luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, (ref string filepath) =>
  16. {
  17. filepath = Application.dataPath + "/XLua/Examples/10_SignatureLoader/" + filepath.Replace('.', '/') + ".lua";
  18. if (File.Exists(filepath))
  19. {
  20. return File.ReadAllBytes(filepath);
  21. }
  22. else
  23. {
  24. return null;
  25. }
  26. }));
  27. #else //为了让手机也能测试
  28. luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, (ref string filepath) =>
  29. {
  30. filepath = filepath.Replace('.', '/') + ".lua";
  31. TextAsset file = (TextAsset)Resources.Load(filepath);
  32. if (file != null)
  33. {
  34. return file.bytes;
  35. }
  36. else
  37. {
  38. return null;
  39. }
  40. }));
  41. #endif
  42. luaenv.DoString(@"
  43. require 'signatured1'
  44. require 'signatured2'
  45. ");
  46. luaenv.Dispose();
  47. }
  48. // Update is called once per frame
  49. void Update()
  50. {
  51. }
  52. }
  53. }