Beispiel #1
0
    public void DoFile(string filename, bool checkContain = true)
    {
        if (checkContain)
        {
            if (code_.Contains(filename))
            {
                return;
            }
            code_.Add(filename);
        }

#if UNITY_EDITOR || UNITY_STANDALONE
#if ASSETBUNDLE || LKFILE
        string path = filename.Replace('\\', '/');
#else
        string path = Application.streamingAssetsPath + "/Script/" + filename;
        filename = path.Replace('/', '\\');
#endif
#elif UNITY_ANDROID || UNITY_IPHONE
#if ASSETBUNDLE || LKFILE
        string path = filename.Replace('\\', '/');
#else
        string path = PluginTool.SharedInstance().PersisitentDataPath + "Script/" + filename;
        path = path.Replace('\\', '/');
#endif
#endif
        lua_.L_DoFile(path);
    }
Beispiel #2
0
    void FirstUnzip()
    {
        string persisitentDataPath = PluginTool.SharedInstance().PersisitentDataPath;

        if (!Directory.Exists(persisitentDataPath))
        {
            if (!Directory.Exists(persisitentDataPath))
            {
                Directory.CreateDirectory(persisitentDataPath);
            }
        }


#if  UNITY_ANDROID
#if  ASSETBUNDLE
        // 这儿本意是想要拷贝一份small资源出来放在assets/temp目录下
        PluginTool.SharedInstance().CopyAssetFromPackageToSdcard("temp/data", persisitentDataPath);
        PluginTool.SharedInstance().CopyAssetFromPackageToSdcard("temp/index", persisitentDataPath);
        PluginTool.SharedInstance().CopyAssetFromPackageToSdcard("temp/fragment", persisitentDataPath);

        StartLua(true);
#else
        string path = "jar:file://" + Application.dataPath + "!/assets/" + "StreamingFile.txt";
        StartCoroutine(EasyDownload(path, (www) =>
        {
            string text = www.text;
            www.Dispose();
            CopyAssetToSdcard(text, persisitentDataPath);
        }));
#endif
#else
        StartLua(true);
#endif
    }
Beispiel #3
0
    public static string GetStreamPath()
    {
        string filePath = null;

#if  UNITY_ANDROID
        filePath = PluginTool.SharedInstance().PersisitentDataPath;
#else
        filePath = Application.streamingAssetsPath + "/";
#endif
        return(filePath);
    }
Beispiel #4
0
    string GetClientVersion()
    {
        string path = Path.Combine(PluginTool.SharedInstance().PersisitentDataPath, "ClientVersion.txt");

        if (!File.Exists(path))
        {
            return(null);
        }
        StreamReader sr = new StreamReader(path);

        return(sr.ReadToEnd());
    }
Beispiel #5
0
    public bool ExistsBackupIndex()
    {
        string path = Path.Combine(PluginTool.SharedInstance().PersisitentDataPath, "index1");
        string clientVersionPath = Path.Combine(PluginTool.SharedInstance().PersisitentDataPath, "ClientVersion.txt");

        if (File.Exists(path))
        {
            File.Delete(clientVersionPath);
            File.Delete(path);
            return(true);
        }
        return(false);
    }
Beispiel #6
0
    void HandleLog(string logString, string stackTrace, LogType type)
    {
        if (type == LogType.Error || type == LogType.Exception)
        {
            string md5str = HashSecurity.Encrypt(logString + stackTrace);
            if (m_logList.Contains(md5str) == false)
            {
                string platform = "win";
#if UNITY_IPHONE
                platform = "ios";
#elif UNITY_ANDROID
                platform = "android";
#endif
                PluginTool pluginTools = PluginTool.SharedInstance();
                string     gameId      = pluginTools.GetPlatformConfig(PluginTool.GAMEID_KEY, "0");
                string     userIdStr   = PlayerPrefsEx.GetString("userId");
                long       userId      = 0;
                if (!string.IsNullOrEmpty(userIdStr))
                {
                    userId = long.Parse(userIdStr);
                }
                long   roleId   = 0;
                string roleName = "";

                LuaState lua = LuaInstance.instance.Get();
                lua.GetGlobal("Client");
                lua.GetField(-1, "RoleInfo");
                if (!lua.IsNil(-1))
                {
                    lua.GetField(-1, "RoleID");
                    roleId = lua.ToInteger(-1);
                    lua.Pop(1);
                    lua.GetField(-1, "RoleName");
                    roleName = lua.ToString(-1);
                    lua.Pop(1);
                }
                lua.Pop(1);
                lua.GetField(-1, "ClientVersion");
                string version = lua.ToString(-1);
                lua.Pop(2);

                string request = string.Format("{0}?GameID={1}&PlayerID={2}&RoleId={3}&logString={4}&StackTrace={5}&LogType={6}&RoleName={7}&platform={8}&servernum={9}&gateway_id={10}&machine={11}&version={12}&GameName={13}",
                                               PluginTool.SharedInstance().logUrl, gameId, userId, roleId, System.Uri.EscapeDataString(logString), System.Uri.EscapeDataString(stackTrace), System.Uri.EscapeDataString(type.ToString()),
                                               System.Uri.EscapeDataString(roleName), platform, PlayerPrefs.GetInt("lastServerNum", 0),
                                               PlayerPrefs.GetInt("lastServerID", 0), SystemInfo.deviceModel, version, "hzmj");

                PluginTool.SharedInstance().logStr = request;
                StartCoroutine(SendException(request, md5str));
            }
        }
    }
Beispiel #7
0
    public void Unzip(string path, string unzipSuccess, string upzipProgress, string unzipError)
    {
        string   persisitentDataPath = PluginTool.SharedInstance().PersisitentDataPath;
        LuaState lua = LuaInstance.instance.Get();

        if (!File.Exists(path))
        {
            lua.LuaFuncCall(mupdateBehaviour.Object_ref, unzipError);
            return;
        }
        unZipInfo = new LKUnZipInfo();
        unZipInfo.unZip.ExcuteUnzip(path, persisitentDataPath);
        unZipInfo.unzipSuccess  = unzipSuccess;
        unZipInfo.unzipError    = unzipError;
        unZipInfo.upzipProgress = upzipProgress;
    }
Beispiel #8
0
    void CopyAssetToSdcard(string text, string destPath)
    {
        string[] lines = text.Split(new char[] { '\n' });
        for (int i = 0; i < lines.Length; ++i)
        {
            string line = lines[i];
            line = line.Replace("\n", "");
            line = line.Trim();
            if (!string.IsNullOrEmpty(line))
            {
                PluginTool.SharedInstance().CopyAssetFromPackageToSdcard(line, destPath);
            }
        }

        StartLua(true);
    }
Beispiel #9
0
    private static void InitPath()
    {
#if UNITY_EDITOR
        data_path_         = Application.dataPath;
        assetbundles_path_ = data_path_.Substring(0, data_path_.Length - "Assets".Length) + "AssetBundles/";
        data_path_         = data_path_.Substring(0, data_path_.Length - "Assets".Length) + "Dest/";
#elif UNITY_STANDALONE_WIN
        data_path_         = Application.dataPath;
        data_path_         = data_path_.Substring(0, data_path_.LastIndexOf("/") + 1);
        assetbundles_path_ = data_path_ + "AssetBundles/";
#elif UNITY_ANDROID || UNITY_IPHONE
        data_path_         = PluginTool.SharedInstance().PersisitentDataPath;
        assetbundles_path_ = data_path_ + "AssetBundles/";
#endif
        Debug.Log("data_path:" + data_path_);
        //Debug.Log("assetbundles_path:" + assetbundles_path_);
    }
Beispiel #10
0
    public void Init(bool isUpdate = false)
    {
#if UNITY_ANDROID || UNITY_IPHONE
        instance_.luaRootPath = PluginTool.SharedInstance().PersisitentDataPath + "Script/?.txt";
#elif UNITY_EDITOR || UNITY_STANDALONE
        instance_.luaRootPath = Application.streamingAssetsPath + "/Script/?.txt";
#endif

        LuaState lua = instance_.Get();
        lua.GetGlobal("package");
        lua.PushString(instance_.luaRootPath);
        lua.SetField(-2, "path");
        lua.Pop(1);

#if UNITY_ANDROID || UNITY_IPHONE
        lua.PushBoolean(false);
        lua.SetGlobal("IS_PLATFORM_DEBUG");
#elif UNITY_EDITOR || UNITY_STANDALONE
        lua.PushBoolean(true);
        lua.SetGlobal("IS_PLATFORM_DEBUG");
#endif
        Debug.Log("Init 11111111111111111");
        if (isUpdate)
        {
            instance_.DoFile("UpdateUI/UpdateRegisterClass.txt");
        }
        else
        {
            instance_.DoFile("Utils/RegisterClass.txt");
        }

        Debug.Log("Init 22222222222222222");
#if UNITY_EDITOR || UNITY_STANDALONE
        Register.PrintLuaClassList();
#endif
        //cache most use table ref
        lua.GetGlobal("Text");
        text_table_ref = lua.L_Ref(LuaAPI.LUA_REGISTRYINDEX);
        lua.GetGlobal("table");
        table_table_ref = lua.L_Ref(LuaAPI.LUA_REGISTRYINDEX);
        lua.GetGlobal("Client");
        client_table_ref = lua.L_Ref(LuaAPI.LUA_REGISTRYINDEX);
    }
Beispiel #11
0
    void Start()
    {
#if UNITY_STANDALONE_WIN
        if (!PluginTool.SharedInstance().Init())
        {
            Debug.LogError("PluginTool Init error!");
        }
        StreamReader sr = new StreamReader(Path.Combine(Application.streamingAssetsPath, "platformconfig"));
        platformCfg = sr.ReadToEnd();
        sr.Close();
        StartLua(false);
#else
        if (!PluginTool.SharedInstance().Init())
        {
            Debug.LogError("PluginTool Init error!");
        }
        GetPlatformCfg();
#endif
    }
Beispiel #12
0
    void StartLua(bool onlyRead)
    {
        InstanceGlobalUpdate();
        if (!IsInit)
        {
            if (onlyRead)
            {
#if UNITY_ANDROID
                ResLoader.InitStreamingAssetsPath(PluginTool.SharedInstance().PersisitentDataPath + "temp");
                ResLoader.InitSmallData();
#elif UNITY_IPHONE //|| UNITY_STANDALONE_WIN || UNITY_EDTOR
                UnityEngine.iOS.Device.SetNoBackupFlag(PluginTool.SharedInstance().PersisitentDataPath);
                ResLoader.InitStreamingAssetsPath(Application.streamingAssetsPath);
                ResLoader.Init();
#endif
            }
            else
            {
                IsInit = true;
                ResLoader.InitData();
                ResLoader.Init();
            }


            LuaInstance.instance.Init(true);
            //IsInit = true;
        }

        if (GlobalUpdate.Instance.gameObject.GetComponent <LogSystem>() == null)
        {
            GlobalUpdate.Instance.gameObject.AddComponent <LogSystem>();
            LogSystem.ReInit(PluginTool.SharedInstance().GetClientVersion());
        }

        LuaState lua = LuaInstance.instance.Get();
        lua.L_DoString(platformCfg);
        GameObject updateUI = NGUITools.AddChildByPath("Update/UpdateControl", null);
        mupdateBehaviour = updateUI.GetComponent <LuaBehaviour>();
        lua.RawGetI(LuaAPI.LUA_REGISTRYINDEX, mupdateBehaviour.Object_ref);
        lua.NewClassUserData(this);
        lua.SetField(-2, "UpdateCtr");
    }
    //Init engine setting


    //Init Lua
    void Start()
    {
        if (GlobalUpdate.Instance.gameObject.GetComponent <LogSystem>() == null)
        {
            GlobalUpdate.Instance.gameObject.AddComponent <LogSystem>();
            LogSystem.ReInit(PluginTool.SharedInstance().GetClientVersion());
        }
        GeneratSDKObj();
        GameObject loginUI = NGUITools.AddChildByPath("Login/LoginUIRoot", UIParent);

        mLoginLuaBehav = loginUI.GetComponent <LuaBehaviour>();
        LuaState lua = LuaInstance.instance.Get();

        lua.RawGetI(LuaAPI.LUA_REGISTRYINDEX, mLoginLuaBehav.Object_ref);
        lua.NewClassUserData(this);
        lua.SetField(-2, "ClientInitCtr");
        lua.Pop(1);
        GameObject GameCoreUpdatePrefab = (GameObject)ResLoader.Load("UI/Prefab/NewSceneMustHave/GameCoreUpdate", typeof(GameObject));

        Instantiate(GameCoreUpdatePrefab);

        //init game logic after lua finish init and show the UI
        InitGameLogic();
    }
Beispiel #14
0
 public void StartCopyFullData(string fileInPackage, string destDir)
 {
     PluginTool.SharedInstance().ThreadCopyAssetFromPackageToSdcard(gameObject.name, fileInPackage, destDir);
 }