Exemple #1
0
        /// <summary>
        /// Downloads a series of scripts from the internet
        /// </summary>
        /// <param name="url">The url of the script manifest</param>
        /// <param name="urlPrefix">The root url</param>
        /// <param name="onScriptDownload">The event where a script was downloaded</param>
        /// <param name="onComplete">The event called when the entire process is complete</param>
        internal static void DownloadScripts(string url, string urlPrefix, Action <ScriptData> onScriptDownload, Action onComplete)
        {
            var www     = UnityWebRequest.Get(url);
            var handler = new DownloadHandlerBuffer();

            www.downloadHandler = handler;
            var op = www.SendWebRequest();

            op.completed += c => {
                var json          = JsonMapper.ToObject(handler.text);
                var array         = json[0];
                var downloadQueue = new DownloadQueue();

                for (var i = 0; i < array.Count; ++i)
                {
                    var datum = array[i];

                    var scriptData = new ScriptData {
                        id   = (uint)datum["id"],
                        name = datum["name"].GetString()
                    };

                    var scriptUrl = string.Format("{0}{1}", urlPrefix, datum["asset-path"]);
                    downloadQueue.Enqueue(new Tuple <ScriptData, string> (scriptData, scriptUrl));
                }

                ProcessDownloadQueue(downloadQueue, onScriptDownload, onComplete);
            };
        }
Exemple #2
0
        private void HandleAddScriptEvent(string script)
        {
            var scriptData = new ScriptData {
                name   = "Custom Script",
                script = script
            };

            AddScript(scriptData, true);
        }
Exemple #3
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");
            }
        }