Ejemplo n.º 1
0
    public static SceneGoInfo[] CreateSceneGoInfoArray(List <GameObject> prefabGoList, ref List <GameObject> errorGoList)
    {
        SceneGoInfo[] res = new SceneGoInfo[prefabGoList.Count];
        for (int i = 0; i < prefabGoList.Count; i++)
        {
            GameObject  gameObject  = prefabGoList[i];
            GameObject  prefab      = PrefabUtility.GetPrefabParent(gameObject) as GameObject;
            SceneGoInfo sceneGoInfo = new SceneGoInfo();
            res[i]         = sceneGoInfo;
            sceneGoInfo.id = i;
            string abName = GetScenePrefabABName(prefab);
            if (abName == null)
            {
                Debug.LogError(gameObject.name + " Can Not Find abName");
            }
            sceneGoInfo.pos            = gameObject.transform.position;
            sceneGoInfo.rotation       = gameObject.transform.rotation;
            sceneGoInfo.scale          = gameObject.transform.localScale;
            sceneGoInfo.prefabName     = prefab.name;
            sceneGoInfo.gameobjectName = gameObject.transform.name;
            SceneGoInfoComponent sceneGoInfoComponent = gameObject.GetComponent <SceneGoInfoComponent>();

            if (sceneGoInfoComponent.bounds.size != Vector3.zero)
            {
                sceneGoInfo.treeLevel = sceneGoInfoComponent.treeLevel;
                MeshRenderer[]      mrArray = gameObject.GetComponentsInChildren <MeshRenderer>();
                List <MeshRenderer> mrList  = new List <MeshRenderer>();
                mrList.AddRange(mrArray);
                foreach (MeshRenderer _mr in mrList)
                {
                    LightMapDetail lightmapDetail = new LightMapDetail();
                    lightmapDetail.offset         = _mr.lightmapScaleOffset;
                    lightmapDetail.index          = _mr.lightmapIndex;
                    lightmapDetail.gameobjectName = _mr.gameObject.name;
                    sceneGoInfo.lightMapDetailList.Add(lightmapDetail);
                }
                Bounds bounds = GetGameObjectBounds(gameObject);
                sceneGoInfo.bounds = bounds;
            }
            else
            {
                errorGoList.Add(gameObject);
            }
        }
        return(res);
    }
Ejemplo n.º 2
0
    public static void CollectPrefabGo(Transform t, ref List <GameObject> prefabGoList)
    {
        if (!t.gameObject.activeInHierarchy)
        {
            return;
        }
        GameObject prefab = PrefabUtility.GetPrefabParent(t.gameObject) as GameObject;

        if (prefab == null)
        {
            foreach (Transform _t in t)
            {
                CollectPrefabGo(_t, ref prefabGoList);
            }
            return;
        }
        else
        {
            var notUseGoInfo = prefab.GetComponent <SceneGoInfoComponent>();
            if (notUseGoInfo != null)
            {
                var path = AssetDatabase.GetAssetPath(prefab);
                Debug.LogError(string.Format("删除多余的 GoInfo:{0}", path));
                Object.DestroyImmediate(notUseGoInfo, true);
            }
        }
        //{
        //    //转换代码
        //    BoxCollider[] boxColliders = t.GetComponentsInChildren<BoxCollider>();
        //    foreach (var boxCollider in boxColliders)
        //    {
        //        SceneGoInfoComponent sceneGoInfoComponent = boxCollider.gameObject.AddComponent<SceneGoInfoComponent>();
        //        sceneGoInfoComponent.bounds = boxCollider.bounds;
        //        sceneGoInfoComponent.treeLevel = GetLevel(boxCollider.tag);
        //        boxCollider.tag = "Untagged";
        //        Editor.DestroyImmediate(boxCollider);
        //    }
        //    Scene currentScene = EditorSceneManager.GetActiveScene();
        //    EditorSceneManager.MarkSceneDirty(currentScene);
        //}
        if (t.GetComponent <SceneGoInfoComponent>() == null)
        {
            SceneGoInfoComponent sceneGoInfoComponent = t.gameObject.AddComponent <SceneGoInfoComponent>();
            var meshFilters = t.gameObject.GetComponentsInChildren <MeshFilter>();
            if (meshFilters.Length > 0)
            {
                Bounds bounds = CaculateBoundsByMeshFilter(meshFilters[0]);
                foreach (MeshFilter meshFilter in meshFilters)
                {
                    bounds.Encapsulate(CaculateBoundsByMeshFilter(meshFilter));
                }
//                bounds.size += new Vector3(0.5f, 0f, 0.5f);
                sceneGoInfoComponent.bounds.center = bounds.center;
                sceneGoInfoComponent.bounds.size   = bounds.size;
            }
            else
            {
                Debug.LogError("未能计算包围盒大小:" + t.gameObject.name);

                sceneGoInfoComponent.bounds.center = t.position;
            }
        }
        prefabGoList.Add(t.gameObject);
    }