Example #1
0
        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);
        }
Example #2
0
        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;
                }
            }
        }
Example #3
0
 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);
 }
Example #4
0
 public LuaCoroutineManager(LuaScriptHost host)
 {
     Host = host;
 }
Example #5
0
 protected HostBase(LuaScriptHost host)
 {
     this.host = host;
 }
Example #6
0
 public GameHost(LuaScriptHost host) : base(host)
 {
 }
Example #7
0
 public Promise(Action <Action> executor, LuaScriptHost host)
 {
     this.executor = executor;
     host.StartCoroutine(Execute());
 }
Example #8
0
 protected GUIHost(LuaScriptHost host) : base(host)
 {
 }
Example #9
0
 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));
 }