示例#1
0
        public void AddScript(LuaScript scriptData, bool invokeStart = false)
        {
            var script = this.luaScript.script;

            script.Globals.Set("entity", UserData.Create(entityObj));
            script.Globals["anim"] = new Anim(GetComponent <Animator> ());
            script.ApplyDefaultValues();

            script.DoString(scriptData.code);

            if (scriptData.properties != null)
            {
                ScriptUtility.ApplyProperties(script, scriptData.properties);
            }

            var luaScript = new LuaScript {
                id         = Id.ToUInt(),
                code       = scriptData.code,
                script     = script,
                properties = ScriptUtility.ExtractProperties(script)
            };

            this.luaScript = luaScript;

            if (invokeStart)
            {
                script.CallFunction("start");
            }
        }
示例#2
0
        /// <summary>
        /// Adds a script to the entity
        /// </summary>
        /// <param name="scriptData">The script data to insert</param>
        /// <param name="invokeStart">Should start() be called after the script is initialized?</param>
        public void AddScript(ScriptData scriptData, bool invokeStart = false)
        {
            var script = this.luaScript.script;

            script.Globals.Set("entity", UserData.Create(entityObj));
            script.Globals["anim"] = new Anim(GetComponent <Animator> ());
            script.ApplyDefaultValues();

            script.DoString(scriptData.script);

            var luaScript = new LuaScript {
                id         = (uint)scriptData.id,
                code       = scriptData.script,
                script     = script,
                properties = ScriptUtility.ExtractProperties(script),
            };

            this.luaScript = luaScript;

            if (invokeStart)
            {
                script.CallFunction("start");
            }
        }