SignatureLoader

SignatureLoaderTest.cs

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