示例#1
0
    public static void BuildFileIndex()
    {
        string resPath = (ResourcePath.GetBaseURL() + UUtility.GetPlatformName() + "/").Remove(0, 7);
        ///----------------------创建文件列表-----------------------
        string newFilePath = resPath + "files.txt";

        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        paths.Clear(); files.Clear();
        Recursive(resPath);

        FileStream   fs = new FileStream(newFilePath, FileMode.CreateNew);
        StreamWriter sw = new StreamWriter(fs);

        for (int i = 0; i < files.Count; i++)
        {
            string file = files[i];
            string ext  = Path.GetExtension(file);
            if (file.EndsWith(".meta") || file.Contains(".DS_Store") || file.Contains(".exe"))
            {
                continue;
            }

            string md5   = LuaUtil.md5file(file);
            string value = file.Replace(resPath, string.Empty);
            sw.WriteLine(value + "|" + md5 + "|" + filesLength[i]);
        }
        sw.Close(); fs.Close();
    }
示例#2
0
        public void LetterCustom(object label, object message, string letterdef)
        {
            var letDef = DefDatabase <LetterDef> .GetNamedSilentFail(letterdef);

            if (letDef == null)
            {
                LuaUtil.ThrowLuaScriptError(Parent, "invalid letter def");
            }
        }
示例#3
0
 public void BeginTestCase_CallsApi()
 {
     Expect.Once.MethodCall(() => apiBridge.BeginTestCase("SimpleHarness", "Mutagen.LuaFrontend.Test.dll"));
     Expect.Once.MethodCall(() => apiBridge.TestHarness()).Returns(new SimpleHarness());
     ReadScript("./LuaScripts/BeginTestCase.lua");
     LuaUtil.PublishObjectMethods(api, luaEnv);
     luaEnv.DoChunk(scriptChunk);
     AssertInvocationsWasMade.MatchingExpectationsFor(apiBridge);
 }
示例#4
0
        public void CallTo_AddFacette_CallsApi()
        {
            Expect.Once.MethodCall(() => apiBridge.AddFacette("fnord", 1, 7));

            ReadScript("./LuaScripts/AddFacette.lua");
            LuaUtil.PublishObjectMethods(api, luaEnv);
            luaEnv.DoChunk(scriptChunk);

            AssertInvocationsWasMade.MatchingExpectationsFor(apiBridge);
        }
示例#5
0
        public void CallTo_CreateFacette_CallsApi()
        {
            Expect.Once.MethodCall(() => apiBridge.CreateFacette("facName", Any <System.Collections.Generic.List <object> > .Value));

            ReadScript("./LuaScripts/CreateFacette.lua");
            LuaUtil.PublishObjectMethods(api, luaEnv);
            luaEnv.DoChunk(scriptChunk);

            AssertInvocationsWasMade.MatchingExpectationsFor(apiBridge);
        }
示例#6
0
    /// <summary>
    /// 资源初始化结束
    /// </summary>
    public void OnResourceInited()
    {
        LuaManager.CreateInstance();
        string url   = LuaUtil.GetRelativePath();
        int    index = url.LastIndexOf("/");

        AssetManager.BaseDownloadingURL = url.Substring(0, index);
        m_openLoginUI = true;

        InitManager();
    }
示例#7
0
        public void CallTo_EndTestCase_CallsApi()
        {
            Expect.Once.MethodCall(() => apiBridge.CommitTestCaseCode(Any <IAssertable> .Value.Matching(x => x != null).AsInterface));

            api.LuaEnv = luaEnv;
            ReadScript("./LuaScripts/EndTestCase.lua");
            LuaUtil.PublishObjectMethods(api, luaEnv);
            luaEnv.DoChunk(scriptChunk);

            AssertInvocationsWasMade.MatchingExpectationsFor(apiBridge);
        }
示例#8
0
        private void checkCallLua(string notificationName, object body)
        {
            List <LuaMvcStruct> lms = LuaUtil.getLusMvcOperate(notificationName);

            if (lms != null)
            {
                for (int i = 0; i < lms.Count; i++)
                {
                    lms[i].luaFun.Call(body);
                }
            }
        }
示例#9
0
        public void BeginTestCase_MakesTestharnessAvailableToScript()
        {
            var myHarness = new SimpleHarness();

            Expect.Once.MethodCall(() => apiBridge.BeginTestCase("SimpleHarness", "Mutagen.LuaFrontend.Test.dll"));
            Expect.Once.MethodCall(() => apiBridge.TestHarness()).Returns(myHarness);
            ReadScript("./LuaScripts/BeginTestCase_UseHarness.lua");
            LuaUtil.PublishObjectMethods(api, luaEnv);
            luaEnv.DoChunk(scriptChunk);
            AssertInvocationsWasMade.MatchingExpectationsFor(apiBridge);
            Assert.AreEqual(myHarness.lastPrint, "Test");
        }
示例#10
0
        public void Execute_CanCallToOtherObject()
        {
            AssertWidget w = new AssertWidget();

            ReadScript("./LuaScripts/Assertable_CallOtherObject.lua");
            var ass = new LuaAssertable(luaEnv);

            LuaUtil.PublishObjectMethods(w, luaEnv);
            var res = ass.Execute();

            Assert.AreEqual(2, res.Count);
            Assert.AreEqual(false, res[0].result);
            Assert.AreEqual(true, res[1].result);
        }
示例#11
0
    public static void EncodeLuaFile(string srcFile, string outFile)
    {
        if (!srcFile.ToLower().EndsWith(".lua"))
        {
            File.Copy(srcFile, outFile, true);
            return;
        }
        bool   isWin   = true;
        string luaexe  = string.Empty;
        string args    = string.Empty;
        string exedir  = string.Empty;
        string currDir = Directory.GetCurrentDirectory();

        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            isWin  = true;
            luaexe = "luajit.exe";
            args   = "-b " + srcFile + " " + outFile;
            exedir = AppDataPath.Replace("assets", "") + "LuaEncoder/luajit/";
        }
        else if (Application.platform == RuntimePlatform.OSXEditor)
        {
            isWin  = false;
            luaexe = "./luac";
            args   = "-o " + outFile + " " + srcFile;
            exedir = AppDataPath.Replace("assets", "") + "LuaEncoder/luavm/";
        }
        Directory.SetCurrentDirectory(exedir);
        ProcessStartInfo info = new ProcessStartInfo();

        info.FileName        = luaexe;
        info.Arguments       = args;
        info.WindowStyle     = ProcessWindowStyle.Hidden;
        info.ErrorDialog     = true;
        info.UseShellExecute = isWin;
        LuaUtil.Log(info.FileName + " " + info.Arguments);

        Process pro = Process.Start(info);

        pro.WaitForExit();
        Directory.SetCurrentDirectory(currDir);
    }
示例#12
0
    public static void RegisterWrapper(bool isUpdate)
    {
        //Debug.Log("RegisterWrapper begin");
        LuaState lua_ = LuaInstance.instance.Get();

        if (isUpdate)
        {
            LuaNTools.RegisterToLua(lua_, typeof(LuaNTools));
        }
        else
        {
            LuaVector3.RegisterToLua(lua_, typeof(LuaVector3));
            LuaQuaternion.RegisterToLua(lua_, typeof(LuaQuaternion));
            LuaColor.RegisterToLua(lua_, typeof(LuaColor));
            LuaNTools.RegisterToLua(lua_, typeof(LuaNTools));
            LuaNetwork.RegisterToLua(lua_, typeof(LuaNetwork));
            LuaLong.RegisterToLua(lua_, typeof(LuaLong));
            LuaDateTime.RegisterToLua(lua_, typeof(LuaDateTime));
            LuaUtil.RegisterToLua(lua_, typeof(LuaUtil));
            LuaClassFactory.RegisterToLua(lua_, typeof(LuaClassFactory));
        }

        //Debug.Log("RegisterWrapper end");
    }
示例#13
0
    public static void GenAutoComplete()
    {
        s_api = new LuaApi();
        s_apiIdx.Clear();
        s_apiTypeIdx.Clear();

        //收集要生成的类
        List <ToLuaMenu.BindType> btList = new List <ToLuaMenu.BindType>();

        allTypes.Clear();
        ToLuaExport.allTypes.Clear();
        ToLuaExport.allTypes.AddRange(ToLuaMenu.baseType);
        ToLuaExport.allTypes.AddRange(CustomSettings.staticClassTypes);
        for (int i = 0; i < ToLuaExport.allTypes.Count; i++)
        {
            btList.Add(new ToLuaMenu.BindType(ToLuaExport.allTypes[i]));
        }
        foreach (var bt in CustomSettings.customTypeList)
        {
            if (ToLuaExport.allTypes.Contains(bt.type))
            {
                continue;
            }
            ToLuaExport.allTypes.Add(bt.type);
            btList.Add(bt);
        }
        GenBindTypes(btList.ToArray(), false);
        foreach (var bt in allTypes)//做最后的检查,进一步排除一些类
        {
            if (bt.type.IsInterface && bt.type != typeof(System.Collections.IEnumerator))
            {
                continue;
            }
            s_apiTypeIdx[bt.type] = bt;
        }
        //一些类需要手动加
        {
            ToLuaMenu.BindType bt = new ToLuaMenu.BindType(typeof(Array));
            s_apiTypeIdx[bt.type] = bt;
            GetClassApi("System.Collections.IEnumerable").AddMethod("GetEnumerator", "()", "System.Collections.IEnumerator", "System.Collections.IEnumerator");
        }


        //生成信息
        foreach (var bt in s_apiTypeIdx.Values)
        {
            GenApi(bt);
        }

        //信息转lua类文件
        ToLuaExport.allTypes.Clear();
        string s;

        if (!LuaUtil.TryToLua(s_api.childs, out s))
        {
            return;
        }
        s = "return " + s;
        string path = LuaConst.zbsDir;

        path = path.Replace("lualibs/mobdebug", "api/lua/gameApiGen.lua");
        System.IO.File.WriteAllText(path, s, System.Text.Encoding.UTF8);
        Debug.Log("生成自动提示文件成功:" + path);
    }
示例#14
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     LuaUtil.CallFunc("Player.CheckCollision", other);
 }
示例#15
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     LuaUtil.CallFunc("Player.CheckCollision", other);
 }
示例#16
0
 private void Update()
 {
     LuaUtil.CallFunc("Player.Update");
 }
示例#17
0
 private void Start()
 {
     LuaUtil.ToLua("Player");
     LuaUtil.CallFunc("Player.Start", gameObject, Speed, JumpForce, Club);
 }
示例#18
0
 void Awake()
 {
     LuaUtil.ToLua("Main");
     LuaUtil.CallFunc("Init", Win, Lose, GroundType1, GroundType2, GroundType3, Flag, MapLength, BarMask);
 }
示例#19
0
文件: Env.cs 项目: DDininD/Level0
 private void Start()
 {
     LuaUtil.ToLua("Env");
     LuaUtil.CallFunc("Env.InitEnv", gameObject);
     LuaUtil.CallFunc("Env.GenStage");
 }
示例#20
0
文件: Club.cs 项目: DDininD/Level0
 void Start()
 {
     LuaUtil.ToLua("Club");
     LuaUtil.CallFunc("Club.Start", gameObject);
 }
示例#21
0
    /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
    /// </summary>
    IEnumerator <object> OnUpdateResource(System.Action Complete)
    {
        //if (!Define.UpdateMode)
        //{
        //    OnResourceInited();
        //    yield break;
        //}
        if (!GameProxy.Instance.m_IsStart)
        {
            yield return(null);
        }

        TotalUpdateLength = 0;

        string dataPath = LuaUtil.DataPath;              //数据目录
        string url      = AssetManager.BaseDownloadingURL + "/";
        string message  = string.Empty;
        string random   = DateTime.Now.ToString("yyyymmddhhmmss");
        string listUrl  = url + "files.txt?v=" + random;

        if (!Define.UpdateMode)
        {
            Debug.LogWarning("LoadUpdate---->>>" + listUrl);
        }

        WWW www = new WWW(listUrl); yield return(www);

        if (www.error != null)
        {
            OnUpdateFailed(string.Empty);
            yield break;
        }
        if (!Directory.Exists(dataPath))
        {
            Directory.CreateDirectory(dataPath);
        }
        File.WriteAllBytes(dataPath + "files.txt", www.bytes);
        string filesText = www.text;

        string[]      files            = filesText.Split('\n');
        List <string> loaderFiles      = new List <string>();
        List <string> loaderLocalFiles = new List <string>();

        for (int i = 0; i < files.Length; i++)
        {
            if (string.IsNullOrEmpty(files[i]))
            {
                continue;
            }
            string[] keyValue  = files[i].Split('|');
            string   f         = keyValue[0];
            string   localfile = (dataPath + f).Trim();
            string   path      = Path.GetDirectoryName(localfile);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            //string fileUrl = url + f + "?v=" + random;
            string fileUrl   = url + f;
            bool   canUpdate = !File.Exists(localfile);
            if (!canUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = LuaUtil.md5file(localfile);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfile);
                }
            }
            if (canUpdate)
            {   //本地缺少文件
                if (!Define.UpdateMode)
                {
                    Debug.Log(fileUrl);
                }
                TotalUpdateLength += int.Parse(keyValue[2]);

                loaderFiles.Add(fileUrl);
                loaderLocalFiles.Add(localfile);
            }
        }

        int cnt = loaderFiles.Count;

        for (int i = 0; i < cnt; i++)
        {
            string fileUrl   = loaderFiles[i];
            string localfile = loaderLocalFiles[i];
            message = "downloading>>" + fileUrl;
            Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

            BeginDownload(fileUrl, localfile);

            while (!(IsDownOK(localfile)))
            {
                yield return(new WaitForEndOfFrame());
            }
        }

        yield return(new WaitForEndOfFrame());

        message    = "更新完成!!";
        loadingstr = message;

        string curl  = LuaUtil.GetRelativePath();
        int    index = curl.LastIndexOf("/");

        AssetManager.BaseDownloadingURL = curl.Substring(0, index);
        m_openLoginUI = true;

        Complete();
        GameProxy.Instance.Init_TextManager();
        Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

        OnResourceInited();
    }
示例#22
0
    public IEnumerator <object> OnExtractResource()
    {
        string dataPath = LuaUtil.DataPath;         //数据目录
        string resPath  = LuaUtil.AppContentPath(); //游戏包资源目录

        if (Directory.Exists(dataPath))
        {
            Directory.Delete(dataPath, true);
        }
        Directory.CreateDirectory(dataPath);

        string infile  = resPath + "files.txt";
        string outfile = dataPath + "files.txt";

        if (File.Exists(outfile))
        {
            File.Delete(outfile);
        }

        string message = "正在解包文件:>files.txt";

        if (!Define.UpdateMode)
        {
            Debug.Log(infile);
            Debug.Log(outfile);
        }

        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(infile);
            yield return(www);

            if (www.isDone)
            {
                File.WriteAllBytes(outfile, www.bytes);
            }
            yield return(0);
        }
        else
        {
            File.Copy(infile, outfile, true);
        }
        yield return(new WaitForEndOfFrame());

        //释放所有文件到数据目录
        string[] files = File.ReadAllLines(outfile);
        foreach (var file in files)
        {
            string[] fs = file.Split('|');
            infile  = resPath + fs[0]; //
            outfile = dataPath + fs[0];

            message = "正在解包文件:>" + fs[0];

            if (!Define.UpdateMode)
            {
                Debug.Log("正在解包文件:>" + infile);
            }

            loadingstr = message;
            Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

            string dir = Path.GetDirectoryName(outfile);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(0);
            }
            else
            {
                if (File.Exists(outfile))
                {
                    File.Delete(outfile);
                }
                File.Copy(infile, outfile, true);
            }
            yield return(new WaitForEndOfFrame());
        }
        message    = "解包完成!!!";
        loadingstr = message;
        Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);
        yield return(new WaitForSeconds(0.1f));

        message = string.Empty;

        //释放完成,开始启动更新资源
        StartCoroutine(OnUpdateResource(OnComplete_UpdateResource));
    }
示例#23
0
文件: Club.cs 项目: DDininD/Level0
 void Update()
 {
     LuaUtil.CallFunc("Club.Update");
 }