add
This commit is contained in:
133
Assets/CoolapeFrame/Editor/Tools/ECLCreateVerCfg.cs
Normal file
133
Assets/CoolapeFrame/Editor/Tools/ECLCreateVerCfg.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
*Copyright(C),coolae.net
|
||||
*Author: chenbin
|
||||
*Version: 2.0
|
||||
*Date: 2017-01-09
|
||||
*Description: 工程中资源文件成生md5配置文件
|
||||
*Others:
|
||||
*History:
|
||||
*********************************************************************************
|
||||
*/
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
using System;
|
||||
using Coolape;
|
||||
|
||||
//生成版本配置文件
|
||||
public static class ECLCreateVerCfg
|
||||
{
|
||||
static string basePath = "";
|
||||
static ArrayList replaces = new ArrayList ();
|
||||
|
||||
static public Hashtable create2Map (string path)
|
||||
{
|
||||
basePath = Application.dataPath + "/";
|
||||
basePath = basePath.Replace ("/Assets/", "/");
|
||||
replaces.Clear ();
|
||||
replaces.Add (basePath + "Assets/StreamingAssets/");
|
||||
replaces.Add (basePath + "Assets/Resources/");
|
||||
replaces.Add (basePath + "Assets/");
|
||||
|
||||
path = basePath + path;
|
||||
|
||||
string lastVerPath = Application.dataPath + "/" + ECLProjectManager.ver4DevelopeMd5;
|
||||
Hashtable lastVerMap = Utl.fileToMap (lastVerPath);
|
||||
if (lastVerMap == null) {
|
||||
lastVerMap = new Hashtable ();
|
||||
}
|
||||
|
||||
Hashtable lastOtherVer = MapEx.getMap (lastVerMap, "other");
|
||||
Hashtable lastPriorityVer = MapEx.getMap (lastVerMap, "priority");
|
||||
Hashtable lastCfgdataVer = MapEx.getMap (lastVerMap, "cfgData");
|
||||
|
||||
Hashtable outMap = new Hashtable ();
|
||||
doCreate (path, lastOtherVer, lastPriorityVer, lastCfgdataVer, ref outMap);
|
||||
return outMap;
|
||||
}
|
||||
|
||||
static public void create (string path, string outPath)
|
||||
{
|
||||
Hashtable outMap = create2Map (path);
|
||||
saveMap (outMap, outPath);
|
||||
}
|
||||
|
||||
static public void saveMap (Hashtable map, string outPath)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream ();
|
||||
B2OutputStream.writeMap (ms, map);
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (outPath));
|
||||
File.WriteAllBytes (outPath, ms.ToArray ());
|
||||
}
|
||||
|
||||
static void doCreate (string path, Hashtable lastOtherVer, Hashtable lastPriorityVer, Hashtable lastCfgdataVer, ref Hashtable outMap)
|
||||
{
|
||||
string[] fileEntries = Directory.GetFiles (path);
|
||||
string extension = "";
|
||||
string filePath = "";
|
||||
string md5Str = "";
|
||||
|
||||
foreach (string fileName in fileEntries) {
|
||||
extension = Path.GetExtension (fileName);
|
||||
if (ECLEditorUtl.isIgnoreFile (fileName)) {
|
||||
continue;
|
||||
}
|
||||
filePath = filter (fileName);
|
||||
filePath = filePath.Replace ("\\", "/");
|
||||
filePath = filePath.Replace ("/upgradeRes4Publish/", "/upgradeRes/");
|
||||
|
||||
if (ECLProjectManager.isModified (fileName)) {
|
||||
md5Str = Utl.MD5Encrypt (File.ReadAllBytes (fileName));
|
||||
} else {
|
||||
md5Str = MapEx.getString (lastOtherVer, filePath);
|
||||
if (string.IsNullOrEmpty (md5Str)) {
|
||||
md5Str = MapEx.getString (lastPriorityVer, filePath);
|
||||
} else if (string.IsNullOrEmpty (md5Str)) {
|
||||
md5Str = MapEx.getString (lastCfgdataVer, filePath);
|
||||
}
|
||||
}
|
||||
outMap [filePath] = md5Str;
|
||||
}
|
||||
|
||||
string[] dirEntries = Directory.GetDirectories (path);
|
||||
foreach (string dir in dirEntries) {
|
||||
//跳过不同平台的资源
|
||||
#if UNITY_ANDROID
|
||||
if (Path.GetFileName (dir).Equals ("IOS") || Path.GetFileName(dir).Equals("Standalone") || Path.GetFileName(dir).Equals("StandaloneOSX")) {
|
||||
continue;
|
||||
}
|
||||
#elif UNITY_IOS
|
||||
if(Path.GetFileName(dir).Equals("Android") || Path.GetFileName(dir).Equals("Standalone") || Path.GetFileName(dir).Equals("StandaloneOSX")) {
|
||||
continue;
|
||||
}
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
if(Path.GetFileName(dir).Equals("Android") || Path.GetFileName(dir).Equals("IOS") || Path.GetFileName(dir).Equals("StandaloneOSX")) {
|
||||
continue;
|
||||
}
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
if(Path.GetFileName(dir).Equals("Android") || Path.GetFileName(dir).Equals("IOS") || Path.GetFileName(dir).Equals("Standalone")) {
|
||||
continue;
|
||||
}
|
||||
#elif UNITY_WEBGL
|
||||
if(Path.GetFileName(dir).Equals("Android") || Path.GetFileName(dir).Equals("IOS") || Path.GetFileName(dir).Equals("Standalone") || Path.GetFileName(dir).Equals("StandaloneOSX")) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
doCreate(dir, lastOtherVer, lastPriorityVer, lastCfgdataVer, ref outMap);
|
||||
}
|
||||
}
|
||||
|
||||
static string filter (string path)
|
||||
{
|
||||
string str = "";
|
||||
for (int i = 0; i < replaces.Count; i++) {
|
||||
str = replaces [i].ToString ();
|
||||
path = path.Replace (str, "");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLCreateVerCfg.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLCreateVerCfg.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1232a20cced34a96a854a4eefd15586
|
||||
timeCreated: 1484206596
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
Assets/CoolapeFrame/Editor/Tools/ECLCurve2Code.cs
Normal file
60
Assets/CoolapeFrame/Editor/Tools/ECLCurve2Code.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Coolape;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public class ECLCurve2Code : EditorWindow
|
||||
{
|
||||
AnimationCurve curve = new AnimationCurve ();
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
if (GUILayout.Button ("Gen C#")) {
|
||||
Debug.Log (getCode ());
|
||||
}
|
||||
if (GUILayout.Button ("Gen Lua")) {
|
||||
Debug.Log (getCodeLua ());
|
||||
}
|
||||
GUILayout.Space (5);
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
|
||||
curve = EditorGUILayout.CurveField ("Curve", curve, GUILayout.Height (200));
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
string getCode ()
|
||||
{
|
||||
|
||||
PStr p = PStr.b ().a ("AnimationCurve curve = new AnimationCurve ();\n");
|
||||
if (curve == null)
|
||||
return "";
|
||||
Keyframe kf = new Keyframe ();
|
||||
for (int i = 0; i < curve.length; i++) {
|
||||
kf = curve [i];
|
||||
p.a ("curve.AddKey(new Keyframe(").a (kf.time).a ("f, ").a (kf.value).a ("f, ").a (kf.inTangent).a ("f, ").a (kf.outTangent).a ("f));\n");
|
||||
}
|
||||
return p.e ();
|
||||
}
|
||||
|
||||
string getCodeLua ()
|
||||
{
|
||||
PStr p = PStr.b ().a ("local curve = AnimationCurve ();\n");
|
||||
if (curve == null)
|
||||
return "";
|
||||
Keyframe kf = new Keyframe ();
|
||||
for (int i = 0; i < curve.length; i++) {
|
||||
kf = curve [i];
|
||||
p.a ("curve:AddKey(Keyframe(").a (kf.time).a (", ").a (kf.value).a (", ").a (kf.inTangent).a (", ").a (kf.outTangent).a ("));\n");
|
||||
}
|
||||
return p.e ();
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLCurve2Code.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLCurve2Code.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6ba5828af992418ba6fb32e16a65ad7
|
||||
timeCreated: 1510104917
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
366
Assets/CoolapeFrame/Editor/Tools/ECLGUIResList.cs
Normal file
366
Assets/CoolapeFrame/Editor/Tools/ECLGUIResList.cs
Normal file
@@ -0,0 +1,366 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using Coolape;
|
||||
|
||||
public class ECLGUIResList : ScriptableWizard
|
||||
{
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
Vector2 scrollPos2 = Vector2.zero;
|
||||
// Rect windowRect = new Rect (0,0,Screen.width/2, Screen.height/2);
|
||||
public Callback callback;
|
||||
public Callback callback2;
|
||||
string rootPath = "";
|
||||
ArrayList datas = new ArrayList ();
|
||||
// FileInfor
|
||||
ArrayList selectedDatas = new ArrayList ();
|
||||
// FileInfor
|
||||
int totalFiles = 0;
|
||||
Hashtable resLastUpgradeVer = null;
|
||||
Hashtable necessaryResMap = new Hashtable ();
|
||||
string searchKey = "";
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
NGUIEditorTools.BeginContents ();
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
searchKey = EditorGUILayout.TextField (searchKey);
|
||||
if (GUILayout.Button ("Search")) {
|
||||
}
|
||||
if (GUILayout.Button ("Refresh")) {
|
||||
searchKey = "";
|
||||
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
NGUIEditorTools.EndContents ();
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Width (position.width / 2), GUILayout.Height (position.height - 80));
|
||||
{
|
||||
int count = datas.Count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
showOneFile ((ECLResInfor)(datas [i]), true, true);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
|
||||
scrollPos2 = EditorGUILayout.BeginScrollView (scrollPos2, GUILayout.Width (position.width / 2), GUILayout.Height (position.height - 80));
|
||||
{
|
||||
getSelectedFiles ();
|
||||
int count = selectedDatas.Count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
showOneFile ((ECLResInfor)(selectedDatas [i]), false, false);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUI.color = Color.yellow;
|
||||
EditorGUILayout.LabelField ("Total Files:" + totalFiles);
|
||||
EditorGUILayout.LabelField ("Selected Files:" + selectedDatas.Count);
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
NGUIEditorTools.BeginContents ();
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
if (GUILayout.Button ("Okay")) {
|
||||
this.Close ();
|
||||
if (callback != null) {
|
||||
callback (getSelectedFiles ());
|
||||
}
|
||||
}
|
||||
GUI.color = Color.yellow;
|
||||
if (GUILayout.Button ("Cancel")) {
|
||||
this.Close ();
|
||||
if (callback2 != null) {
|
||||
callback2 ();
|
||||
}
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
NGUIEditorTools.EndContents ();
|
||||
}
|
||||
|
||||
ArrayList getSelectedFiles ()
|
||||
{
|
||||
selectedDatas.Clear ();
|
||||
ECLResInfor ri = null;
|
||||
int count = datas.Count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ri = (ECLResInfor)(datas [i]);
|
||||
if (ri.selected && !ri.isDir) {
|
||||
selectedDatas.Add (ri);
|
||||
}
|
||||
}
|
||||
return selectedDatas;
|
||||
}
|
||||
|
||||
void initData (string path, int tabs)
|
||||
{
|
||||
//跳过不同平台的资源
|
||||
#if UNITY_ANDROID
|
||||
if (Path.GetFileName(path).Equals("IOS") || Path.GetFileName(path).Equals("Standalone") || Path.GetFileName(path).Equals("StandaloneOSX"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#elif UNITY_IOS
|
||||
if(Path.GetFileName(path).Equals("Android") || Path.GetFileName(path).Equals("Standalone") || Path.GetFileName(path).Equals("StandaloneOSX")) {
|
||||
return;
|
||||
}
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
if(Path.GetFileName(path).Equals("Android") || Path.GetFileName(path).Equals("IOS") || Path.GetFileName(path).Equals("StandaloneOSX")) {
|
||||
return;
|
||||
}
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
if(Path.GetFileName(path).Equals("Android") || Path.GetFileName(path).Equals("IOS") || Path.GetFileName(path).Equals("Standalone")) {
|
||||
return;
|
||||
}
|
||||
#elif UNITY_WEBGL
|
||||
if (Path.GetFileName(path).Equals("Android") || Path.GetFileName(path).Equals("IOS") || Path.GetFileName(path).Equals("Standalone") || Path.GetFileName(path).Equals("StandaloneOSX"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
ECLResInfor ri = new ECLResInfor ();
|
||||
path = path.Replace ("\\", "/");
|
||||
ri.path = path;
|
||||
ri.name = Path.GetFileName (path);
|
||||
ri.isDir = true;
|
||||
ri.selected = true;
|
||||
ri.tabs = tabs;
|
||||
ri.relativePath = ri.path.Replace (Application.dataPath + "/", "");
|
||||
ri.publishPath = Utl.filterPath (ri.relativePath);
|
||||
ri.ver = "";
|
||||
datas.Add (ri);
|
||||
|
||||
string[] fileEntries = Directory.GetFiles (path);//因为Application.dataPath得到的是型如 "工程名称/Assets"
|
||||
int count = fileEntries.Length;
|
||||
string fileName = "";
|
||||
string extension = "";
|
||||
for (int i = 0; i < count; i++) {
|
||||
fileName = fileEntries [i];
|
||||
extension = Path.GetExtension (fileName);
|
||||
if (ECLEditorUtl.isIgnoreFile (fileName)) {
|
||||
continue;
|
||||
}
|
||||
totalFiles++;
|
||||
ri = new ECLResInfor ();
|
||||
fileName = fileName.Replace ("\\", "/");
|
||||
ri.path = fileName;
|
||||
ri.name = Path.GetFileName (fileName);
|
||||
ri.isDir = false;
|
||||
ri.selected = true;
|
||||
ri.tabs = tabs + 1;
|
||||
ri.relativePath = ri.path.Replace (Application.dataPath + "/", "");
|
||||
ri.publishPath = Utl.filterPath (ri.relativePath);
|
||||
ri.ver = Utl.MD5Encrypt (File.ReadAllBytes (fileName));//MapEx.getString (resLastUpgradeVer, ri.publishPath);
|
||||
datas.Add (ri);
|
||||
selectedDatas.Add (ri);
|
||||
}
|
||||
|
||||
string[] dirEntries = Directory.GetDirectories (path);
|
||||
count = dirEntries.Length;
|
||||
string dir = "";
|
||||
for (int i = 0; i < count; i++) {
|
||||
initData (dirEntries [i], tabs + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void showOneFile (ECLResInfor ri, bool canEdite, bool needFilter)
|
||||
{
|
||||
if (needFilter && searchKey != "") {
|
||||
if (!ri.path.ToLower ().Contains (searchKey.ToLower ())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string fname = ri.relativePath;
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
if (canEdite) {
|
||||
bool selected = GUILayout.Toggle (ri.selected, "", GUILayout.Width (20));
|
||||
if (selected != ri.selected) {
|
||||
ri.selected = selected;
|
||||
if (ri.isDir) {
|
||||
ArrayList list = new ArrayList ();
|
||||
list.AddRange (datas);
|
||||
int count = list.Count;
|
||||
ECLResInfor res = null;
|
||||
for (int i = 0; i < count; i++) {
|
||||
res = (ECLResInfor)(list [i]);
|
||||
if (res.path.Contains (ri.path)) {
|
||||
res.selected = selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// EditorGUILayout.LabelField ("", GUILayout.Width (ri.tabs * 4));
|
||||
// EditorGUILayout.SelectableLabel (StrEx.appendSpce ("v." + ri.ver, 6) + fname, GUILayout.Height (18));
|
||||
EditorGUILayout.SelectableLabel (StrEx.appendSpce ("", 6) + fname, GUILayout.Height (18));
|
||||
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
public static void show (string rootPath, Callback callback, Callback callback2)
|
||||
{
|
||||
ECLGUIResList window = ScriptableWizard.DisplayWizard<ECLGUIResList> ("Res List");
|
||||
// if (window == null) {
|
||||
// window = new ECLGUIResList ();
|
||||
// }
|
||||
// window.position = new Rect (Screen.width / 2 - Screen.width / 4, Screen.height / 2 - Screen.height / 4, Screen.width / 2, Screen.height / 2);
|
||||
window.title = "资源列表";
|
||||
window.rootPath = rootPath;
|
||||
window.callback = callback;
|
||||
window.callback2 = callback2;
|
||||
window.totalFiles = 0;
|
||||
|
||||
window.datas.Clear ();
|
||||
window.selectedDatas.Clear ();
|
||||
|
||||
window.resLastUpgradeVer = ECLProjectManager.getLastUpgradeVer ();
|
||||
window.initData (rootPath, 0);
|
||||
window.Show ();
|
||||
}
|
||||
|
||||
public static void show4PublishSeting (string rootPath, Callback callback, Callback callback2)
|
||||
{
|
||||
show4PublishSeting (rootPath, null, callback, callback2);
|
||||
}
|
||||
|
||||
public static void show4PublishSeting (string rootPath, string publishConfig, Callback callback, Callback callback2)
|
||||
{
|
||||
ECLGUIResList window = ScriptableWizard.DisplayWizard<ECLGUIResList> ("Res List");
|
||||
// Rect rect = window.position;
|
||||
// // rect = new Rect (-Screen.width/2, Screen.height / 2 - Screen.height / 4, Screen.width / 2, Screen.height / 2);
|
||||
// rect.x = -Screen.width - Screen.width / 4;
|
||||
// rect.y = Screen.height / 2 - Screen.height / 4;
|
||||
// rect.width = Screen.width / 2;
|
||||
// rect.height = Screen.height / 2;
|
||||
// window.position = rect;
|
||||
|
||||
window.title = "资源列表";
|
||||
window.rootPath = rootPath;
|
||||
window.callback = callback;
|
||||
window.callback2 = callback2;
|
||||
window.totalFiles = 0;
|
||||
|
||||
window.datas.Clear ();
|
||||
window.selectedDatas.Clear ();
|
||||
|
||||
window.resLastUpgradeVer = ECLProjectManager.getLastUpgradeVer ();
|
||||
window.initData (rootPath, 0);
|
||||
window.init4PublishSetting (publishConfig);
|
||||
// window.ShowPopup ();
|
||||
window.Show ();
|
||||
}
|
||||
|
||||
public static void show4Upgrade (string rootPath, Callback callback, Callback callback2)
|
||||
{
|
||||
ECLGUIResList window = ScriptableWizard.DisplayWizard<ECLGUIResList> ("Res List");
|
||||
|
||||
// Rect rect = window.position;
|
||||
// rect.x = -Screen.width - Screen.width / 4;
|
||||
// rect.y = Screen.height / 2 - Screen.height / 4;
|
||||
// rect.width = Screen.width / 2;
|
||||
// rect.height = Screen.height / 2;
|
||||
|
||||
// Vector2 size = Handles.GetMainGameViewSize ();
|
||||
// rect = new Rect (-size.x/2, size.y / 2 - size.y / 4, size.x / 2, size.y / 2);
|
||||
// window.position = rect;
|
||||
|
||||
window.title = "Upgrade资源列表";
|
||||
window.rootPath = rootPath;
|
||||
window.callback = callback;
|
||||
window.callback2 = callback2;
|
||||
window.totalFiles = 0;
|
||||
|
||||
window.datas.Clear ();
|
||||
window.selectedDatas.Clear ();
|
||||
|
||||
window.resLastUpgradeVer = ECLProjectManager.getLastUpgradeVer ();
|
||||
window.initData (rootPath, 0);
|
||||
window.init4Upgrade4Publish ();
|
||||
|
||||
window.Show ();
|
||||
}
|
||||
|
||||
void init4Upgrade4Publish ()
|
||||
{
|
||||
AssetDatabase.Refresh ();
|
||||
Hashtable tmpResVer = ECLCreateVerCfg.create2Map ("Assets/" + ECLProjectManager.data.name + "/upgradeRes4Publish");
|
||||
Hashtable lastResVer = ECLProjectManager.getLastUpgradeMd5Ver ();
|
||||
string key = "";
|
||||
ECLResInfor ri = null;
|
||||
Hashtable needUpgradeRes = new Hashtable ();
|
||||
foreach (DictionaryEntry cell in tmpResVer) {
|
||||
key = cell.Key.ToString ().Replace ("/upgradeRes/", "/upgradeRes4Publish/");
|
||||
if (lastResVer [key] == null || string.Compare (cell.Value.ToString (), lastResVer [key].ToString ()) != 0) {
|
||||
needUpgradeRes [key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
int count = datas.Count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ri = (ECLResInfor)(datas [i]);
|
||||
if (needUpgradeRes [ri.relativePath] != null) {
|
||||
ri.selected = true;
|
||||
} else {
|
||||
ri.selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init4PublishSetting (string oldPublishPath)
|
||||
{
|
||||
AssetDatabase.Refresh ();
|
||||
string publishVerPath = "";
|
||||
if (string.IsNullOrEmpty (oldPublishPath)) {
|
||||
publishVerPath = Application.dataPath + "/" + ECLProjectManager.ver4Publish;
|
||||
} else {
|
||||
publishVerPath = oldPublishPath;
|
||||
}
|
||||
Hashtable oldSettingCfg = ECLProjectManager.fileToMap (publishVerPath);
|
||||
string key = "";
|
||||
ECLResInfor ri = null;
|
||||
Hashtable needUpgradeRes = new Hashtable ();
|
||||
foreach (DictionaryEntry cell in oldSettingCfg) {
|
||||
key = cell.Key.ToString ().Replace ("/upgradeRes/", "/upgradeRes4Publish/");
|
||||
needUpgradeRes [key] = true;
|
||||
}
|
||||
|
||||
int count = datas.Count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ri = (ECLResInfor)(datas [i]);
|
||||
if (needUpgradeRes [ri.relativePath] != null) {
|
||||
ri.selected = true;
|
||||
} else {
|
||||
ri.selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class ECLResInfor
|
||||
{
|
||||
public string path = "";
|
||||
public string name = "";
|
||||
public string relativePath = "";
|
||||
public string publishPath = "";
|
||||
public int tabs = 0;
|
||||
public string ver = "";
|
||||
public bool isDir = false;
|
||||
public bool selected = false;
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLGUIResList.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLGUIResList.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1c89176398114ee3b05d4ec6c76ee71
|
||||
timeCreated: 1484206596
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
245
Assets/CoolapeFrame/Editor/Tools/ECLLocalizeSelection.cs
Normal file
245
Assets/CoolapeFrame/Editor/Tools/ECLLocalizeSelection.cs
Normal file
@@ -0,0 +1,245 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Coolape;
|
||||
using System.IO;
|
||||
|
||||
public class ECLLocalizeSelection : ScriptableWizard
|
||||
{
|
||||
string newKey = "";
|
||||
// string newContent = "";
|
||||
static public ECLLocalizeSelection instance;
|
||||
string editKey = "";
|
||||
string editVal = "";
|
||||
bool isShowList = false;
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
void OnDisable ()
|
||||
{
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public delegate void OnSlecteCallback (string key, string val);
|
||||
|
||||
OnSlecteCallback mCallback;
|
||||
static Dictionary<string, ArrayList> dictOrgs = new Dictionary<string, ArrayList> ();
|
||||
static Dictionary<string, ArrayList> dict = new Dictionary<string, ArrayList> ();
|
||||
ArrayList languageList = new ArrayList ();
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
string searchKey = "";
|
||||
string oldSearchKey = "";
|
||||
|
||||
public static void open (OnSlecteCallback callback)
|
||||
{
|
||||
if (instance != null) {
|
||||
instance.Close ();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
ECLLocalizeSelection comp = ScriptableWizard.DisplayWizard<ECLLocalizeSelection> ("Select a Localize");
|
||||
comp.mCallback = callback;
|
||||
comp.refreshContent ();
|
||||
comp.searchKey = "";
|
||||
comp.oldSearchKey = "";
|
||||
}
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
if (GUILayout.Button ("Rfresh", GUILayout.Width (60))) {
|
||||
editKey = "";
|
||||
refreshContent ();
|
||||
}
|
||||
GUI.color = Color.green;
|
||||
if (GUILayout.Button ("Search", GUILayout.Width (60))) {
|
||||
search (searchKey);
|
||||
isShowList = true;
|
||||
}
|
||||
GUI.color = Color.yellow;
|
||||
searchKey = GUILayout.TextField (searchKey);
|
||||
GUI.color = Color.white;
|
||||
GUILayout.Label ("New Key:", GUILayout.Width (70));
|
||||
newKey = GUILayout.TextField (newKey, GUILayout.Width (120));
|
||||
GUI.color = Color.yellow;
|
||||
// newContent = GUILayout.TextField (newContent);
|
||||
if (GUILayout.Button ("Add", GUILayout.Width (60))) {
|
||||
addVal (newKey, searchKey);
|
||||
newKey = "";
|
||||
isShowList = false;
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
GUI.color = Color.white;
|
||||
|
||||
// if (searchKey != oldSearchKey) {
|
||||
// oldSearchKey = searchKey;
|
||||
// search (searchKey);
|
||||
// }
|
||||
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("Key", GUILayout.Width (120));
|
||||
for (int i = 0; i < languageList.Count; i++) {
|
||||
GUILayout.Label (languageList [i].ToString ());
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Width (position.width), GUILayout.Height (position.height - 65));
|
||||
{
|
||||
if (isShowList) {
|
||||
foreach (KeyValuePair<string ,ArrayList> cell in dict) {
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.TextField (cell.Key, GUILayout.Width (120));
|
||||
for (int i = 0; i < cell.Value.Count; i++) {
|
||||
if (editKey != cell.Key) {
|
||||
GUILayout.TextArea (cell.Value [i].ToString ());
|
||||
if (GUILayout.Button ("Edit", GUILayout.Width (50))) {
|
||||
editKey = cell.Key;
|
||||
editVal = cell.Value [i].ToString ();
|
||||
}
|
||||
} else {
|
||||
GUI.color = Color.green;
|
||||
editVal = GUILayout.TextArea (editVal);
|
||||
if (GUILayout.Button ("Modify", GUILayout.Width (50))) {
|
||||
addVal (editKey, editVal, true);
|
||||
editKey = "";
|
||||
editVal = "";
|
||||
GUI.color = Color.white;
|
||||
return;
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
if (GUILayout.Button ("Select", GUILayout.Width (60))) {
|
||||
if (mCallback != null) {
|
||||
mCallback (cell.Key, cell.Value [0].ToString ());
|
||||
Close ();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button ("-", GUILayout.Width (20))) {
|
||||
if (EditorUtility.DisplayDialog ("Alert", "Really want to delete?", "Okay", "Cancel")) {
|
||||
cutVal (cell.Key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
}
|
||||
|
||||
void search (string searchKey)
|
||||
{
|
||||
if (string.IsNullOrEmpty (searchKey)) {
|
||||
dict = dictOrgs;
|
||||
return;
|
||||
}
|
||||
dict = new Dictionary<string, ArrayList> ();
|
||||
foreach (KeyValuePair<string, ArrayList> cell in dictOrgs) {
|
||||
if (cell.Key.ToUpper ().Contains (searchKey.ToUpper ())) {
|
||||
dict [cell.Key] = cell.Value;
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < cell.Value.Count; i++) {
|
||||
if (cell.Value [i].ToString ().ToUpper ().Contains (searchKey.ToUpper ())) {
|
||||
dict [cell.Key] = cell.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cutVal (string key)
|
||||
{
|
||||
string fileName = Application.dataPath + "/" + CLPathCfg.self.localizationPath + "Chinese.txt";
|
||||
fileName = fileName.Replace ("/upgradeRes/", "/upgradeRes4Dev/");
|
||||
Dictionary<string, string> tempDic = null;
|
||||
byte[] buff = File.ReadAllBytes (fileName);
|
||||
ByteReader reader = new ByteReader (buff);
|
||||
tempDic = reader.ReadDictionary ();
|
||||
if (!tempDic.ContainsKey (key))
|
||||
return;
|
||||
tempDic.Remove (key);
|
||||
|
||||
PStr pstr = PStr.b ();
|
||||
foreach (KeyValuePair<string, string> cell in tempDic) {
|
||||
pstr.a (cell.Key).a ("=").a (cell.Value.Replace ("\n", "\\n")).a ("\n");
|
||||
}
|
||||
File.WriteAllText (fileName, pstr.e ());
|
||||
refreshContent ();
|
||||
}
|
||||
|
||||
void addVal (string key, string val, bool isForce = false)
|
||||
{
|
||||
if (!string.IsNullOrEmpty (key) && !string.IsNullOrEmpty (val)) {
|
||||
if (dictOrgs.ContainsKey (key) && !isForce) {
|
||||
EditorUtility.DisplayDialog ("error", "The key is allready exist!", "Okay");
|
||||
} else {
|
||||
string fileName = Application.dataPath + "/" + CLPathCfg.self.localizationPath + "Chinese.txt";
|
||||
fileName = fileName.Replace ("/upgradeRes/", "/upgradeRes4Dev/");
|
||||
if (isForce) {
|
||||
Dictionary<string, string> tempDic = null;
|
||||
byte[] buff = File.ReadAllBytes (fileName);
|
||||
ByteReader reader = new ByteReader (buff);
|
||||
tempDic = reader.ReadDictionary ();
|
||||
tempDic [key] = val;
|
||||
|
||||
PStr pstr = PStr.b ();
|
||||
foreach (KeyValuePair<string, string> cell in tempDic) {
|
||||
pstr.a (cell.Key).a ("=").a (cell.Value.Replace ("\n", "\\n")).a ("\n");
|
||||
}
|
||||
File.WriteAllText (fileName, pstr.e ());
|
||||
} else {
|
||||
File.AppendAllText (fileName, "\n" + key + "=" + val);
|
||||
}
|
||||
refreshContent ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void refreshContent ()
|
||||
{
|
||||
editKey = "";
|
||||
languageList.Clear ();
|
||||
dictOrgs.Clear ();
|
||||
dict.Clear ();
|
||||
string dir = Application.dataPath + "/" + CLPathCfg.self.localizationPath;
|
||||
dir = dir.Replace ("/upgradeRes/", "/upgradeRes4Dev/");
|
||||
string[] files = Directory.GetFiles (dir);
|
||||
byte[] buff = null;
|
||||
Dictionary<string, string> tempDic = null;
|
||||
for (int i = 0; i < files.Length; i++) {
|
||||
if (ECLEditorUtl.isIgnoreFile (files [i]))
|
||||
continue;
|
||||
buff = File.ReadAllBytes (files [i]);
|
||||
languageList.Add (Path.GetFileNameWithoutExtension (files [i]));
|
||||
ByteReader reader = new ByteReader (buff);
|
||||
tempDic = reader.ReadDictionary ();
|
||||
foreach (KeyValuePair<string, string> cell in tempDic) {
|
||||
if (dictOrgs.ContainsKey (cell.Key.ToString ())) {
|
||||
ArrayList list = dictOrgs [cell.Key.ToString ()];
|
||||
if (list == null) {
|
||||
list = new ArrayList ();
|
||||
}
|
||||
list.Add (cell.Value);
|
||||
dictOrgs [cell.Key.ToString ()] = list;
|
||||
} else {
|
||||
ArrayList list = new ArrayList ();
|
||||
list.Add (cell.Value);
|
||||
dictOrgs [cell.Key.ToString ()] = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
dict = dictOrgs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 560a625be329547b488d47192a8cea27
|
||||
timeCreated: 1490665493
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Assets/CoolapeFrame/Editor/Tools/ECLLuaEncodeTool.cs
Normal file
128
Assets/CoolapeFrame/Editor/Tools/ECLLuaEncodeTool.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using Coolape;
|
||||
|
||||
/*
|
||||
* 1.获取LuaJIT!地址http://luajit.org/
|
||||
注意!!!!!============>>>>> uLua uses LuaJIT 2.0.2 which can be obtained from http://luajit.org/
|
||||
一定要下载LuaJIT 2.0.2 (当前release version 2.0.3)
|
||||
|
||||
2.解压下载的压缩包
|
||||
在terminal依次输入
|
||||
cd /Users/YourAccount/Download/LuaJIT-2.0.2
|
||||
make
|
||||
sudo make install
|
||||
luajit
|
||||
如果能看到luajit的版本号,到此mac上luajit环境就ok了!!!
|
||||
|
||||
3.通过luajit对所有lua文件进行编译,生成bytecode二进制文件
|
||||
find . -name "*.lua" -exec luajit -b {} {}.out \;
|
||||
{}.out 至于这个后缀,本人其实建议还是用lua
|
||||
|
||||
4.最后就是既关键!又简单!的一步!
|
||||
大家使用ulua,一般调用的是Lua.cs里的LuaState实例的DoString、DoFile
|
||||
如果想使用LuaJIT的bytecode文件,只需要调用LuaDLL.luaL_dofile(IntPtr luaState, string fileName)
|
||||
|
||||
本人亲测win、mac、android、ios均通过测试!!!解决了lua加密的问题!嘿嘿!
|
||||
|
||||
|
||||
本次测试正好确认了一件事!那就是ulua插件提供的库里已经把LuaJIT打进去了!
|
||||
*/
|
||||
public class ECLLuaEncodeTool
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Luajits the encode.
|
||||
/// </summary>
|
||||
public static void luajitEncode ()
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath (Selection.activeObject);//Selection表示你鼠标选择激活的对象
|
||||
if (string.IsNullOrEmpty (path) || !File.Exists (path)) {
|
||||
UnityEngine.Debug.LogWarning ("请选择lua 文件!");
|
||||
return;
|
||||
}
|
||||
// luajitEncode (path);
|
||||
xxteaEncode (path);
|
||||
EditorUtility.DisplayDialog ("success", "Encode cuccess!", "Okey");
|
||||
}
|
||||
|
||||
public static void luajitEncodeAll ()
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath (Selection.activeObject);//Selection表示你鼠标选择激活的对象
|
||||
if (string.IsNullOrEmpty (path) || !Directory.Exists (path)) {
|
||||
UnityEngine.Debug.LogWarning ("请选择目录!");
|
||||
return;
|
||||
}
|
||||
luajitEncodeAll (path);
|
||||
EditorUtility.DisplayDialog ("success", "Encode cuccess!", "Okey");
|
||||
}
|
||||
|
||||
public static void luajitEncodeAll (string dir)
|
||||
{
|
||||
string[] fileEntries = Directory.GetFiles (dir);//因为Application.dataPath得到的是型如 "工程名称/Assets"
|
||||
string extension = "";
|
||||
foreach (string f in fileEntries) {
|
||||
extension = Path.GetExtension (f);
|
||||
extension = extension.ToLower ();
|
||||
if (extension != ".lua") {
|
||||
continue;
|
||||
}
|
||||
// luajitEncode (f);
|
||||
xxteaEncode (f);
|
||||
}
|
||||
string[] dirEntries = Directory.GetDirectories (dir);
|
||||
foreach (string d in dirEntries) {
|
||||
luajitEncodeAll (d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void luajitEncode (string path)
|
||||
{
|
||||
string basePath = Application.dataPath;
|
||||
path = path.Replace ("Assets/", "/");
|
||||
string dir = Path.GetDirectoryName (path);
|
||||
string fname = Path.GetFileNameWithoutExtension (path);
|
||||
string fext = Path.GetExtension (path);
|
||||
string outPath = basePath + dir + "/" + fname + fext;
|
||||
outPath = outPath.Replace("\\", "/");
|
||||
outPath = outPath.Replace ("/upgradeRes4Dev", "/upgradeRes4Publish");
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (outPath));
|
||||
#if UNITY_IOS
|
||||
byte[] bytes = XXTEA.Encrypt(File.ReadAllBytes(basePath + path), XXTEA.defaultKey);
|
||||
File.WriteAllBytes(outPath, bytes);
|
||||
#elif UNITY_ANDROID
|
||||
// string exeName = "/usr/local/bin/luajit";
|
||||
string exeName = "/usr/local/bin/luajit-2.0.4";
|
||||
// string exeName = "/usr/local/bin/luajit-2.0.3";
|
||||
// string exeName = "/usr/local/bin/luajit-2.1.0-alpha";
|
||||
if (!File.Exists (exeName)) {
|
||||
UnityEngine.Debug.LogError ("Ecode lua failed. file not fou" + exeName);
|
||||
return;
|
||||
}
|
||||
string arguments = "-b " + basePath + path + " " + outPath;
|
||||
Process.Start (exeName, arguments);
|
||||
//#else
|
||||
// byte[] bytes = XXTEA.Encrypt(File.ReadAllBytes(basePath + path), XXTEA.defaultKey);
|
||||
// File.WriteAllBytes(outPath, bytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void xxteaEncode (string path)
|
||||
{
|
||||
string basePath = Application.dataPath;
|
||||
path = path.Replace ("Assets/", "/");
|
||||
string dir = Path.GetDirectoryName (path);
|
||||
string fname = Path.GetFileNameWithoutExtension (path);
|
||||
string fext = Path.GetExtension (path);
|
||||
string outPath = basePath + dir + "/" + fname + fext;
|
||||
outPath = outPath.Replace("\\", "/");
|
||||
outPath = outPath.Replace ("/upgradeRes4Dev", "/upgradeRes4Publish");
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (outPath));
|
||||
byte[] bytes = XXTEA.Encrypt (System.Text.Encoding.UTF8.GetBytes (File.ReadAllText (basePath + path)), XXTEA.defaultKey);
|
||||
File.WriteAllBytes (outPath, bytes);
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLLuaEncodeTool.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLLuaEncodeTool.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97d5fbba12525422cb4e6d3f83f64e8f
|
||||
timeCreated: 1484206596
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1863
Assets/CoolapeFrame/Editor/Tools/ECLProjectManager.cs
Normal file
1863
Assets/CoolapeFrame/Editor/Tools/ECLProjectManager.cs
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/CoolapeFrame/Editor/Tools/ECLProjectManager.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLProjectManager.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 024f11fa20b154b6799ffad88562df8e
|
||||
timeCreated: 1484206596
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1253
Assets/CoolapeFrame/Editor/Tools/ECLProjectSetting.cs
Normal file
1253
Assets/CoolapeFrame/Editor/Tools/ECLProjectSetting.cs
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/CoolapeFrame/Editor/Tools/ECLProjectSetting.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLProjectSetting.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b337ef9047f4453193ea30160452d3e
|
||||
timeCreated: 1485055820
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1875
Assets/CoolapeFrame/Editor/Tools/ECLPublisher.cs
Normal file
1875
Assets/CoolapeFrame/Editor/Tools/ECLPublisher.cs
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/CoolapeFrame/Editor/Tools/ECLPublisher.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLPublisher.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3765ec9bacbf40a996c08ffafecb9a2
|
||||
timeCreated: 1484206596
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
762
Assets/CoolapeFrame/Editor/Tools/ECLSpritePacker.cs
Normal file
762
Assets/CoolapeFrame/Editor/Tools/ECLSpritePacker.cs
Normal file
@@ -0,0 +1,762 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Coolape;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public class ECLSpritePacker : EditorWindow
|
||||
{
|
||||
public enum PackerSize
|
||||
{
|
||||
max_Sprite_Count_50 = 50,
|
||||
max_Sprite_Count_100 = 100,
|
||||
max_Sprite_Count_150 = 150,
|
||||
max_Sprite_Count_200 = 200,
|
||||
}
|
||||
|
||||
public enum PackerTextureSize
|
||||
{
|
||||
Texture_Size_512 = 512,
|
||||
Texture_Size_1024 = 1024,
|
||||
Texture_Size_2048 = 2048,
|
||||
Texture_Size_4096 = 4096,
|
||||
}
|
||||
|
||||
public enum SortSprite
|
||||
{
|
||||
none,
|
||||
SortArea,
|
||||
SortLength,
|
||||
}
|
||||
|
||||
static string mSpritesBorrowInforFile = "";
|
||||
static int cellSize = 70;
|
||||
static Rect rect = new Rect (50f, 0, cellSize, cellSize);
|
||||
static ArrayList mSpriteList = new ArrayList ();
|
||||
PackerSize packerSize = PackerSize.max_Sprite_Count_100;
|
||||
PackerTextureSize textureSize = PackerTextureSize.Texture_Size_1024;
|
||||
SortSprite sortSprite = SortSprite.SortArea;
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
Vector2 scrollPos2 = Vector2.zero;
|
||||
static string mSelectedSprite = "";
|
||||
Hashtable item;
|
||||
bool isSelectedAll = false;
|
||||
int selectedCount = 0;
|
||||
int allSpriteCount = 0;
|
||||
Hashtable currSelectSprite;
|
||||
bool isShowParckerView = false;
|
||||
bool isShowParckerTextureBg = false;
|
||||
Texture2D packTex;
|
||||
static Rect[] packRects;
|
||||
static List<Hashtable> packSprites = new List<Hashtable> ();
|
||||
static string packedName = "";
|
||||
Texture2D _empty;
|
||||
bool isUseUnityPacking = true;
|
||||
bool showDeltail = false;
|
||||
bool removePublishRes = true;
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
GUILayout.Space (5);
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
if (GUILayout.Button ("Sprites Borrow Infor File", ECLEditorUtl.width150)) {
|
||||
string _mSpritesBorrowInforFile = EditorUtility.OpenFilePanel ("Select Infor File", Application.dataPath + "/KOK/xRes/spriteBorrow", "json");
|
||||
if (!mSpritesBorrowInforFile.Equals (_mSpritesBorrowInforFile)) {
|
||||
mSpritesBorrowInforFile = _mSpritesBorrowInforFile;
|
||||
initData ();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button ("Refresh", ECLEditorUtl.width80)) {
|
||||
initData ();
|
||||
}
|
||||
GUILayout.TextField (mSpritesBorrowInforFile);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
GUILayout.Space (5);
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
packerSize = (PackerSize)EditorGUILayout.EnumPopup ("", packerSize);
|
||||
GUI.color = Color.yellow;
|
||||
if (GUILayout.Button ("Packer View")) {
|
||||
isShowParckerView = true;
|
||||
currSelectSprite = null;
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
GUILayout.Space (5);
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.BeginVertical ();
|
||||
{
|
||||
bool _isSelectedAll = EditorGUILayout.ToggleLeft ("All", isSelectedAll, ECLEditorUtl.width150);
|
||||
if (isSelectedAll != _isSelectedAll) {
|
||||
isSelectedAll = _isSelectedAll;
|
||||
for (int i = 0; i < mSpriteList.Count && i < (int)packerSize; i++) {
|
||||
item = mSpriteList [i] as Hashtable;
|
||||
item ["selected"] = isSelectedAll;
|
||||
}
|
||||
refreshSelectedCount ();
|
||||
}
|
||||
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, ECLEditorUtl.width150);
|
||||
{
|
||||
rect.y = 0;
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
// GUILayout.Space (10);
|
||||
for (int i = 0; i < mSpriteList.Count && i < (int)packerSize; i++) {
|
||||
item = mSpriteList [i] as Hashtable;
|
||||
bool selected = GUI.Toggle (new Rect (5, rect.y, 50, cellSize + 30), MapEx.getBool (item, "selected"), (i + 1).ToString ());
|
||||
if (selected != MapEx.getBool (item, "selected")) {
|
||||
item ["selected"] = selected;
|
||||
refreshSelectedCount ();
|
||||
}
|
||||
showCellSprite (item);
|
||||
}
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
}
|
||||
EditorGUILayout.EndVertical ();
|
||||
//=========================================
|
||||
//=========================================
|
||||
EditorGUILayout.BeginVertical ();
|
||||
{
|
||||
GUILayout.Label (PStr.b ().a ("Selected: ").a (selectedCount).a ("/").a (allSpriteCount).e ());
|
||||
scrollPos2 = EditorGUILayout.BeginScrollView (scrollPos2, GUILayout.Width (position.width - 150));
|
||||
{
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
if (isShowParckerView) {
|
||||
showPackerView ();
|
||||
} else {
|
||||
showSpriteInfor ();
|
||||
}
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
}
|
||||
EditorGUILayout.EndVertical ();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
void refreshSelectedCount ()
|
||||
{
|
||||
int ret = 0;
|
||||
allSpriteCount = 0;
|
||||
selectedCount = 0;
|
||||
for (int i = 0; i < mSpriteList.Count && i < (int)packerSize; i++) {
|
||||
allSpriteCount += 1;
|
||||
item = mSpriteList [i] as Hashtable;
|
||||
if (MapEx.getBool (item, "selected")) {
|
||||
ret += 1;
|
||||
}
|
||||
}
|
||||
selectedCount = ret;
|
||||
}
|
||||
|
||||
void showPackerView ()
|
||||
{
|
||||
if (packTex != null) {
|
||||
//=================
|
||||
float h = 0;
|
||||
float w = position.width - 160;
|
||||
float rate = w / packTex.width;
|
||||
if (rate < 1) {
|
||||
h = packTex.height * rate;
|
||||
} else {
|
||||
h = packTex.height;
|
||||
}
|
||||
h = h > 512 ? h : 512;
|
||||
Rect r = new Rect (0, 0, NumEx.getIntPart (w), NumEx.getIntPart (h));
|
||||
NGUIEditorTools.DrawTiledTexture (r, NGUIEditorTools.backdropTexture);
|
||||
if (isShowParckerTextureBg) {
|
||||
GUI.DrawTexture (r, _empty, ScaleMode.ScaleToFit, false);
|
||||
}
|
||||
GUI.DrawTexture (r, packTex, ScaleMode.ScaleToFit);
|
||||
GUILayout.Space (r.height + r.y); //这句主要目的是为了可以滑动
|
||||
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("width", packTex.width);
|
||||
EditorGUILayout.IntField ("height", packTex.height);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
if (GUILayout.Button ("Show/Hide Detail")) {
|
||||
showDeltail = !showDeltail;
|
||||
}
|
||||
if (showDeltail) {
|
||||
if (packSprites != null) {
|
||||
Hashtable m = null;
|
||||
Hashtable d = null;
|
||||
Rect _rect;
|
||||
for (int i = 0; i < packSprites.Count; i++) {
|
||||
_rect = packRects [i];
|
||||
m = packSprites [i] as Hashtable;
|
||||
d = MapEx.getMap (m, "data");
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.LabelField (MapEx.getString (d, "name"));
|
||||
EditorGUILayout.LabelField (Mathf.RoundToInt (_rect.x) + "x" + Mathf.RoundToInt (_rect.y));
|
||||
EditorGUILayout.LabelField (Mathf.RoundToInt (_rect.width) + "x" + Mathf.RoundToInt (_rect.height));
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
|
||||
}
|
||||
|
||||
isShowParckerTextureBg = EditorGUILayout.ToggleLeft ("Show Background", isShowParckerTextureBg);
|
||||
textureSize = (PackerTextureSize)EditorGUILayout.EnumPopup ("", textureSize);
|
||||
isUseUnityPacking = EditorGUILayout.ToggleLeft ("UnityPacking", isUseUnityPacking);
|
||||
sortSprite = (SortSprite)EditorGUILayout.EnumPopup ("", sortSprite);
|
||||
GUILayout.Space (5);
|
||||
GUI.color = Color.yellow;
|
||||
if (GUILayout.Button ("Review Pack Texture")) {
|
||||
if (!packTextures ((int)textureSize, isUseUnityPacking)) {
|
||||
Debug.LogError ("Some errors happened!");
|
||||
}
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
GUILayout.Space (10);
|
||||
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
packedName = EditorGUILayout.TextField ("Packed Texture Name", string.IsNullOrEmpty (packedName) ? "Packed" + (int)packerSize : packedName);
|
||||
GUI.color = Color.red;
|
||||
removePublishRes = EditorGUILayout.ToggleLeft ("Remove Publish AssetsBundle", removePublishRes);
|
||||
if (GUILayout.Button ("Apply Pack Texture")) {
|
||||
applyPackTexture ((int)textureSize, isUseUnityPacking);
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
|
||||
void applyPackTexture (int maxSize, bool unityPacking)
|
||||
{
|
||||
string texturePath = EditorUtility.OpenFolderPanel ("Save packed texture", Application.dataPath + "/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other", "");
|
||||
if (string.IsNullOrEmpty (texturePath)) {
|
||||
return;
|
||||
}
|
||||
if (packTex == null || packRects == null || packRects.Length == 0 || packSprites == null || packSprites.Count == 0 || packRects.Length != packSprites.Count) {
|
||||
packTextures (maxSize, isUseUnityPacking);
|
||||
}
|
||||
string packTextureFile = Path.Combine (texturePath, packedName + ".png");
|
||||
string packTextureFile4Atlas = packTextureFile.Replace (Application.dataPath + "/", "");
|
||||
Debug.LogWarning (packTextureFile4Atlas);
|
||||
|
||||
byte[] bytes = packTex.EncodeToPNG ();
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (packTextureFile));
|
||||
File.WriteAllBytes (packTextureFile, bytes);
|
||||
AssetDatabase.ImportAsset ("Assets/" + packTextureFile4Atlas);
|
||||
TextureImporter textureImporter = AssetImporter.GetAtPath ("Assets/" + packTextureFile4Atlas) as TextureImporter;
|
||||
textureImporter.textureType = TextureImporterType.GUI;
|
||||
textureImporter.mipmapEnabled = false;
|
||||
textureImporter.wrapMode = TextureWrapMode.Clamp;
|
||||
textureImporter.alphaIsTransparency = true;
|
||||
textureImporter.npotScale = TextureImporterNPOTScale.None;
|
||||
textureImporter.filterMode = FilterMode.Trilinear; //改成这种模式好像更省内存
|
||||
AssetDatabase.ImportAsset ("Assets/" + packTextureFile4Atlas);
|
||||
|
||||
Hashtable m = null;
|
||||
Hashtable d = null;
|
||||
Hashtable atlasMap = null;
|
||||
UIAtlas atlas = null;
|
||||
UISpriteData spData = null;
|
||||
Rect _rect;
|
||||
for (int i = 0; i < packSprites.Count; i++) {
|
||||
m = packSprites [i] as Hashtable;
|
||||
_rect = packRects [i];
|
||||
d = MapEx.getMap (m, "data");
|
||||
atlasMap = MapEx.getMap (m, "atlas");
|
||||
foreach (DictionaryEntry item in atlasMap) {
|
||||
atlas = getAtlasByName (item.Key.ToString ());
|
||||
if (atlas == null) {
|
||||
Debug.LogError ("Get atlas is null!!==" + item.Key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// spData = atlas.GetSprite (MapEx.getString (d, "name"));
|
||||
string spName = MapEx.getString (d, "name");
|
||||
if (!atlas.spriteMap.ContainsKey (spName)) {
|
||||
Debug.LogError ("atlas.GetSprite is null!!==" + spName);
|
||||
continue;
|
||||
}
|
||||
int index = MapEx.getInt (atlas.spriteMap, spName);
|
||||
spData = atlas.spriteList [index];
|
||||
if (spData == null) {
|
||||
Debug.LogError ("atlas.GetSprite is null!!==" + spName);
|
||||
continue;
|
||||
}
|
||||
string toPath = texturePath + "/" + spData.path.Replace (CLPathCfg.self.basePath + "/upgradeRes4Dev/other/", "");
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (toPath));
|
||||
toPath = toPath.Replace (Application.dataPath + "/", "");
|
||||
AssetDatabase.ImportAsset (Path.GetDirectoryName ("Assets/" + toPath));
|
||||
string err = AssetDatabase.MoveAsset ("Assets/" + spData.path, "Assets/" + toPath);
|
||||
if (!string.IsNullOrEmpty (err)) {
|
||||
Debug.LogError (err);
|
||||
}
|
||||
if (removePublishRes) {
|
||||
string fromPath = Path.GetDirectoryName (spData.path) + "/Android/" + Path.GetFileNameWithoutExtension (spData.path) + ".unity3d";
|
||||
fromPath = fromPath.Replace ("/upgradeRes4Dev/", "/upgradeRes4Publish/");
|
||||
if (File.Exists (Application.dataPath + "/" + fromPath)) {
|
||||
File.Delete (Application.dataPath + "/" + fromPath);
|
||||
}
|
||||
|
||||
fromPath = Path.GetDirectoryName (spData.path) + "/IOS/" + Path.GetFileNameWithoutExtension (spData.path) + ".unity3d";
|
||||
fromPath = fromPath.Replace ("/upgradeRes4Dev/", "/upgradeRes4Publish/");
|
||||
if (File.Exists (Application.dataPath + "/" + fromPath)) {
|
||||
File.Delete (Application.dataPath + "/" + fromPath);
|
||||
}
|
||||
}
|
||||
spData.path = packTextureFile4Atlas;
|
||||
spData.x = Mathf.RoundToInt (_rect.x);
|
||||
spData.y = Mathf.RoundToInt (_rect.y);
|
||||
|
||||
EditorUtility.SetDirty (atlas.gameObject);
|
||||
AssetDatabase.ImportAsset (AssetDatabase.GetAssetPath (atlas.gameObject));
|
||||
}
|
||||
}
|
||||
AssetDatabase.SaveAssets ();
|
||||
AssetDatabase.Refresh (ImportAssetOptions.ForceSynchronousImport);
|
||||
|
||||
|
||||
EditorUtility.DisplayDialog ("success", "Finished!", "Okay");
|
||||
}
|
||||
|
||||
UIAtlas getAtlasByName (string atlasName)
|
||||
{
|
||||
string tmpPath = PStr.begin ()
|
||||
.a ("Assets/").a (CLPathCfg.self.basePath).a ("/").a ("upgradeRes4Dev").
|
||||
a ("/priority/atlas/").a (atlasName).a (".prefab").end ();
|
||||
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath (tmpPath, typeof(UnityEngine.Object));
|
||||
if (obj != null) {
|
||||
return ((GameObject)obj).GetComponent<UIAtlas> ();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bool packTextures (int maxSize, bool unityPacking)//, ref ArrayList outSprites, ref Rect[] rects)
|
||||
{
|
||||
if (packTex != null) {
|
||||
DestroyImmediate (packTex, true);
|
||||
packTex = null;
|
||||
}
|
||||
|
||||
refreshSelectedCount ();
|
||||
if (selectedCount == 0) {
|
||||
Debug.LogError ("Please select some sprites, that need packe");
|
||||
return false;
|
||||
}
|
||||
|
||||
packSprites.Clear ();
|
||||
List<Texture2D> listTexs = new List<Texture2D> ();
|
||||
for (int i = 0; i < mSpriteList.Count; i++) {
|
||||
Hashtable m = mSpriteList [i] as Hashtable;
|
||||
if (MapEx.getBool (m, "selected")) {
|
||||
Hashtable d = MapEx.getMap (m, "data");
|
||||
string name = MapEx.getString (d, "name");
|
||||
string path = MapEx.getString (d, "path");
|
||||
Texture2D tex = ECLEditorUtl.getObjectByPath (path) as Texture2D;
|
||||
listTexs.Add (tex);
|
||||
packSprites.Add (m);
|
||||
}
|
||||
}
|
||||
if (sortSprite != SortSprite.none) {
|
||||
if (sortSprite == SortSprite.SortArea) {
|
||||
packSprites.Sort (CompareSprite);
|
||||
} else {
|
||||
packSprites.Sort (CompareSprite2);
|
||||
}
|
||||
listTexs.Clear ();
|
||||
for (int i = 0; i < packSprites.Count; i++) {
|
||||
Hashtable d = MapEx.getMap (packSprites [i], "data");
|
||||
string path = MapEx.getString (d, "path");
|
||||
setTextureReadable ("Assets/" + path, TextureImporterFormat.RGBA32, TextureImporterCompression.Uncompressed, true);
|
||||
Texture2D tex = ECLEditorUtl.getObjectByPath (path) as Texture2D;
|
||||
listTexs.Add (tex);
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i = 0; i < listTexs.Count; i++) {
|
||||
// setTextureReadable (listTexs [i] as Texture, TextureImporterFormat.RGBA32, TextureImporterCompression.Uncompressed, true);
|
||||
// }
|
||||
packTex = new Texture2D (1, 1, TextureFormat.ARGB32, false);
|
||||
|
||||
if (unityPacking) {
|
||||
packRects = packTex.PackTextures (listTexs.ToArray (), NGUISettings.atlasPadding, maxSize);
|
||||
} else {
|
||||
packRects = UITexturePacker.PackTextures (packTex, listTexs.ToArray (), 4, 4, NGUISettings.atlasPadding, maxSize);
|
||||
}
|
||||
_empty = new Texture2D (packTex.width, packTex.height, TextureFormat.ARGB32, false);
|
||||
bool ret = true;
|
||||
for (int i = 0; i < listTexs.Count; ++i) {
|
||||
Rect rect = NGUIMath.ConvertToPixels (packRects [i], packTex.width, packTex.height, true);
|
||||
packRects [i] = rect;
|
||||
|
||||
// Apparently Unity can take the liberty of destroying temporary textures without any warning
|
||||
if (listTexs [i] == null) {
|
||||
Debug.LogWarning ("Apparently Unity can take the liberty of destroying temporary textures without any warning");
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Make sure that we don't shrink the textures
|
||||
if (Mathf.RoundToInt (rect.width) != listTexs [i].width) {
|
||||
Debug.LogError (rect.width + "====" + listTexs [i].width);
|
||||
Debug.LogWarning ("Make sure that we don't shrink the textures=" + listTexs [i].name);
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i = 0; i < listTexs.Count; i++) {
|
||||
// setTextureReadable (listTexs [i] as Texture, TextureImporterFormat.Automatic, false);
|
||||
// }
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CompareSprite (Hashtable a, Hashtable b)
|
||||
{
|
||||
// A is null b is not b is greater so put it at the front of the list
|
||||
if (a == null && b != null)
|
||||
return 1;
|
||||
|
||||
// A is not null b is null a is greater so put it at the front of the list
|
||||
if (a != null && b == null)
|
||||
return -1;
|
||||
|
||||
Hashtable d1 = MapEx.getMap (a, "data");
|
||||
Hashtable d2 = MapEx.getMap (b, "data");
|
||||
// Get the total pixels used for each sprite
|
||||
int aPixels = MapEx.getInt (d1, "width") * MapEx.getInt (d1, "height");
|
||||
int bPixels = MapEx.getInt (d2, "width") * MapEx.getInt (d2, "height");
|
||||
|
||||
if (aPixels > bPixels)
|
||||
return -1;
|
||||
else if (aPixels < bPixels)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CompareSprite2 (Hashtable a, Hashtable b)
|
||||
{
|
||||
// A is null b is not b is greater so put it at the front of the list
|
||||
if (a == null && b != null)
|
||||
return 1;
|
||||
|
||||
// A is not null b is null a is greater so put it at the front of the list
|
||||
if (a != null && b == null)
|
||||
return -1;
|
||||
|
||||
Hashtable d1 = MapEx.getMap (a, "data");
|
||||
Hashtable d2 = MapEx.getMap (b, "data");
|
||||
// Get the total pixels used for each sprite
|
||||
int w = MapEx.getInt (d1, "width");
|
||||
int h = MapEx.getInt (d1, "height");
|
||||
int aPixels = w > h ? w : h;
|
||||
w = MapEx.getInt (d2, "width");
|
||||
h = MapEx.getInt (d2, "height");
|
||||
int bPixels = w > h ? w : h;
|
||||
|
||||
if (aPixels > bPixels)
|
||||
return -1;
|
||||
else if (aPixels < bPixels)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setTextureReadable (Texture2D tex, TextureImporterFormat format, TextureImporterCompression compression, bool val, bool importNow = true)
|
||||
{
|
||||
string texPath = AssetDatabase.GetAssetPath (tex);
|
||||
setTextureReadable (texPath, format, compression, val, importNow);
|
||||
}
|
||||
|
||||
void setTextureReadable (string texPath, TextureImporterFormat format, TextureImporterCompression compression, bool val, bool importNow = true)
|
||||
{
|
||||
TextureImporter textureImporter = AssetImporter.GetAtPath (texPath) as TextureImporter;
|
||||
textureImporter.isReadable = val;
|
||||
|
||||
//textureImporter.textureFormat = format;
|
||||
textureImporter.textureCompression = compression;
|
||||
TextureImporterPlatformSettings texSettings = new TextureImporterPlatformSettings();
|
||||
texSettings.format = format;
|
||||
texSettings.maxTextureSize = 4096;
|
||||
texSettings.allowsAlphaSplitting = true;
|
||||
texSettings.compressionQuality = 100;
|
||||
#if UNITY_ANDROID
|
||||
texSettings.name = "Android";
|
||||
//textureImporter.SetPlatformTextureSettings ("Android", 4096, format, 100, true);
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
texSettings.name = "iPhone";
|
||||
//textureImporter.SetPlatformTextureSettings("iPhone", 4096, format, 100, true);
|
||||
#else
|
||||
texSettings.name = "Standalone";
|
||||
//textureImporter.SetPlatformTextureSettings("Standalone", 4096, format, 100, true);
|
||||
#endif
|
||||
textureImporter.SetPlatformTextureSettings(texSettings);
|
||||
EditorUtility.SetDirty (textureImporter);
|
||||
textureImporter.SaveAndReimport ();
|
||||
if (importNow) {
|
||||
AssetDatabase.ImportAsset (texPath);
|
||||
}
|
||||
}
|
||||
|
||||
void showSpriteInfor ()
|
||||
{
|
||||
if (currSelectSprite == null)
|
||||
return;
|
||||
Hashtable d = MapEx.getMap (currSelectSprite, "data");
|
||||
int times = MapEx.getInt (currSelectSprite, "times");
|
||||
string name = MapEx.getString (d, "name");
|
||||
string path = MapEx.getString (d, "path");
|
||||
int x = MapEx.getInt (d, "x");
|
||||
int y = MapEx.getInt (d, "y");
|
||||
int width = MapEx.getInt (d, "width");
|
||||
int height = MapEx.getInt (d, "height");
|
||||
int borderLeft = MapEx.getInt (d, "borderLeft");
|
||||
int borderRight = MapEx.getInt (d, "borderRight");
|
||||
int borderTop = MapEx.getInt (d, "borderTop");
|
||||
int borderBottom = MapEx.getInt (d, "borderBottom");
|
||||
int paddingLeft = MapEx.getInt (d, "paddingLeft");
|
||||
int paddingRight = MapEx.getInt (d, "paddingRight");
|
||||
int paddingTop = MapEx.getInt (d, "paddingTop");
|
||||
int paddingBottom = MapEx.getInt (d, "paddingBottom");
|
||||
Hashtable atlas = MapEx.getMap (currSelectSprite, "atlas");
|
||||
string atlasStr = "";
|
||||
foreach (DictionaryEntry item in atlas) {
|
||||
atlasStr = PStr.b ().a (atlasStr).a (",").a (item.Key.ToString ()).e ();
|
||||
}
|
||||
Texture tex = ECLEditorUtl.getObjectByPath (path) as Texture;
|
||||
Rect r = Rect.zero;
|
||||
if (tex != null) {
|
||||
float h = 0;
|
||||
float w = position.width - 160;
|
||||
float rate = w / tex.width;
|
||||
if (rate < 1) {
|
||||
h = tex.height * rate;
|
||||
} else {
|
||||
h = tex.height;
|
||||
}
|
||||
h = h > 200 ? h : 200;
|
||||
r = new Rect (0, 0, NumEx.getIntPart (w), NumEx.getIntPart (h));
|
||||
GUI.DrawTexture (r, tex, ScaleMode.ScaleToFit);
|
||||
GUILayout.Space (r.height + r.y); //这句主要目的是为了可以滑动
|
||||
} else {
|
||||
r = new Rect (0, 0, position.width - 160, 100);
|
||||
GUILayout.Space (r.height + r.y); //这句主要目的是为了可以滑动
|
||||
}
|
||||
|
||||
GUILayout.Space (10);
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.TextField ("name", name);
|
||||
EditorGUILayout.IntField ("times", times);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("x", x);
|
||||
EditorGUILayout.IntField ("y", y);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("width", width);
|
||||
EditorGUILayout.IntField ("height", height);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("borderLeft", borderLeft);
|
||||
EditorGUILayout.IntField ("borderRight", borderRight);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("borderTop", borderTop);
|
||||
EditorGUILayout.IntField ("borderBottom", borderBottom);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("paddingLeft", paddingLeft);
|
||||
EditorGUILayout.IntField ("paddingRight", paddingRight);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.IntField ("paddingTop", paddingTop);
|
||||
EditorGUILayout.IntField ("paddingBottom", paddingBottom);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
EditorGUILayout.TextField ("path", path);
|
||||
EditorGUILayout.TextField ("Atlas", atlasStr);
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
void showCellSprite (Hashtable m)
|
||||
{
|
||||
Hashtable d = MapEx.getMap (m, "data");
|
||||
Texture tex = ECLEditorUtl.getObjectByPath (MapEx.getString (d, "path")) as Texture;
|
||||
if (tex == null) {
|
||||
return;
|
||||
}
|
||||
// NGUIEditorTools.DrawTiledTexture (rect, NGUIEditorTools.backdropTexture);
|
||||
Rect uv = new Rect (MapEx.getInt (d, "x"), MapEx.getInt (d, "y"), MapEx.getInt (d, "width"), MapEx.getInt (d, "height"));
|
||||
uv = NGUIMath.ConvertToTexCoords (uv, tex.width, tex.height);
|
||||
|
||||
float scaleX = rect.width / uv.width;
|
||||
float scaleY = rect.height / uv.height;
|
||||
|
||||
// Stretch the sprite so that it will appear proper
|
||||
float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width);
|
||||
Rect clipRect = rect;
|
||||
|
||||
if (aspect != 1f) {
|
||||
if (aspect < 1f) {
|
||||
// The sprite is taller than it is wider
|
||||
float padding = cellSize * (1f - aspect) * 0.5f;
|
||||
clipRect.xMin += padding;
|
||||
clipRect.xMax -= padding;
|
||||
} else {
|
||||
// The sprite is wider than it is taller
|
||||
float padding = cellSize * (1f - 1f / aspect) * 0.5f;
|
||||
clipRect.yMin += padding;
|
||||
clipRect.yMax -= padding;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUI.Button (rect, "")) {
|
||||
mSelectedSprite = MapEx.getString (d, "name");
|
||||
isShowParckerView = false;
|
||||
currSelectSprite = m;
|
||||
}
|
||||
GUI.DrawTextureWithTexCoords (clipRect, tex, uv);
|
||||
|
||||
// Draw the selection
|
||||
if (mSelectedSprite == MapEx.getString (d, "name")) {
|
||||
NGUIEditorTools.DrawOutline (rect, new Color (0.4f, 1f, 0f, 1f));
|
||||
}
|
||||
|
||||
GUI.backgroundColor = new Color (1f, 1f, 1f, 0.5f);
|
||||
GUI.contentColor = new Color (1f, 1f, 1f, 0.7f);
|
||||
GUI.Label (new Rect (rect.x, rect.y + rect.height, rect.width, 32f), MapEx.getString (d, "name"), "ProgressBarBack");
|
||||
GUI.contentColor = Color.white;
|
||||
GUI.backgroundColor = Color.white;
|
||||
GUILayout.Space (cellSize + 30); //这句主要目的是为了可以滑动
|
||||
rect.y += (cellSize + 30);
|
||||
}
|
||||
|
||||
//=================================
|
||||
/*
|
||||
m.atlas[atlas.name] = atlas.name;
|
||||
m.data = {};
|
||||
m.data.name = spData.name;
|
||||
m.data.path = spData.path;
|
||||
|
||||
m.data.x = spData.x;
|
||||
m.data.y = spData.y;
|
||||
m.data.width = spData.width;
|
||||
m.data.height = spData.height;
|
||||
|
||||
m.data.borderLeft = spData.borderLeft
|
||||
m.data.borderRight = spData.borderRight
|
||||
m.data.borderTop = spData.borderTop
|
||||
m.data.borderBottom = spData.borderBottom
|
||||
|
||||
m.data.paddingLeft = spData.paddingLeft
|
||||
m.data.paddingRight = spData.paddingRight
|
||||
m.data.paddingTop = spData.paddingTop
|
||||
m.data.paddingBottom = spData.paddingBottom
|
||||
end
|
||||
m.times = m.times or 0;
|
||||
m.times = m.times + 1;
|
||||
|
||||
*/
|
||||
|
||||
void initData ()
|
||||
{
|
||||
isShowParckerView = false;
|
||||
isSelectedAll = false;
|
||||
currSelectSprite = null;
|
||||
packTex = null;
|
||||
packRects = null;
|
||||
packSprites.Clear ();
|
||||
mSpriteList.Clear ();
|
||||
if (string.IsNullOrEmpty (mSpritesBorrowInforFile)) {
|
||||
return;
|
||||
}
|
||||
string content = File.ReadAllText (mSpritesBorrowInforFile);
|
||||
Hashtable spriteMap = JSON.DecodeMap (content);
|
||||
Hashtable m = null;
|
||||
Hashtable data = null;
|
||||
mSpriteList = MapEx.vals2List (spriteMap);
|
||||
mSpriteList.Sort (new MySortSpriteBorrow ());
|
||||
// for (int i = 0; i < mSpriteList.Count; i++) {
|
||||
// m = mSpriteList [i] as Hashtable;
|
||||
// data = MapEx.getMap (m, "data");
|
||||
// Debug.Log (MapEx.getString (data, "name") + "," + MapEx.getInt (m, "times"));
|
||||
// }
|
||||
}
|
||||
|
||||
int sortBorrowTimes (object a, object b)
|
||||
{
|
||||
Hashtable m1 = a as Hashtable;
|
||||
Hashtable m2 = b as Hashtable;
|
||||
int ret = 0;
|
||||
if (MapEx.getInt (m1, "times") > MapEx.getInt (m2, "times")) {
|
||||
ret = 1;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public class MySortSpriteBorrow : IComparer
|
||||
{
|
||||
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
|
||||
int IComparer.Compare (object a, object b)
|
||||
{
|
||||
Hashtable m1 = a as Hashtable;
|
||||
Hashtable m2 = b as Hashtable;
|
||||
int ret = 0;
|
||||
int time1 = MapEx.getInt (m1, "times");
|
||||
int time2 = MapEx.getInt (m2, "times");
|
||||
if (time1 < time2) {
|
||||
ret = 1;
|
||||
} else if (time1 == time2) {
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLSpritePacker.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLSpritePacker.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db4297ecaa1ba4847908ed0855e63ad9
|
||||
timeCreated: 1510104917
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
178
Assets/CoolapeFrame/Editor/Tools/ECLTextureSetting.cs
Normal file
178
Assets/CoolapeFrame/Editor/Tools/ECLTextureSetting.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class ECLTextureSetting
|
||||
{
|
||||
|
||||
//The values for the chosen platform are returned in the "out" parameters.
|
||||
//The options for the platform string are "Standalone", "Web", "iPhone", "Android", "WebGL", "Windows Store Apps", "PSP2", "PS4", "XboxOne", "Nintendo 3DS", "WiiU" and "tvOS".
|
||||
public static string platform {
|
||||
get {
|
||||
#if UNITY_ANDROID
|
||||
return "Android";
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
return "iPhone";
|
||||
#endif
|
||||
return "Standalone";
|
||||
}
|
||||
}
|
||||
|
||||
public static bool isPot (Texture tex)
|
||||
{
|
||||
int w = tex.width;
|
||||
int h = tex.height;
|
||||
if (w != h)
|
||||
return false;
|
||||
if ((w & w - 1) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool multipleOf4 (Texture tex)
|
||||
{
|
||||
int w = tex.width;
|
||||
int h = tex.height;
|
||||
if (w % 4 == 0 && h % 4 == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool alphaIsTransparency (TextureImporter ti)
|
||||
{
|
||||
return ti.DoesSourceTextureHaveAlpha ();
|
||||
}
|
||||
|
||||
public static bool setTexture (string path)
|
||||
{
|
||||
Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D> (path);
|
||||
if (tex == null)
|
||||
return false;
|
||||
TextureImporter ti = TextureImporter.GetAtPath (path) as TextureImporter;
|
||||
if (ti == null)
|
||||
return false;
|
||||
TextureImporterPlatformSettings tips = ti.GetPlatformTextureSettings (platform);
|
||||
|
||||
// Debug.Log (tips.format);
|
||||
switch (tips.format) {
|
||||
case TextureImporterFormat.ETC_RGB4:
|
||||
if (isPot (tex)) {
|
||||
return false;
|
||||
} else {
|
||||
return doSetTexture (path, ti, tips, tex);
|
||||
}
|
||||
case TextureImporterFormat.ETC2_RGB4:
|
||||
case TextureImporterFormat.ETC2_RGBA8:
|
||||
case TextureImporterFormat.ETC2_RGB4_PUNCHTHROUGH_ALPHA:
|
||||
if (isPot (tex) || multipleOf4 (tex)) {
|
||||
return false;
|
||||
} else {
|
||||
return doSetTexture (path, ti, tips, tex);
|
||||
}
|
||||
case TextureImporterFormat.PVRTC_RGB2:
|
||||
case TextureImporterFormat.PVRTC_RGB4:
|
||||
case TextureImporterFormat.PVRTC_RGBA2:
|
||||
case TextureImporterFormat.PVRTC_RGBA4:
|
||||
if (isPot (tex)) {
|
||||
return false;
|
||||
} else {
|
||||
return doSetTexture (path, ti, tips, tex);
|
||||
}
|
||||
case TextureImporterFormat.ASTC_RGBA_10x10:
|
||||
case TextureImporterFormat.ASTC_RGBA_12x12:
|
||||
case TextureImporterFormat.ASTC_RGBA_4x4:
|
||||
case TextureImporterFormat.ASTC_RGBA_5x5:
|
||||
case TextureImporterFormat.ASTC_RGBA_6x6:
|
||||
case TextureImporterFormat.ASTC_RGBA_8x8:
|
||||
case TextureImporterFormat.ASTC_RGB_10x10:
|
||||
case TextureImporterFormat.ASTC_RGB_12x12:
|
||||
case TextureImporterFormat.ASTC_RGB_4x4:
|
||||
case TextureImporterFormat.ASTC_RGB_5x5:
|
||||
case TextureImporterFormat.ASTC_RGB_6x6:
|
||||
case TextureImporterFormat.ASTC_RGB_8x8:
|
||||
return false;
|
||||
case TextureImporterFormat.RGB16:
|
||||
case TextureImporterFormat.RGBA16:
|
||||
case TextureImporterFormat.RGBAHalf:
|
||||
return false;
|
||||
case TextureImporterFormat.RGBA32:
|
||||
case TextureImporterFormat.RGB24:
|
||||
return doSetTexture (path, ti, tips, tex);
|
||||
case TextureImporterFormat.Automatic:
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
if(isPot(tex)) {
|
||||
return false;
|
||||
} else {
|
||||
return doSetTexture (path, ti, tips, tex);
|
||||
}
|
||||
#elif UNITY_ANDROID
|
||||
if (isPot (tex) || multipleOf4 (tex)) {
|
||||
return false;
|
||||
} else {
|
||||
return doSetTexture (path, ti, tips, tex);
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
Debug.LogError ("some case not cased===" + path + "===" + tips.format.ToString ());
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool doSetTexture (string path, TextureImporter ti, TextureImporterPlatformSettings tips, Texture2D tex)
|
||||
{
|
||||
tips.overridden = true;
|
||||
Debug.Log ("doSetTexture==" + path);
|
||||
if (isPot (tex)) {
|
||||
if (alphaIsTransparency (ti)) {
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
tips.format = TextureImporterFormat.PVRTC_RGBA4;
|
||||
#else
|
||||
tips.format = TextureImporterFormat.ETC2_RGBA8;
|
||||
#endif
|
||||
} else {
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
tips.format = TextureImporterFormat.PVRTC_RGB4;
|
||||
#else
|
||||
tips.format = TextureImporterFormat.ETC_RGB4;
|
||||
#endif
|
||||
}
|
||||
} else if (multipleOf4 (tex)) {
|
||||
if (alphaIsTransparency (ti)) {
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
tips.format = TextureImporterFormat.ASTC_RGBA_4x4;
|
||||
#else
|
||||
tips.format = TextureImporterFormat.ETC2_RGBA8;
|
||||
#endif
|
||||
} else {
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
tips.format = TextureImporterFormat.ASTC_RGB_4x4;
|
||||
#else
|
||||
tips.format = TextureImporterFormat.ETC2_RGB4;
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
if (alphaIsTransparency (ti)) {
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
tips.format = TextureImporterFormat.ASTC_RGBA_4x4;
|
||||
#else
|
||||
tips.format = TextureImporterFormat.RGBA16;
|
||||
#endif
|
||||
} else {
|
||||
#if UNITY_IPHONE || UNITY_IOS
|
||||
tips.format = TextureImporterFormat.ASTC_RGB_4x4;
|
||||
#else
|
||||
tips.format = TextureImporterFormat.RGB16;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
ti.SetPlatformTextureSettings (tips);
|
||||
EditorUtility.SetDirty (ti);
|
||||
AssetDatabase.WriteImportSettingsIfDirty (path);
|
||||
AssetDatabase.ImportAsset (path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLTextureSetting.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLTextureSetting.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32af560a0ec3c4ad895e52abaaf46da3
|
||||
timeCreated: 1524737904
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
399
Assets/CoolapeFrame/Editor/Tools/ECLUpgradeBindingServer.cs
Normal file
399
Assets/CoolapeFrame/Editor/Tools/ECLUpgradeBindingServer.cs
Normal file
@@ -0,0 +1,399 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Coolape;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
public class ECLUpgradeBindingServer : EditorWindow
|
||||
{
|
||||
Hashtable servers;
|
||||
Hashtable server;
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
ArrayList upgradePkgList;
|
||||
bool isSelectAll = false;
|
||||
static int selectedServerIndex = 0;
|
||||
HotUpgradeServerInfor selectedServer = null;
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
if (!ECLProjectSetting.isProjectExit (ECLProjectManager.self)) {
|
||||
GUIStyle style = new GUIStyle ();
|
||||
style.fontSize = 20;
|
||||
style.normal.textColor = Color.yellow;
|
||||
GUILayout.Label ("The scene is not ready, create it now?", style);
|
||||
if (GUILayout.Button ("Show Project Manager")) {
|
||||
EditorWindow.GetWindow<ECLProjectManager> (false, "CoolapeProject", true);
|
||||
}
|
||||
Close ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ECLProjectManager.data.hotUpgradeServers.Count <= 0) {
|
||||
GUI.color = Color.red;
|
||||
GUILayout.Label ("There is no server");
|
||||
GUI.color = Color.white;
|
||||
return;
|
||||
}
|
||||
if (ECLProjectManager.data.hotUpgradeServers.Count > 0) {
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
List<string> toolbarNames = new List<string> ();
|
||||
for (int i = 0; i < ECLProjectManager.data.hotUpgradeServers.Count; i++) {
|
||||
HotUpgradeServerInfor dd = ECLProjectManager.data.hotUpgradeServers [i] as HotUpgradeServerInfor;
|
||||
toolbarNames.Add (dd.name);
|
||||
}
|
||||
int index = GUILayout.Toolbar (selectedServerIndex, toolbarNames.ToArray ());
|
||||
HotUpgradeServerInfor hsi = ECLProjectManager.data.hotUpgradeServers [index] as HotUpgradeServerInfor;
|
||||
selectedServer = hsi;
|
||||
|
||||
if (selectedServerIndex != index) {
|
||||
selectedServerIndex = index;
|
||||
refreshData ();
|
||||
}
|
||||
//===================================================
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("Key:", ECLEditorUtl.width200);
|
||||
GUILayout.TextField (selectedServer.key);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
//===================================================
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("URL of get server list:", ECLEditorUtl.width200);
|
||||
GUILayout.TextField (selectedServer.getServerListUrl);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
//===================================================
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("URL of set upgrade pkg md5:", ECLEditorUtl.width200);
|
||||
GUILayout.TextField (selectedServer.setServerPkgMd5Url);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
GUI.color = Color.green;
|
||||
if (GUILayout.Button ("Refresh")) {
|
||||
refreshData ();
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
if (servers == null || servers.Count == 0)
|
||||
return;
|
||||
GUILayout.Space (5);
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
if (GUILayout.Button ("All", GUILayout.Width (30))) {
|
||||
isSelectAll = !isSelectAll;
|
||||
foreach (DictionaryEntry cell in servers) {
|
||||
server = (Hashtable)(cell.Value);
|
||||
server ["selected"] = isSelectAll;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.LabelField ("SID", GUILayout.Width (80));
|
||||
EditorGUILayout.LabelField ("SName", GUILayout.Width (100));
|
||||
GUI.color = Color.yellow;
|
||||
#if UNITY_ANDROID
|
||||
EditorGUILayout.LabelField ("UpgradeMd5Ver(Android)", GUILayout.Width (250));
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
EditorGUILayout.LabelField ("UpgradeMd5Ver(ios)", GUILayout.Width (250));
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
EditorGUILayout.LabelField ("UpgradeMd5Ver(win)", GUILayout.Width (250));
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
EditorGUILayout.LabelField ("UpgradeMd5Ver(osx)", GUILayout.Width (250));
|
||||
#elif UNITY_WEBGL
|
||||
EditorGUILayout.LabelField ("UpgradeMd5Ver(webgl)", GUILayout.Width (250));
|
||||
#endif
|
||||
EditorGUILayout.LabelField ("UpgradePkg Name", GUILayout.Width (160));
|
||||
EditorGUILayout.LabelField ("UpgradePkg Mark", GUILayout.Width (250));
|
||||
GUI.color = Color.white;
|
||||
#if UNITY_ANDROID
|
||||
if (GUILayout.Button ("Select Md5(Android)")) {
|
||||
setUpgradePkgMutlMode ("Android");
|
||||
}
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
if (GUILayout.Button ("Select Md5(ios)")) {
|
||||
setUpgradePkgMutlMode ("ios");
|
||||
}
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
if (GUILayout.Button ("Select Md5(win)")) {
|
||||
setUpgradePkgMutlMode ("win");
|
||||
}
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
if (GUILayout.Button ("Select Md5(osx)")) {
|
||||
setUpgradePkgMutlMode ("osx");
|
||||
}
|
||||
#elif UNITY_WEBGL
|
||||
if (GUILayout.Button ("Select Md5(webgl)")) {
|
||||
setUpgradePkgMutlMode ("webgl");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
GUILayout.Space (5);
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Width (position.width), GUILayout.Height (position.height - 50));
|
||||
{
|
||||
foreach (DictionaryEntry cell in servers) {
|
||||
server = (Hashtable)(cell.Value);
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
server ["selected"] = EditorGUILayout.Toggle (MapEx.getBool (server, "selected"), GUILayout.Width (30));
|
||||
if (MapEx.getBool (server, "selected")) {
|
||||
GUI.color = Color.cyan;
|
||||
} else {
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "idx"), GUILayout.Width (80));
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "servername"), GUILayout.Width (100));
|
||||
GUI.color = Color.yellow;
|
||||
#if UNITY_ANDROID
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "androidversion"), GUILayout.Width (250));
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "iosversion"), GUILayout.Width (250));
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "winversion"), GUILayout.Width (250));
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "osxversion"), GUILayout.Width (250));
|
||||
#elif UNITY_WEBGL
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "webglversion"), GUILayout.Width (250));
|
||||
#endif
|
||||
EditorGUILayout.TextField (MapEx.getString (server, "pkgName"), GUILayout.Width (160));
|
||||
EditorGUILayout.TextArea (MapEx.getString (server, "pkgRemark"), GUILayout.Width (250));
|
||||
GUI.color = Color.white;
|
||||
#if UNITY_ANDROID
|
||||
if (GUILayout.Button ("Select Md5(Android)")) {
|
||||
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder ().Add (cell.Key).Add ("Android").ToList ());
|
||||
}
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
if (GUILayout.Button ("Select Md5(ios)")) {
|
||||
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("ios").ToList());
|
||||
}
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
if (GUILayout.Button ("Select Md5(win)")) {
|
||||
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("win").ToList());
|
||||
}
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
if (GUILayout.Button ("Select Md5(osx)")) {
|
||||
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("osx").ToList());
|
||||
}
|
||||
#elif UNITY_WEBGL
|
||||
if (GUILayout.Button ("Select Md5(webgl)")) {
|
||||
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("wegbl").ToList());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
public void onGetUpgradePkg (params object[] paras)
|
||||
{
|
||||
string oldMd5 = "";
|
||||
Hashtable d = paras [0] as Hashtable;
|
||||
ArrayList orgsList = paras [1] as ArrayList;
|
||||
string key = orgsList [0] as string;
|
||||
string platform = orgsList [1] as string;
|
||||
|
||||
Hashtable server = MapEx.getMap (servers, key);
|
||||
string verKey = "";
|
||||
string vetType = "1";
|
||||
if (platform.Equals ("ios")) {
|
||||
verKey = "iosversion";
|
||||
vetType = "1";
|
||||
} else if(platform.Equals("Android"))
|
||||
{
|
||||
verKey = "androidversion";
|
||||
vetType = "2";
|
||||
}
|
||||
else if (platform.Equals("win"))
|
||||
{
|
||||
verKey = "winversion";
|
||||
vetType = "3";
|
||||
}
|
||||
else if (platform.Equals("osx"))
|
||||
{
|
||||
verKey = "osxversion";
|
||||
vetType = "4";
|
||||
}
|
||||
oldMd5 = MapEx.getString (server, verKey);
|
||||
string newMd5 = MapEx.getString (d, "md5");
|
||||
if (!newMd5.Equals (oldMd5)) {
|
||||
if (EditorUtility.DisplayDialog ("Alert", "Really want to upgrade this server!!", "Okay", "Cancel")) {
|
||||
server [verKey] = newMd5;
|
||||
server ["pkgName"] = MapEx.getString (d, "name");
|
||||
server ["pkgRemark"] = MapEx.getString (d, "remark");
|
||||
servers [key] = server;
|
||||
saveData (MapEx.getString (server, "idx"), newMd5, vetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpgradePkgMutlMode (string platform)
|
||||
{
|
||||
bool canSetMd5 = false;
|
||||
foreach (DictionaryEntry cell in servers) {
|
||||
Hashtable server = cell.Value as Hashtable;
|
||||
if (MapEx.getBool (server, "selected")) {
|
||||
canSetMd5 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (canSetMd5) {
|
||||
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkgMultMode, platform);
|
||||
} else {
|
||||
Debug.LogError ("Please select some servers!!");
|
||||
}
|
||||
}
|
||||
|
||||
public void onGetUpgradePkgMultMode (params object[] paras)
|
||||
{
|
||||
Hashtable d = paras [0] as Hashtable;
|
||||
string platform = paras [1] as string;
|
||||
string oldMd5 = "";
|
||||
//
|
||||
if (EditorUtility.DisplayDialog ("Alert", "Really want to upgrade all selected servers!!", "Okay", "Cancel")) {
|
||||
foreach (DictionaryEntry cell in servers) {
|
||||
Hashtable server = cell.Value as Hashtable;
|
||||
if (MapEx.getBool (server, "selected")) {
|
||||
string verKey = "";
|
||||
string vetType = "1";
|
||||
if (platform.Equals ("ios")) {
|
||||
verKey = "iosversion";
|
||||
vetType = "1";
|
||||
}
|
||||
else if (platform.Equals("Android"))
|
||||
{
|
||||
verKey = "androidversion";
|
||||
vetType = "2";
|
||||
}
|
||||
else if (platform.Equals("win"))
|
||||
{
|
||||
verKey = "winversion";
|
||||
vetType = "3";
|
||||
}
|
||||
else if (platform.Equals("osx"))
|
||||
{
|
||||
verKey = "osxversion";
|
||||
vetType = "4";
|
||||
}
|
||||
oldMd5 = MapEx.getString (server, verKey);
|
||||
string newMd5 = MapEx.getString (d, "md5");
|
||||
if (!newMd5.Equals (oldMd5)) {
|
||||
server [verKey] = newMd5;
|
||||
server ["pkgName"] = MapEx.getString (d, "name");
|
||||
server ["pkgRemark"] = MapEx.getString (d, "remark");
|
||||
saveData (MapEx.getString (server, "idx"), newMd5, vetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getUpgradePkgListData ()
|
||||
{
|
||||
string cfgPath = ECLProjectManager.ver4UpgradeList;
|
||||
string str = "";
|
||||
string p = Application.dataPath + "/" + cfgPath;
|
||||
if (File.Exists (p)) {
|
||||
str = File.ReadAllText (p);
|
||||
}
|
||||
ArrayList list = JSON.DecodeList (str);
|
||||
upgradePkgList = list == null ? new ArrayList () : list;
|
||||
}
|
||||
|
||||
Hashtable getUpgradePkgByMd5 (string md5)
|
||||
{
|
||||
if (upgradePkgList == null) {
|
||||
getUpgradePkgListData ();
|
||||
}
|
||||
Hashtable cell = null;
|
||||
for (int i = 0; i < upgradePkgList.Count; i++) {
|
||||
cell = (Hashtable)(upgradePkgList [i]);
|
||||
if (MapEx.getString (cell, "md5") == md5) {
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveData (string serverID, string version, string verType)
|
||||
{
|
||||
// string __httpBaseUrl = PStr.b ().a ("http://").a (Net.self.gateHost).a (":").a (Net.self.gatePort).e ();
|
||||
// string url = PStr.b ().a (__httpBaseUrl).a ("/KokDirServer/UpdateVerServlet").e ();
|
||||
string url = selectedServer.setServerPkgMd5Url;
|
||||
Dictionary<string,object> paras = new Dictionary<string, object> ();
|
||||
paras ["serverid"] = serverID;
|
||||
paras ["version"] = version;
|
||||
paras ["versionType"] = verType;
|
||||
HttpWebResponse response = HttpEx.CreatePostHttpResponse (url, paras, 10000, System.Text.Encoding.UTF8);
|
||||
if (response == null)
|
||||
return;
|
||||
response.Close ();
|
||||
}
|
||||
|
||||
public void refreshData ()
|
||||
{
|
||||
servers = null;
|
||||
getUpgradePkgListData ();
|
||||
if (selectedServer == null) {
|
||||
return;
|
||||
}
|
||||
// string __httpBaseUrl = PStr.b ().a ("http://").a (Net.self.gateHost).a (":").a (Net.self.gatePort).e ();
|
||||
// string url = PStr.b ().a (__httpBaseUrl).a ("/KokDirServer/ServerServlet").e ();
|
||||
string url = selectedServer.getServerListUrl;
|
||||
if (string.IsNullOrEmpty (url)) {
|
||||
return;
|
||||
}
|
||||
Dictionary<string,object> paras = new Dictionary<string, object> ();
|
||||
paras ["serverType"] = 1;
|
||||
HttpWebResponse response = HttpEx.CreatePostHttpResponse (url, paras, 10000, System.Text.Encoding.UTF8);
|
||||
if (response == null)
|
||||
return;
|
||||
string str = HttpEx.readString (response);
|
||||
response.Close ();
|
||||
// Debug.Log (url);
|
||||
// string str = HttpEx.readString (url, null);
|
||||
Debug.Log (str);
|
||||
servers = JSON.DecodeMap (str);
|
||||
Hashtable server = null;
|
||||
Hashtable pkg = null;
|
||||
if (servers != null) {
|
||||
foreach (DictionaryEntry cell in servers) {
|
||||
server = cell.Value as Hashtable;
|
||||
pkg = getUpgradePkgByMd5 (MapEx.getString (server, "version"));
|
||||
server ["pkgName"] = MapEx.getString (pkg, "name");
|
||||
server ["pkgRemark"] = MapEx.getString (pkg, "remark");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void show ()
|
||||
{
|
||||
ECLUpgradeBindingServer window = ECLUpgradeBindingServer.GetWindow<ECLUpgradeBindingServer> (true, "Server List", true);
|
||||
if (window == null) {
|
||||
window = new ECLUpgradeBindingServer ();
|
||||
}
|
||||
// Vector2 size = Handles.GetMainGameViewSize ();
|
||||
Rect rect = window.position;
|
||||
rect.x = -Screen.width - Screen.width / 4;
|
||||
rect.y = Screen.height / 2 - Screen.height / 4;
|
||||
rect.width = Screen.width;
|
||||
rect.height = Screen.height / 2;
|
||||
|
||||
// rect = new Rect (-size.x/2, size.y / 2 - size.y / 4, size.x / 2, size.y / 2);
|
||||
window.position = rect;
|
||||
window.title = "Server List";
|
||||
window.refreshData ();
|
||||
window.ShowPopup ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69b24f748780d410b97d2b2de61132f9
|
||||
timeCreated: 1495608606
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
474
Assets/CoolapeFrame/Editor/Tools/ECLUpgradeListProc.cs
Normal file
474
Assets/CoolapeFrame/Editor/Tools/ECLUpgradeListProc.cs
Normal file
@@ -0,0 +1,474 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Coolape;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ECLUpgradeListProc : EditorWindow
|
||||
{
|
||||
public static ECLUpgradeListProc self;
|
||||
|
||||
public static ArrayList mList = null;
|
||||
public static string cfgPath = "";
|
||||
Hashtable item;
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
static bool isFinishUpload = false;
|
||||
static bool uploadResult = false;
|
||||
static float uploadProgerss = 0;
|
||||
static bool isUploading = false;
|
||||
static string selectedPackageName = "";
|
||||
static bool isSelectMod = false;
|
||||
static Callback onSelectedCallback;
|
||||
static object selectedCallbackParams;
|
||||
static int selectedServerIndex = 0;
|
||||
static HotUpgradeServerInfor selectedServer = null;
|
||||
|
||||
public ECLUpgradeListProc ()
|
||||
{
|
||||
self = this;
|
||||
EditorApplication.update += OnUpdate;
|
||||
}
|
||||
|
||||
void OnUpdate ()
|
||||
{
|
||||
if (isFinishUpload) {
|
||||
isFinishUpload = false;
|
||||
//TODO:
|
||||
Debug.Log ("finished");
|
||||
EditorUtility.ClearProgressBar ();
|
||||
if (uploadResult) {
|
||||
// success
|
||||
updateState (selectedPackageName);
|
||||
uploadOss (selectedPackageName);
|
||||
EditorUtility.DisplayDialog ("Success", "Success !", "Okey");
|
||||
} else {
|
||||
EditorUtility.DisplayDialog ("Fail", "Failed !", "Okey");
|
||||
}
|
||||
}
|
||||
if (isUploading) {
|
||||
EditorUtility.DisplayProgressBar ("UpLoad", "Uploading....!", uploadProgerss);
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
if (!ECLProjectSetting.isProjectExit (ECLProjectManager.self)) {
|
||||
GUIStyle style = new GUIStyle ();
|
||||
style.fontSize = 20;
|
||||
style.normal.textColor = Color.yellow;
|
||||
GUILayout.Label ("The scene is not ready, create it now?", style);
|
||||
if (GUILayout.Button ("Show Project Manager")) {
|
||||
EditorWindow.GetWindow<ECLProjectManager> (false, "CoolapeProject", true);
|
||||
}
|
||||
Close ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ECLProjectManager.data.hotUpgradeServers.Count > 0) {
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
List<string> toolbarNames = new List<string> ();
|
||||
for (int i = 0; i < ECLProjectManager.data.hotUpgradeServers.Count; i++) {
|
||||
HotUpgradeServerInfor dd = ECLProjectManager.data.hotUpgradeServers [i] as HotUpgradeServerInfor;
|
||||
toolbarNames.Add (dd.name);
|
||||
}
|
||||
selectedServerIndex = GUILayout.Toolbar (selectedServerIndex, toolbarNames.ToArray ());
|
||||
HotUpgradeServerInfor hsi = ECLProjectManager.data.hotUpgradeServers [selectedServerIndex] as HotUpgradeServerInfor;
|
||||
selectedServer = hsi;
|
||||
// ECLProjectSetting.cellServerInor (hsi, false);
|
||||
//===================================================
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("Key:", ECLEditorUtl.width200);
|
||||
GUILayout.TextField (selectedServer.key);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
//===================================================
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("Hot Upgrade Base Url:", ECLEditorUtl.width200);
|
||||
GUILayout.TextField (selectedServer.hotUpgradeBaseUrl);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
//===================================================
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("Host 4 Upload Upgrade Package:", ECLEditorUtl.width200);
|
||||
GUILayout.TextField (selectedServer.host4UploadUpgradePackage);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUILayout.Label ("Port 4 Upload Upgrade Package:", ECLEditorUtl.width200);
|
||||
EditorGUILayout.IntField (selectedServer.port4UploadUpgradePackage);
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
if (selectedServer == null) {
|
||||
GUILayout.Label ("Please select a server!");
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
GUI.color = Color.green;
|
||||
if (GUILayout.Button ("Refresh", GUILayout.Height (40f))) {
|
||||
setData ();
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
if (!isSelectMod) {
|
||||
if (GUILayout.Button ("Save", GUILayout.Height (40f))) {
|
||||
if (mList == null || mList.Count == 0) {
|
||||
Debug.LogWarning ("Nothing need to save!");
|
||||
return;
|
||||
}
|
||||
string str = JSON.JsonEncode (mList);
|
||||
File.WriteAllText (Application.dataPath + "/" + cfgPath, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
ECLEditorUtl.BeginContents ();
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.LabelField ("Package Name", GUILayout.Width (160));
|
||||
EditorGUILayout.LabelField ("MD5", GUILayout.Width (250));
|
||||
EditorGUILayout.LabelField ("Exist?", GUILayout.Width (40));
|
||||
EditorGUILayout.LabelField ("Upload?", GUILayout.Width (60));
|
||||
EditorGUILayout.LabelField ("...", GUILayout.Width (60));
|
||||
EditorGUILayout.LabelField ("Notes");
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
if (mList == null) {
|
||||
return;
|
||||
}
|
||||
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Width (position.width), GUILayout.Height (position.height - 75));
|
||||
{
|
||||
for (int i = mList.Count - 1; i >= 0; i--) {
|
||||
item = ListEx.getMap (mList, i);
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
EditorGUILayout.TextField (MapEx.getString (item, "name"), GUILayout.Width (160));
|
||||
EditorGUILayout.TextField (MapEx.getString (item, "md5"), GUILayout.Width (250));
|
||||
|
||||
if (!MapEx.getBool (item, "exist")) {
|
||||
GUI.color = Color.red;
|
||||
}
|
||||
EditorGUILayout.TextField (MapEx.getBool (item, "exist") ? "Yes" : "No", GUILayout.Width (40));
|
||||
GUI.color = Color.white;
|
||||
if (!isUploaded (item)) {
|
||||
GUI.color = Color.red;
|
||||
}
|
||||
EditorGUILayout.TextField (isUploaded (item) ? "Yes" : "No", GUILayout.Width (60));
|
||||
GUI.color = Color.white;
|
||||
if (MapEx.getBool (item, "exist")) {
|
||||
GUI.enabled = true;
|
||||
} else {
|
||||
GUI.enabled = false;
|
||||
}
|
||||
GUI.color = Color.yellow;
|
||||
if (isSelectMod) {
|
||||
if (GUILayout.Button ("select", GUILayout.Width (60f))) {
|
||||
Close ();
|
||||
Utl.doCallback (onSelectedCallback, item, selectedCallbackParams);
|
||||
}
|
||||
} else {
|
||||
if (GUILayout.Button ("upload", GUILayout.Width (60f))) {
|
||||
if (EditorUtility.DisplayDialog ("Alert", "Really want to upload the upgrade package?", "Okey", "cancel")) {
|
||||
selectedPackageName = MapEx.getString (item, "name");
|
||||
uploadUpgradePackage (MapEx.getString (item, "name"));
|
||||
}
|
||||
}
|
||||
if(GUILayout.Button("同步OSS", GUILayout.Width (60f))) {
|
||||
if (EditorUtility.DisplayDialog ("Alert", "Really want to upload the upgrade package?", "Okey", "cancel")) {
|
||||
uploadOss (MapEx.getString (item, "name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUI.color = Color.white;
|
||||
GUI.enabled = true;
|
||||
item ["remark"] = EditorGUILayout.TextArea (MapEx.getString (item, "remark"));
|
||||
|
||||
GUILayout.Space (5);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
}
|
||||
ECLEditorUtl.EndContents ();
|
||||
}
|
||||
|
||||
public bool isUploaded (Hashtable item)
|
||||
{
|
||||
if (selectedServer == null) {
|
||||
return false;
|
||||
}
|
||||
Hashtable m = MapEx.getMap (item, "upload");
|
||||
return MapEx.getBool (m, selectedServer.key);
|
||||
}
|
||||
|
||||
public void uploadUpgradePackage (string name)
|
||||
{
|
||||
if (!Utl.netIsActived ()) {
|
||||
EditorUtility.DisplayDialog ("Alert", "The net work is not connected!", "Okay");
|
||||
return;
|
||||
}
|
||||
EditorUtility.ClearProgressBar();
|
||||
string localDir = getUpgradePackagePath (name);
|
||||
ThreadEx.exec (new System.Threading.ParameterizedThreadStart (doUploadUpgradePackage), localDir);
|
||||
// doUploadUpgradePackage (localDir);
|
||||
}
|
||||
|
||||
void onSftpProgress (params object[] pars)
|
||||
{
|
||||
uploadProgerss = (float)(pars [0]);
|
||||
}
|
||||
|
||||
void onftpFinish (params object[] pars)
|
||||
{
|
||||
isUploading = false;
|
||||
isFinishUpload = true;
|
||||
bool ret = (bool)(pars [0]);
|
||||
ECLUpgradeListProc.uploadResult = ret;
|
||||
}
|
||||
|
||||
public void doUploadUpgradePackage (object localDir)
|
||||
{
|
||||
if (selectedServer == null) {
|
||||
Debug.LogError ("Please select a server!");
|
||||
return;
|
||||
}
|
||||
isUploading = true;
|
||||
if (selectedServer.useSFTP) {
|
||||
/*SFTPHelper sftp = new SFTPHelper (selectedServer.host4UploadUpgradePackage,
|
||||
selectedServer.port4UploadUpgradePackage,
|
||||
selectedServer.ftpUser,
|
||||
selectedServer.ftpPassword);
|
||||
if (sftp.Connect ()) {
|
||||
if (selectedServer.isUploadOSSTemp) {
|
||||
sftp.PutDir (localDir.ToString (), selectedServer.RemoteBaseDir, (Callback)onSftpProgress, null);
|
||||
sftp.PutDir (localDir.ToString (), selectedServer.RemoteBaseDir + "_OSS", (Callback)onSftpProgress, (Callback)onftpFinish);
|
||||
} else {
|
||||
sftp.PutDir (localDir.ToString (), selectedServer.RemoteBaseDir, (Callback)onSftpProgress, (Callback)onftpFinish);
|
||||
}
|
||||
sftp.Exit ();
|
||||
sftp = null;
|
||||
} else {
|
||||
Utl.doCallback ((Callback)onftpFinish, false);
|
||||
}*/
|
||||
|
||||
RenciSFTPHelper sftp = new RenciSFTPHelper(
|
||||
selectedServer.host4UploadUpgradePackage,
|
||||
selectedServer.port4UploadUpgradePackage,
|
||||
selectedServer.ftpUser,
|
||||
selectedServer.ftpPassword);
|
||||
if (sftp.connect())
|
||||
{
|
||||
sftp.putDir(localDir.ToString(), selectedServer.RemoteBaseDir, (Callback)onSftpProgress, (Callback)onftpFinish);
|
||||
sftp.disConnect();
|
||||
sftp = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Utl.doCallback((Callback)onftpFinish, false);
|
||||
}
|
||||
} else {
|
||||
bool ret = FTP.UploadDir (localDir.ToString (),
|
||||
selectedServer.host4UploadUpgradePackage,
|
||||
selectedServer.ftpUser,
|
||||
selectedServer.ftpPassword,
|
||||
selectedServer.RemoteBaseDir, false);
|
||||
if (selectedServer.isUploadOSSTemp && ret) {
|
||||
ret = FTP.UploadDir (localDir.ToString (),
|
||||
selectedServer.host4UploadUpgradePackage,
|
||||
selectedServer.ftpUser,
|
||||
selectedServer.ftpPassword,
|
||||
selectedServer.RemoteBaseDir + "_OSS", false);
|
||||
}
|
||||
Utl.doCallback ((Callback)onftpFinish, ret);
|
||||
}
|
||||
}
|
||||
|
||||
void uploadOss (string name = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty (selectedServer.ossCmd)) {
|
||||
Debug.LogError ("请先设置同步脚本!");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty (name)) {
|
||||
name = selectedPackageName;
|
||||
}
|
||||
string localDir = getUpgradePackagePath (name);
|
||||
string shell = Path.Combine(Application.dataPath, ECLEditorUtl.getPathByObject( selectedServer.ossShell));
|
||||
string arg1 = Path.GetDirectoryName(shell);
|
||||
string arg2 = localDir.ToString ();
|
||||
// Debug.LogError (argss);
|
||||
// System.Diagnostics.Process process = System.Diagnostics.Process.Start ("/bin/bash", argss);
|
||||
//重新定向标准输入,输入,错误输出
|
||||
// process.StartInfo.RedirectStandardInput = true;
|
||||
// process.StartInfo.RedirectStandardOutput = true;
|
||||
// process.StartInfo.RedirectStandardError = true;
|
||||
//
|
||||
// string ret = process.StandardOutput.ReadToEnd ();
|
||||
// Debug.Log (ret);
|
||||
|
||||
// Debug.LogError (shell + " " + arg1 + " " + arg2);
|
||||
if ("MacOSX".Equals (SystemInfo.operatingSystemFamily.ToString())) {
|
||||
string argss = Path.Combine(Path.GetDirectoryName(shell), Path.GetFileNameWithoutExtension(shell)) +".sh" + " " + arg1 + " " + arg2;
|
||||
// Debug.LogError (argss);
|
||||
System.Diagnostics.Process process = System.Diagnostics.Process.Start ("/bin/bash", argss);
|
||||
} else {
|
||||
string batFile = Path.Combine (Path.GetDirectoryName (shell), Path.GetFileNameWithoutExtension (shell)) + ".bat";
|
||||
System.Diagnostics.Process.Start (batFile, arg1 + " " + arg2);
|
||||
}
|
||||
Debug.LogWarning("Finished===" + name);
|
||||
}
|
||||
|
||||
public void setData ()
|
||||
{
|
||||
if (string.IsNullOrEmpty (cfgPath)) {
|
||||
cfgPath = ECLProjectManager.ver4UpgradeList;
|
||||
}
|
||||
string str = "";
|
||||
string p = Application.dataPath + "/" + cfgPath;
|
||||
if (File.Exists (p)) {
|
||||
str = File.ReadAllText (p);
|
||||
}
|
||||
ArrayList list = JSON.DecodeList (str);
|
||||
list = list == null ? new ArrayList () : list;
|
||||
ECLUpgradeListProc.mList = list;
|
||||
refreshData ();
|
||||
}
|
||||
|
||||
public void refreshData ()
|
||||
{
|
||||
if (mList == null)
|
||||
return;
|
||||
Hashtable item = null;
|
||||
|
||||
for (int i = 0; i < mList.Count; i++) {
|
||||
item = ListEx.getMap (mList, i);
|
||||
if (Directory.Exists (getUpgradePackagePath (MapEx.getString (item, "name")))) {
|
||||
item ["exist"] = true;
|
||||
} else {
|
||||
item ["exist"] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateState (string name)
|
||||
{
|
||||
if (selectedServer == null) {
|
||||
return;
|
||||
}
|
||||
if (mList == null) {
|
||||
return;
|
||||
}
|
||||
Hashtable item = null;
|
||||
|
||||
for (int i = 0; i < mList.Count; i++) {
|
||||
item = ListEx.getMap (mList, i);
|
||||
if (name.Equals (MapEx.getString (item, "name"))) {
|
||||
// item ["upload"] = true;
|
||||
Hashtable m = MapEx.getMap (item, "upload");
|
||||
m = m == null ? new Hashtable () : m;
|
||||
m [selectedServer.key] = true;
|
||||
item ["upload"] = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string str = JSON.JsonEncode (mList);
|
||||
File.WriteAllText (Application.dataPath + "/" + cfgPath, str);
|
||||
}
|
||||
|
||||
public string getUpgradePackageMd5 (string name)
|
||||
{
|
||||
string p = getUpgradePackagePath (name);
|
||||
p = PStr.b ().a (p).a ("/").a (CLPathCfg.self.basePath).a ("/resVer/").a (CLPathCfg.self.platform).e ();
|
||||
if (Directory.Exists (p)) {
|
||||
string[] files = Directory.GetFiles (p);
|
||||
string fileName = "";
|
||||
for (int i = 0; i < files.Length; i++) {
|
||||
fileName = Path.GetFileName (files [i]);
|
||||
if (fileName.StartsWith ("VerCtl.ver")) {
|
||||
return Utl.MD5Encrypt (File.ReadAllBytes (files [i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public string getUpgradePackagePath (string name)
|
||||
{
|
||||
string p = Path.Combine (Application.dataPath, name);
|
||||
if (Application.platform == RuntimePlatform.WindowsEditor) {
|
||||
p = p.Replace ("\\", "/");
|
||||
p = p.Replace ("//", "/");
|
||||
p = p.Replace ("/Assets/", "/Assets4Upgrade/");
|
||||
} else {
|
||||
p = p.Replace ("/Assets/", "/Assets4Upgrade/");
|
||||
}
|
||||
// p = Path.Combine (p, CLPathCfg.self.basePath);
|
||||
return p;
|
||||
}
|
||||
|
||||
public static void show4UpgradeList (string cfgPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty (cfgPath)) {
|
||||
cfgPath = ECLProjectManager.ver4UpgradeList;
|
||||
}
|
||||
isSelectMod = false;
|
||||
string str = "";
|
||||
string p = Application.dataPath + "/" + cfgPath;
|
||||
if (File.Exists (p)) {
|
||||
str = File.ReadAllText (p);
|
||||
}
|
||||
ArrayList list = JSON.DecodeList (str);
|
||||
if (list == null || list.Count == 0) {
|
||||
EditorUtility.DisplayDialog ("Alert", "no data to show!", "Okay");
|
||||
return;
|
||||
}
|
||||
|
||||
ECLUpgradeListProc window = ECLUpgradeListProc.GetWindow<ECLUpgradeListProc> (true, "Upgrade Res List", true);
|
||||
if (window == null) {
|
||||
window = new ECLUpgradeListProc ();
|
||||
}
|
||||
Vector2 size = Handles.GetMainGameViewSize ();
|
||||
Rect rect = window.position;
|
||||
rect.x = -Screen.width - Screen.width / 4;
|
||||
rect.y = Screen.height / 2 - Screen.height / 4;
|
||||
rect.width = Screen.width;
|
||||
rect.height = Screen.height / 2;
|
||||
|
||||
rect = new Rect (10, 40, size.x, size.y / 2);
|
||||
window.position = rect;
|
||||
window.title = "Upgrade资源包列表";
|
||||
ECLUpgradeListProc.mList = list;
|
||||
window.refreshData ();
|
||||
ECLUpgradeListProc.cfgPath = cfgPath;
|
||||
// window.ShowPopup ();
|
||||
window.ShowAuxWindow ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void popup4Select (Callback cb, object orgs)
|
||||
{
|
||||
show4UpgradeList (null);
|
||||
isSelectMod = true;
|
||||
onSelectedCallback = cb;
|
||||
selectedCallbackParams = orgs;
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Tools/ECLUpgradeListProc.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Tools/ECLUpgradeListProc.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30bfa9b54d8034ae2a849ce5aadf7143
|
||||
timeCreated: 1487557022
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user