Exemplo n.º 1
0
 private void InitUi()
 {
     if (abLoading != null)
     {
         GameObject prefab = abLoading.LoadAsset("LoadingView") as GameObject;
         LoadingUI = Instantiate(prefab);
         Scene        scene  = SceneManager.GetActiveScene();
         GameObject[] gos    = scene.GetRootGameObjects();
         Transform    parent = null;
         Camera       camera = null;;
         for (int i = 0; i < gos.Length; i++)
         {
             if (gos[i].name == "LoadingPart")
             {
                 parent = gos[i].transform;
             }
             if (gos[i].name == "MainCamera" || gos[i].name == "Main Camera")
             {
                 camera = gos[i].GetComponent <Camera>();
             }
         }
         Canvas can = LoadingUI.GetComponent <Canvas>();
         can.worldCamera = camera;
         LoadingUI.transform.SetParent(parent);
         LoadingUI.transform.localPosition = Vector3.zero;
         LoadingUI.transform.localRotation = Quaternion.Euler(Vector3.zero);
         LoadingUI.transform.localScale    = Vector3.one;
         LoadingUI.name = "Load";
         FirstUtil.RefreshShaderInEditor(LoadingUI);
         ChangeLayerAll(LoadingUI, gameObject.layer);
         load = LoadingUI.AddComponent <LoadingView>();
     }
 }
Exemplo n.º 2
0
        private static void Send(string recordMsg, int msgType)
        {
            if (string.IsNullOrEmpty(Record_Url))
            {
                return;
            }

            AppPerMonitoring.Inst.apiUrl       = Record_Url;
            AppPerMonitoring.Inst.code         = msgType;
            AppPerMonitoring.Inst.server_id    = 0;
            AppPerMonitoring.Inst.uid          = "0";
            AppPerMonitoring.Inst.code_msg     = recordMsg;
            AppPerMonitoring.Inst.did          = did;
            AppPerMonitoring.Inst.device       = device;
            AppPerMonitoring.Inst.device_name  = device_name;
            AppPerMonitoring.Inst.game_version = game_version;
            AppPerMonitoring.Inst.os           = os;
            AppPerMonitoring.Inst.os_version   = os_version;
            AppPerMonitoring.Inst.Mno          = "";
            AppPerMonitoring.Inst.Nm           = Nm;
            AppPerMonitoring.Inst.f_code       = 7001;
            AppPerMonitoring.Inst.Run();

            FirstUtil.WriteLog(recordMsg);
        }
Exemplo n.º 3
0
 private static void CopyOutTmpFile(List <string> fileList)
 {
     foreach (string path in fileList)
     {
         FirstUtil.CreateFileDirectory(FirstUtil.OutDir + path);
         File.Copy(OutTmpPath + path, FirstUtil.OutDir + path, true);
     }
 }
Exemplo n.º 4
0
        private void InitData()
        {
            string[] arr = FirstUtil.ReadAllLines(outLocalVersion);
            foreach (string line in arr)
            {
                string[] row = line.Split('=');
                if (row.Length < 2)
                {
                    continue;
                }
                string value = row[1].Trim();
                switch (row[0].Trim())
                {
                case "version":
                    FirstUtil.OutVersion = value;
                    break;
                }
            }

            arr = FirstUtil.ReadAllLines(outLocalGameDefine);
            foreach (string line in arr)
            {
                string[] row = line.Split('=');
                if (row.Length < 2)
                {
                    continue;
                }
                string value = row[1].Trim();
                switch (row[0].Trim())
                {
                case "update_url":
#if !UNITY_EDITOR
                    _updateUrl = value;
#endif
                    break;

                case "isAc":
                    _isActiveSDK = value != "FYMM";
                    break;

                case "isShowLog":
                    FirstUtil.IsShowLog = (value == "FYMM");
                    break;

                case "isPlayMovie":
                    _isPlayMovie = int.Parse(value);
                    break;
                }
            }

            if (_isNewApk && _isPlayMovie == 1)
            {
                PlayMovie();
            }
        }
Exemplo n.º 5
0
 static void _ReadFileList(out Dictionary <string, string> dic, string text)
 {
     dic = new Dictionary <string, string>();
     foreach (string line in FirstUtil.ReadAllLines(text))
     {
         string[] row = line.Split('\t');
         if (row.Length == 2)
         {
             dic.Add(row[0], row[1]);
         }
     }
 }
Exemplo n.º 6
0
        //no platform
        private string GetPathNoTarget(string fielName)
        {
            string path = Path.Combine(FirstUtil.OutDir, fielName);

            if (!File.Exists(path))
            {
                path = FirstUtil.GetStreamingAssetsPathNoTarget() + fielName;
            }
            else
            {
                path = "file:///" + path;
            }
            return(path);
        }
Exemplo n.º 7
0
 void parseSizeFile(string text)
 {
     string[] arr = FirstUtil.ReadAllLines(text);
     foreach (string line in arr)
     {
         string[] row = line.Split('\t');
         if (row.Length == 2)
         {
             _fielSizeDic.Add(row[0], int.Parse(row[1]));
         }
         else if (row.Length == 3)
         {
             _fielSizeDic.Add(row[0], int.Parse(row[1]));
         }
     }
 }
Exemplo n.º 8
0
        bool WriteTmpFile(string path, byte[] buf)
        {
#if !UNITY_WEBPLAYER
            try
            {
                string tmpPath = OutTmpPath + path;
                FirstUtil.CreateFileDirectory(tmpPath);
                File.WriteAllBytes(tmpPath, buf);
                WriteLog("WriteTmpFile: {0} ok!", path);
                return(true);
            }
            catch (Exception e)
            {
                Debug.LogException(e);

                FirstRecordMsg.Error("Write Error:" + path + ":::Stack:" + e.StackTrace, MsgType.WriteFileError);
            }
            return(false);
#endif
        }
Exemplo n.º 9
0
        void InitCheck(string txt)
        {
            string[] allLines = FirstUtil.ReadAllLines(txt);
            foreach (string line in allLines)
            {
                string[] row = line.Split(';');
                if (row.Length < 2)
                {
                    if (line.Contains("updateCustomServer"))
                    {
                        string temp = line.Replace("updateCustomServer,", "");
                        var    arr  = temp.Split(',');
                        if (arr.Length > 1)
                        {
                            FirstUtil.NeedToUpdateServerList = new List <int>();
                            for (int i = 1; i < arr.Length; i++)
                            {
                                FirstUtil.NeedToUpdateServerList.Add(int.Parse(arr[i]));
                            }
                            int selectServerId = PlayerPrefs.GetInt(FirstUtil.SelectServerKey, -1);

                            if (FirstUtil.NeedToUpdateServerList.Contains(selectServerId))
                            {
                                _updateUrl            = arr[0]; //替换掉更新url
                                FirstUtil.IsUrlChange = true;
                            }
                        }
                    }
                    continue;
                }

                if (row.Length >= 2)
                {
                    FirstResource.UpdateUrlDic[row[0]] = row[1];
                }
                if (row.Length >= 3)
                {
                    FirstResource.ServerListDic[row[0]] = row[2];
                }
            }
        }
Exemplo n.º 10
0
 //Android alter端返回 0#0   第一个表示传入的alter id  第二个表示 1确定 2,取消
 public void Android_Showalter(string info)
 {
     WriteLog("Android_Showalter" + info);
     string[] infos = info.Split('#');
     if (infos.Length > 1)
     {
         if (infos[0] == "1")
         {
             if (infos[1] == "1")
             {
                 WriteLog("返回确认");
                 FirstUtil.ExitApp();
             }
             else if (infos[1] == "2")
             {
                 WriteLog("返回取消");
                 Debug.Log(FirstUtil.ApkUrl);
                 Application.OpenURL(FirstUtil.ApkUrl);
             }
         }
     }
 }
Exemplo n.º 11
0
 static void WriteLog(string msg, params object[] args)
 {
     FirstUtil.WriteLog("[sdk]" + msg, args);
 }
Exemplo n.º 12
0
        public void ExitCallback()
        {
            WriteLog("ExitCallback()");

            FirstUtil.ExitApp();
        }
Exemplo n.º 13
0
        IEnumerator InitInfos()
        {
            FirstRecordMsg.Init();

            gameObject.AddComponent <FirstPlatform>();

            string path = FirstUtil.GetStreamingAssetsPathNoTarget() + "version.txt";
            WWW    www  = new WWW(path);

            yield return(www);

            localVersion = getWWWTxt(www, false);
            www          = null;

            path = FirstUtil.GetStreamingAssetsPathNoTarget() + "gameDefine.txt";
            www  = new WWW(path);
            yield return(www);

            localGameDefine = getWWWTxt(www, false);
            www             = null;

            path = FirstUtil.GetStreamingAssetsPathNoTarget() + "filelist.txt";
            www  = new WWW(path);
            yield return(www);

            loccalFileList = getWWWTxt(www, false);
            www            = null;

            InitLocalInfo();

            InitOutDir();

            path = GetPathNoTarget("version.txt");
            www  = new WWW(path);
            yield return(www);

            outLocalVersion = getWWWTxt(www);
            www             = null;

            path = GetPathNoTarget("gameDefine.txt");
            www  = new WWW(path);
            yield return(www);

            outLocalGameDefine = getWWWTxt(www);
            www = null;

            path = GetPathNoTarget("filelist.txt");
            www  = new WWW(path);
            yield return(www);

            outloccalFileList = getWWWTxt(www, false);
            www = null;

            path = GetPathNoTarget("FirstLang.txt");
            www  = new WWW(path);
            yield return(www);

            InitLang(getWWWTxt(www, false));
            www = null;

            WriteLog("InitFilstInfo");

            InitData();

            StartCoroutine(CheckUpdate());

            FirstResource.InitAppFileList(loccalFileList);
#if UNITY_EDITOR
            FirstResource.InitSdFileList("");
#else
            FirstResource.InitSdFileList(outloccalFileList);
#endif

            localVersion       = null;
            outLocalVersion    = null;
            localGameDefine    = null;
            outLocalGameDefine = null;
            loccalFileList     = null;
            outloccalFileList  = null;

            StartCoroutine(WorkerUI());
        }
Exemplo n.º 14
0
 void WriteLog(string msg, params object[] args)
 {
     FirstUtil.WriteLog(msg, args);
 }
Exemplo n.º 15
0
        IEnumerator LoadAssetReal(string path)
        {
            if (IsLoadFail)
            {
                yield break;
            }

            if (IsStopUpdate)
            {
                _infoTips = FirstLang.FIRST_MSG_10;
                yield break;
            }

            string fullPath;
            string needCRC = FirstResource.SdFileDic[path];
            string tmpPath = Path.Combine(OutTmpPath, path);

            byte[] buf = null;

#if !UNITY_WEBPLAYER
            if (File.Exists(tmpPath))   // 已经下载过
            {
                buf = File.ReadAllBytes(tmpPath);
                if (FirstUtil.CRC32(buf).ToString("X") == needCRC)   // crc一致
                {
                    //WriteLog("download pass by: {0}", path);

                    HandlerLoadEnd(path);

                    yield break;
                }
            }
#endif

            WriteLog("download file:" + path);
            if (failDic.ContainsKey(path))
            {
                fullPath = loadRootPath + path + "?id=" + (DateTime.Now.ToFileTime() / 10);
            }
            else
            {
                fullPath = loadRootPath + path + "?id=" + needCRC;
            }

            WWW www = new WWW(fullPath);
            loadingDic[path] = www;
            yield return(www);

            RemoveLoading(path);

            if (!string.IsNullOrEmpty(www.error) || !www.isDone)
            {
                string temp = string.Format("{0} download error: {1}", www.url, www.error);
                WriteLog(temp);

                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else
            {
                buf = www.bytes;
                //WriteLog("{0} download ok [{1}]", www.url, buf.Length);
            }

            www.Dispose();
            www = null;

            if (buf == null)
            {
                HandlerLoadEnd(path, 1);

                yield break;
            }

            string crc = FirstUtil.CRC32(buf).ToString("X");
            if (crc == needCRC || path.Contains("Android/Android"))
            {
                if (WriteTmpFile(path, buf))
                {
                    HandlerLoadEnd(path);
                }
                else
                {
                    HandlerLoadEnd(path, 3);
                }
            }
            else
            {
                string temp = string.Format("{0} crc error! down:{1}  need:{2}", path, crc, needCRC);
                WriteLog(temp);
                FirstRecordMsg.Error(temp, MsgType.CrcError);

                HandlerLoadEnd(path, 2);
                yield break;
            }
        }
Exemplo n.º 16
0
 private void OnCancel()
 {
     FirstUtil.ExitApp();
 }
Exemplo n.º 17
0
        IEnumerator WorkerFunction()
        {
            bool test = false;

#if UNITY_EDITOR
            if (test)
            {
                if (load != null)
                {
                    load.ShowAlert(123.45, OnConfirm, OnCancel);
                }
                yield break;
            }
            else
            {
                ProcessPercent = 100;
                _updateOk      = true;
                Debug.Log("下载完成");
                yield break;
            }
#endif
            if (string.IsNullOrEmpty(_updateUrl))
            {
                _updateOk = true;
                yield break;
            }

            yield return(BeginDownLoad(_updateUrl + "check.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2));

            string buf2 = EndDownLoadTxt();
            if (string.IsNullOrEmpty(buf2) == false)
            {
                InitCheck(buf2);
                FirstResource.ResourceKey = FirstUtil.ApkId + "_" + FirstUtil.PackVersion;
                if (FirstResource.UpdateUrlDic.ContainsKey(FirstResource.ResourceKey))
                {
                    _updateUrl = FirstResource.UpdateUrlDic[FirstResource.ResourceKey];
                }
            }

            FirstUtil.UpdateUrl = _updateUrl;

            // DateTime.ToFileTime()以100毫秒为单位。此处只取秒数。
            // 用户获取此文件最新版本精确到1秒。cdn服务器理论上每小时最大产生3600个文件缓存。
            yield return(BeginDownLoad(_updateUrl + "SecondVersion.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2));

            _secondVersion = EndDownLoadTxt();
            yield return(BeginDownLoad(_updateUrl + "version.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2));

            string buf = EndDownLoadTxt();
            if (string.IsNullOrEmpty(buf))
            {
                _infoTips = FirstLang.FIRST_MSG_4;
                _updateOk = true;
                yield break;
            }

            if (_sdkName.Contains("IOS"))
            {
                yield return(BeginDownLoad(_updateUrl + _sdkName + "_apkversion.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2));

                string tempVerStr = EndDownLoadTxt();

                if (string.IsNullOrEmpty(tempVerStr) == false)
                {
                    _serverSdkVersion = FirstUtil.ReadAllLines(tempVerStr)[0];
                    int compareResult = String.Compare(_serverSdkVersion, FirstUtil.PackVersion, StringComparison.Ordinal);  // 直接字符串比较,和运营保持规则一致
                    WriteLog("CheckAPKVersion - _localVersion:{0} _serverVersion:{1} Compare:{2}", FirstUtil.PackVersion, _serverSdkVersion, compareResult);
                    if (compareResult > 0)
                    {
                        yield return(BeginDownLoad(_updateUrl + _sdkName + "_apkurl.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2));

                        tempVerStr = EndDownLoadTxt();
                        if (string.IsNullOrEmpty(tempVerStr) == false)
                        {
                            FirstUtil.ApkUrl = FirstUtil.ReadAllLines(tempVerStr)[0];
                            FirstPlatform.ShowAlert(FirstLang.FIRST_MSG_15, FirstLang.FIRST_MSG_16, FirstLang.FIRST_MSG_18, FirstLang.FIRST_MSG_17, "1");
                            _infoTips      = FirstLang.FIRST_MSG_19;
                            ProcessPercent = 100;
                            //apk需要更新
                            yield break;
                        }
                    }
                }
            }

            string svrVer = FirstUtil.ReadAllLines(buf)[0];
            svrVer = svrVer.Trim();
            FirstRecordMsg.game_version = svrVer;

            string myVer = FirstUtil.OutVersion ?? FirstUtil.PackVersion;
            int    cmp   = String.Compare(svrVer, myVer, StringComparison.Ordinal); // 直接字符串比较,和运营保持规则一致
            WriteLog("CheckVer - MyVer:{0} ServerVer:{1} Compare:{2}", myVer, svrVer, cmp);
            if (cmp == 0 || svrVer == "0")                                          //版本号不等需要更新
            {
                ProcessPercent = 100;
                _updateOk      = true;
                yield break;
            }

            foreach (object o in DownloadUpdate(svrVer))
            {
                if (o == null)
                {
                    yield break;
                }
                yield return(o);
            }
        }
Exemplo n.º 18
0
        //gamedefine 可能会被热更,但是有些变量值是永远不变,所以取包里的值
        private void InitLocalInfo()
        {
            string[] arr = FirstUtil.ReadAllLines(localGameDefine);
            foreach (string line in arr)
            {
                string[] row = line.Split('=');
                if (row.Length < 2)
                {
                    continue;
                }
                string value = row[1].Trim();
                switch (row[0].Trim())
                {
                case "SDKName":
                    _sdkName          = value;
                    FirstUtil.SDKName = value;
                    break;

                case "id":
                    FirstUtil.ApkId = value;
                    break;

                case "platform":
#if UNITY_ANDROID || UNITY_EDITOR
                    FirstUtil.platform = "Android";
#elif UNITY_IOS
                    FirstUtil.platform = "IOS";
#elif UNITY_STANDALONE
                    FirstUtil.platform = "PC";
#elif UNITY_WEBPLAYER
                    FirstUtil.platform = "WEB";
#endif
                    break;

                case "update_url":
                    _updateUrl = value;
                    break;

                case "isShowLog":
                    FirstUtil.IsShowLog = (value == "FYMM");
                    break;
                }
            }

            arr = FirstUtil.ReadAllLines(localVersion);
            foreach (string line in arr)
            {
                string[] row = line.Split('=');
                if (row.Length < 2)
                {
                    continue;
                }
                string value = row[1].Trim();
                switch (row[0].Trim())
                {
                case "version":
                    FirstUtil.PackVersion = value;
                    break;
                }
            }
        }