using UnityEngine; using UnityEditor; using System.Text; using System.Collections.Generic; using Unity.VisualScripting; using System; using System.Linq; # if UNITY_EDITOR_WIN public class ChangePicType2Sprite : EditorWindow { StringBuilder stringBuilder = new StringBuilder(); static float endCloumn; static float endlayor; static string editRow; static string editLayor; static int m_goCount; static int m_missingCount; [MenuItem("Tool/更改排信息")] public static void ShowWindow() { EditorWindow.GetWindow(typeof(ChangePicType2Sprite)); } void OnGUI() { this.maxSize = new Vector2(800,800); // 空格 EditorGUILayout.Space(20); // 样式颜色 GUIStyle style = new GUIStyle(); style.normal.textColor = Color.red; style.fontSize = 20; editRow = EditorGUILayout.TextField("更改排号", editRow); editLayor = EditorGUILayout.TextField("更改层号", editLayor); List d = new List() { GUILayout.Width(160), GUILayout.Height(50) }; if (GUILayout.Button("开始修改",d.ToArray())) { GameObject[] target = Selection.gameObjects; if(target.Length == 1) { GameObject game = target[0]; Transform[] transforms = game.GetComponentsInChildren(); Debug.Log("t =" + transforms.Length); foreach (Transform t in transforms) { Debug.Log(t.name); if (t.name.Contains("-")) { string[] strName = t.name.Split("-"); if (strName.Length == 3) { string nowName = ""; nowName += !string.IsNullOrEmpty(editRow) ? editRow + "-" : strName[0] + "-"; nowName += strName[1] + "-"; nowName += !string.IsNullOrEmpty(editLayor) ? editLayor : strName[2]; t.name = nowName; } } } } else { foreach (GameObject t in target) { if (t.name.Contains("-")) { string[] strName = t.name.Split("-"); string nowName = ""; nowName += !string.IsNullOrEmpty(editRow) ? editRow + "-" : strName[0] + "-"; nowName += strName[1] + "-"; nowName += !string.IsNullOrEmpty(editLayor) ? editLayor : strName[2]; t.name = nowName; } } } } if (GUILayout.Button("clear", d.ToArray())) { GameObject[] target = Selection.gameObjects; foreach (GameObject t in target) { Container container = t.GetComponent(); if (container != null) { Undo.DestroyObjectImmediate(container); } } } } void checkSricpt(Transform transform) { // 获取游戏对象上的所有组件 MonoBehaviour[] components = transform.GetComponents(); // 遍历所有组件 foreach (MonoBehaviour comp in components) { // 检查组件是否已经被销毁 if (comp == null) continue; // 如果组件没有gameObject属性,那么它是无效的 if (comp.gameObject == null) { Debug.LogWarning("无效的脚本: " + comp.GetType().Name, comp); } } } } #endif