Exemple #1
0
    public static void DecryptFile(string inFile, string outFile, string passwd)
    {
        if (!File.Exists(inFile))
        {
            Debug.LogError(inFile + " is not found!");
            return;
        }

        GameUtil.CreateDirectory(outFile);

        using (FileStream fin = new FileStream(inFile, FileMode.Open))
        {
            using (FileStream fout = new FileStream(outFile, FileMode.Create))
            {
                using (CryptoStream cs = new CryptoStream(fin, GetDecryptoTransform(passwd), CryptoStreamMode.Read))
                {
                    byte[] data = new byte[1024 * 1024];
                    int    len  = 0;
                    while (true)
                    {
                        len = cs.Read(data, 0, data.Length);
                        if (len <= 0)
                        {
                            break;
                        }
                        fout.Write(data, 0, len);
                    }
                }
            }
        }
    }
Exemple #2
0
    //[MenuItem("Tools/Decrypt Lua Code", false, 101)]
    static void DecryptLuaCode()
    {
        try
        {
            string[] files = Directory.GetFiles(Application.dataPath + "/Build/LuaScripts", "*.lua", SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                string name = files[i];
                name = name.Replace('\\', '/');
                name = name.Replace(Application.dataPath + "/Build/", "");
                string outName = @"C:\Users\Administrator\Desktop\" + name;
                GameUtil.CreateDirectory(outName);
                //byte[] decryptBytes = EncryptUtil.DecryptFileToBytes(files[i], "19930822");
                //byte[] decompressedBytes = GameUtil.DecompressBytes(decryptBytes);
                //File.WriteAllBytes(outName, decompressedBytes);
                EncryptUtil.DecryptFile(files[i], outName, "19930822");
                //GameUtil.CreateDirectory(outName);
                //File.WriteAllBytes(outName, EncryptUtil.DecryptBytes(File.ReadAllBytes(files[i]), "19930822"));
                EditorUtility.DisplayProgressBar("decrypt lua code...", name, (float)i / files.Length);
            }
            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
        }
        catch (Exception ex)
        {
            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
            throw new Exception(ex.Message + "\n" + ex.StackTrace);
        }
    }
Exemple #3
0
    static void GenerateAnimatorController()
    {
        var modelPath     = "Assets/Res/Models/Entity";
        var files         = Directory.GetFiles(modelPath, "*.FBX", SearchOption.AllDirectories);
        var animationList = new[] { "Idle", "Move", "Attack01", "Cast_Remote", "Cast_Blink", "Cast_Near", "Cast_Self", "Cast_Unique", "Die" };

        foreach (var file in files)
        {
            var path   = file.Replace('\\', '/');
            var acPath = "Assets/Res/AnimatorController/" + Path.GetFileNameWithoutExtension(path) + ".controller";
            GameUtil.CreateDirectory(acPath);
            var ac           = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(acPath);
            var layer        = ac.layers[0];
            var stateMachine = layer.stateMachine;
            var stateList    = new List <UnityEditor.Animations.AnimatorState>();
            var objs         = AssetDatabase.LoadAllAssetsAtPath(path);
            var index        = 0;
            foreach (var o in objs)
            {
                if (o is AnimationClip)
                {
                    var state = stateMachine.AddState(o.name);
                    state.motion = o as Motion;
                    stateList.Add(state);
                    ac.AddParameter(o.name, AnimatorControllerParameterType.Bool);
                    if (animationList.Contains(o.name))
                    {
                        index++;
                    }
                }
            }
            if (index < animationList.Length)
            {
                Debug.LogError("动画不完整!");
            }
            for (int i = 0; i < stateList.Count; i++)
            {
                for (int j = 0; j < stateList.Count; j++)
                {
                    if (i != j)
                    {
                        var anstateTras = stateList[i].AddTransition(stateList[j], false);
                        anstateTras.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, stateList[j].name);
                    }
                }
                if (stateList[i].name == "Idle")
                {
                    stateMachine.defaultState = stateList[i];
                }
            }
        }
    }
Exemple #4
0
 /// <summary>
 /// 下载大文件专用
 /// </summary>
 /// <param name="url"></param>
 /// <param name="fileName"></param>
 /// <param name="progress"></param>
 /// <param name="complete"></param>
 public void DownLoadFile(string url, string fileName, Action <long, long> progress, Action complete)
 {
     try
     {
         //print("start download");
         GameUtil.CreateDirectory(fileName);
         download = true;
         WebClient  wc        = new WebClient();
         FileStream fs        = new FileStream(fileName, FileMode.Append);
         Stream     s         = wc.OpenRead(url);
         int        length    = 0;
         long       curSize   = 0;
         long       totalSize = GetRemoteHTTPFileSize(url);
         //print("total size: " + totalSize + "M");
         byte[] buffer = new byte[1024 * 1024];
         while (true)
         {
             length = s.Read(buffer, 0, buffer.Length);
             if (length <= 0)
             {
                 break;
             }
             fs.Write(buffer, 0, length);
             curSize += length;
             if (progress != null)
             {
                 progress(curSize, totalSize);
             }
             if (!download)
             {
                 fs.Close();
                 s.Close();
                 wc.Dispose();
                 UnityEngine.Debug.LogError("意外中止!");
                 File.Delete(fileName);
                 return;
             }
         }
         fs.Close();
         s.Close();
         wc.Dispose();
         if (complete != null)
         {
             complete();
         }
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogError(e + "\n" + url);
     }
 }
Exemple #5
0
    //[MenuItem("Tool/Decompress Lua Code", false, 1002)]
    public static void DecompressLuaCode()
    {
        string[] files = Directory.GetFiles(Application.dataPath + "/Build/LuaScripts", "*.lua", SearchOption.AllDirectories);

        for (int i = 0; i < files.Length; i++)
        {
            string name = files[i];
            name = name.Replace('\\', '/');
            name = name.Replace(Application.dataPath + "/Build/", "");
            string outName = @"C:\Users\Administrator\Desktop\" + name;
            GameUtil.CreateDirectory(outName);
            byte[] bytes = GameUtil.DecompressBytes(File.ReadAllBytes(files[i]));
            File.WriteAllBytes(outName, bytes);
            EditorUtility.DisplayProgressBar("encrypt lua code...", name, (float)i / files.Length);
        }
        EditorUtility.ClearProgressBar();
        AssetDatabase.Refresh();
    }