using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Analytics; public class tmptool : MonoBehaviour { public Transform a; public Transform b; public List arender = new List(); public List brender = new List(); public List amats = new List(); public List bmats = new List(); [ContextMenu("GetRenderer")] public void GetMat() { arender.Clear(); brender.Clear(); var xa = a.GetComponentsInChildren(); for (int i = 0; i < xa.Length; i++) { if (xa[i].name.Contains("R")) { arender.Add(xa[i]); } } var xb = b.GetComponentsInChildren(); 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().mesh.name == arender[i].GetComponent().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 ameshs = new List(); //[ContextMenu("获取AMeshFilter组件")] ///// ///// 获取Mesh组件 ///// //void GetAMeshFilter() //{ // for (int i = 0; i < a.childCount; i++) // { // //if (a.GetChild(i).GetComponent()) // //{ // // ameshs.Add(a.GetChild(i).GetComponent()); // //} // //else // //{ // // ameshs.Add(a.GetChild(i).getc()); // //} // ameshs.Add(a.GetChild(i).GetComponentInChildren()); // } //} //public List bmeshs = new List(); //[ContextMenu("获取BMeshFilter组件")] ///// ///// 获取Mesh组件 ///// //void GetBMeshFilter() //{ // for (int i = 0; i < b.childCount; i++) // { // //if (a.GetChild(i).GetComponent()) // //{ // // ameshs.Add(a.GetChild(i).GetComponent()); // //} // //else // //{ // // ameshs.Add(a.GetChild(i).getc()); // //} // bmeshs.Add(b.GetChild(i).GetComponentInChildren()); // } //} //[ContextMenu("Replace BMeshFilter")] //public void ReplaceABMesh() //{ // for (int i = 0; i < ameshs.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(ameshs[i]); // UnityEditorInternal.ComponentUtility.PasteComponentValues(bmeshs[i]); // } //} #endregion #region Mesh public List a_meshs = new List(); [ContextMenu("获取AMesh组件")] /// /// 获取Mesh组件 /// void GetAMesh() { for (int i = 0; i < a.childCount; i++) { //a_meshs.Add(a.GetChild(i).GetComponentInChildren()); if (a.GetChild(i).GetComponent()) a_meshs.Add(a.GetChild(i).GetComponent()); } } public List b_meshs = new List(); [ContextMenu("获取BMesh组件")] /// /// 获取Mesh组件 /// void GetBMesh() { for (int i = 0; i < b.childCount; i++) { //b_meshs.Add(b.GetChild(i).GetComponentInChildren()); if (b.GetChild(i).GetComponent()) b_meshs.Add(b.GetChild(i).GetComponent()); } } [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() { } }