1. * created by shenjun
    2. */
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using XLua;
    7. namespace shenjun
    8. {
    9. [LuaCallCSharp]
    10. public class Coroutine : MonoBehaviour {
    11. LuaEnv luaEnv = new LuaEnv();
    12. void Start () {
    13. luaEnv.DoString("require 'LuaCoroutine'");
    14. System.Action luaStart = luaEnv.Global.Get<System.Action>("Start");
    15. if (null != luaStart)
    16. luaStart();
    17. }
    18. void Update () {
    19. }
    20. private void OnDestroy()
    21. {
    22. luaEnv.Dispose();
    23. }
    24. public void InvokeSpawn(object yield_return, System.Action callback)
    25. {
    26. StartCoroutine(SpawnObj(yield_return, callback));
    27. }
    28. IEnumerator SpawnObj(object yield_return, System.Action callback)
    29. {
    30. for (int i = 0; i < 10; i++)
    31. {
    32. GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    33. go.transform.position = Random.insideUnitSphere * 5;
    34. if(yield_return is IEnumerator)
    35. {
    36. else
    37. {
    38. yield return yield_return;
    39. }
    40. }
    41. callback();
    42. }
    43. }
    44. [LuaCallCSharp]
    45. public static class CoroutineConfig
    46. {
    47. public static List<System.Type> LuaCallCSharp
    48. {
    49. get{
    50. return new List<System.Type>()
    51. {
    52. typeof(WaitForSeconds)
    53. };
    54. }
    55. }
    56. }