530 lines
20 KiB
C#
530 lines
20 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
using LitJson;
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
namespace DemoSpace
|
|
{
|
|
public class BuildAssetBundle
|
|
{
|
|
/// <summary>
|
|
/// 打包生成所有的AssetBundles包
|
|
/// </summary>
|
|
[MenuItem("AssetBundleTools/BuildAllAssestBundles _`")]
|
|
public static void BulidAllAB()
|
|
{
|
|
string strABpath = Path.Combine(Application.streamingAssetsPath, "AssetBundle");
|
|
if (!Directory.Exists(strABpath))
|
|
Directory.CreateDirectory(strABpath);
|
|
BuildPipeline.BuildAssetBundles(strABpath, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.WebGL);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ModelInfo
|
|
{
|
|
public int index = -1;
|
|
public string ModelName = null;//属性需要初始化
|
|
public string ABName = null;
|
|
public string ModelPath = null;
|
|
public string ABPath = null;
|
|
public string PrePath = null;
|
|
}
|
|
|
|
public class ModelNameInfo
|
|
{
|
|
public string ModelName = null;
|
|
}
|
|
|
|
public class ModelNameInfoRoot
|
|
{
|
|
public List<ModelNameInfo> ModelInfos = new List<ModelNameInfo>();//属性需要初始化
|
|
}
|
|
|
|
public class ModelInfoRoot
|
|
{
|
|
public List<ModelInfo> ModelInfos = new List<ModelInfo>();//属性需要初始化
|
|
}
|
|
|
|
public class MyEditor : Editor
|
|
{
|
|
[MenuItem("GameObject/MyTools/AddComponent", priority = 10)]
|
|
private static void NewMenuItem()
|
|
{
|
|
int value = 0;
|
|
if (Selection.gameObjects[0])
|
|
{
|
|
foreach (MeshRenderer item in Selection.gameObjects[0].GetComponentsInChildren<MeshRenderer>(true))
|
|
{
|
|
//item.gameObject.AddComponent<PoolItem>();
|
|
//item.gameObject.GetComponent<PoolItem>().index = value;
|
|
//item.gameObject.GetComponent<PoolItem>()._OriginalColor = item.gameObject.GetComponent<MeshRenderer>().sharedMaterial.color;
|
|
//if (item.GetComponent<ConstructionMember>())
|
|
//{
|
|
// item.gameObject.GetComponent<PoolItem>().boolSpecialShader = item.GetComponent<ConstructionMember>().boolSpecialShader;
|
|
// item.gameObject.GetComponent<PoolItem>().spanNo = item.GetComponent<ConstructionMember>().spanNo;
|
|
// item.gameObject.GetComponent<PoolItem>().supportAttribute = item.GetComponent<ConstructionMember>().SupportAttribute;
|
|
// item.gameObject.GetComponent<PoolItem>().attributeSelectLayers = item.GetComponent<ConstructionMember>().AttributeSelectLayers;
|
|
//}
|
|
value++;
|
|
}
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/MyTools/CheckModelComponet", priority = 10)]
|
|
public static void CheckModelComponet()
|
|
{
|
|
if (Selection.gameObjects[0])
|
|
{
|
|
foreach (MeshRenderer item in Selection.gameObjects[0].GetComponentsInChildren<MeshRenderer>(true))
|
|
{
|
|
//if (item.GetComponent<ConstructionMember>())
|
|
//{
|
|
// Debug.Log(item.name);
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/MyTools/RemoveConstruction", priority = 10)]
|
|
public static void RemoveConstruction()
|
|
{
|
|
if (Selection.gameObjects[0])
|
|
{
|
|
foreach (Transform item in Selection.gameObjects[0].GetComponentsInChildren<Transform>(true))
|
|
{
|
|
//if (item.GetComponent<ConstructionMember>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<ConstructionMember>());
|
|
//}
|
|
//if (item.GetComponent<RendererObj>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<RendererObj>());
|
|
//}
|
|
//if (item.GetComponent<GenerationToolScript_HF_DU>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<GenerationToolScript_HF_DU>());
|
|
//}
|
|
//if (item.GetComponent<GenerationToolScript_U>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<GenerationToolScript_U>());
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
[MenuItem("GameObject/MyTools/RemoveAll", priority = 10)]
|
|
public static void RemoveAll()
|
|
{
|
|
if (Selection.gameObjects[0])
|
|
{
|
|
foreach (LODGroup item in Selection.gameObjects[0].GetComponentsInChildren<LODGroup>(true))
|
|
{
|
|
//if (item.gameObject.GetComponent<ConstructionMember>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<ConstructionMember>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<BoxCollider>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<BoxCollider>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<MeshCollider>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<MeshCollider>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<MeshFilter>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<MeshFilter>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<RendererObj>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<RendererObj>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<GenerationToolScript_HF_DU>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<GenerationToolScript_HF_DU>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<GenerationToolScript_U>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<GenerationToolScript_U>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<MeshRenderer>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<MeshRenderer>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<TransData>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<TransData>());
|
|
//}
|
|
//if (item.transform.Find("model"))
|
|
//{
|
|
// DestroyImmediate(item.transform.Find("model").gameObject);
|
|
//}
|
|
//if (item.transform.Find("empty"))
|
|
//{
|
|
// DestroyImmediate(item.transform.Find("empty").gameObject);
|
|
//}
|
|
//if (item.gameObject.GetComponent<PoolItem>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<PoolItem>());
|
|
//}
|
|
//if (item.gameObject.GetComponent<LODGroup>())
|
|
//{
|
|
// DestroyImmediate(item.gameObject.GetComponent<LODGroup>());
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
//[MenuItem("GameObject/MyTools/CheckModelTran", priority = 10)]
|
|
//public static void CheckModelTran()
|
|
//{
|
|
// if (Selection.gameObjects[0])
|
|
// {
|
|
// foreach (MeshRenderer item in Selection.gameObjects[0].GetComponentsInChildren<MeshRenderer>(true))
|
|
// {
|
|
// if (item.transform.localPosition != Vector3.zero)
|
|
// {
|
|
// //DestroyImmediate(item.gameObject.GetComponent<ConstructionMember>());
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
//[MenuItem("GameObject/MyTools/CreatePrefabs", priority = 10)]
|
|
//public static void CreatePrefabs()
|
|
//{
|
|
// Transform tParent = ((GameObject)Selection.activeObject).transform;
|
|
|
|
// object tempPrefab;
|
|
// int i = 0;
|
|
// foreach (Transform t in tParent)
|
|
// {
|
|
// string path = "Assets/Resources/Prefab/01/prefab" + i;
|
|
|
|
// if (!Directory.Exists(path))
|
|
// Directory.CreateDirectory(path);
|
|
|
|
// string fullPath = string.Format("{0}/{1}.prefab", path, t.name);
|
|
|
|
// bool savePrefabResult;
|
|
// PrefabUtility.SaveAsPrefabAsset(t.gameObject, fullPath, out savePrefabResult);
|
|
|
|
// //GameObject.DestroyImmediate(t.gameObject);
|
|
|
|
// AssetDatabase.SaveAssets();
|
|
// AssetDatabase.Refresh();
|
|
|
|
// if (!savePrefabResult)
|
|
// Debug.LogError("保存失败 : " + fullPath);
|
|
|
|
|
|
// //tempPrefab = PrefabUtility.CreateEmptyPrefab("Assets/Prefab/prefab" + i + ".prefab");
|
|
// //tempPrefab = PrefabUtility.ReplacePrefab(t.gameObject, tempPrefab);
|
|
|
|
// i++;
|
|
// }
|
|
// AssetDatabase.Refresh();
|
|
//}
|
|
|
|
[MenuItem("GameObject/MyTools/SaveJsonData", false, 10)]
|
|
static void SaveData()
|
|
{
|
|
//GameObject obj = new GameObject("ItemA");//创建新物体
|
|
//GameObjectUtility.SetParentAndAlign(obj, menuCommand.context as GameObject);//设置父节点为当前选中物体
|
|
//Undo.RegisterCreatedObjectUndo(obj, "Create" + obj.name);//注册到Undo系统,允许撤销
|
|
//Selection.activeObject = obj;//将新建物体设为当前选中物体
|
|
Transform tParent = ((GameObject)Selection.activeObject).transform;
|
|
object tempPrefab;
|
|
|
|
ModelInfoRoot modelInfoRoot = new ModelInfoRoot();
|
|
foreach (MeshRenderer item in tParent.GetComponentsInChildren<MeshRenderer>(true))
|
|
{
|
|
ModelInfo info = new ModelInfo();
|
|
info.ModelName = item.transform.name;
|
|
info.ABName = item.transform.name;
|
|
modelInfoRoot.ModelInfos.Add(info);
|
|
}
|
|
|
|
var vbasePath = Path.Combine(Application.streamingAssetsPath, "ObjData");
|
|
DirectoryInfo dir = new DirectoryInfo(vbasePath);
|
|
if (!dir.Exists)
|
|
dir.Create();
|
|
var vconfigPath = Path.Combine(vbasePath, "ModelInfo.json");
|
|
FileInfo fileInfo = new FileInfo(vconfigPath);
|
|
if (fileInfo.Exists)
|
|
fileInfo.Delete();
|
|
StreamWriter writer = fileInfo.CreateText();
|
|
string jsonStr = ParseJsonData(JsonMapper.ToJson(modelInfoRoot));
|
|
writer.Write(jsonStr);
|
|
writer.Flush();
|
|
writer.Dispose();
|
|
writer.Close();
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
public static string ParseJsonData(string json)
|
|
{
|
|
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
|
|
string targetJson = reg.Replace(json, delegate (Match m) { return ((char)System.Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });
|
|
return targetJson;
|
|
}
|
|
|
|
static List<string> m_listPath = new List<string>();
|
|
|
|
public static string GetPath(Transform target)
|
|
{
|
|
string path = string.Empty;
|
|
Transform tran = target;
|
|
while (tran.parent != null)
|
|
{
|
|
tran = tran.parent;
|
|
if (path == string.Empty)
|
|
path = tran.name;
|
|
else
|
|
path = tran.name + "/" + path;
|
|
}
|
|
return path;
|
|
}
|
|
|
|
public static string GetChildPath(Transform trans, string childName)
|
|
{
|
|
m_listPath.Clear();
|
|
FindChildGameObject(trans.gameObject, childName);
|
|
string path = "";
|
|
for (int i = 1; i < m_listPath.Count; i++)
|
|
{
|
|
path += m_listPath[i];
|
|
if (i != m_listPath.Count - 1)
|
|
path += "/";
|
|
}
|
|
return path;
|
|
}
|
|
|
|
|
|
public static GameObject FindChildGameObject(GameObject parent, string childName)
|
|
{
|
|
m_listPath.Add(parent.name);
|
|
if (parent.name == childName)
|
|
{
|
|
|
|
return parent;
|
|
}
|
|
if (parent.transform.childCount < 1)
|
|
{
|
|
return null;
|
|
}
|
|
GameObject obj = null;
|
|
for (int i = 0; i < parent.transform.childCount; i++)
|
|
{
|
|
GameObject go = parent.transform.GetChild(i).gameObject;
|
|
obj = FindChildGameObject(go, childName);
|
|
if (obj != null)
|
|
{
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
|
|
|
|
|
|
[MenuItem("GameObject/MyTools/CreatTrans", false, 10)]
|
|
static void CreatTrans()
|
|
{
|
|
foreach (Transform item in Selection.activeTransform.GetComponentsInChildren<Transform>(true))
|
|
{
|
|
for (int i = -11; i < 17; i++)
|
|
{
|
|
GameObject g = new GameObject();
|
|
g.transform.parent = Selection.gameObjects[0].transform;
|
|
g.name = (i * 4).ToString() + "_Up";
|
|
g.transform.localPosition = new Vector3(i * 4, -0.65f, 0.8f);
|
|
g.transform.localEulerAngles = Vector3.zero;
|
|
g.transform.localScale = Vector3.one;
|
|
//g.AddComponent<CameraDisControl>();
|
|
|
|
GameObject g1 = new GameObject();
|
|
g1.transform.parent = Selection.gameObjects[0].transform;
|
|
g1.name = (i * 4).ToString() + "_Down";
|
|
g1.transform.localPosition = new Vector3(i * 4, -0.65f, -0.8f);
|
|
g1.transform.localEulerAngles = Vector3.zero;
|
|
g1.transform.localScale = Vector3.one;
|
|
//g1.AddComponent<CameraDisControl>();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[MenuItem("GameObject/MyTools/CalObjCount", false, 10)]
|
|
static void CalObjCount()
|
|
{
|
|
int value = 0;
|
|
for (int i = 0; i < Selection.gameObjects[0].transform.childCount; i++)
|
|
{
|
|
//int x = Selection.gameObjects[0].transform.GetComponent<CameraDisControl>().oprateObjs.Count;
|
|
//value += x;
|
|
}
|
|
|
|
Debug.Log(value);
|
|
}
|
|
|
|
[MenuItem("GameObject/MyTools/ClearABNames", false, 10)]
|
|
static void ClearABNames()
|
|
{
|
|
AssetDatabase.RemoveUnusedAssetBundleNames();
|
|
}
|
|
|
|
|
|
|
|
//[MenuItem("GameObject/MyTools/AddLODComponent", false, 10)]
|
|
//static void AddLODComponent()
|
|
//{
|
|
// if (Selection.gameObjects[0])
|
|
// {
|
|
// foreach (MeshRenderer item in Selection.gameObjects[0].GetComponentsInChildren<MeshRenderer>(true))
|
|
// {
|
|
// //item.isChildRender = true;
|
|
// //Vector3 pos = item.transform.localPosition;
|
|
// //Vector3 rot = item.transform.localEulerAngles;
|
|
// //Vector3 sca = item.transform.localScale;
|
|
|
|
// //GameObject temp1 = new GameObject();
|
|
// //temp1.name = item.name;
|
|
// //temp1.transform.parent = item.transform.parent;
|
|
// //temp1.transform.localPosition = Vector3.zero;
|
|
// //temp1.transform.localEulerAngles = Vector3.zero;
|
|
// //temp1.transform.localScale = Vector3.one;
|
|
|
|
// //item.transform.parent = temp1.transform;
|
|
// //item.name = "model";
|
|
// //item.transform.localPosition = pos;
|
|
// //item.transform.localEulerAngles = rot;
|
|
// //item.transform.localScale = sca;
|
|
|
|
|
|
// //UnityEditorInternal.ComponentUtility.CopyComponent(item);
|
|
// //UnityEditorInternal.ComponentUtility.PasteComponentAsNew(temp1);
|
|
|
|
// //temp1.AddComponent<LODGroup>();
|
|
|
|
// //GameObject temp2 = new GameObject();
|
|
// //temp2.name = "empty";
|
|
// //temp2.transform.parent = item.transform.parent;
|
|
// //temp2.transform.localPosition = Vector3.zero;
|
|
// //temp2.transform.localEulerAngles = Vector3.zero;
|
|
// //temp2.transform.localScale = Vector3.one;
|
|
|
|
// //MeshRenderer[] renders = new MeshRenderer[1];
|
|
// //renders[0] = item.gameObject.GetComponent<MeshRenderer>();
|
|
// //LOD[] lods = new LOD[2];
|
|
// //lods[0] = new LOD(0.3f, renders);
|
|
// //lods[1] = new LOD(0.1f, null);
|
|
// //temp1.GetComponent<LODGroup>().SetLODs(lods);
|
|
// //temp1.GetComponent<LODGroup>().RecalculateBounds();
|
|
|
|
// //DestroyImmediate(item.gameObject.GetComponent<PoolItem>());
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
[MenuItem("GameObject/MyTools/SaveModelNameJson", false, 10)]
|
|
static void SaveModelNameJson()
|
|
{
|
|
//GameObject obj = new GameObject("ItemA");//创建新物体
|
|
//GameObjectUtility.SetParentAndAlign(obj, menuCommand.context as GameObject);//设置父节点为当前选中物体
|
|
//Undo.RegisterCreatedObjectUndo(obj, "Create" + obj.name);//注册到Undo系统,允许撤销
|
|
//Selection.activeObject = obj;//将新建物体设为当前选中物体
|
|
Transform tParent = ((GameObject)Selection.activeObject).transform;
|
|
object tempPrefab;
|
|
int i = 0;
|
|
|
|
ModelNameInfoRoot modelInfoRoot = new ModelNameInfoRoot();
|
|
foreach (MeshRenderer item in tParent.GetComponentsInChildren<MeshRenderer>(true))
|
|
{
|
|
ModelNameInfo info = new ModelNameInfo();
|
|
info.ModelName = item.transform.name;
|
|
modelInfoRoot.ModelInfos.Add(info);
|
|
AssetDatabase.SaveAssets();
|
|
i++;
|
|
}
|
|
Debug.Log(i);
|
|
var vbasePath = Path.Combine(Application.streamingAssetsPath, "ObjData");
|
|
DirectoryInfo dir = new DirectoryInfo(vbasePath);
|
|
if (!dir.Exists)
|
|
dir.Create();
|
|
var vconfigPath = Path.Combine(vbasePath, "ModelInfo.json");
|
|
FileInfo fileInfo = new FileInfo(vconfigPath);
|
|
if (fileInfo.Exists)
|
|
fileInfo.Delete();
|
|
StreamWriter writer = fileInfo.CreateText();
|
|
string jsonStr = ParseJsonData(JsonMapper.ToJson(modelInfoRoot));
|
|
writer.Write(jsonStr);
|
|
writer.Flush();
|
|
writer.Dispose();
|
|
writer.Close();
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
|
|
[MenuItem("GameObject/MyTools/CreateModel", false, 10)]
|
|
static void CreateModel()
|
|
{
|
|
foreach (MeshRenderer item in Selection.gameObjects[0].transform.GetComponentsInChildren<MeshRenderer>(true))
|
|
{
|
|
if (item.name == "编号牌")
|
|
{
|
|
string index = item.transform.parent.parent.name[2].ToString();
|
|
|
|
GameObject right = new GameObject();
|
|
GameObject wrong = new GameObject();
|
|
|
|
string[] names = new string[] { "敏行", "敏学", "敏知", "敏慧", "毓秀" };
|
|
List<GameObject> tempList = new List<GameObject>();
|
|
for (int i = 0; i < names.Length; i++)
|
|
{
|
|
GameObject temp = Instantiate(item.gameObject);
|
|
tempList.Add(temp);
|
|
}
|
|
|
|
right.name = "正确";
|
|
right.transform.SetParent(item.transform);
|
|
right.transform.localEulerAngles = Vector3.zero;
|
|
right.transform.localPosition = Vector3.zero;
|
|
right.transform.localScale = Vector3.one;
|
|
|
|
wrong.name = "错误";
|
|
wrong.transform.SetParent(item.transform);
|
|
wrong.transform.localEulerAngles = Vector3.zero;
|
|
wrong.transform.localPosition = Vector3.zero;
|
|
wrong.transform.localScale = Vector3.one;
|
|
|
|
|
|
for (int i = 0; i < tempList.Count; i++)
|
|
{
|
|
tempList[i].transform.SetParent(right.transform);
|
|
tempList[i].name = names[i];
|
|
tempList[i].transform.localEulerAngles = Vector3.zero;
|
|
tempList[i].transform.localPosition = Vector3.zero;
|
|
tempList[i].transform.localScale = Vector3.one;
|
|
tempList[i].GetComponent<MeshRenderer>().material = Findmat("Assets/Arts/Mat/电线杆/编号牌/" + names[i] + "/" + names[i] + "低压/" + index + ".mat");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Material Findmat(string path)
|
|
{
|
|
Material mat = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material));
|
|
return mat;
|
|
}
|
|
} |