Ejemplo n.º 1
0
        /// <summary>
        /// Loads script through resources + executes.
        /// </summary>
        /// <param name="scriptName"></param>
        private JsValue Require(string scriptName)
        {
            if (null == Loader)
            {
                return(JsValue.Undefined);
            }

            string script;

            if (!Loader.Load(scriptName, out script))
            {
                return(JsValue.Undefined);
            }

            // modularize it
            var variableName = "require" + _ids++;
            var moduleCode   = REQUIRE_TEMPLATE
                               .Replace("{{script}}", script)
                               .Replace("{{variableName}}", variableName);

            JsValue module;

            try
            {
                Execute(moduleCode);
                module = GetValue(variableName);
            }
            catch (Exception exception)
            {
                Debug.LogError(exception.Message);

                return(JsValue.Undefined);
            }

            return(module);
        }