91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

unity3d 資源打包加密

發布時間:2020-06-03 20:20:31 來源:網絡 閱讀:2670 作者:螞蟻雄心 欄目:游戲開發

資源打包腳本,放到Assets\Editor 文件夾下

using UnityEngine;

using System.Collections;

using UnityEditor;

using System.IO;


public class assetPack : Editor

{

[MenuItem("Custom Editor/Save Scene2")]

static void ExportResource()

{

// Bring up save panel

string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");

if (path.Length != 0)

{

// Build the resource file from the active selection.

Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path,

                              BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);

Selection.objects = selection;

}

}

[MenuItem("Custom Editor/Make unity3d file to bytes file")]

static void ExportResourceNoTrackSS()

{

Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

foreach(Object obj in selection)

{

string path2 = AssetDatabase.GetAssetPath(obj);

FileStream fs = new FileStream(path2, FileMode.Open, FileAccess.ReadWrite);

byte[] buff = new byte[fs.Length];

fs.Read(buff, 0, (int)fs.Length);

string password = "llh";

packXor(buff, buff.Length, password);

Debug.Log("filelength:" + buff.Length);

fs.Close();

string BinPath = path2.Substring(0, path2.LastIndexOf('.')) + ".bytes";

FileStream cfs = new FileStream(BinPath, FileMode.Create);

cfs.Write(buff, 0, buff.Length);

Debug.Log("filelength:" + buff.Length);

buff = null;

cfs.Close();

}

}

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++];

}

}

}

菜單上就會出現兩個子菜單, 把要打包的資源做成Prefab,選中資源,然后菜單Custom Editor/Save Scene2  輸入名字新生成的文件,再選中新生成的文件,點擊菜單Custom Editor/Make unity3d file to bytes file   輸入名字

又生成了一個文件,再點擊這個文件,菜單Custom Editor/Save Scene2  ,這樣就打包加密好了

即打包AssetBundle之后加密再重新打包AssetBundle(能否直接加密打包?顯然是不行的,加載資源時,LoadBundle會通過解密之后的字節重新創建AssetBundle,所以必須先打包出AssetBundle)


加載打包資源

using UnityEngine;

using System.Collections;


public class loadnew : MonoBehaviour

{

public string filename = "My Resource";

private string BundleURL;

private string AssetName;

void Start()

{

//StartCoroutine(loadScenee());

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;

GameObject obj =  (GameObject)Instantiate(bundle.mainAsset);

//obj.SetActive (true);

}

byte[] Decryption(byte[] data)

{

byte[] tmp = new byte[data.Length];

for (int i = 0; i < data.Length; i++)

{

tmp[i] = data[i];

}

//   shanghaichaolan

string password ="llh";

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

{

}

}



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

河曲县| 四会市| 西充县| 阳新县| 临城县| 湖州市| 青龙| 桃源县| 三门县| 大姚县| 无棣县| 九江市| 高雄市| 荔浦县| 新安县| 镇雄县| 阳城县| 姜堰市| 汤阴县| 九龙县| 庆城县| 元江| 灵寿县| 那坡县| 仁怀市| 忻城县| 临高县| 平潭县| 武邑县| 恭城| 台北县| 隆安县| 文水县| 鲁甸县| 姚安县| 荆州市| 饶阳县| 徐闻县| 阿荣旗| 新兴县| 阿克苏市|