309 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			309 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections.Generic;
 | ||
| using System.IO;
 | ||
| using System.Linq;
 | ||
| using Unity.VisualScripting;
 | ||
| using UnityEditor;
 | ||
| using UnityEngine;
 | ||
| 
 | ||
| public class tmptool : MonoBehaviour
 | ||
| {
 | ||
|     public Transform a;
 | ||
|     public Transform b;
 | ||
|     public List<Transform> A;
 | ||
|     public List<Transform> B;
 | ||
|     public List<MeshRenderer> arender = new List<MeshRenderer>();
 | ||
|     public List<MeshRenderer> brender = new List<MeshRenderer>();
 | ||
|     public List<Material> amats = new List<Material>();
 | ||
|     public List<Material> bmats = new List<Material>();
 | ||
| 
 | ||
|     [ContextMenu("GetRenderer")]
 | ||
|     public void GetMat()
 | ||
|     {
 | ||
|         arender.Clear();
 | ||
|         brender.Clear();
 | ||
| 
 | ||
|         var xa = a.GetComponentsInChildren<MeshRenderer>();
 | ||
|         for (int i = 0; i < xa.Length; i++)
 | ||
|         {
 | ||
|             if (xa[i].name.Contains("R"))
 | ||
|             {
 | ||
|                 arender.Add(xa[i]);
 | ||
|             }
 | ||
|         }
 | ||
|         var xb = b.GetComponentsInChildren<MeshRenderer>();
 | ||
|         for (int i = 0; i < xb.Length; i++)
 | ||
|         {
 | ||
|             if (xb[i].name.Contains("R"))
 | ||
|             {
 | ||
|                 brender.Add(xb[i]);
 | ||
|             }
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     [ContextMenu("Compair")]
 | ||
|     public void Compair()
 | ||
|     {
 | ||
|         //for (int i = 0; i < arender.Count; i++)
 | ||
|         //{
 | ||
|         //    if (brender[i].GetComponent<MeshFilter>().mesh.name == arender[i].GetComponent<MeshFilter>().mesh.name)
 | ||
|         //    {
 | ||
| 
 | ||
|         //    }
 | ||
|         //    else
 | ||
|         //    {
 | ||
|         //        Debug.Log("Ãû³Æ²»Æ¥Åä");
 | ||
|         //    }
 | ||
|         //}
 | ||
|     }
 | ||
| 
 | ||
|     [ContextMenu("Replace Materials")]
 | ||
|     public void Replace()
 | ||
|     {
 | ||
|         for (int i = 0; i < arender.Count; i++)
 | ||
|         {
 | ||
|             //brender[i].materials = new Material[arender[i].materials.Length];
 | ||
|             //for (int j = 0; j < brender[i].materials.Length; j++)
 | ||
|             //{
 | ||
|             //    brender[i].CopyComponent
 | ||
|             //}
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(arender[i]);
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(brender[i]);
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     #region Mesh Filter
 | ||
| 
 | ||
|     public List<MeshFilter> ameshFilter = new List<MeshFilter>();
 | ||
| 
 | ||
|     [ContextMenu("»ñÈ¡AMeshFilter×é¼þ")]
 | ||
|     /// <summary>
 | ||
|     /// »ñÈ¡Mesh×é¼þ
 | ||
|     /// </summary>
 | ||
|     void GetAMeshFilter()
 | ||
|     {
 | ||
|         for (int i = 0; i < a.childCount; i++)
 | ||
|         {
 | ||
|             //if (a.GetChild(i).GetComponent<Mesh>())
 | ||
|             //{
 | ||
|             //    ameshs.Add(a.GetChild(i).GetComponent<Mesh>());
 | ||
|             //}
 | ||
|             //else
 | ||
|             //{
 | ||
|             //    ameshs.Add(a.GetChild(i).getc<Mesh>());
 | ||
|             //}
 | ||
|             //ameshs.Add(a.GetChild(i).GetComponentInChildren<MeshFilter>());
 | ||
|             if (a.GetChild(i).GetComponent<MeshFilter>())
 | ||
|                 ameshFilter.Add(a.GetChild(i).GetComponent<MeshFilter>());
 | ||
|         }
 | ||
|         //if (a.childCount == 0)
 | ||
|         ameshFilter.Add(a.GetComponent<MeshFilter>());
 | ||
|     }
 | ||
| 
 | ||
|     public List<MeshFilter> bmeshsFilter = new List<MeshFilter>();
 | ||
| 
 | ||
|     [ContextMenu("»ñÈ¡BMeshFilter×é¼þ")]
 | ||
|     /// <summary>
 | ||
|     /// »ñÈ¡Mesh×é¼þ
 | ||
|     /// </summary>
 | ||
|     void GetBMeshFilter()
 | ||
|     {
 | ||
|         if (false)
 | ||
|         {
 | ||
|             bmeshsFilter.Add(b.GetComponent<MeshFilter>());
 | ||
|             return;
 | ||
|         }
 | ||
|         for (int i = 0; i < b.childCount; i++)
 | ||
|         {
 | ||
|             //if (a.GetChild(i).GetComponent<Mesh>())
 | ||
|             //{
 | ||
|             //    ameshs.Add(a.GetChild(i).GetComponent<Mesh>());
 | ||
|             //}
 | ||
|             //else
 | ||
|             //{
 | ||
|             //    ameshs.Add(a.GetChild(i).getc<Mesh>());
 | ||
|             //}
 | ||
|             //bmeshs.Add(b.GetChild(i).GetComponentInChildren<MeshFilter>());
 | ||
|             if (b.GetChild(i).GetComponent<MeshFilter>())
 | ||
|                 bmeshsFilter.Add(b.GetChild(i).GetComponent<MeshFilter>());
 | ||
|         }
 | ||
|         //if (b.GetChild(0).name == "êµã")
 | ||
|         bmeshsFilter.Add(b.GetComponent<MeshFilter>());
 | ||
|     }
 | ||
| 
 | ||
|     [ContextMenu("Replace BMeshFilter")]
 | ||
|     public void ReplaceABMesh()
 | ||
|     {
 | ||
|         for (int i = 0; i < ameshFilter.Count; i++)
 | ||
|         {
 | ||
|             //brender[i].materials = new Material[arender[i].materials.Length];
 | ||
|             //for (int j = 0; j < brender[i].materials.Length; j++)
 | ||
|             //{
 | ||
|             //    brender[i].CopyComponent
 | ||
|             //}
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(ameshFilter[i]);
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(bmeshsFilter[i]);
 | ||
|         }
 | ||
|     }
 | ||
|     #endregion
 | ||
|     [ContextMenu("-----------------------------------------------------------------")]
 | ||
|     public void asd() { }
 | ||
|     #region Mesh
 | ||
| 
 | ||
|     public List<MeshRenderer> a_meshs = new List<MeshRenderer>();
 | ||
| 
 | ||
|     [ContextMenu("»ñÈ¡AMesh×é¼þ")]
 | ||
|     /// <summary>
 | ||
|     /// »ñÈ¡Mesh×é¼þ
 | ||
|     /// </summary>
 | ||
|     void GetAMesh()
 | ||
|     {
 | ||
|         for (int i = 0; i < a.childCount; i++)
 | ||
|         {
 | ||
| 
 | ||
|             //a_meshs.Add(a.GetChild(i).GetComponentInChildren<MeshRenderer>());
 | ||
| 
 | ||
|             if (a.GetChild(i).GetComponent<MeshRenderer>())
 | ||
|                 a_meshs.Add(a.GetChild(i).GetComponent<MeshRenderer>());
 | ||
|         }
 | ||
|         //if (a.childCount == 0)
 | ||
|         a_meshs.Add(a.GetComponent<MeshRenderer>());
 | ||
|     }
 | ||
| 
 | ||
|     public List<MeshRenderer> b_meshs = new List<MeshRenderer>();
 | ||
| 
 | ||
|     [ContextMenu("»ñÈ¡BMesh×é¼þ")]
 | ||
|     /// <summary>
 | ||
|     /// »ñÈ¡Mesh×é¼þ
 | ||
|     /// </summary>
 | ||
|     void GetBMesh()
 | ||
|     {
 | ||
|         if (false)
 | ||
|         {
 | ||
|             b_meshs.Add(b.GetComponent<MeshRenderer>());
 | ||
|             return;
 | ||
|         }
 | ||
|         for (int i = 0; i < b.childCount; i++)
 | ||
|         {
 | ||
| 
 | ||
|             //b_meshs.Add(b.GetChild(i).GetComponentInChildren<MeshRenderer>());
 | ||
|             if (b.GetChild(i).GetComponent<MeshRenderer>())
 | ||
|                 b_meshs.Add(b.GetChild(i).GetComponent<MeshRenderer>());
 | ||
|         }
 | ||
|         //if (b.GetChild(0).name == "êµã")
 | ||
|         b_meshs.Add(b.GetComponent<MeshRenderer>());
 | ||
|     }
 | ||
| 
 | ||
|     [ContextMenu("Replace BMesh")]
 | ||
|     public void ReplaceA_BMesh()
 | ||
|     {
 | ||
|         for (int i = 0; i < a_meshs.Count; i++)
 | ||
|         {
 | ||
| 
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(a_meshs[i]);
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(b_meshs[i]);
 | ||
|         }
 | ||
|     }
 | ||
|     #endregion
 | ||
| 
 | ||
|     public void change_mat()
 | ||
|     {
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     [ContextMenu("Õ³Ìù5¸ö½Å±¾£¨É豸£©")]
 | ||
|     public void Replace5()
 | ||
|     {
 | ||
|         var b1 = b.AddComponent<DeviceQuery>();
 | ||
|         var b2 = b.AddComponent<DragTest>();
 | ||
|         var b3 = b.AddComponent<TmsAlarmQuery>();
 | ||
|         var b4 = b.AddComponent<TransparentGlow>();
 | ||
|         var b5 = b.AddComponent<DragTest1>();
 | ||
| 
 | ||
|         UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent<DeviceQuery>());
 | ||
|         UnityEditorInternal.ComponentUtility.PasteComponentValues(b1);
 | ||
| 
 | ||
|         UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent<DragTest>());
 | ||
|         UnityEditorInternal.ComponentUtility.PasteComponentValues(b2);
 | ||
| 
 | ||
|         UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent<TmsAlarmQuery>());
 | ||
|         UnityEditorInternal.ComponentUtility.PasteComponentValues(b3);
 | ||
| 
 | ||
|         UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent<TransparentGlow>());
 | ||
|         UnityEditorInternal.ComponentUtility.PasteComponentValues(b4);
 | ||
| 
 | ||
|         UnityEditorInternal.ComponentUtility.CopyComponent(a.GetComponent<DragTest1>());
 | ||
|         UnityEditorInternal.ComponentUtility.PasteComponentValues(b5);
 | ||
| 
 | ||
|         if (!b.GetComponent<MeshCollider>()) b.AddComponent<MeshCollider>();
 | ||
|     }
 | ||
| 
 | ||
|     [ContextMenu("Õ³Ìù4¸ö½Å±¾£¨°å¿¨£©")]
 | ||
|     public void Replace4()
 | ||
|     {
 | ||
|         for (int i = 0; i < A.Count; i++)
 | ||
|         {
 | ||
|             var b1 = B[i].AddComponent<DeviceQuery>();
 | ||
|             //var b2 = B.AddComponent<DragTest>();
 | ||
|             var b3 = B[i].AddComponent<TmsAlarmQuery>();
 | ||
|             var b4 = B[i].AddComponent<TransparentGlow>();
 | ||
|             //var b5 = B.AddComponent<DragTest1>();
 | ||
|             var b6 = B[i].AddComponent<ClickEvent>();
 | ||
| 
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent<DeviceQuery>());
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(b1);
 | ||
| 
 | ||
|             //UnityEditorInternal.ComponentUtility.CopyComponent(A.GetComponent<DragTest>());
 | ||
|             //UnityEditorInternal.ComponentUtility.PasteComponentValues(b2);
 | ||
| 
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent<TmsAlarmQuery>());
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(b3);
 | ||
| 
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent<TransparentGlow>());
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(b4);
 | ||
| 
 | ||
|             //UnityEditorInternal.ComponentUtility.CopyComponent(A.GetComponent<DragTest1>());
 | ||
|             //UnityEditorInternal.ComponentUtility.PasteComponentValues(b5);
 | ||
| 
 | ||
|             UnityEditorInternal.ComponentUtility.CopyComponent(A[i].GetComponent<ClickEvent>());
 | ||
|             UnityEditorInternal.ComponentUtility.PasteComponentValues(b6);
 | ||
| 
 | ||
|             if (!B[i].GetComponent<MeshCollider>()) B[i].AddComponent<MeshCollider>();
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|     [ContextMenu("################################################")]
 | ||
|     //[ContextMenu("»ñȡģÐÍËõÂÔͼ")]
 | ||
|     //public void SaveThumbnail()
 | ||
|     //{
 | ||
|     //}
 | ||
|     [ContextMenu("Ò»¼ü»ñÈ¡Filter¡¢Mesh")]
 | ||
|     public void autoget()
 | ||
|     {
 | ||
| 
 | ||
|         for (int i = 0; i < A.Count; i++)
 | ||
|         {
 | ||
|             a = A[i];
 | ||
|             b = B[i];
 | ||
|             ameshFilter.Clear();
 | ||
|             bmeshsFilter.Clear();
 | ||
|             a_meshs.Clear();
 | ||
|             b_meshs.Clear();
 | ||
| 
 | ||
|             GetAMesh();
 | ||
|             GetBMesh();
 | ||
| 
 | ||
|             GetAMeshFilter();
 | ||
|             GetBMeshFilter();
 | ||
| 
 | ||
|             ReplaceABMesh();
 | ||
|             ReplaceA_BMesh();
 | ||
|         }
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
| }
 |