public static Script CreateScriptRuntime(LuaScriptHost host) { host.CoroutineManager = new LuaCoroutineManager(host); var script = new Script(CoreModules.Preset_Default | CoreModules.Debug); script.Options.UseLuaErrorLocations = false; script.Globals["_host"] = host; script.Globals["console"] = typeof(LuaRuntime.Console); script.Globals["scene"] = new SceneHost(); script.Globals["resources"] = new ResourcesHost(); script.Globals["game"] = new GameHost(host); script.Globals["vec2"] = (Func <float, float, Vector2>)MathUtilities.vec2; script.Globals["vec3"] = (Func <float, float, float, Vector3>)MathUtilities.vec3; var utility = new UtilityHost(host); script.Globals["timeout"] = (Func <Closure, float, int>)utility.SetTimeout; script.Globals["interval"] = (Func <Closure, float, int>)utility.Interval; script.Globals["removeTimeout"] = (Action <int>)utility.RemoveTimeout; script.Globals["removeInterval"] = (Action <int>)utility.RemoveInterval; script.Globals["waitForSeconds"] = (Func <float, YieldInstruction>)utility.WaitForSeconds; script.Globals["Time"] = typeof(Time); script.Globals["timer"] = (Func <float, IEnumerable <float> >)Utility.Timer; script.Globals["entity"] = host.GetComponent <GameEntity>(); script.Globals["startCoroutine"] = (Func <Closure, UnityEngine.Coroutine>)host.CoroutineManager.StartCoroutine; script.Globals["stopCoroutine"] = (Action <UnityEngine.Coroutine>)host.CoroutineManager.StopCoroutine; script.Globals["utility"] = utility; script.Globals["camera"] = SceneCamera.Instance; script.Globals["wait"] = (Func <string, UnityEngine.Coroutine>)((t) => host.StartCoroutine(Wait(host, t))); script.Globals["sign"] = (Func <float, int>)MathUtility.SignInt; GUIHost.InitHost(host, script); return(script); }
static IEnumerator Wait(LuaScriptHost host, string t) { float time; var entity = host.GetComponent <GameEntity>(); if (float.TryParse(t, out time)) { yield return(new WaitForSeconds(time)); } else if (entity) { switch (t) { case "skill": yield return(entity.GetComponent <SkillController>().WaitSkill()); break; case "animation": case "animate": case "anim": case "action": yield return(entity.GetComponent <AnimationController>().WaitAnimation()); break; } } }
public override void InitRuntime() { LuaScript = new Script(); UserData.RegisterAssembly(); UserData.RegisterType <Vector3>(); UserData.RegisterType <Vector2>(); LuaScriptHost.EnableConsole(LuaScript); ResourcesHost.AddHost(LuaScript); UserData.RegisterProxyType <InventoryHost.ItemProxy, Inventory.Item>(item => new InventoryHost.ItemProxy(item, this)); UserData.RegisterProxyType <InventoryHost.RecipeProxy, Inventory.Recipe>(obj => new InventoryHost.RecipeProxy(obj, this)); LuaScript.Globals["RecipeType"] = typeof(InventoryHost.RecipeProxy); }
public LuaCoroutineManager(LuaScriptHost host) { Host = host; }
protected HostBase(LuaScriptHost host) { this.host = host; }
public GameHost(LuaScriptHost host) : base(host) { }
public Promise(Action <Action> executor, LuaScriptHost host) { this.executor = executor; host.StartCoroutine(Execute()); }
protected GUIHost(LuaScriptHost host) : base(host) { }
public static void InitHost(LuaScriptHost host, Script script) { script.Globals["gui"] = new GUIHost(host); UserData.RegisterProxyType <Proxy.UIPanelProxy <SkillPanel>, SkillPanel>(obj => new Proxy.UIPanelProxy <SkillPanel>(obj, host)); }