using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.IO;
using System;
public
class
MainBehaviourScript : MonoBehaviour
{
Text listText;
Text matrixPath;
Text configPath;
private Texture2D duplicateTexture(Texture2D source)
{
RenderTexture renderTex
=
RenderTexture.GetTemporary(
source.width,
source.height,
0
,
RenderTextureFormat.Default,
RenderTextureReadWrite.Linear);
Graphics.Blit(source, renderTex);
RenderTexture previous
=
RenderTexture.active;
RenderTexture.active
=
renderTex;
Texture2D readableText
=
new Texture2D(source.width, source.height);
readableText.ReadPixels(new Rect(
0
,
0
, renderTex.width, renderTex.height),
0
,
0
);
readableText.
Apply
();
RenderTexture.active
=
previous;
RenderTexture.ReleaseTemporary(renderTex);
return
readableText;
}
/
/
Start
is
called before the first frame update
void Start()
{
/
/
listText
=
GameObject.Find(
"Canvas/Panel/Text"
).GetComponent<Text>();
matrixPath
=
GameObject.Find(
"Canvas/matrixPath"
).GetComponent<Text>();
configPath
=
GameObject.Find(
"Canvas/configPath"
).GetComponent<Text>();
}
public void OnClick1()
{
configPath.text
=
MyLocalDialog.GetDir().Trim(
'\0'
);
}
public void OnClick2()
{
matrixPath.text
=
MyLocalDialog.GetDir().Trim(
'\0'
);
}
public void OnClick3()
{
AssetBundle.SetAssetBundleDecryptKey(
"kurokurokurokuro"
);
FileStream newfst
=
new FileStream(configPath.text
+
"\\newoutfile.txt"
, FileMode.Create, FileAccess.Write);
FileStream allfst
=
new FileStream(configPath.text
+
"\\alloutfile.txt"
, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter newfWriter
=
new StreamWriter(newfst);
StreamWriter allfWriter
=
new StreamWriter(allfst);
StreamReader allfReader
=
new StreamReader(allfst);
Dictionary<string,
int
> myDictionary
=
new Dictionary<string,
int
>();
DirectoryInfo TheFolder
=
new DirectoryInfo(matrixPath.text);
string outdir
=
MyLocalDialog.GetDir().Trim(
'\0'
)
+
"\\"
;
if
(outdir
=
=
"")
return
;
/
/
istText.text
=
"";
string
str
;
bool
outtext
=
GameObject.Find(
"Canvas/TextToggle"
).GetComponent<Toggle>().isOn;
bool
outpic
=
GameObject.Find(
"Canvas/PicToggle"
).GetComponent<Toggle>().isOn;
while
((
str
=
allfReader.ReadLine()) !
=
null)
{
myDictionary.Add(
str
,
1
);
}
foreach (FileInfo NextFile
in
TheFolder.GetFiles())
{
MyLocalDialog.MessageBox((IntPtr)
0
, NextFile.ToString(),
"提示"
,
0
);
var ab
=
AssetBundle.LoadFromFile(NextFile.ToString());
Debug.LogError(ab);
string[] patht
=
ab.GetAllAssetNames();
MyLocalDialog.MessageBox((IntPtr)
0
, patht[
0
],
"提示"
,
0
);
return
;
foreach (string s
in
patht)
{
if
(!myDictionary.ContainsKey(s))
{
var o
=
ab.LoadAsset(s);
if
(o
=
=
null)
continue
;
if
(outpic && o.GetType()
=
=
typeof(Texture2D))
{
Texture2D tx
=
(Texture2D)o;
Texture2D readableText
=
duplicateTexture(tx);
string file_path
=
outdir
+
s;
int
len
=
file_path.Length
-
1
;
while
(
len
>
0
&& file_path[
len
] !
=
'/'
)
len
-
-
;
Directory.CreateDirectory(file_path.Substring(
0
,
len
));
byte[] filedata
=
readableText.EncodeToPNG();
using (var fs
=
new FileStream(file_path, FileMode.Create, FileAccess.Write))
{
fs.Write(filedata,
0
, filedata.Length);
}
newfWriter.WriteLine(s);
allfWriter.WriteLine(s);
}
else
if
(outtext && o.GetType()
=
=
typeof(TextAsset))
{
TextAsset ta
=
(TextAsset)o;
string file_path
=
outdir
+
s;
int
len
=
file_path.Length
-
1
;
while
(
len
>
0
&& file_path[
len
] !
=
'/'
)
len
-
-
;
Directory.CreateDirectory(file_path.Substring(
0
,
len
));
using (var fs
=
new FileStream(file_path, FileMode.Create, FileAccess.Write))
{
fs.Write(ta.bytes,
0
, ta.bytes.Length);
}
newfWriter.WriteLine(s);
allfWriter.WriteLine(s);
}
}
}
}
newfWriter.Close();
newfst.Close();
allfWriter.Close();
allfReader.Close();
allfst.Close();
MyLocalDialog.MessageBox((IntPtr)
0
,
"导出完成!"
,
"提示"
,
0
);
}
public void OnClick4()
{
AssetBundle.SetAssetBundleDecryptKey(
"kurokurokurokuro"
);
var ab
=
AssetBundle.LoadFromFile(
"E:\\matrix2\\fff6ce1e25b48a043aa026247cbb231fbd2f225c"
);
/
/
string[] patht
=
ab.GetAllAssetNames();
/
/
Debug.LogError(patht[
0
]);
var o
=
ab.LoadAsset(
"assets/product/scene/sceneres/common/scene020/textures/2003.png"
);
MyLocalDialog.MessageBox((IntPtr)
0
, o.name,
"提示"
,
0
);
}
/
/
Update
is
called once per frame
void Update()
{
}
}