示例#1
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            byte[] data = Tools.Load(ctx.assetPath);
            string json = System.Text.UTF8Encoding.UTF8.GetString(data);

            LitJson.JsonData jsonData = Tools.DeserializeObject(json);
            mJsonList = new List <StringStringDictionary>();
            for (int i = 0; i < jsonData.Count; i++)
            {
                LitJson.JsonData       tmp  = jsonData[i];
                StringStringDictionary dict = new StringStringDictionary();
                IEnumerator            ite  = jsonData[i].Keys.GetEnumerator();
                while (ite.MoveNext())
                {
                    string key   = ite.Current.ToString();
                    string value = tmp[key].ToString();
                    dict.Add(key, value);
                }
                mJsonList.Add(dict);
            }

            string fileName = Path.GetFileNameWithoutExtension(ctx.assetPath);
            Object asset    = AssetDatabase.LoadAssetAtPath(ctx.assetPath, typeof(Object));

            ctx.AddObjectToAsset(fileName, asset);
            ctx.SetMainObject(asset);
        }
        private static void CreateCrcFile(string path, string fileName, uint code)
        {
            string json = Tools.SerializeObject(new rCRC(fileName + ".unity3d", code));

            Tools.Save(path, "." + fileName + ".crc", System.Text.UTF8Encoding.UTF8.GetBytes(json));
            File.SetAttributes(path + "." + fileName + ".crc", FileAttributes.Hidden);
        }
        private static void BuildVersion(string lang, string path, string versionName)
        {
            //檢查目錄是否存在
            if (Directory.Exists(path) == true)
            {
                List <rRes> container = new List <rRes>();
                //取得目錄底下的Data檔案
                string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo info = new FileInfo(files[i]);
                    if (!CheckFileExtension(info))
                    {
                        continue;
                    }

                    string filePath = Path.GetDirectoryName(files[i]).Replace("\\", "/");
                    rRes   data     = new rRes();
                    data.Version  = Setting.Ver;
                    data.FileName = info.Name;
                    data.Path     = GetDataPath(filePath, Application.dataPath + "/" + Setting.OutputAssetsFolder + "/");
                    data.FileSize = info.Length;
                    data.MD5Code  = GetMd5File(filePath + "/", info.Name);
                    container.Add(data);
                }
                //整合資料
                rRes[] resData = container.ToArray();
                //轉成Json
                string json = Tools.SerializeObject(resData);
                //寫入檔案
                Tools.Save(Application.dataPath + "/" + Setting.OutputAssetsFolder + "/" + lang + "/" + "Versions" + "/", versionName, System.Text.UTF8Encoding.UTF8.GetBytes(json));
            }
        }
示例#4
0
        private static void Download(eLanguage lang, string path, string name)
        {
            using (WWW bundle = new WWW(path + name))
            {
                //檢查下載錯誤訊息
                if (bundle.error != null)
                {
                    throw new System.Exception(bundle.error);
                }

                while (bundle.isDone == false)
                {
                    if (bundle.error != null)
                    {
                        throw new System.Exception(bundle.error);
                    }
                }

                //檢查是否下載完成
                if (bundle.isDone == true)
                {
                    byte[] xor   = Tools.XOR(bundle.bytes, Setting.EncryptionKeyValue);
                    string str   = GetLocation(Setting.HTTP, Setting.User);
                    string zPath = Application.dataPath + "/" + Setting.DownloadAssetsFolder + "/" + path.Replace(str, "");
                    Tools.Save(zPath, name, xor);
                }
                else
                {
                    throw new System.Exception(bundle.error);
                }
            }
        }
示例#5
0
        private static void SaveInfo(rSave save)
        {
            string path = Application.streamingAssetsPath + "/";
            string name = "HTTP.dat";
            string json = Tools.SerializeObject(save);

            Tools.Save(path, name, System.Text.UTF8Encoding.UTF8.GetBytes(json));

            AssetDatabase.Refresh();
        }
        //取得Bundle的MD5編號
        private static string GetMd5Unity(string path, string name)
        {
            FileInfo info = new FileInfo(path + name);

            byte[] data = Tools.Load(path, name.Replace(info.Extension, ".crc"));

            if (data == null)
            {
                return(string.Empty);
            }

            //取出Json字串
            string json = System.Text.UTF8Encoding.UTF8.GetString(data);
            //Json反序列化
            rCRC crc = Tools.DeserializeObject <rCRC>(json);

            return(crc.CRC.ToString());
        }
示例#7
0
        //處理最小包
        public static void HandleOutputAssets(eLanguage lang, bool isShow = true)
        {
            for (int i = 0; i < Setting.OutputCount; i++)
            {
                string[] files = Directory.GetFiles(Application.dataPath + "/" + Setting.InputAssetsFolder + "/" + GetLangPath(lang), Setting.OutputItems[i].value, SearchOption.AllDirectories);
                for (int j = 0; j < files.Length; j++)
                {
                    string path      = files[j].Replace("\\", "/");
                    string name      = Path.GetFileName(path);
                    string extension = Path.GetExtension(path);

                    if (extension == ".meta")
                    {
                        continue;
                    }

                    string sourcePath = Application.dataPath + "/" + Setting.InputAssetsFolder + "/" + GetDataPath(Path.GetDirectoryName(path), Application.dataPath + "/" + Setting.InputAssetsFolder + "/");
                    string destPath   = Application.dataPath + "/" + Setting.OutputAssetsFolder + "/" + GetDataPath(Path.GetDirectoryName(path), Application.dataPath + "/" + Setting.InputAssetsFolder + "/");

                    if (extension != ".txt")
                    {
                        CopyFile(name, sourcePath, destPath);
                    }
                    else
                    {
                        //讀取資料
                        byte[] data = Tools.Load(GetDataPath(sourcePath, name), name);

                        //加密存檔
                        Tools.Save(GetDataPath(destPath, name), name, data, Setting.EncryptionKeyValue);
                    }
                }
            }

            if (isShow)
            {
                EditorUtility.DisplayDialog("Copy", "Copy complete!", "OK");
            }

            AssetDatabase.Refresh();
        }
示例#8
0
        //取得下載列表
        private static List <rRes> GetDownloadList(eLanguage lang)
        {
            List <rRes> list = new List <rRes>();

            byte[] data    = null;
            rRes[] resData = null;
            string json    = string.Empty;
            string path    = Application.dataPath + "/" + Setting.DownloadAssetsFolder + "/" + GetLangPath(lang, true) + "Versions/";

            if (Setting.VersionItems == null || Setting.VersionItems.Count == 0)
            {
                data = Tools.Load(path, "Main.res", Setting.EncryptionKeyValue);
                if (data != null)
                {
                    json    = System.Text.UTF8Encoding.UTF8.GetString(data);
                    resData = Tools.DeserializeObject <rRes[]>(json);
                    for (int i = 0; i < resData.Length; i++)
                    {
                        list.Add(resData[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < Setting.VersionItems.Count; i++)
                {
                    data = Tools.Load(path, Setting.VersionItems[i].ver, Setting.EncryptionKeyValue);
                    if (data != null)
                    {
                        json    = System.Text.UTF8Encoding.UTF8.GetString(data);
                        resData = Tools.DeserializeObject <rRes[]>(json);
                        for (int j = 0; j < resData.Length; j++)
                        {
                            list.Add(resData[j]);
                        }
                    }
                }
            }
            return(list);
        }
        //取得檔案的MD5編碼
        private static string GetMd5File(string path, string name)
        {
            FileInfo info = new FileInfo(path + name);

            if ((info.Extension == ".unity3d") || (info.Extension == ".zip"))
            {
                return(GetMd5Unity(path, "." + name));
            }

            byte[] data = Tools.Load(path, name);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            data = md5.ComputeHash(data);
            StringBuilder sb = new StringBuilder(32);

            for (int i = 0; i < data.Length; i++)
            {
                sb.Append(data[i].ToString("x").PadLeft(2, '0'));
            }

            return(sb.ToString());
        }