zoukankan      html  css  js  c++  java
  • u3d加载加密和未加密

    using UnityEngine;
    using System.Collections;
    
    public class loadnew : MonoBehaviour 
    {
        public bool IsCompressed =false;
        public string filename;
        private string BundleURL;
        private string AssetName;
        void Start()
        {
            if (!IsCompressed)
            {
                StartCoroutine(loadScenee());
            }
            else
            {
                StartCoroutine(LoadResource());
            
            }
            //StartCoroutine(LoadResource());
        }
    
        IEnumerator loadScenee()
        {
            string path;
            path = "file://" + Application.dataPath + "/" + filename + ".unity3d";
            Debug.Log(path);
            WWW www = new WWW(path);
            yield return www;
            AssetBundle bundle = www.assetBundle;
            //GameObject go = bundle.Load("gCube",typeof(GameObject)) as GameObject;
    
            GameObject ObjScene = Instantiate(www.assetBundle.mainAsset) as GameObject;
            bundle.Unload(false);
    
        }
    
        IEnumerator LoadResource()
        {
            BundleURL = "file://" + Application.dataPath + "/" + filename + ".unity3d";
            Debug.Log("path:" + BundleURL);
            WWW m_Download = new WWW(BundleURL);
    
            yield return m_Download;
            if (m_Download.error != null)
            {
                //   Debug.LogError(m_Download.error);
                Debug.LogError("Warning errow: " + "NewScene");
                yield break;
            }
    
            TextAsset txt = m_Download.assetBundle.Load(filename, typeof(TextAsset)) as TextAsset;
            byte[] data = txt.bytes;
    
            byte[] decryptedData = Decryption(data);
            Debug.Log("decryptedData length:" + decryptedData.Length);
            StartCoroutine(LoadBundle(decryptedData));
        }
    
        IEnumerator LoadBundle(byte[] decryptedData)
        {
            AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
            yield return acr;
            AssetBundle bundle = acr.assetBundle;
            Instantiate(bundle.mainAsset);
    
        }
    
        byte[] Decryption(byte[] data)
        {
            byte[] tmp = new byte[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                tmp[i] = data[i];
            }
                         //   shanghai
            string password ="shanghai";
            packXor(tmp,tmp.Length,password);
            return tmp;
    
        }
        static void packXor(byte[] _data, int _len, string _pstr)
        {
            int length = _len;
            int strCount = 0;
    
    
            for (int i = 0; i < length; ++i)
            {
                if (strCount >= _pstr.Length)
                    strCount = 0;
                _data[i] ^= (byte)_pstr[strCount++];
    
    
            }
    
    
        }
    
        void update()
        {
    
        }
    }
    
  • 相关阅读:
    CentOS7设置开机自启动命令大全
    CentOS查看何人何时登陆用户
    CentOS显示设置时间命令- date
    CentOS系统命令
    CentOS系统中last命令的作用
    CentOS命令top下你不一定懂的cpu显示信息
    CentOS系统安装后的基础优化
    查看CentOS的网络带宽出口
    storm深入研究
    hadoop学习笔记之-hbase完全分布模式安装-5
  • 原文地址:https://www.cnblogs.com/dragon2012/p/4112273.html
Copyright © 2011-2022 走看看