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()
    {

    }
}
时间: 2024-07-30 00:26:29

u3d加载加密和未加密的相关文章

ASP.NET Ajax 客户端框架未能加载、&quot;Sys&quot;未定义

在Windows Server 2003 系统上部署asp.net项目出现以下问题: IIS为6.0 导致菜单控件的图片显示不出来: WebSite:程序中的图片显示正常. 但用到ASP.net 2.0 的 asp:TreeView 控件,控件显示不出图片 图片属性: 地址:http://localhost/WebSite/WebResource.axd?d=41VAQHZc9t11gcfcSh8IynBrLxqhiiUYVpPeaSf8-4s1&t=633965754543750000协议:超

u3d加载外部视屏

u3d的外部加载视屏,采用www方式,可以使用gui播放,也可以绑定到gameobject上作为动态材质使用,不过目前只支持.ogg格式,需要转... using UnityEngine;using System.Collections; public class movie : MonoBehaviour{    private MovieTexture movTexture;     private string movPath;     void Start()    {        m

u3d 加载PNG做 UI图片

using UnityEngine; using System.Collections; using System.IO; using UnityEngine.UI; public class UITexLoader : MonoBehaviour { public string _Path ="Assets/pic/01/"; public string _texname; private Texture2D m_Tex; private void LoadFromFile(stri

实现异步加载js文件及加载完成后回调

模块化工具类实现方式 基于AMD.CMD模式的JS模块化管理工具越来越流行,这些工具通常只需在页面中加载对应的工具JS,其他JS文件都是异步加载的,比如RequireJS就可以象下面这样做. 首先在页面加载 <script data-main="scripts/main.js" src="scripts/require.js"></script> 然后工具会自动识别data-main属性值,并加载对应的JS文件,在main.js可以加载更多模

检测jQuery.js是否已加载的判断代码

转载自http://www.jb51.net/article/27185.htm 测类.方法.变量或属性是否已存在,这是Javascript编程基础知识.在这里我们就是要检测jQuery()或$()函数是否存在 当然,该方法不局限于jQuery的检测,对与任何Javascript变量或函数都是通用的. 当前网页加载jQuery后,jQuery()或$()函数将会被定义,所以检测jQuery是否已经加载存在以下2种方法: 方法1: 复制代码代码如下: if (jQuery) { // jQuery

Android图片异步加载框架Universal Image Loader的源码分析

项目地址:https://github.com/nostra13/android-universal-image-loader 1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL. 简单的说 UIL 就做了一件事--获取图片并显示在相应的控件上. 1.2 基本使用 1.2.1 初始化 添加完依赖后在Application或Activity中初始化I

Android 框架练成 教你打造高效的图片加载框架

转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/41874561,本文出自:[张鸿洋的博客] 1.概述 优秀的图片加载框架不要太多,什么UIL , Volley ,Picasso,Imageloader等等.但是作为一名合格的程序猿,必须懂其中的实现原理,于是乎,今天我就带大家一起来设计一个加载网络.本地的图片框架.有人可能会说,自己写会不会很渣,运行效率,内存溢出神马的.放心,我们拿demo说话,拼得就是速度,奏事这么任性.

hibernate之xml映射文件关系维护,懒加载,级联

一:关系维护 --->inverse默认值false,表示不放弃关系的维护.   --->inverse="true"配置在那一端,表示那一端xml对应的po放弃关系的维护(交由hibernate内部进行维护),由另一端进行关系维护.  例子:学生班级模型[多对一模型]一端放弃关系的维护,由学生端进行关系维护              ----->班级的xml映射文件中<set name="students" class="Stud

实现图片的异步加载

图片异步加载功能是现在web中非常常见的一个针对web做优化的方法.尤其是在移动端,面对大量的图片列表的时候,如果没有做相应的优化,会直接导致页面滑动和加载的卡顿,而且用户会莫名的发现当前应用占用的流量会很大,因为他可能都没有浏览到很多图片,而程序就自动加载了所以的图片,对于一个流量吃紧的人来讲,这个也是很讨厌的.所以实现按浏览需求加载时十分有必要的. 其实实现图片异步加载的核心思路十分简单,就是通过判断当图片元素是否出现在视窗范围内后,则去加载图片资源,否则不加载.所以我们需要首先解决判断im