using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class tooltest : MonoBehaviour { public Transform a; public Transform b; public List A; public List B; public int CardCount = 0; void Start() { } // Update is called once per frame void Update() { } [ContextMenu("粘贴5个脚本(设备)")] public void Replace5() { var b1 = b.AddComponent(); var b2 = b.AddComponent(); var b3 = b.AddComponent(); var b4 = b.AddComponent(); var b5 = b.AddComponent(); UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b1); UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b2); UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b3); UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b4); UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b5); if (!b.GetComponent()) b.AddComponent(); b.gameObject.layer = 8; } [ContextMenu("-----------------------------------------------------------------")] [ContextMenu("粘贴4个脚本(板卡)")] public void Replace4() { for (int i = 0; i < A.Count; i++) { var b1 = B[i].AddComponent(); //var b2 = B.AddComponent(); var b3 = B[i].AddComponent(); var b4 = B[i].AddComponent(); //var b5 = B.AddComponent(); var b6 = B[i].AddComponent(); UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b1); //UnityEditorInternal.ComponentUtility.CopyComponent(A.GetComponent()); //UnityEditorInternal.ComponentUtility.PasteComponentValues(b2); UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b3); UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b4); //UnityEditorInternal.ComponentUtility.CopyComponent(A.GetComponent()); //UnityEditorInternal.ComponentUtility.PasteComponentValues(b5); UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b6); if (!B[i].GetComponent()) B[i].AddComponent(); B[i].gameObject.layer = 13; } } [ContextMenu("-----------------------------------------------------------------")] [ContextMenu("粘贴2个脚本(端口)")] public void Replace2() { for (int i = 0; i < A.Count; i++) { PortQuery b1 = B[i].AddComponent(); //var b2= B[i].AddComponent<> UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent()); UnityEditorInternal.ComponentUtility.PasteComponentValues(b1); B[i].position = A[i].position; B[i].gameObject.layer = 11; B[i].GetComponent().portList.portPosition = (i + 1).ToString(); } } [ContextMenu("端口位置排序")] public void Replace2_() { for (int i = 0; i < B.Count; i++) { var b1 = B[i].GetComponent(); b1.portList.portPosition = (i + 1).ToString(); } } [ContextMenu("-----------------------------------------------------------------")] [ContextMenu("创建U位")] public void Replace1() { GameObject emptyObject = new GameObject("U位"); emptyObject.transform.parent = b; emptyObject.transform.localPosition = Vector3.zero; emptyObject.transform.localEulerAngles = Vector3.zero; emptyObject.AddComponent(); for (int i = 0; i < CardCount; i++) { GameObject g = new GameObject(); g.transform.parent = emptyObject.transform; g.transform.localPosition = Vector3.zero; g.transform.localEulerAngles = Vector3.zero; g.name = (i + 1).ToString(); g.AddComponent(); } } }