add
This commit is contained in:
324
Assets/CoolapeFrame/Editor/Utl/ECLCreatAssetBundle4Update.cs
Normal file
324
Assets/CoolapeFrame/Editor/Utl/ECLCreatAssetBundle4Update.cs
Normal file
@@ -0,0 +1,324 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System;
|
||||
using Coolape;
|
||||
|
||||
public class ECLCreatAssetBundle4Update
|
||||
{
|
||||
public delegate void CreateDelegate (string file, UnityEngine.Object obj);
|
||||
|
||||
public static void makeAssetBundles ()//该函数表示通过上面的点击响应的函数
|
||||
{
|
||||
foreach (UnityEngine.Object o in Selection.objects) {
|
||||
Debug.Log (o.name);
|
||||
string path = AssetDatabase.GetAssetPath (o);//Selection表示你鼠标选择激活的对象
|
||||
UnityEngine.Object t = AssetDatabase.LoadMainAssetAtPath (path);
|
||||
path = Path.GetDirectoryName (path);
|
||||
// path = path.Replace ("Assets/", "");
|
||||
createAssets4Upgrade (path, t, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void makeAssetBundlesUncompressed ()//该函数表示通过上面的点击响应的函数
|
||||
{
|
||||
foreach (UnityEngine.Object o in Selection.objects) {
|
||||
Debug.Log (o.name);
|
||||
string path = AssetDatabase.GetAssetPath (o);//Selection表示你鼠标选择激活的对象
|
||||
UnityEngine.Object t = AssetDatabase.LoadMainAssetAtPath (path);
|
||||
path = Path.GetDirectoryName (path);
|
||||
// path = path.Replace ("Assets/", "");
|
||||
createAssets4Upgrade (path, t, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void makeAssetBundlesSelections ()//该函数表示通过上面的点击响应的函数
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath (Selection.activeObject);//Selection表示你鼠标选择激活的对象
|
||||
Debug.Log ("Selected Folder: " + path);
|
||||
if (string.IsNullOrEmpty (path) || !Directory.Exists (path)) {
|
||||
Debug.LogWarning ("请选择目录!");
|
||||
return;
|
||||
}
|
||||
path = Application.dataPath + "/" + path.Replace ("Assets/", "");
|
||||
createUnity3dFiles (path, null, true);
|
||||
}
|
||||
|
||||
public static void createAssets4Upgrade (string file, bool isCompress = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty (file))
|
||||
return;
|
||||
string path = Path.GetDirectoryName (file);
|
||||
createAssets4Upgrade (path, AssetDatabase.LoadMainAssetAtPath (file), isCompress);
|
||||
}
|
||||
|
||||
public static void createAssets4Upgrade (string file, UnityEngine.Object obj, bool isCompress)
|
||||
{
|
||||
// Debug.Log (file);
|
||||
if (string.IsNullOrEmpty (file) || obj == null) {
|
||||
Debug.LogError ("file==" + file);
|
||||
return;
|
||||
}
|
||||
cleanShardAssets (obj);
|
||||
//==================================
|
||||
file = file.Replace("\\", "/");
|
||||
file = file.Replace ("/upgradeRes4Dev", "/upgradeRes4Publish");
|
||||
|
||||
BuildAssetBundleOptions opt = BuildAssetBundleOptions.CollectDependencies;
|
||||
if (isCompress) {
|
||||
opt = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.IgnoreTypeTreeChanges | BuildAssetBundleOptions.ChunkBasedCompression;
|
||||
} else {
|
||||
opt = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.IgnoreTypeTreeChanges | BuildAssetBundleOptions.UncompressedAssetBundle;
|
||||
}
|
||||
|
||||
string bundlePath = "";
|
||||
// Directory.CreateDirectory (Application.dataPath + "/" + file);
|
||||
#if UNITY_ANDROID
|
||||
bundlePath = file + "/Android/" + obj.name + ".unity3d";
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (bundlePath));
|
||||
Debug.Log ("bundlePath==" + bundlePath);
|
||||
BuildPipeline.BuildAssetBundle (obj, null, bundlePath, opt, BuildTarget.Android);
|
||||
#elif UNITY_IPHONE || UNITY_IOS
|
||||
bundlePath = file + "/IOS/" +obj.name + ".unity3d";
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(bundlePath));
|
||||
BuildPipeline.BuildAssetBundle(obj, null, bundlePath, opt, BuildTarget.iOS);
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
bundlePath = file + "/Standalone/" + obj.name + ".unity3d";
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (bundlePath));
|
||||
Debug.Log ("bundlePath==" + bundlePath);
|
||||
BuildPipeline.BuildAssetBundle (obj, null, bundlePath, opt, BuildTarget.StandaloneWindows64);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
bundlePath = file + "/StandaloneOSX/" + obj.name + ".unity3d";
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (bundlePath));
|
||||
Debug.Log ("bundlePath==" + bundlePath);
|
||||
BuildPipeline.BuildAssetBundle (obj, null, bundlePath, opt, BuildTarget.StandaloneOSX);
|
||||
#elif UNITY_WEBGL
|
||||
bundlePath = file + "/WebGL/" + obj.name + ".unity3d";
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (bundlePath));
|
||||
Debug.Log ("bundlePath==" + bundlePath);
|
||||
//BuildPipeline.BuildAssetBundle (obj, null, bundlePath, opt, BuildTarget.WebGL);
|
||||
BuildPipeline.BuildAssetBundle (obj, null, bundlePath, opt, BuildTarget.WebGL);
|
||||
#endif
|
||||
FileInfo fileInfo = new FileInfo (bundlePath);
|
||||
long size = (fileInfo.Length / 1024);
|
||||
if (size >= 900) {
|
||||
Debug.LogError (" size== " + size + "KB," + fileInfo.FullName);
|
||||
} else {
|
||||
Debug.Log (" size== " + size + "KB");
|
||||
}
|
||||
|
||||
//==================================
|
||||
resetShardAssets (obj);
|
||||
}
|
||||
|
||||
public static void cleanShardAssets (UnityEngine.Object obj)
|
||||
{
|
||||
CLSharedAssets sharedAsset = null;
|
||||
CLRoleAvata avata = null;
|
||||
if (obj is GameObject) {
|
||||
sharedAsset = ((GameObject)obj).GetComponent<CLSharedAssets> ();
|
||||
avata = ((GameObject)obj).GetComponent<CLRoleAvata> ();
|
||||
if (AssetDatabase.GetAssetPath (obj).Contains ("/other/model/")) {
|
||||
ECLEditorUtl.cleanModleMaterials (AssetDatabase.GetAssetPath (obj));
|
||||
}
|
||||
UIFont font = ((GameObject)obj).GetComponent<UIFont> ();
|
||||
if (font != null) {
|
||||
string spName = font.spriteName;
|
||||
font.atlas = null;
|
||||
font.material = null;
|
||||
font.spriteName = spName;
|
||||
}
|
||||
} else if (obj is Material) {
|
||||
CLMaterialPool.cleanTexRef (ECLEditorUtl.getAssetName4Upgrade (obj), (Material)obj);
|
||||
sharedAsset = null;
|
||||
} else {
|
||||
sharedAsset = null;
|
||||
}
|
||||
bool isRefresh = false;
|
||||
if (avata != null) {
|
||||
avata.cleanMaterial ();
|
||||
isRefresh = true;
|
||||
}
|
||||
if (sharedAsset != null) {
|
||||
sharedAsset.cleanRefAssets ();
|
||||
isRefresh = true;
|
||||
}
|
||||
if (isRefresh && obj is GameObject) {
|
||||
// AssetDatabase.Refresh ();
|
||||
//string path = AssetDatabase.GetAssetPath (obj);
|
||||
//EditorUtility.SetDirty (obj);
|
||||
//AssetDatabase.WriteImportSettingsIfDirty (path);
|
||||
//AssetDatabase.ImportAsset (path);
|
||||
PrefabUtility.SavePrefabAsset(obj as GameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetShardAssets (UnityEngine.Object obj)
|
||||
{
|
||||
CLSharedAssets sharedAsset = null;
|
||||
CLRoleAvata avata = null;
|
||||
if (obj != null && obj is GameObject) {
|
||||
// 没搞明白,执行到这里时,textureMgr已经为null了,因此再取一次
|
||||
sharedAsset = ((GameObject)obj).GetComponent<CLSharedAssets> ();
|
||||
avata = ((GameObject)obj).GetComponent<CLRoleAvata> ();
|
||||
|
||||
UIFont font = ((GameObject)obj).GetComponent<UIFont> ();
|
||||
if (font != null) {
|
||||
if(!string.IsNullOrEmpty(font.atlasName)) {
|
||||
font.atlas = CLUIInit.self.getAtlasByName (font.atlasName);
|
||||
if(font.atlas) {
|
||||
font.material = font.atlas.spriteMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (obj != null && obj is Material) {
|
||||
CLMaterialPool.resetTexRef (ECLEditorUtl.getAssetName4Upgrade (obj), (Material)obj, null, null);
|
||||
sharedAsset = null;
|
||||
} else {
|
||||
sharedAsset = null;
|
||||
}
|
||||
|
||||
bool isRefresh = false;
|
||||
if (avata != null) {
|
||||
avata.setDefaultMaterial ();
|
||||
isRefresh = true;
|
||||
}
|
||||
if (sharedAsset != null) {
|
||||
sharedAsset.reset ();
|
||||
sharedAsset.resetAssets ();
|
||||
isRefresh = true;
|
||||
}
|
||||
if (isRefresh && obj is GameObject) {
|
||||
//string path = AssetDatabase.GetAssetPath (obj);
|
||||
//EditorUtility.SetDirty (obj);
|
||||
//AssetDatabase.WriteImportSettingsIfDirty (path);
|
||||
//AssetDatabase.ImportAsset (path);
|
||||
PrefabUtility.SavePrefabAsset(obj as GameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createUnity3dFiles (string path, CreateDelegate procDelegate, bool isTraversal)
|
||||
{
|
||||
if (path.Length != 0) {
|
||||
//path = path.Replace ("Assets/", "");//因为AssetDatabase.GetAssetPath得到的是型如Assets/文件夹名称,且看下面一句,所以才有这一句。
|
||||
string[] fileEntries = Directory.GetFiles (path);//因为Application.dataPath得到的是型如 "工程名称/Assets"
|
||||
string[] div_line = new string[] { "Assets/" };
|
||||
foreach (string fileName in fileEntries) {
|
||||
Debug.Log ("fileName=" + fileName);
|
||||
string[] sTemp = fileName.Split (div_line, StringSplitOptions.RemoveEmptyEntries);
|
||||
string filePath = sTemp [1];
|
||||
filePath = filePath.Replace("\\", "/");
|
||||
//Debug.Log(filePath);S
|
||||
string localPath = "Assets/" + filePath;
|
||||
|
||||
UnityEngine.Object t = AssetDatabase.LoadMainAssetAtPath (localPath);
|
||||
if (t != null) {
|
||||
if (procDelegate != null) {
|
||||
procDelegate (path.Replace (Application.dataPath + "/", ""), t);
|
||||
} else {
|
||||
createAssets4Upgrade (path, t, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//=============
|
||||
if (isTraversal) {
|
||||
string[] dirEntries = Directory.GetDirectories (path);
|
||||
foreach (string dir in dirEntries) {
|
||||
createUnity3dFiles (dir.Replace("\\", "/"), procDelegate, isTraversal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================
|
||||
// C# Example
|
||||
// Builds an asset bundle from the selected objects in the project view.
|
||||
// Once compiled go to "Menu" -> "Assets" and select one of the choices
|
||||
// to build the Asset Bundle
|
||||
|
||||
// public class ExportAssetBundles
|
||||
// {
|
||||
// [MenuItem ("Assets/Build AssetBundle From Selection - Track dependencies")]
|
||||
// static void ExportResource ()
|
||||
// {
|
||||
// // Bring up save panel
|
||||
// string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
|
||||
// if (path.Length != 0) {
|
||||
// // Build the resource file from the active selection.
|
||||
// UnityEngine.Object[] selection = Selection.GetFiltered (typeof(UnityEngine.Object), SelectionMode.DeepAssets);
|
||||
// #if UNITY_IPHONE
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, selection, path,
|
||||
// BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,
|
||||
// BuildTarget.iOS);
|
||||
// #elif UNITY_ANDROID
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, selection, path,
|
||||
// BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,
|
||||
// BuildTarget.Android);
|
||||
// #else
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, selection, path,
|
||||
// BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
|
||||
// #endif
|
||||
//
|
||||
// Selection.objects = selection;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [MenuItem ("Assets/Build AssetBundle From Selection - Track dependencies(Uncompress)")]
|
||||
// static void ExportResourceUncompress ()
|
||||
// {
|
||||
// // Bring up save panel
|
||||
// string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
|
||||
// if (path.Length != 0) {
|
||||
// // Build the resource file from the active selection.
|
||||
// UnityEngine.Object[] selection = Selection.GetFiltered (typeof(UnityEngine.Object), SelectionMode.DeepAssets);
|
||||
//#if UNITY_IPHONE
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, selection, path,
|
||||
// BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.UncompressedAssetBundle,
|
||||
// BuildTarget.iOS);
|
||||
// #elif UNITY_ANDROID
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, selection, path,
|
||||
// BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.UncompressedAssetBundle,
|
||||
// BuildTarget.Android);
|
||||
// #else
|
||||
// BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path,
|
||||
// BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.UncompressedAssetBundle);
|
||||
//#endif
|
||||
// Selection.objects = selection;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [MenuItem ("Assets/Build AssetBundle From Selection - No dependency tracking")]
|
||||
// static void ExportResourceNoTrack ()
|
||||
// {
|
||||
// // Bring up save panel
|
||||
// string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
|
||||
// if (path.Length != 0) {
|
||||
// // Build the resource file from the active selection.
|
||||
// #if UNITY_IPHONE
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.CompleteAssets, BuildTarget.iOS);
|
||||
// #elif UNITY_ANDROID
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.CompleteAssets, BuildTarget.Android);
|
||||
// #else
|
||||
// BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.CompleteAssets);
|
||||
// #endif
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [MenuItem ("Assets/Build AssetBundle From Selection - No dependency tracking(Uncompress)")]
|
||||
// static void ExportResourceNoTrackUncompress ()
|
||||
// {
|
||||
// // Bring up save panel
|
||||
// string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
|
||||
// if (path.Length != 0) {
|
||||
// // Build the resource file from the active selection.
|
||||
// #if UNITY_IPHONE
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.iOS);
|
||||
// #elif UNITY_ANDROID
|
||||
// BuildPipeline.BuildAssetBundle (Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android);
|
||||
// #else
|
||||
// BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.UncompressedAssetBundle);
|
||||
// #endif
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf43a84c27d5842858cc479532ee27c6
|
||||
timeCreated: 1484206432
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
108
Assets/CoolapeFrame/Editor/Utl/ECLCreateFile.cs
Normal file
108
Assets/CoolapeFrame/Editor/Utl/ECLCreateFile.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEditor.ProjectWindowCallback;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
/*
|
||||
* 有个简单粗暴的办法, 直接在Editor\Data\Resources\ScriptTemplates文件夹下
|
||||
* 建一个文件,文件名类似即可...如89-LuaScript-NewLuaScript.lua.txt
|
||||
* 文件名的意义=>优先级为:89;右键Create名为:Lua Sprite;
|
||||
* 创建初始名为:NewLuaScript.lua 文件里的#SCRIPTNAME# 也会自动替换
|
||||
*/
|
||||
public class ECLCreateFile
|
||||
{
|
||||
[MenuItem ("Assets/Create/Lua Script/New Lua Panel", false, 81)]
|
||||
public static void CreatNewLuaPanel ()
|
||||
{
|
||||
PubCreatNewFile ("Assets/CoolapeFrame/Templates/Lua/NewLuaPanel.lua", GetSelectedPathOrFallback () + "/NewLuaPanel.lua");
|
||||
}
|
||||
|
||||
[MenuItem ("Assets/Create/Lua Script/New Lua Cell", false, 81)]
|
||||
public static void CreatNewLuaCell ()
|
||||
{
|
||||
PubCreatNewFile ("Assets/CoolapeFrame/Templates/Lua/NewLuaCell.lua", GetSelectedPathOrFallback () + "/NewLuaCell.lua");
|
||||
}
|
||||
|
||||
[MenuItem ("Assets/Create/Txt file", false, 82)]
|
||||
public static void CreatNewTxtFile ()
|
||||
{
|
||||
PubCreatNewFile ("Assets/CoolapeFrame/Templates/textEmpty.txt", GetSelectedPathOrFallback () + "/NewText.txt");
|
||||
}
|
||||
|
||||
public static void PubCreatNewFile (string tempFile, string desFile)
|
||||
{
|
||||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists (0,
|
||||
ScriptableObject.CreateInstance<MyDoCreateScriptAsset> (),
|
||||
desFile,
|
||||
null,
|
||||
tempFile);
|
||||
}
|
||||
|
||||
public static void PubCreatNewFile2 (string tempFile, string desFile)
|
||||
{
|
||||
// File.Copy (tempFile, desFile);
|
||||
CreateScriptAssetFromTemplate (desFile, tempFile);
|
||||
}
|
||||
|
||||
public static string GetSelectedPathOrFallback ()
|
||||
{
|
||||
string path = "Assets";
|
||||
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets)) {
|
||||
path = AssetDatabase.GetAssetPath (obj);
|
||||
if (!string.IsNullOrEmpty (path) && File.Exists (path)) {
|
||||
path = Path.GetDirectoryName (path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static UnityEngine.Object CreateScriptAssetFromTemplate (string pathName, string resourceFile)
|
||||
{
|
||||
string fullPath = Path.GetFullPath (pathName);
|
||||
StreamReader streamReader = new StreamReader (resourceFile);
|
||||
string text = streamReader.ReadToEnd ();
|
||||
streamReader.Close ();
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension (pathName);
|
||||
text = Regex.Replace (text, "#SCRIPTNAME#", fileNameWithoutExtension);
|
||||
//string text2 = Regex.Replace(fileNameWithoutExtension, " ", string.Empty);
|
||||
//text = Regex.Replace(text, "#SCRIPTNAME#", text2);
|
||||
//if (char.IsUpper(text2, 0))
|
||||
//{
|
||||
// text2 = char.ToLower(text2[0]) + text2.Substring(1);
|
||||
// text = Regex.Replace(text, "#SCRIPTNAME_LOWER#", text2);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// text2 = "my" + char.ToUpper(text2[0]) + text2.Substring(1);
|
||||
// text = Regex.Replace(text, "#SCRIPTNAME_LOWER#", text2);
|
||||
//}
|
||||
bool encoderShouldEmitUTF8Identifier = true;
|
||||
bool throwOnInvalidBytes = false;
|
||||
UTF8Encoding encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier, throwOnInvalidBytes);
|
||||
bool append = false;
|
||||
StreamWriter streamWriter = new StreamWriter (fullPath, append, encoding);
|
||||
streamWriter.Write (text);
|
||||
streamWriter.Close ();
|
||||
AssetDatabase.ImportAsset (pathName);
|
||||
return AssetDatabase.LoadAssetAtPath (pathName, typeof(UnityEngine.Object));
|
||||
}
|
||||
}
|
||||
|
||||
class MyDoCreateScriptAsset : EndNameEditAction
|
||||
{
|
||||
public override void Action (int instanceId, string pathName, string resourceFile)
|
||||
{
|
||||
UnityEngine.Object o = CreateScriptAssetFromTemplate (pathName, resourceFile);
|
||||
ProjectWindowUtil.ShowCreatedAsset (o);
|
||||
}
|
||||
|
||||
internal static UnityEngine.Object CreateScriptAssetFromTemplate (string pathName, string resourceFile)
|
||||
{
|
||||
return ECLCreateFile.CreateScriptAssetFromTemplate (pathName, resourceFile);
|
||||
}
|
||||
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Utl/ECLCreateFile.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Utl/ECLCreateFile.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52138cd71999c4e239e1affb4cb04e33
|
||||
timeCreated: 1484291606
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
411
Assets/CoolapeFrame/Editor/Utl/ECLEditorUtl.cs
Normal file
411
Assets/CoolapeFrame/Editor/Utl/ECLEditorUtl.cs
Normal file
@@ -0,0 +1,411 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using Coolape;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditorInternal;
|
||||
|
||||
public static class ECLEditorUtl
|
||||
{
|
||||
public static GUILayoutOption width30 = GUILayout.Width (30);
|
||||
public static GUILayoutOption width50 = GUILayout.Width (50);
|
||||
public static GUILayoutOption width80 = GUILayout.Width (80);
|
||||
public static GUILayoutOption width100 = GUILayout.Width (100);
|
||||
public static GUILayoutOption width120 = GUILayout.Width (120);
|
||||
public static GUILayoutOption width150 = GUILayout.Width (150);
|
||||
public static GUILayoutOption width200 = GUILayout.Width (200);
|
||||
public static GUILayoutOption width250 = GUILayout.Width (250);
|
||||
public static GUILayoutOption width300 = GUILayout.Width (300);
|
||||
public static GUILayoutOption width400 = GUILayout.Width (400);
|
||||
public static GUILayoutOption width500 = GUILayout.Width (500);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path by object.取得工程对象的路径,但不包含Assets;
|
||||
/// </summary>
|
||||
/// <returns>The path by object.</returns>
|
||||
/// <param name="obj">Object.</param>
|
||||
public static string getPathByObject (Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return "";
|
||||
string tmpPath = AssetDatabase.GetAssetPath (obj.GetInstanceID ());
|
||||
if (string.IsNullOrEmpty (tmpPath)) {
|
||||
Debug.LogError ("Cannot get path! [obj name]==" + obj.name);
|
||||
return "";
|
||||
}
|
||||
int startPos = 0;
|
||||
|
||||
startPos = tmpPath.IndexOf ("Assets/");
|
||||
startPos += 7;
|
||||
tmpPath = tmpPath.Substring (startPos, tmpPath.Length - startPos);
|
||||
return tmpPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the object by path.
|
||||
/// </summary>
|
||||
/// <returns>The object by path.</returns>
|
||||
/// <param name="path">Path.</param>
|
||||
public static Object getObjectByPath (string path)
|
||||
{
|
||||
string tmpPath = path;
|
||||
if (!tmpPath.StartsWith ("Assets/")) {
|
||||
tmpPath = PStr.b ().a ("Assets/").a (tmpPath).e ();
|
||||
}
|
||||
return AssetDatabase.LoadAssetAtPath (
|
||||
tmpPath, typeof(UnityEngine.Object));
|
||||
}
|
||||
|
||||
static public void BeginContents ()
|
||||
{
|
||||
GUILayout.BeginHorizontal ();
|
||||
EditorGUILayout.BeginHorizontal (NGUIEditorTools.textArea, GUILayout.MinHeight (10f));
|
||||
GUILayout.BeginVertical ();
|
||||
GUILayout.Space (2f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End drawing the content area.
|
||||
/// </summary>
|
||||
static public void EndContents ()
|
||||
{
|
||||
GUILayout.Space (3f);
|
||||
GUILayout.EndVertical ();
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
GUILayout.Space (3f);
|
||||
GUILayout.EndHorizontal ();
|
||||
GUILayout.Space (3f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ises the ignore file.是否需要忽略的文件
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if ignore file was ised, <c>false</c> otherwise.</returns>
|
||||
/// <param name="filePath">File path.</param>
|
||||
static public bool isIgnoreFile (string filePath)
|
||||
{
|
||||
if (ECLProjectManager.data == null
|
||||
|| string.IsNullOrEmpty (filePath)
|
||||
|| string.IsNullOrEmpty (ECLProjectManager.data.ingoreResWithExtensionNames)) {
|
||||
return false;
|
||||
}
|
||||
string extension = Path.GetExtension (filePath).ToLower ();
|
||||
string extensionList = ECLProjectManager.data.ingoreResWithExtensionNames.ToLower ();
|
||||
|
||||
if (!string.IsNullOrEmpty (extension) && extensionList.Contains (extension)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the asset4 upgrade.把想关引用的asset移动对应的目录,以便可以支持热更新
|
||||
/// </summary>
|
||||
/// <param name="obj">Object.</param>
|
||||
static public bool moveAsset4Upgrade (Object obj)
|
||||
{
|
||||
string objPath = getPathByObject (obj);
|
||||
objPath = objPath.Replace("\\", "/");
|
||||
if (objPath.Contains ("/upgradeRes4Dev/")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string toPathBase = CLPathCfg.self.basePath + "/upgradeRes4Dev/other/";
|
||||
if (obj is Material) {
|
||||
toPathBase = toPathBase + "Materials/";
|
||||
} else if (obj is Texture) {
|
||||
toPathBase = toPathBase + "Textures/";
|
||||
} else if (obj is CLUnit) {
|
||||
toPathBase = toPathBase + "roles/";
|
||||
} else if (obj is CLBulletBase) {
|
||||
toPathBase = toPathBase + "bullet/";
|
||||
} else if (obj is CLEffect) {
|
||||
toPathBase = toPathBase + "effect/";
|
||||
} else if (obj is AudioClip) {
|
||||
toPathBase = toPathBase + "sound/";
|
||||
} else if (obj is Mesh || obj is Avatar) {
|
||||
toPathBase = toPathBase + "model/";
|
||||
} else {
|
||||
toPathBase = toPathBase + "things/";
|
||||
}
|
||||
string toPath = "";
|
||||
if (objPath.StartsWith (CLPathCfg.self.basePath + "/xRes/")) {
|
||||
toPath = toPathBase + objPath.Replace (CLPathCfg.self.basePath + "/xRes/", "");
|
||||
} else if (objPath.StartsWith (CLPathCfg.self.basePath + "/")) {
|
||||
toPath = toPathBase + objPath.Replace (CLPathCfg.self.basePath + "/", "");
|
||||
} else if (objPath.Contains ("/Resources/")) {
|
||||
toPath = toPathBase + objPath.Replace ("/Resources/", "/Res/");
|
||||
} else {
|
||||
toPath = toPathBase + objPath;
|
||||
}
|
||||
// Debug.Log ("111=======Assets/" + objPath);
|
||||
// Debug.Log ("222=======Assets/" + toPath);
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (Application.dataPath + "/" + toPath));
|
||||
AssetDatabase.Refresh ();
|
||||
string ret = AssetDatabase.MoveAsset ("Assets/" + objPath, "Assets/" + toPath);
|
||||
if (!string.IsNullOrEmpty (ret)) {
|
||||
Debug.LogError (ret);
|
||||
return false;
|
||||
} else {
|
||||
AssetDatabase.Refresh ();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file name4 upgrade.取得asset的名字,给资源管理用
|
||||
/// </summary>
|
||||
/// <returns>The file name4 upgrade.</returns>
|
||||
/// <param name="obj">Object.</param>
|
||||
static public string getAssetName4Upgrade (Object obj)
|
||||
{
|
||||
string objPath = getPathByObject (obj);
|
||||
// Debug.Log ("objPath===" + objPath);
|
||||
string objName = Path.GetFileNameWithoutExtension (objPath);
|
||||
string basePath = Path.GetDirectoryName (objPath) + "/";
|
||||
basePath = basePath.Replace("\\", "/");
|
||||
// Debug.Log (objName);
|
||||
// Debug.Log (basePath);
|
||||
string replacePath = CLPathCfg.self.basePath + "/upgradeRes4Dev/other/";
|
||||
if (obj is Material) {
|
||||
replacePath = replacePath + "Materials/";
|
||||
} else if (obj is Texture) {
|
||||
replacePath = replacePath + "Textures/";
|
||||
} else if (obj is CLUnit) {
|
||||
replacePath = replacePath + "roles/";
|
||||
} else if (obj is CLBulletBase) {
|
||||
replacePath = replacePath + "bullet/";
|
||||
} else if (obj is CLEffect) {
|
||||
replacePath = replacePath + "effect/";
|
||||
} else if (obj is AudioClip) {
|
||||
replacePath = replacePath + "sound/";
|
||||
} else if (obj is Mesh || obj is Avatar) {
|
||||
replacePath = replacePath + "model/";
|
||||
} else {
|
||||
replacePath = replacePath + "things/";
|
||||
}
|
||||
|
||||
// Debug.Log ("replacePath===" + replacePath);
|
||||
objName = basePath.Replace (replacePath, "");
|
||||
if (objName != "") {
|
||||
objName = Path.Combine (objName, Path.GetFileNameWithoutExtension (objPath));
|
||||
} else {
|
||||
objName = Path.GetFileNameWithoutExtension (objPath);
|
||||
}
|
||||
objName = objName.Replace("\\", "/");
|
||||
objName = objName.Replace ("/", ".");
|
||||
// Debug.Log ("objName===" + objName);
|
||||
return objName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all textures from a material
|
||||
/// </summary>
|
||||
/// <returns>The textures from material.</returns>
|
||||
/// <param name="mat">Mat.</param>
|
||||
public static bool getTexturesFromMaterial (Material mat, ref ArrayList propNames, ref ArrayList texNames, ref ArrayList texPaths)
|
||||
{
|
||||
bool ret = false;
|
||||
if (mat == null) {
|
||||
Debug.LogWarning ("The mat is null");
|
||||
return ret;
|
||||
}
|
||||
Shader shader = mat.shader;
|
||||
string propName = "";
|
||||
for (int i = 0; i < ShaderUtil.GetPropertyCount (shader); i++) {
|
||||
if (ShaderUtil.GetPropertyType (shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) {
|
||||
propName = ShaderUtil.GetPropertyName (shader, i);
|
||||
Texture texture = mat.GetTexture (propName);
|
||||
if (texture != null) {
|
||||
ret = ECLEditorUtl.moveAsset4Upgrade (texture) || ret ? true : false;
|
||||
propNames.Add (propName);
|
||||
texNames.Add (ECLEditorUtl.getAssetName4Upgrade (texture));
|
||||
texPaths.Add (ECLEditorUtl.getPathByObject (texture));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dir list.取得目录列表
|
||||
/// </summary>
|
||||
/// <param name="dir">Dir.</param>
|
||||
/// <param name="left">Left.</param>
|
||||
/// <param name="result">Result.</param>
|
||||
static public void getDirList (string dir, string left, ref string result)
|
||||
{
|
||||
result = string.IsNullOrEmpty (result) ? "" : result;
|
||||
/*
|
||||
─━│┃┄┅┆┇┈┉┊┋┌
|
||||
┍┎┏┐┑┒┓└┕┖
|
||||
┗┘┙┚┛├┝┞┟
|
||||
┠┡┢┣┤┥┦┧┨
|
||||
┩┪┫┬┭┮┯┰
|
||||
┱┲┳┴┵┶┷┸┹
|
||||
┺┻┼┽┾┿╀╁╂
|
||||
╃╄╅╆╇╈╉╊╋═║
|
||||
╒╓╔╕╖╗╘╙
|
||||
╚╛╜╝╞╟╠╡
|
||||
╢╣╤╥╦╧╨╩
|
||||
╪╫╬╳╔ ╗╝╚
|
||||
╬ ═ ╓ ╩ ┠ ┨┯
|
||||
┷┏ ┓┗ ┛┳⊥﹃﹄┌╭╮╯╰
|
||||
*/
|
||||
result = result + left + dir.Replace (Application.dataPath + "/", " ") + " \n";
|
||||
string[] dirs = Directory.GetDirectories (dir);
|
||||
string left2 = "";
|
||||
if (dirs.Length > 0 && left.Length > 0) {
|
||||
char[] chars = left.ToCharArray ();
|
||||
if (chars [chars.Length - 1] == '┖') {
|
||||
chars [chars.Length - 1] = ' ';
|
||||
} else {
|
||||
chars [chars.Length - 1] = '┃';
|
||||
}
|
||||
left2 = new string (chars);
|
||||
}
|
||||
if (dirs.Length > 0) {
|
||||
for (int i = 0; i < dirs.Length; i++) {
|
||||
if (i == dirs.Length - 1) {
|
||||
getDirList (dirs [i], left2 + "┖", ref result);
|
||||
} else {
|
||||
getDirList (dirs [i], left2 + "┠", ref result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SaveRenderTextureToPNG (Texture inputTex, Shader outputShader, string contents, string pngName)
|
||||
{
|
||||
RenderTexture temp = RenderTexture.GetTemporary (inputTex.width, inputTex.height, 0, RenderTextureFormat.ARGB32);
|
||||
Material mat = new Material (outputShader);
|
||||
Graphics.Blit (inputTex, temp, mat);
|
||||
bool ret = SaveRenderTextureToPNG (temp, contents, pngName);
|
||||
RenderTexture.ReleaseTemporary (temp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//将RenderTexture保存成一张png图片
|
||||
public static bool SaveRenderTextureToPNG (RenderTexture rt, string contents, string pngName)
|
||||
{
|
||||
RenderTexture prev = RenderTexture.active;
|
||||
RenderTexture.active = rt;
|
||||
Texture2D png = new Texture2D (rt.width, rt.height, TextureFormat.ARGB32, false);
|
||||
png.ReadPixels (new Rect (0, 0, rt.width, rt.height), 0, 0);
|
||||
byte[] bytes = png.EncodeToPNG ();
|
||||
if (!Directory.Exists (contents))
|
||||
Directory.CreateDirectory (contents);
|
||||
FileStream file = File.Open (contents + "/" + pngName + ".png", FileMode.Create);
|
||||
BinaryWriter writer = new BinaryWriter (file);
|
||||
writer.Write (bytes);
|
||||
file.Close ();
|
||||
Texture2D.DestroyImmediate (png);
|
||||
png = null;
|
||||
RenderTexture.active = prev;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setModelProp (ModelImporter mi, bool isReadable, ModelImporterNormals modelNormals, ModelImporterTangents modelTangents)
|
||||
{
|
||||
if (mi != null) {
|
||||
mi.importMaterials = false;
|
||||
mi.isReadable = isReadable;
|
||||
mi.importNormals = modelNormals;
|
||||
mi.importTangents = modelTangents;
|
||||
AssetDatabase.Refresh ();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setModelProp (string modelName, bool isReadable, ModelImporterNormals modelNormals, ModelImporterTangents modelTangents)
|
||||
{
|
||||
string matPath = PStr.b ().a ("Assets/").a (CLPathCfg.self.basePath).a ("/")
|
||||
.a ("upgradeRes4Dev").a ("/other/model/").a (modelName.Replace (".", "/")).a (".FBX").e ();
|
||||
|
||||
ModelImporter mi = ModelImporter.GetAtPath (matPath) as ModelImporter;
|
||||
setModelProp (mi, isReadable, modelNormals, modelTangents);
|
||||
doCleanModelMaterials (matPath);
|
||||
}
|
||||
|
||||
public static void cleanModleMaterials (ModelImporter mi)
|
||||
{
|
||||
if (mi != null) {
|
||||
mi.importMaterials = false;
|
||||
AssetDatabase.Refresh ();
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanModleMaterials (string modelName)
|
||||
{
|
||||
string matPath = PStr.b ().a ("Assets/").a (CLPathCfg.self.basePath).a ("/")
|
||||
.a ("upgradeRes4Dev").a ("/other/model/").a (modelName.Replace (".", "/")).a (".FBX").e ();
|
||||
doCleanModelMaterials (matPath);
|
||||
}
|
||||
|
||||
public static void doCleanModelMaterials (string matPath)
|
||||
{
|
||||
checkModleSetting (matPath);
|
||||
ModelImporter mi = ModelImporter.GetAtPath (matPath) as ModelImporter;
|
||||
if (mi != null) {
|
||||
cleanModleMaterials (mi);
|
||||
AssetDatabase.ImportAsset (matPath);
|
||||
}
|
||||
|
||||
GameObject go = ECLEditorUtl.getObjectByPath (matPath) as GameObject;
|
||||
if (go != null) {
|
||||
MeshRenderer mf = go.GetComponentInChildren<MeshRenderer> ();
|
||||
if (mf != null) {
|
||||
mf.sharedMaterial = null;
|
||||
Material[] mats = mf.sharedMaterials;
|
||||
for (int i = 0; i < mats.Length; i++) {
|
||||
mats [i] = null;
|
||||
}
|
||||
mf.sharedMaterials = mats;
|
||||
}
|
||||
SkinnedMeshRenderer smr = go.GetComponentInChildren<SkinnedMeshRenderer> ();
|
||||
if (smr != null) {
|
||||
smr.sharedMaterial = null;
|
||||
Material[] mats = smr.sharedMaterials;
|
||||
for (int i = 0; i < mats.Length; i++) {
|
||||
mats [i] = null;
|
||||
}
|
||||
smr.sharedMaterials = mats;
|
||||
}
|
||||
EditorUtility.SetDirty (go);
|
||||
AssetDatabase.WriteImportSettingsIfDirty (matPath);
|
||||
AssetDatabase.Refresh ();
|
||||
}
|
||||
}
|
||||
|
||||
public static string checkModleSetting (string path)
|
||||
{
|
||||
string ret = "";
|
||||
ModelImporter mi = ModelImporter.GetAtPath (path) as ModelImporter;
|
||||
if (mi != null) {
|
||||
if (mi.isReadable) {
|
||||
ret = PStr.b ().a (ret).a ("can reade write! ").e ();
|
||||
}
|
||||
if (mi.importMaterials) {
|
||||
ret = PStr.b ().a (ret).a ("import Materials! ").e ();
|
||||
}
|
||||
if (mi.importNormals != ModelImporterNormals.None) {
|
||||
ret = PStr.b ().a (ret).a ("import Normals! ").e ();
|
||||
}
|
||||
}
|
||||
Debug.LogError (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static LayerMask drawMaskField(string text, LayerMask mask)
|
||||
{
|
||||
return drawMaskField(new GUIContent(text, ""), mask);
|
||||
}
|
||||
|
||||
public static LayerMask drawMaskField(GUIContent uIContent, LayerMask mask) {
|
||||
int tempMask = EditorGUILayout.MaskField(uIContent,
|
||||
InternalEditorUtility.LayerMaskToConcatenatedLayersMask(mask),
|
||||
InternalEditorUtility.layers);
|
||||
return InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask);
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Utl/ECLEditorUtl.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Utl/ECLEditorUtl.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d83784e8535384ae2955777334fb7821
|
||||
timeCreated: 1484206371
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
92
Assets/CoolapeFrame/Editor/Utl/ECLGUIMsgBox.cs
Normal file
92
Assets/CoolapeFrame/Editor/Utl/ECLGUIMsgBox.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using Coolape;
|
||||
|
||||
public class ECLGUIMsgBox : EditorWindow
|
||||
{
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
// Rect windowRect = new Rect (0,0,Screen.width/2, Screen.height/2);
|
||||
public string msg;
|
||||
public Callback callback;
|
||||
public Callback callback2;
|
||||
bool is2Buttons = true;
|
||||
int eachLen = 10000;
|
||||
|
||||
void OnGUI ()
|
||||
{
|
||||
// Begin Window
|
||||
// BeginWindows ();
|
||||
|
||||
// All GUI.Window or GUILayout.Window must come inside here
|
||||
//所有GUI.Window 或 GUILayout.Window 必须在这里面
|
||||
// windowRect = GUILayout.Window (1, windowRect, DoWindow, title);
|
||||
|
||||
// Collect all the windows between the two.
|
||||
//在这两者之间搜集所有窗口
|
||||
// EndWindows ();
|
||||
|
||||
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Width (position.width), GUILayout.Height (position.height - 30));
|
||||
int pos = 0;
|
||||
while (pos < msg.Length) {
|
||||
GUILayout.TextArea (msg.Substring (pos, msg.Length - pos > eachLen ? eachLen : msg.Length - pos));
|
||||
pos += eachLen;
|
||||
}
|
||||
EditorGUILayout.EndScrollView ();
|
||||
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
|
||||
if (GUILayout.Button ("Okay")) {
|
||||
this.Close ();
|
||||
if (callback != null) {
|
||||
callback ();
|
||||
}
|
||||
}
|
||||
if (is2Buttons) {
|
||||
GUI.color = Color.yellow;
|
||||
if (GUILayout.Button ("Cancel")) {
|
||||
this.Close ();
|
||||
if (callback2 != null) {
|
||||
callback2 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
// void DoWindow (int index) {
|
||||
//
|
||||
// if(GUILayout.Button ("Okay"))
|
||||
// this.Close();
|
||||
// GUI.DragWindow ();
|
||||
// }
|
||||
|
||||
|
||||
public static void show (string title, string msg, Callback callback)
|
||||
{
|
||||
show (title, msg, callback, null, false);
|
||||
}
|
||||
|
||||
public static void show (string title, string msg, Callback callback, Callback callback2, bool _is2Buttons = true)
|
||||
{
|
||||
ECLGUIMsgBox window = EditorWindow.GetWindow<ECLGUIMsgBox> (true, "GUIMsgBox", true);
|
||||
if (window == null) {
|
||||
window = new ECLGUIMsgBox ();
|
||||
}
|
||||
window.title = title;
|
||||
window.msg = msg;
|
||||
window.callback = callback;
|
||||
window.callback2 = callback2;
|
||||
window.is2Buttons = _is2Buttons;
|
||||
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.Show ();
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Utl/ECLGUIMsgBox.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Utl/ECLGUIMsgBox.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44c7ad5506bba42fb8a44e8213bdd301
|
||||
timeCreated: 1484206460
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
119
Assets/CoolapeFrame/Editor/Utl/FindReferense.cs
Normal file
119
Assets/CoolapeFrame/Editor/Utl/FindReferense.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class FindReferences
|
||||
{
|
||||
|
||||
[MenuItem("Coolape/Tools/Find References(Coolape)", false, 10)]
|
||||
static private void Find()
|
||||
{
|
||||
EditorSettings.serializationMode = SerializationMode.ForceText;
|
||||
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
string guid = AssetDatabase.AssetPathToGUID(path);
|
||||
List<string> withoutExtensions = new List<string>(){".prefab",".unity",".mat",".asset"};
|
||||
string[] files = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories)
|
||||
.Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
|
||||
int startIndex = 0;
|
||||
|
||||
EditorApplication.update = delegate()
|
||||
{
|
||||
string file = files[startIndex];
|
||||
|
||||
bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length);
|
||||
|
||||
if (Regex.IsMatch(File.ReadAllText(file), guid))
|
||||
{
|
||||
Debug.Log(file, AssetDatabase.LoadAssetAtPath<Object>(GetRelativeAssetsPath(file)));
|
||||
}
|
||||
|
||||
startIndex++;
|
||||
if (isCancel || startIndex >= files.Length)
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
EditorApplication.update = null;
|
||||
startIndex = 0;
|
||||
Debug.Log("匹配结束");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Coolape/Tools/Find References", true)]
|
||||
static private bool VFind()
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
|
||||
return (!string.IsNullOrEmpty(path));
|
||||
}
|
||||
|
||||
static private string GetRelativeAssetsPath(string path)
|
||||
{
|
||||
return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR_OSX
|
||||
|
||||
[MenuItem("Coolape/Tools/Find References In Project(Coolape)", false, 10)]
|
||||
private static void FindProjectReferences()
|
||||
{
|
||||
string appDataPath = Application.dataPath;
|
||||
string output = "";
|
||||
string selectedAssetPath = AssetDatabase.GetAssetPath (Selection.activeObject);
|
||||
List<string> references = new List<string>();
|
||||
|
||||
string guid = AssetDatabase.AssetPathToGUID (selectedAssetPath);
|
||||
|
||||
var psi = new System.Diagnostics.ProcessStartInfo();
|
||||
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
|
||||
psi.FileName = "/usr/bin/mdfind";
|
||||
psi.Arguments = "-onlyin " + Application.dataPath + " " + guid;
|
||||
psi.UseShellExecute = false;
|
||||
psi.RedirectStandardOutput = true;
|
||||
psi.RedirectStandardError = true;
|
||||
|
||||
System.Diagnostics.Process process = new System.Diagnostics.Process();
|
||||
process.StartInfo = psi;
|
||||
|
||||
process.OutputDataReceived += (sender, e) => {
|
||||
if(string.IsNullOrEmpty(e.Data))
|
||||
return;
|
||||
|
||||
string relativePath = "Assets" + e.Data.Replace(appDataPath, "");
|
||||
|
||||
// skip the meta file of whatever we have selected
|
||||
if(relativePath == selectedAssetPath + ".meta")
|
||||
return;
|
||||
|
||||
references.Add(relativePath);
|
||||
|
||||
};
|
||||
process.ErrorDataReceived += (sender, e) => {
|
||||
if(string.IsNullOrEmpty(e.Data))
|
||||
return;
|
||||
|
||||
output += "Error: " + e.Data + "\n";
|
||||
};
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
process.WaitForExit(2000);
|
||||
|
||||
foreach(var file in references){
|
||||
output += file + "\n";
|
||||
Debug.Log(file, AssetDatabase.LoadMainAssetAtPath(file));
|
||||
}
|
||||
|
||||
Debug.LogWarning(references.Count + " references found for object " + Selection.activeObject.name + "\n\n" + output);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Utl/FindReferense.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Utl/FindReferense.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f5f8cbd217cc48329f6538b79ffff5a
|
||||
timeCreated: 1495129849
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
270
Assets/CoolapeFrame/Editor/Utl/SFTPHelper.cs
Normal file
270
Assets/CoolapeFrame/Editor/Utl/SFTPHelper.cs
Normal file
@@ -0,0 +1,270 @@
|
||||
using Tamir.SharpSsh.jsch;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using Coolape;
|
||||
|
||||
public class SFTPHelper
|
||||
{
|
||||
private Session m_session;
|
||||
private Channel m_channel;
|
||||
private ChannelSftp m_sftp;
|
||||
|
||||
//host:sftp地址 user:用户名 pwd:密码
|
||||
public SFTPHelper (string host, int _port, string user, string pwd)
|
||||
{
|
||||
string[] arr = host.Split (':');
|
||||
string ip = arr [0];
|
||||
// int port = 22;
|
||||
int port = _port;
|
||||
if (arr.Length > 1)
|
||||
port = Int32.Parse (arr [1]);
|
||||
|
||||
JSch jsch = new JSch ();
|
||||
m_session = jsch.getSession (user, ip, port);
|
||||
MyUserInfo ui = new MyUserInfo ();
|
||||
ui.setPassword (pwd);
|
||||
m_session.setUserInfo (ui);
|
||||
|
||||
}
|
||||
|
||||
//SFTP连接状态
|
||||
public bool Connected { get { return m_session.isConnected (); } }
|
||||
|
||||
//连接SFTP
|
||||
public bool Connect ()
|
||||
{
|
||||
try {
|
||||
if (!Connected) {
|
||||
m_session.connect ();
|
||||
m_channel = m_session.openChannel ("sftp");
|
||||
m_channel.connect ();
|
||||
m_sftp = (ChannelSftp)m_channel;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Debug.Log ("connect failed!!" + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//断开SFTP
|
||||
public void Disconnect ()
|
||||
{
|
||||
if (Connected) {
|
||||
m_channel.disconnect ();
|
||||
m_session.disconnect ();
|
||||
}
|
||||
}
|
||||
|
||||
public bool PutDir (string localDir, string remoteDir, Callback onProgressCallback, Callback onFinishCallback)
|
||||
{
|
||||
bool ret = false;
|
||||
if (!Directory.Exists (localDir)) {
|
||||
Debug.LogError ("There is no directory exist!");
|
||||
Utl.doCallback (onFinishCallback, false);
|
||||
return false;
|
||||
}
|
||||
Mkdir (remoteDir);
|
||||
string[] files = Directory.GetFiles (localDir);
|
||||
string file = "";
|
||||
string[] dirs = Directory.GetDirectories (localDir);
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.Length; i++) {
|
||||
file = files [i];
|
||||
Debug.Log (file);
|
||||
ret = Put (file, remoteDir, onProgressCallback, null);
|
||||
if (!ret) {
|
||||
Utl.doCallback (onFinishCallback, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dirs != null) {
|
||||
for (int i = 0; i < dirs.Length; i++) {
|
||||
// Debug.Log (PStr.b ().a (remotePath).a ("/").a (Path.GetFileName (dirs [i])).e ());
|
||||
ret = PutDir (dirs [i], PStr.b ().a (remoteDir).a ("/").a (Path.GetFileName (dirs [i])).e (), onProgressCallback, null);
|
||||
if (!ret) {
|
||||
Utl.doCallback (onFinishCallback, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Utl.doCallback (onFinishCallback, true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Mkdir (string dir)
|
||||
{
|
||||
try {
|
||||
m_sftp.mkdir (new Tamir.SharpSsh.java.String (dir));
|
||||
} catch (Exception e) {
|
||||
// Debug.LogError (e);
|
||||
}
|
||||
}
|
||||
//SFTP存放文件
|
||||
public bool Put (string localPath, string remotePath, Callback onProgressCallback, Callback onFinishCallback)
|
||||
{
|
||||
try {
|
||||
Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String (localPath);
|
||||
Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String (remotePath);
|
||||
ProgressMonitor progressMonitor = new ProgressMonitor (onProgressCallback, onFinishCallback);
|
||||
m_sftp.put (src, dst, progressMonitor, ChannelSftp.OVERWRITE);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Debug.LogError (e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//SFTP获取文件
|
||||
public bool Get (string remotePath, string localPath)
|
||||
{
|
||||
try {
|
||||
Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String (remotePath);
|
||||
Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String (localPath);
|
||||
m_sftp.get (src, dst);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Debug.LogError (e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//删除SFTP文件
|
||||
public bool Delete (string remoteFile)
|
||||
{
|
||||
try {
|
||||
m_sftp.rm (remoteFile);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit ()
|
||||
{
|
||||
try {
|
||||
if (m_sftp != null) {
|
||||
m_sftp.disconnect ();
|
||||
m_sftp.quit ();
|
||||
m_sftp.exit ();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debug.LogError (e);
|
||||
}
|
||||
}
|
||||
//获取SFTP文件列表
|
||||
public ArrayList GetFileList (string remotePath, string fileType)
|
||||
{
|
||||
try {
|
||||
Tamir.SharpSsh.java.util.Vector vvv = m_sftp.ls (remotePath);
|
||||
ArrayList objList = new ArrayList ();
|
||||
foreach (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry qqq in vvv) {
|
||||
string sss = qqq.getFilename ();
|
||||
if (sss.Length > (fileType.Length + 1) && fileType == sss.Substring (sss.Length - fileType.Length)) {
|
||||
objList.Add (sss);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return objList;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//登录验证信息
|
||||
public class MyUserInfo : UserInfo
|
||||
{
|
||||
String passwd;
|
||||
|
||||
public String getPassword ()
|
||||
{
|
||||
return passwd;
|
||||
}
|
||||
|
||||
public void setPassword (String passwd)
|
||||
{
|
||||
this.passwd = passwd;
|
||||
}
|
||||
|
||||
public String getPassphrase ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool promptPassphrase (String message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool promptPassword (String message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool promptYesNo (String message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showMessage (String message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ProgressMonitor : SftpProgressMonitor
|
||||
{
|
||||
private long max = 0;
|
||||
private long mCount = 0;
|
||||
private float percent = 0;
|
||||
Callback onProgress;
|
||||
Callback onFinish;
|
||||
|
||||
// If you need send something to the constructor, change this method
|
||||
public ProgressMonitor (Callback onProgress, Callback onFinish)
|
||||
{
|
||||
this.onProgress = onProgress;
|
||||
this.onFinish = onFinish;
|
||||
}
|
||||
|
||||
public override void init (int op, string src, string dest, long max)
|
||||
{
|
||||
this.max = max;
|
||||
// System.out.println("starting");
|
||||
// System.out.println(src); // Origin destination
|
||||
// System.out.println(dest); // Destination path
|
||||
// System.out.println(max); // Total filesize
|
||||
}
|
||||
|
||||
public override bool count (long bytes)
|
||||
{
|
||||
mCount += bytes;
|
||||
float percentNow = mCount / (float)max;
|
||||
if (percentNow > this.percent) {
|
||||
this.percent = percentNow;
|
||||
Utl.doCallback (onProgress, percentNow);
|
||||
// Debug.Log("progress=="+ this.percent); // Progress 0,0
|
||||
// System.out.println(max); //Total ilesize
|
||||
// System.out.println(this.count); // Progress in bytes from the total
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public override void end ()
|
||||
{
|
||||
Utl.doCallback (onFinish, true);
|
||||
// System.out.println("finished");// The process is over
|
||||
// System.out.println(this.percent); // Progress
|
||||
// System.out.println(max); // Total filesize
|
||||
// System.out.println(this.count); // Process in bytes from the total
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Utl/SFTPHelper.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Utl/SFTPHelper.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf2f7b2de63564dd78b44c397b15c70d
|
||||
timeCreated: 1487580315
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
500
Assets/CoolapeFrame/Editor/Utl/XLuaIDEAapiMaker.cs
Normal file
500
Assets/CoolapeFrame/Editor/Utl/XLuaIDEAapiMaker.cs
Normal file
@@ -0,0 +1,500 @@
|
||||
|
||||
/*
|
||||
|
||||
changed from HaYaShi ToShiTaKa
|
||||
|
||||
*/
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using XLua;
|
||||
using System.Linq;
|
||||
|
||||
static public class XLuaIDEAapiMaker
|
||||
{
|
||||
#region member
|
||||
private static string m_apiDir = Path.Combine(Path.GetDirectoryName(Application.dataPath), "UnityAPI");
|
||||
|
||||
private static Dictionary<string, int> m_nameCounter = new Dictionary<string, int> ();
|
||||
|
||||
private static List<ConstructorInfo> m_constructs = new List<ConstructorInfo> ();
|
||||
private static List<MethodInfo> m_methods = new List<MethodInfo> ();
|
||||
private static List<PropertyInfo> m_propertys = new List<PropertyInfo> ();
|
||||
private static List<FieldInfo> m_fields = new List<FieldInfo> ();
|
||||
private static string m_argsText;
|
||||
|
||||
public static bool IsMemberFilter (MemberInfo mi)
|
||||
{
|
||||
return false;
|
||||
// return ToLuaExport.memberFilter.Contains(mi.ReflectedType.Name + "." + mi.Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取类型的文件名
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
static string GetTypeFileName (Type type)
|
||||
{
|
||||
return type.ToString ().Replace ("+", ".").Replace (".", "").Replace ("`", "").Replace ("&", "").Replace ("[", "").Replace ("]", "").Replace (",", "");
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取类型标签名
|
||||
// /// </summary>
|
||||
// /// <param name="type"></param>
|
||||
// /// <returns></returns>
|
||||
static string GetTypeTagName (Type type)
|
||||
{
|
||||
return type.ToString ().Replace ("+", ".").Replace ("`", "").Replace ("&", "").Replace ("[", "").Replace ("]", "").Replace (",", "");
|
||||
}
|
||||
|
||||
#region export api
|
||||
|
||||
[MenuItem ("XLua/IDEA生成自动提示的文件")]
|
||||
public static void ExportLuaApi ()
|
||||
{
|
||||
List<Type> classList = new List<Type> ();
|
||||
|
||||
IEnumerable<FieldInfo> LuaCallCSharps = (from type in XLua.Utils.GetAllTypes ()
|
||||
from method in type.GetFields (BindingFlags.Static | BindingFlags.Public)
|
||||
where method.IsDefined (typeof(LuaCallCSharpAttribute), false)
|
||||
select method);
|
||||
|
||||
|
||||
|
||||
// object[] ccla = test.GetCustomAttributes(typeof(LuaCallCSharpAttribute), false);
|
||||
// if (ccla.Length == 1 && (((ccla[0] as LuaCallCSharpAttribute).Flag & GenFlag.GCOptimize) != 0))
|
||||
// {
|
||||
// AddToList(GCOptimizeList, get_cfg);
|
||||
// }
|
||||
foreach (var memeber in LuaCallCSharps) {
|
||||
object LuaCallCSharpList = memeber.GetValue (null);
|
||||
if (LuaCallCSharpList is IEnumerable<Type>) {
|
||||
classList.AddRange (LuaCallCSharpList as IEnumerable<Type>);
|
||||
}
|
||||
}
|
||||
|
||||
// return;
|
||||
// classList = XluaGenCodeConfig.LuaCallCSharp;
|
||||
|
||||
// Dictionary<Type, ToLuaMenu.BindType> s_apiTypeIdx = new Dictionary<Type, ToLuaMenu.BindType>();
|
||||
// //收集要生成的类
|
||||
// List<ToLuaMenu.BindType> btList = new List<ToLuaMenu.BindType>();
|
||||
// ToLuaExport.allTypes.Clear();
|
||||
// ToLuaExport.allTypes.AddRange(ToLuaMenu.baseType);
|
||||
// ToLuaExport.allTypes.AddRange(CustomSettings.staticClassTypes);
|
||||
// for (int i = 0; i < ToLuaExport.allTypes.Count; i++)
|
||||
// {
|
||||
// btList.Add(new ToLuaMenu.BindType(ToLuaExport.allTypes[i]));
|
||||
// }
|
||||
// foreach(var bt in CustomSettings.customTypeList)
|
||||
// {
|
||||
// if (ToLuaExport.allTypes.Contains(bt.type)) continue;
|
||||
// ToLuaExport.allTypes.Add(bt.type);
|
||||
// btList.Add(bt);
|
||||
// }
|
||||
// ToLuaMenu.BindType[] allTypes = GenBindTypes(btList.ToArray(), false);
|
||||
// foreach(var bt in allTypes)//做最后的检查,进一步排除一些类
|
||||
// {
|
||||
// if (bt.type.IsInterface && bt.type != typeof(System.Collections.IEnumerator))
|
||||
// continue;
|
||||
// s_apiTypeIdx[bt.type] = bt;
|
||||
// if (classList.Contains (bt.type)) {
|
||||
// Debug.LogWarning ("type:"+bt.type.FullName+" has add");
|
||||
// } else {
|
||||
//
|
||||
// classList.Add (bt.type);
|
||||
// }
|
||||
// }
|
||||
|
||||
//一些类需要手动加
|
||||
// {
|
||||
// ToLuaMenu.BindType bt = new ToLuaMenu.BindType(typeof(Array));
|
||||
// s_apiTypeIdx[bt.type] = bt;
|
||||
// GetClassApi("System.Collections.IEnumerable").AddMethod("GetEnumerator", "()", "System.Collections.IEnumerator", "System.Collections.IEnumerator");
|
||||
// }
|
||||
|
||||
string unityAPI = "";
|
||||
// add class here
|
||||
BindingFlags bindType = BindingFlags.DeclaredOnly |
|
||||
BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public;
|
||||
MethodInfo[] methods;
|
||||
FieldInfo[] fields;
|
||||
PropertyInfo[] properties;
|
||||
List<ConstructorInfo> constructors;
|
||||
ParameterInfo[] paramInfos;
|
||||
int delta;
|
||||
string path = m_apiDir;
|
||||
if (path == "") {
|
||||
return;
|
||||
}
|
||||
if (Directory.Exists (path)) {
|
||||
Directory.Delete (path, true);
|
||||
}
|
||||
Directory.CreateDirectory (path);
|
||||
|
||||
foreach (Type t in classList) {
|
||||
FileStream fs = new FileStream (path + "/" + t.FullName.Replace ('.', '_') + "Wrap.lua", FileMode.Create);
|
||||
var utf8WithoutBom = new System.Text.UTF8Encoding (false);
|
||||
StreamWriter sw = new StreamWriter (fs, utf8WithoutBom);
|
||||
|
||||
if (t.BaseType != null && t.BaseType != typeof(object)) {
|
||||
sw.WriteLine (string.Format ("---@class {0} : {1}", t.FullName, t.BaseType.FullName));
|
||||
} else {
|
||||
sw.WriteLine (string.Format ("---@class {0}", t.FullName));
|
||||
}
|
||||
|
||||
|
||||
#region field
|
||||
fields = t.GetFields (bindType);
|
||||
foreach (var field in fields) {
|
||||
if (IsObsolete (field)) {
|
||||
continue;
|
||||
}
|
||||
WriteField (sw, GetTypeTagName (field.FieldType), field.Name);
|
||||
}
|
||||
|
||||
properties = t.GetProperties (bindType);
|
||||
foreach (var property in properties) {
|
||||
if (IsObsolete (property)) {
|
||||
continue;
|
||||
}
|
||||
WriteField (sw, GetTypeTagName (property.PropertyType), property.Name);
|
||||
}
|
||||
|
||||
//sw.Write ("\n");
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
constructors = new List<ConstructorInfo> (t.GetConstructors (bindType));
|
||||
constructors.Sort ((left, right) => {
|
||||
return left.GetParameters ().Length - right.GetParameters ().Length;
|
||||
});
|
||||
bool isDefineTable = false;
|
||||
if (constructors.Count > 0) {
|
||||
sw.WriteLine ("local m = { }");
|
||||
WriteCtorComment (sw, constructors);
|
||||
paramInfos = constructors [constructors.Count - 1].GetParameters ();
|
||||
delta = paramInfos.Length - constructors [0].GetParameters ().Length;
|
||||
if (constructors [0].IsPublic) {
|
||||
WriteFun (sw, paramInfos, delta, t, "New", true);
|
||||
}
|
||||
isDefineTable = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region method
|
||||
methods = t.GetMethods (bindType);
|
||||
MethodInfo method;
|
||||
|
||||
Dictionary<string, List<MethodInfo>> methodDict = new Dictionary<string, List<MethodInfo>> ();
|
||||
if (methods.Length != 0 && !isDefineTable) {
|
||||
sw.WriteLine ("local m = { }");
|
||||
}
|
||||
|
||||
for (int i = 0; i < methods.Length; i++) {
|
||||
method = methods [i];
|
||||
string methodName = method.Name;
|
||||
if (IsObsolete (method)) {
|
||||
continue;
|
||||
}
|
||||
if (method.IsGenericMethod) {
|
||||
continue;
|
||||
}
|
||||
if (!method.IsPublic)
|
||||
continue;
|
||||
if (methodName.StartsWith ("get_") || methodName.StartsWith ("set_"))
|
||||
continue;
|
||||
|
||||
List<MethodInfo> list;
|
||||
if (!methodDict.TryGetValue (methodName, out list)) {
|
||||
list = new List<MethodInfo> ();
|
||||
methodDict.Add (methodName, list);
|
||||
}
|
||||
list.Add (method);
|
||||
}
|
||||
|
||||
var itr = methodDict.GetEnumerator ();
|
||||
while (itr.MoveNext ()) {
|
||||
List<MethodInfo> list = itr.Current.Value;
|
||||
// RemoveRewriteFunHasTypeAndString(list);
|
||||
list.Sort ((left, right) => {
|
||||
return left.GetParameters ().Length - right.GetParameters ().Length;
|
||||
});
|
||||
WriteFunComment (sw, list);
|
||||
paramInfos = list [list.Count - 1].GetParameters ();
|
||||
delta = paramInfos.Length - list [0].GetParameters ().Length;
|
||||
|
||||
WriteFun (sw, paramInfos, delta, list [0].ReturnType, list [0].Name, list [0].IsStatic);
|
||||
}
|
||||
itr.Dispose ();
|
||||
|
||||
if (methods.Length != 0 || isDefineTable) {
|
||||
sw.WriteLine (t.FullName + " = m");
|
||||
if (t.FullName.Contains (".")) {
|
||||
unityAPI += t.FullName.Replace ('.', '_') + " = " + t.FullName + "\r\n";
|
||||
}
|
||||
sw.WriteLine ("return m");
|
||||
}
|
||||
#endregion
|
||||
|
||||
//清空缓冲区
|
||||
sw.Flush ();
|
||||
//关闭流
|
||||
sw.Close ();
|
||||
fs.Close ();
|
||||
}
|
||||
|
||||
File.WriteAllText (path + "/unity_api.lua", unityAPI);
|
||||
if (Directory.Exists (Application.dataPath + "/lua/")) {
|
||||
File.WriteAllText (Application.dataPath + "/lua/" + "/unity_api.lua", unityAPI);
|
||||
}
|
||||
|
||||
Debug.Log ("转换完成");
|
||||
}
|
||||
|
||||
public static bool IsObsolete (MemberInfo mb)
|
||||
{
|
||||
object[] attrs = mb.GetCustomAttributes (true);
|
||||
|
||||
for (int j = 0; j < attrs.Length; j++) {
|
||||
Type t = attrs [j].GetType ();
|
||||
|
||||
if (t == typeof(System.ObsoleteAttribute)) { // || t.ToString() == "UnityEngine.WrapperlessIcall")
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsMemberFilter (mb)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void WriteField (StreamWriter sw, string returnType, string fieldName)
|
||||
{
|
||||
sw.WriteLine (string.Format ("---@field public {0} {1}", fieldName, returnType));
|
||||
}
|
||||
|
||||
static void WriteFunComment (StreamWriter sw, List<MethodInfo> list)
|
||||
{
|
||||
for (int i = 0, imax = list.Count; i < imax; i++) {
|
||||
WriteOneComment (sw, list [i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteCtorComment (StreamWriter sw, List<ConstructorInfo> list)
|
||||
{
|
||||
for (int i = 0, imax = list.Count; i < imax; i++) {
|
||||
WriteOneComment (sw, list [i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteOneComment (StreamWriter sw, MethodBase method)
|
||||
{
|
||||
ParameterInfo[] paramInfos;
|
||||
string argsStr = "";
|
||||
paramInfos = method.GetParameters ();
|
||||
for (int i = 0, imax = paramInfos.Length; i < imax; i++) {
|
||||
if (i != 0) {
|
||||
argsStr += ", ";
|
||||
}
|
||||
argsStr += paramInfos [i].ParameterType.Name + " " + RepalceLuaKeyWord (paramInfos [i].Name);
|
||||
// sw.WriteLine ("---@param " + paramInfos [i].ParameterType.Name + " " + RepalceLuaKeyWord (paramInfos [i].Name));
|
||||
}
|
||||
if (method is MethodInfo) {
|
||||
sw.WriteLine ("---public {0} {1}({2})", ((MethodInfo)method).ReturnType.Name, method.Name, argsStr);
|
||||
} else if (method is ConstructorInfo) {
|
||||
sw.WriteLine ("---public {0} {1}({2})", method.ReflectedType.Name, method.Name, argsStr);
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteFun (StreamWriter sw, ParameterInfo[] paramInfos, int delta, Type methodReturnType, string methodName, bool isStatic)
|
||||
{
|
||||
string typeStr = ConvertToLuaType (methodReturnType);
|
||||
if (methodReturnType != typeof(void)) {
|
||||
sw.WriteLine (string.Format ("---@return {0}", typeStr));
|
||||
}
|
||||
|
||||
string argsStr = "";
|
||||
for (int i = 0, imax = paramInfos.Length; i < imax; i++) {
|
||||
if (i != 0) {
|
||||
argsStr += ", ";
|
||||
}
|
||||
// argsStr += RepalceLuaKeyWord(paramInfos[i].Name);
|
||||
argsStr += paramInfos [i].Name;
|
||||
if (i < delta) {
|
||||
sw.WriteLine ("---@param " + paramInfos [i].ParameterType.Name + " " + RepalceLuaKeyWord (paramInfos [i].Name));
|
||||
} else {
|
||||
sw.WriteLine ("---@param optional " + paramInfos [i].ParameterType.Name + " " + RepalceLuaKeyWord (paramInfos [i].Name));
|
||||
}
|
||||
}
|
||||
// for (int i = 1, imax = delta; i <= imax; i++) {
|
||||
// int index = paramInfos.Length - 1 - delta + i;
|
||||
// sw.WriteLine(string.Format("---@param optional {0} {1}", RepalceLuaKeyWord(paramInfos[index].Name), ConvertToLuaType(paramInfos[index].ParameterType)));
|
||||
// }
|
||||
if (isStatic) {
|
||||
sw.WriteLine (string.Format ("function m.{0}({1}) end", methodName, argsStr));
|
||||
} else {
|
||||
sw.WriteLine (string.Format ("function m:{0}({1}) end", methodName, argsStr));
|
||||
}
|
||||
}
|
||||
|
||||
static string ConvertToLuaType (Type methodReturnType)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
if (methodReturnType != typeof(void)) {
|
||||
|
||||
if (methodReturnType == typeof(bool)) {
|
||||
result = "bool";
|
||||
} else if (methodReturnType == typeof(long) || methodReturnType == typeof(ulong)) {
|
||||
result = "long";
|
||||
} else if (methodReturnType.IsPrimitive || methodReturnType.IsEnum) {
|
||||
result = "number";
|
||||
} else if (methodReturnType == typeof(LuaFunction)) {
|
||||
result = "function";
|
||||
} else if (methodReturnType == typeof(Type)) {
|
||||
result = "string";
|
||||
} else if (methodReturnType.IsArray) {
|
||||
result = "table";
|
||||
} else if (methodReturnType.IsGenericType
|
||||
&& methodReturnType.GetGenericTypeDefinition () == typeof(IDictionary<,>)) {
|
||||
result = "table";
|
||||
}
|
||||
// else if (methodReturnType.IsGenericType && methodReturnType.IsSubclassOf(typeof(LuaValueBase))) {
|
||||
// result = "table";
|
||||
// }
|
||||
else {
|
||||
result = methodReturnType.Name;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static string RepalceLuaKeyWord (string name)
|
||||
{
|
||||
if (name == "table") {
|
||||
name = "tb";
|
||||
} else if (name == "function") {
|
||||
name = "func";
|
||||
} else if (name == "type") {
|
||||
name = "t";
|
||||
} else if (name == "end") {
|
||||
name = "ed";
|
||||
} else if (name == "local") {
|
||||
name = "loc";
|
||||
} else if (name == "and") {
|
||||
name = "ad";
|
||||
} else if (name == "or") {
|
||||
name = "orz";
|
||||
} else if (name == "not") {
|
||||
name = "no";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//
|
||||
// static List<ToLuaMenu.BindType> allTypes;
|
||||
// static ToLuaMenu.BindType[] GenBindTypes(ToLuaMenu.BindType[] list, bool beDropBaseType = true)
|
||||
// {
|
||||
// allTypes = new List<ToLuaMenu.BindType>(list);
|
||||
//
|
||||
// for (int i = 0; i < list.Length; i++)
|
||||
// {
|
||||
// for (int j = i + 1; j < list.Length; j++)
|
||||
// {
|
||||
// if (list[i].type == list[j].type)
|
||||
// throw new NotSupportedException("Repeat BindType:" + list[i].type);
|
||||
// }
|
||||
//
|
||||
// if (ToLuaMenu.dropType.IndexOf(list[i].type) >= 0)
|
||||
// {
|
||||
// Debug.LogWarning(list[i].type.FullName + " in dropType table, not need to export");
|
||||
// allTypes.Remove(list[i]);
|
||||
// continue;
|
||||
// }
|
||||
// else if (beDropBaseType && ToLuaMenu.baseType.IndexOf(list[i].type) >= 0)
|
||||
// {
|
||||
// Debug.LogWarning(list[i].type.FullName + " is Base Type, not need to export");
|
||||
// allTypes.Remove(list[i]);
|
||||
// continue;
|
||||
// }
|
||||
// else if (list[i].type.IsEnum)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// AutoAddBaseType(list[i], beDropBaseType);
|
||||
// }
|
||||
//
|
||||
// return allTypes.ToArray();
|
||||
// }
|
||||
//
|
||||
// static void AutoAddBaseType(ToLuaMenu.BindType bt, bool beDropBaseType)
|
||||
// {
|
||||
// Type t = bt.baseType;
|
||||
//
|
||||
// if (t == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (t.IsInterface)
|
||||
// {
|
||||
// Debugger.LogWarning("{0} has a base type {1} is Interface, use SetBaseType to jump it", bt.name, t.FullName);
|
||||
// bt.baseType = t.BaseType;
|
||||
// }
|
||||
// else if (ToLuaMenu.dropType.IndexOf(t) >= 0)
|
||||
// {
|
||||
// Debugger.LogWarning("{0} has a base type {1} is a drop type", bt.name, t.FullName);
|
||||
// bt.baseType = t.BaseType;
|
||||
// }
|
||||
// else if (!beDropBaseType || ToLuaMenu.baseType.IndexOf(t) < 0)
|
||||
// {
|
||||
// int index = allTypes.FindIndex((iter) => { return iter.type == t; });
|
||||
//
|
||||
// if (index < 0)
|
||||
// {
|
||||
// #if JUMP_NODEFINED_ABSTRACT
|
||||
// if (t.IsAbstract && !t.IsSealed)
|
||||
// {
|
||||
// Debugger.LogWarning("not defined bindtype for {0}, it is abstract class, jump it, child class is {1}", t.FullName, bt.name);
|
||||
// bt.baseType = t.BaseType;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debugger.LogWarning("not defined bindtype for {0}, autogen it, child class is {1}", t.FullName, bt.name);
|
||||
// bt = new BindType(t);
|
||||
// allTypes.Add(bt);
|
||||
// }
|
||||
// #else
|
||||
// Debugger.LogWarning("not defined bindtype for {0}, autogen it, child class is {1}", t.FullName, bt.name);
|
||||
// bt = new ToLuaMenu.BindType(t);
|
||||
// allTypes.Add(bt);
|
||||
// #endif
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// AutoAddBaseType(bt, beDropBaseType);
|
||||
// }
|
||||
}
|
||||
12
Assets/CoolapeFrame/Editor/Utl/XLuaIDEAapiMaker.cs.meta
Normal file
12
Assets/CoolapeFrame/Editor/Utl/XLuaIDEAapiMaker.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 670a53e2568c94fe98035a8db431b7e3
|
||||
timeCreated: 1504249430
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user