459 lines
13 KiB
C#
459 lines
13 KiB
C#
using AutoMapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TOOL : MonoBehaviour
|
|
{
|
|
|
|
public List<GameObject> gameObjects;
|
|
public List<Transform> Uwei;
|
|
public GameObject prefab;
|
|
|
|
public string port;
|
|
public string deviceId;
|
|
public string conDevice;
|
|
public string conPort;
|
|
|
|
public Transform UI_follow;
|
|
|
|
public RedactDevice redactDevice;
|
|
|
|
public TMP_FontAsset f_old;
|
|
public TMP_FontAsset f_new;
|
|
public Font font_old;
|
|
public Font font_new;
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnDropdownValueChanged_port(int arg0)
|
|
{
|
|
Debug.Log("索引改变为" + arg0);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
[ContextMenu("重命名")]
|
|
public void reName()
|
|
{
|
|
if (gameObjects.Count == 0 && gameObjects == null) return;
|
|
for (int i = 0; i < gameObjects.Count; i++)
|
|
{
|
|
var deviceQuery = gameObjects[i].GetComponent<DeviceQuery>();
|
|
|
|
int a = int.Parse(gameObjects[i].name.Split('R')[1]);
|
|
string b = "";
|
|
if (a <= 8) { b = "I-"; }
|
|
else if (a <= 16) { b = "H-"; }
|
|
else if (a <= 24) { b = "G-"; }
|
|
else if (a <= 32) { b = "F-"; }
|
|
else if (a <= 40) { b = "E-"; }
|
|
else if (a <= 48) { b = "D-"; }
|
|
else if (a <= 56) { b = "C-"; }
|
|
else if (a <= 64) { b = "B-"; }
|
|
else if (a <= 72) { b = "A-"; }
|
|
|
|
var nub = (a % 8).ToString().PadLeft(2, '0');
|
|
if (nub == "00") nub = "08";
|
|
var devicePosition = b + nub;
|
|
if (deviceQuery == null)
|
|
{
|
|
var D = gameObjects[i].AddComponent<DeviceQuery>();
|
|
D.deviceList.deviceCode = "";
|
|
D.deviceList.devicePosition = devicePosition;
|
|
D.deviceList.type = "1";
|
|
}
|
|
else
|
|
{
|
|
deviceQuery.deviceList.deviceCode = "";
|
|
deviceQuery.deviceList.devicePosition = devicePosition;
|
|
deviceQuery.deviceList.type = "1";
|
|
}
|
|
continue;
|
|
var U = gameObjects[i].transform.Find("U位");
|
|
if (U == null)
|
|
{
|
|
//var go = new GameObject("U位");
|
|
//go.transform.SetParent(gameObjects[i].transform);
|
|
//for (int j = 0; j < 42; j++)
|
|
//{
|
|
// var g = new GameObject((j + 1).ToString());
|
|
// g.transform.SetParent(go.transform);
|
|
//}
|
|
var go = GameObject.Instantiate(Resources.Load<GameObject>("机柜/U位")).transform;
|
|
go.position = gameObjects[i].transform.position;
|
|
go.SetParent(gameObjects[i].transform);
|
|
go.name = "U位";
|
|
}
|
|
else
|
|
{
|
|
DestroyImmediate(U.gameObject);
|
|
|
|
//if (U.transform.childCount != 42)
|
|
//{
|
|
// for (int j = 0; j < 42; j++)
|
|
// {
|
|
// var g = new GameObject((j + 1).ToString());
|
|
// g.transform.SetParent(U.transform);
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
[ContextMenu("寻找物体组")]
|
|
public void das()
|
|
{
|
|
GameManager.Inst.FindPortPos();
|
|
}
|
|
|
|
|
|
[ContextMenu("U位修改")]
|
|
public void us()
|
|
{
|
|
List<Transform> ts = new List<Transform>();
|
|
//for (int i = 0; i < transform.childCount; i++)
|
|
//{
|
|
// ts.Add(transform.GetChild(i).transform);
|
|
//}
|
|
//ts.Reverse();
|
|
//for (int i = 0; i < ts.Count; i++)
|
|
//{
|
|
// ts[i].name = (i + 1).ToString();
|
|
//}
|
|
//ts.Reverse();
|
|
|
|
|
|
for (int i = 0; i < Uwei.Count; i++)
|
|
{
|
|
ts.Clear();
|
|
for (int j = 0; j < Uwei[i].childCount; j++)
|
|
{
|
|
ts.Add(Uwei[i].GetChild(j).transform);
|
|
}
|
|
ts.Reverse();
|
|
for (int k = 0; k < ts.Count; k++)
|
|
{
|
|
ts[k].name = (k + 1).ToString();
|
|
}
|
|
SortChildrenByName(ts);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据数字编号排序
|
|
/// </summary>
|
|
[ContextMenu("根据数字编号排序")]
|
|
void SortChildrenByName(List<Transform> children)
|
|
{
|
|
//List<Transform> children = new List<Transform>();
|
|
|
|
//foreach (Transform child in transform)
|
|
//{
|
|
// children.Add(child);
|
|
//}
|
|
|
|
children.Sort((a, b) =>
|
|
{
|
|
int numberA = int.Parse(a.name);
|
|
int numberB = int.Parse(b.name);
|
|
|
|
return numberA.CompareTo(numberB);
|
|
});
|
|
|
|
for (int i = 0; i < children.Count; i++)
|
|
{
|
|
children[i].SetSiblingIndex(i);
|
|
}
|
|
}
|
|
|
|
|
|
[ContextMenu("匹配U位")]
|
|
public void dsad()
|
|
{
|
|
foreach (var item in Uwei)
|
|
{
|
|
for (int i = 0; i < gameObjects.Count; i++)
|
|
{
|
|
if (item.name == gameObjects[i].name)
|
|
{
|
|
item.SetParent(gameObjects[i].transform);
|
|
item.name = "U位";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[ContextMenu("UI跟随")]
|
|
public void dasda()
|
|
{
|
|
for (int i = 0; i < gameObjects.Count; i++)
|
|
{
|
|
Renderer renderer = null;
|
|
try
|
|
{
|
|
renderer = gameObjects[i].transform.Find(gameObjects[i].name).GetComponent<Renderer>();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
renderer = gameObjects[i].GetComponent<Renderer>();
|
|
}
|
|
if (renderer != null)
|
|
{
|
|
Bounds bounds = renderer.bounds;
|
|
Vector3 topPosition = gameObjects[i].transform.position + new Vector3(0, bounds.size.y, 0);
|
|
UI_follow.GetChild(i).position = topPosition;
|
|
}
|
|
}
|
|
}
|
|
|
|
[ContextMenu("修改机柜")]
|
|
public void dsadsa()
|
|
{
|
|
var objA = gameObjects[0].GetComponent<DeviceQuery>().deviceList;
|
|
|
|
|
|
MapperConfiguration config = new MapperConfiguration(cfg =>
|
|
{
|
|
cfg.CreateMap<RedactDevice.Body, DeviceQuery.DeviceList>();
|
|
cfg.CreateMap<DeviceQuery.DeviceList, RedactDevice.Body>();
|
|
});
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
// 转换 ClassA 到 ClassB
|
|
redactDevice.mybody = mapper.Map<RedactDevice.Body>(objA);
|
|
}
|
|
|
|
[ContextMenu("xg端口碰撞器")]
|
|
public void ssadsa()
|
|
{
|
|
|
|
if (transform.Find("端口碰撞器"))
|
|
{
|
|
|
|
for (int i = 0; i < transform.Find("端口碰撞器").childCount; i++)
|
|
{
|
|
transform.Find("端口碰撞器").GetChild(i).SetParent(transform);
|
|
}
|
|
DestroyImmediate(transform.Find("端口碰撞器").gameObject);
|
|
}
|
|
}
|
|
|
|
[ContextMenu("add告警")]
|
|
public void sadsadsasssssss()
|
|
{
|
|
var a = GetComponentsInChildren<DeviceQuery>();
|
|
Array.ForEach(a, item =>
|
|
{
|
|
if (!item.gameObject.GetComponent<TmsAlarmQuery>())
|
|
item.gameObject.AddComponent<TmsAlarmQuery>();
|
|
});
|
|
}
|
|
|
|
[ContextMenu("add温湿度")]
|
|
public void dasd()
|
|
{
|
|
Array.ForEach(gameObjects.ToArray(), item =>
|
|
{
|
|
if (!item.gameObject.GetComponent<ENVQuery>())
|
|
item.gameObject.AddComponent<ENVQuery>();
|
|
});
|
|
}
|
|
|
|
|
|
public GameObject originalObject; // 模型的原始游戏对象
|
|
|
|
[ContextMenu("根据mesh生成立方体")]
|
|
public void GenerateCubeFromMesh()
|
|
{
|
|
//获取原始对象的Mesh
|
|
Mesh originalMesh = originalObject.GetComponent<MeshFilter>().sharedMesh;
|
|
|
|
//创建一个新的游戏对象和网格
|
|
GameObject cubeObject = new GameObject("Cube");
|
|
|
|
Mesh cubeMesh = new Mesh();
|
|
|
|
//设置立方体的顶点数据
|
|
Vector3[] vertices = new Vector3[originalMesh.vertices.Length];
|
|
for (int i = 0; i < vertices.Length; i++)
|
|
{
|
|
vertices[i] = originalMesh.vertices[i];
|
|
}
|
|
|
|
//创建立方体的三角形面
|
|
int[] triangles = new int[originalMesh.triangles.Length];
|
|
for (int i = 0; i < triangles.Length; i++)
|
|
{
|
|
triangles[i] = originalMesh.triangles[i];
|
|
}
|
|
|
|
//将顶点和三角形面设置到网格中
|
|
cubeMesh.vertices = vertices;
|
|
cubeMesh.triangles = triangles;
|
|
|
|
//设置网格的UV坐标和法线
|
|
cubeMesh.uv = originalMesh.uv;
|
|
cubeMesh.normals = originalMesh.normals;
|
|
|
|
//将网格赋值给立方体对象的MeshFilter组件
|
|
MeshFilter cubeMeshFilter = cubeObject.AddComponent<MeshFilter>();
|
|
cubeMeshFilter.mesh = cubeMesh;
|
|
|
|
//添加立方体对象的MeshRenderer组件并共享材质
|
|
MeshRenderer cubeMeshRenderer = cubeObject.AddComponent<MeshRenderer>();
|
|
cubeMeshRenderer.sharedMaterial = originalObject.GetComponent<MeshRenderer>().sharedMaterial;
|
|
|
|
cubeObject.transform.parent = transform;
|
|
}
|
|
|
|
[ContextMenu("添加高亮立方体")]
|
|
public void addcube()
|
|
{
|
|
|
|
for (int i = 0; i < gameObjects.Count; i++)
|
|
{
|
|
// GameObject cubeObject = GameObject.Instantiate(Resources.Load<GameObject>("高亮"), gameObjects[i].transform);
|
|
|
|
//// cubeObject.transform.parent = gameObjects[i].transform;
|
|
|
|
// cubeObject.transform.transform.localPosition = Vector3.zero;
|
|
// cubeObject.transform.transform.localEulerAngles = Vector3.zero;
|
|
// //cubeObject.transform.transform.localScale = Vector3.one;
|
|
|
|
|
|
var a = gameObjects[i].transform.GetChild(gameObjects[i].transform.childCount - 1);
|
|
a.name = "高亮";
|
|
}
|
|
}
|
|
|
|
[ContextMenu("修改tmp字体")]
|
|
public void srtTMP()
|
|
{
|
|
Array.ForEach(GameObject.FindObjectsOfType<TextMeshProUGUI>(true), (item) =>
|
|
{
|
|
if (item.font == null)
|
|
item.font = f_new;
|
|
});
|
|
}
|
|
|
|
[ContextMenu("修改字体")]
|
|
public void setFont()
|
|
{
|
|
Array.ForEach(GameObject.FindObjectsOfType<Text>(true), (item) =>
|
|
{
|
|
if (item.font == null)
|
|
item.font = font_new;
|
|
});
|
|
}
|
|
|
|
[ContextMenu("端口修改层级")]
|
|
public void setport()
|
|
{
|
|
Array.ForEach(transform.GetComponentsInChildren<PortQuery>(), (item) =>
|
|
{
|
|
item.gameObject.layer = 11;
|
|
});
|
|
}
|
|
|
|
[ContextMenu("add端口高亮")]
|
|
public void addporthight()
|
|
{
|
|
Array.ForEach(transform.GetComponentsInChildren<PortQuery>(), (item) =>
|
|
{
|
|
if (!item.transform.Find("端口高亮"))
|
|
{
|
|
//GameObject go = Instantiate(prefab);
|
|
prefab.transform.SetParent(item.transform);
|
|
prefab.name = "端口高亮";
|
|
}
|
|
});
|
|
}
|
|
|
|
[ContextMenu("加门脚本")]
|
|
public void adddoor()
|
|
{
|
|
var s = Array.FindAll(GameObject.FindObjectsOfType<Transform>(), (itme) =>
|
|
{
|
|
return itme.name == "门把手";
|
|
});
|
|
|
|
for (int i = 0; i < s.Length; i++)
|
|
{
|
|
if (!s[i].Find("Canvas/Image").GetComponent<Door>())
|
|
s[i].Find("Canvas/Image").gameObject.AddComponent<Door>();
|
|
}
|
|
}
|
|
|
|
[ContextMenu("预制体加透明脚本")]
|
|
public void tm()
|
|
{
|
|
Array.ForEach(transform.GetComponentsInChildren<Transform>(), (item) =>
|
|
{
|
|
if (!item.gameObject.GetComponent<TransparentGlow>())
|
|
item.gameObject.AddComponent<TransparentGlow>();
|
|
});
|
|
}
|
|
|
|
|
|
[ContextMenu("板卡预制体加检测器")]
|
|
public void DSA()
|
|
{
|
|
var a = Array.FindAll(transform.GetComponentsInChildren<PortQuery>(), (item) =>
|
|
{
|
|
return true;
|
|
}).ToList();
|
|
|
|
foreach (var item in a)
|
|
{
|
|
Renderer renderer = item.transform.parent.GetComponent<Renderer>();
|
|
if (renderer != null)
|
|
{
|
|
|
|
var initrot = item.transform.parent.transform.rotation;
|
|
item.transform.parent.transform.rotation = Quaternion.Euler(Vector3.zero);
|
|
item.transform.parent.transform.rotation = Quaternion.identity;
|
|
|
|
var bounds = renderer.bounds;
|
|
if (item.transform.parent.gameObject.GetComponent<BoxCollider>())
|
|
{
|
|
if (!item.transform.parent.GetComponent<ClickEvent>())
|
|
{
|
|
item.transform.parent.gameObject.AddComponent<ClickEvent>();
|
|
item.transform.parent.gameObject.layer = 13;
|
|
}
|
|
continue;
|
|
}
|
|
var aa = item.transform.parent.gameObject.AddComponent<BoxCollider>();
|
|
aa.isTrigger = false;
|
|
aa.center = bounds.center - item.transform.parent.transform.position;
|
|
|
|
aa.size = bounds.size;
|
|
|
|
|
|
item.transform.parent.transform.rotation = initrot;
|
|
|
|
}
|
|
if (!item.transform.parent.GetComponent<ClickEvent>())
|
|
{
|
|
item.transform.parent.gameObject.AddComponent<ClickEvent>();
|
|
item.transform.parent.gameObject.layer = 13;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|