Beispiel #1
0
 /// <summary>
 /// UI显示模型
 /// </summary>
 ///<param name="topStruct"></param>
 private void UIShowGameObject(TargetTreeStruct topStruct)
 {
     EditorGUILayout.BeginHorizontal();
     GUILayout.Space(topStruct.space);
     EditorGUILayout.ObjectField(topStruct.targetTrans.gameObject, typeof(GameObject), true, GUILayout.Width(100));
     EditorGUILayout.Toggle(topStruct.meshRenderer != null, GUILayout.Width(20));
     EditorGUILayout.Toggle(topStruct.collider != null, GUILayout.Width(20));
     EditorGUILayout.EndHorizontal();
     if (topStruct.childs != null && topStruct.childs.Length > 0)
     {
         foreach (TargetTreeStruct childStruct in topStruct.childs)
         {
             UIShowGameObject(childStruct);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 设置显示的结构
 /// </summary>
 /// <param name="objs"></param>
 /// <returns></returns>
 private TargetTreeStruct[] SetShowGameObject(GameObject[] objs, int deep)
 {
     TargetTreeStruct[] results = new TargetTreeStruct[objs.Length];
     for (int i = 0; i < results.Length; i++)
     {
         TargetTreeStruct result = new TargetTreeStruct();
         result.space        = deep * 20;
         result.targetTrans  = objs[i].transform;
         result.meshRenderer = result.targetTrans.GetComponent <MeshRenderer>();
         result.collider     = result.targetTrans.GetComponent <Collider>();
         int          childCount = result.targetTrans.childCount;
         GameObject[] objChilds  = Enumerable.Range(0, childCount).Select(temp => result.targetTrans.GetChild(temp).gameObject).ToArray();
         result.childs = SetShowGameObject(objChilds, deep + 1);
         results[i]    = result;
     }
     return(results);
 }
Beispiel #3
0
 /// <summary>
 /// 添加触发器
 /// </summary>
 /// <param name="topStruct"></param>
 private void AddTrigger(TargetTreeStruct topStruct)
 {
     if (topStruct.meshRenderer != null && topStruct.collider == null)
     {
         bool canSet = true;
         foreach (string removeStr in removeStrs)
         {
             if (topStruct.targetTrans.name.Contains(removeStr))
             {
                 canSet = false;
                 break;
             }
         }
         if (canSet)
         {
             try
             {
                 MeshCollider meshCollider = topStruct.targetTrans.gameObject.AddComponent <MeshCollider>();
                 if (meshCollider != null)
                 {
                     topStruct.collider       = meshCollider;
                     meshCollider.inflateMesh = true;
                     meshCollider.convex      = true;
                     meshCollider.isTrigger   = true;
                 }
             }
             catch { }
         }
     }
     if (topStruct.childs != null && topStruct.childs.Length > 0)
     {
         foreach (TargetTreeStruct childStruct in topStruct.childs)
         {
             AddTrigger(childStruct);
         }
     }
 }